diff options
| author | Max Horn | 2009-02-20 16:03:50 +0000 | 
|---|---|---|
| committer | Max Horn | 2009-02-20 16:03:50 +0000 | 
| commit | bc360ee5258b44ab2e08adb70d619a230027ee29 (patch) | |
| tree | e0ce556b592e0b780039ab3545cc93305d70a364 /engines/sci/scicore/tools.cpp | |
| parent | e736b7fa625f6155737fdad333d337dd282096a8 (diff) | |
| download | scummvm-rg350-bc360ee5258b44ab2e08adb70d619a230027ee29.tar.gz scummvm-rg350-bc360ee5258b44ab2e08adb70d619a230027ee29.tar.bz2 scummvm-rg350-bc360ee5258b44ab2e08adb70d619a230027ee29.zip | |
SCI: Started rewriting file handling. Warning: This will likely introduce
regressions, but we just have to start somewhere.
- factored out some common code in engine/kfile.cpp into a separate func
- replaced many uses of chdir, getcwd, sci_init_dir etc. by equivalent
   or better functionality from SearchMan etc.
- replaced many uses of sci_open and sci_fopen by using Common::File
   and Common::Stream
- C++ified some stuff
- simplified ResourceSource a bit (loosing some unused functionality)
svn-id: r38597
Diffstat (limited to 'engines/sci/scicore/tools.cpp')
| -rw-r--r-- | engines/sci/scicore/tools.cpp | 84 | 
1 files changed, 22 insertions, 62 deletions
| diff --git a/engines/sci/scicore/tools.cpp b/engines/sci/scicore/tools.cpp index 9b192cbf24..417165af99 100644 --- a/engines/sci/scicore/tools.cpp +++ b/engines/sci/scicore/tools.cpp @@ -24,6 +24,11 @@   */ +#include "common/archive.h" +#include "common/file.h" +#include "common/util.h" + +  #ifdef _MSC_VER  #  include <sys/timeb.h>  #  include <windows.h> @@ -439,90 +444,45 @@ sci_sched_yield() {  **             (sci_dir_t *) dir: Directory to find file within.  ** Returns   : (char *) Case-sensitive filename of the file.  */ -char *_fcaseseek(const char *fname, sci_dir_t *dir) { +Common::String _fcaseseek(const char *fname) {  /* Expects *dir to be uninitialized and the caller to   ** free it afterwards  */ -	Common::String buf; -	char *retval = NULL, *name; - -#ifdef _MSC_VER -	return (char *)fname; -#endif -  	if (strchr(fname, G_DIR_SEPARATOR)) {  		fprintf(stderr, "_fcaseseek() does not support subdirs\n");  		BREAKPOINT();  	} -	sci_init_dir(dir); - -	/* Replace all letters with '?' chars */ -	buf = fname; -	 -	for (Common::String::iterator iterator = buf.begin(); iterator != buf.end(); ++iterator) { -		if (isalpha(*iterator)) -			*iterator = '?'; -	} - -	name = sci_find_first(dir, buf.c_str()); +	// Look up the file, ignoring case +	Common::ArchiveMemberList files; +	SearchMan.listMatchingMembers(files, fname); -	while (name && !retval) { -		if (!scumm_stricmp(fname, name)) -			retval = name; -		else -			name = sci_find_next(dir); +	for (Common::ArchiveMemberList::const_iterator x = files.begin(); x != files.end(); ++x) { +		const Common::String name = (*x)->getName(); +		if (name.equalsIgnoreCase(fname)) +			return name;  	} - -	return retval; +	return Common::String();  } -FILE * -sci_fopen(const char *fname, const char *mode) { -	sci_dir_t dir; -	char *name = _fcaseseek(fname, &dir); +FILE *sci_fopen(const char *fname, const char *mode) { +	Common::String name = _fcaseseek(fname);  	FILE *file = NULL; -	if (name) -		file = fopen(name, mode); +	if (!name.empty()) +		file = fopen(name.c_str(), mode);  	else if (strchr(mode, 'w'))  		file = fopen(fname, mode); -	sci_finish_find(&dir); /* Free memory */ -  	return file;  } -int -sci_open(const char *fname, int flags) { -	sci_dir_t dir; -	char *name; +int sci_open(const char *fname, int flags) {  	int file = SCI_INVALID_FD; -	char *separator_position; -	char *path; -	char *caller_cwd; - -	sci_init_dir(&dir); - -	separator_position = (char *)strrchr(fname, G_DIR_SEPARATOR); -	if (separator_position) { -		path = (char *) malloc(separator_position - fname + 1); -		path[separator_position-fname] = 0; -		strncpy(path, fname, separator_position - fname); -		chdir(path); -		free(path); -	} - -	name = _fcaseseek(separator_position ? separator_position + 1 : fname, &dir); -	if (name) -		file = open(name, flags); - -	sci_finish_find(&dir); /* Free memory */ - -	caller_cwd = sci_getcwd(); -	chdir(caller_cwd); -	free(caller_cwd); +	Common::String name = _fcaseseek(fname); +	if (!name.empty()) +		file = open(name.c_str(), flags);  	return file;  } | 
