[Scummvm-cvs-logs] SF.net SVN: scummvm: [21443] scummvm/trunk/base

sev at users.sourceforge.net sev at users.sourceforge.net
Fri Mar 24 20:18:13 CET 2006


Revision: 21443
Author:   sev
Date:     2006-03-24 20:17:17 -0800 (Fri, 24 Mar 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm/?rev=21443&view=rev

Log Message:
-----------
- Implemented case insensitive file reading. Left old system as a fallback
  in case some engine writer decide to do something unwise
- Removed used of ConfMan.getKey("path") in file-related cases, because
  now File class handles that
- Fixed bug in ScummEngine_v80he::o80_getFileSize() where path delimiters
  weren't translated

Modified Paths:
--------------
    scummvm/trunk/base/main.cpp
    scummvm/trunk/common/file.cpp
    scummvm/trunk/common/file.h
    scummvm/trunk/engines/gob/gob.cpp
    scummvm/trunk/engines/kyra/kyra.cpp
    scummvm/trunk/engines/lure/lure.cpp
    scummvm/trunk/engines/scumm/he/script_v72he.cpp
    scummvm/trunk/engines/scumm/he/script_v80he.cpp
    scummvm/trunk/engines/scumm/plugin.cpp
Modified: scummvm/trunk/base/main.cpp
===================================================================
--- scummvm/trunk/base/main.cpp	2006-03-24 18:33:47 UTC (rev 21442)
+++ scummvm/trunk/base/main.cpp	2006-03-25 04:17:17 UTC (rev 21443)
@@ -276,6 +276,10 @@
 }
 
 static int runGame(GameDetector &detector, OSystem &system, const Common::String &edebuglevels) {
+	// We add it here, so MD5-based detection will be able to
+	// read mixed case files
+	Common::File::addDefaultDirectory(ConfMan.get("path"));
+
 	// Create the game engine
 	Engine *engine = detector.createEngine(&system);
 	if (!engine) {
@@ -301,13 +305,18 @@
 		system.setWindowCaption(caption.c_str());
 	}
 
+	Common::File::addDefaultDirectoryRecursive(ConfMan.get("path"));
+
 	// Add extrapath (if any) to the directory search list
 	if (ConfMan.hasKey("extrapath"))
-		Common::File::addDefaultDirectory(ConfMan.get("extrapath"));
+		Common::File::addDefaultDirectoryRecursive(ConfMan.get("extrapath"));
 
 	if (ConfMan.hasKey("extrapath", Common::ConfigManager::kApplicationDomain))
-		Common::File::addDefaultDirectory(ConfMan.get("extrapath", Common::ConfigManager::kApplicationDomain));
+		Common::File::addDefaultDirectoryRecursive(ConfMan.get("extrapath", Common::ConfigManager::kApplicationDomain));
 
+	// As a last resort add current directory and lock further additions
+	Common::File::addDefaultDirectory(".", true);
+
 	int result;
 
 	// Init the engine (this might change the screen parameters

Modified: scummvm/trunk/common/file.cpp
===================================================================
--- scummvm/trunk/common/file.cpp	2006-03-24 18:33:47 UTC (rev 21442)
+++ scummvm/trunk/common/file.cpp	2006-03-25 04:17:17 UTC (rev 21443)
@@ -22,6 +22,7 @@
 
 #include "common/file.h"
 #include "common/util.h"
+#include "backends/fs/fs.h"
 
 #ifdef MACOSX
 #include "CoreFoundation/CoreFoundation.h"
@@ -30,6 +31,8 @@
 namespace Common {
 
 StringList File::_defaultDirectories;
+File::FilesMap File::_filesMap;
+bool File::_lockedDirectories;
 
 
 static FILE *fopenNoCase(const char *filename, const char *directory, const char *mode) {
@@ -105,16 +108,80 @@
 	return file;
 }
 
-void File::addDefaultDirectory(const String &directory) {
+void File::addDefaultDirectory(const String &directory, bool lockDirectories) {
+	String lfn;
+
+	if (_lockedDirectories)
+		error("addDefaultDirectory is called too late. Move all calls to engine constructor");
+
+	_lockedDirectories = lockDirectories;
+
+	FilesystemNode dir(directory.c_str());
+
+	if (!dir.isDirectory())
+		return;
+
 	_defaultDirectories.push_back(directory);
+
+	FSList fslist(dir.listDir(FilesystemNode::kListFilesOnly));
+	
+	for (FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
+		lfn = file->displayName();
+		lfn.toLowercase();
+		if (!_filesMap.contains(lfn))
+			_filesMap[lfn] = file->path();
+	}
 }
 
+void File::addDefaultDirectoryRecursive(const String &directory, int level, int baseLen) {
+	if (level > 4)
+		return;
+
+	String lfn;
+
+	if (_lockedDirectories)
+		error("addDefaultDirectoryRecursive is called too late. Move all calls to engine constructor");
+
+	FilesystemNode dir(directory.c_str());
+
+	if (!dir.isDirectory())
+		return;
+
+	_defaultDirectories.push_back(directory);
+
+	if (baseLen == 0) {
+		baseLen = directory.size();
+		if (directory.lastChar() != '/'
+#if defined(__MORPHOS__) || defined(__amigaos4__)
+					&& directory.lastChar() != ':'
+#endif
+					&& directory.lastChar() != '\\')
+			baseLen++;
+	}
+
+	FSList fslist(dir.listDir(FilesystemNode::kListAll));
+	
+	for (FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
+		if (file->isDirectory()) {
+			addDefaultDirectoryRecursive(file->path(), level + 1, baseLen);
+		} else {
+			lfn = String(file->path().c_str() + baseLen);
+			lfn.toLowercase();
+			if (!_filesMap.contains(lfn))
+				_filesMap[lfn] = file->path();
+		}
+	}
+}
+
 void File::resetDefaultDirectories() {
 	_defaultDirectories.clear();
+	_filesMap.clear();
+	_lockedDirectories = false;
 }
 
 File::File()
- : _handle(0), _ioFailed(false), _refcount(1) {
+	: _handle(0), _ioFailed(false), _refcount(1) {
+	_lockedDirectories = false;
 }
 
 //#define DEBUG_FILE_REFCOUNT
@@ -155,10 +222,18 @@
 
 	clearIOFailed();
 
+	String fname(filename);
+
+	fname.toLowercase();
+
 	const char *modeStr = (mode == kFileReadMode) ? "rb" : "wb";
 	if (mode == kFileWriteMode || directory) {
 		_handle = fopenNoCase(filename, directory ? directory : "", modeStr);
+	} else if (_filesMap.contains(fname)) {
+		debug(3, "Opening hashed: %s", _filesMap[fname].c_str());
+		_handle = fopen(_filesMap[fname].c_str(), modeStr);
 	} else {
+
 		StringList::const_iterator x;
 		// Try all default directories
 		for (x = _defaultDirectories.begin(); _handle == NULL && x != _defaultDirectories.end(); ++x) {

Modified: scummvm/trunk/common/file.h
===================================================================
--- scummvm/trunk/common/file.h	2006-03-24 18:33:47 UTC (rev 21442)
+++ scummvm/trunk/common/file.h	2006-03-25 04:17:17 UTC (rev 21443)
@@ -27,6 +27,7 @@
 #include "common/scummsys.h"
 #include "common/str.h"
 #include "common/stream.h"
+#include "common/assocarray.h"
 
 namespace Common {
 
@@ -44,8 +45,11 @@
 	/** The name of this file, for debugging. */
 	String _name;
 
+	typedef AssocArray<String, String> FilesMap;
 
 	static StringList _defaultDirectories;
+	static FilesMap _filesMap;
+	static bool _lockedDirectories;
 
 public:
 	enum AccessMode {
@@ -53,7 +57,8 @@
 		kFileWriteMode = 2
 	};
 
-	static void addDefaultDirectory(const String &directory);
+	static void addDefaultDirectory(const String &directory, bool lockDirectories = false);
+	static void addDefaultDirectoryRecursive(const String &directory, int level = 0, int baseLen = 0);
 	static void resetDefaultDirectories();
 
 	File();

Modified: scummvm/trunk/engines/gob/gob.cpp
===================================================================
--- scummvm/trunk/engines/gob/gob.cpp	2006-03-24 18:33:47 UTC (rev 21442)
+++ scummvm/trunk/engines/gob/gob.cpp	2006-03-25 04:17:17 UTC (rev 21443)
@@ -343,7 +343,7 @@
 	uint8 md5sum[16];
 	char md5str[32 + 1];
 
-	if (Common::md5_file("intro.stk", md5sum, ConfMan.get("path").c_str(), kMD5FileSizeLimit)) {
+	if (Common::md5_file("intro.stk", md5sum, NULL, kMD5FileSizeLimit)) {
 		for (int j = 0; j < 16; j++) {
 			sprintf(md5str + j*2, "%02x", (int)md5sum[j]);
 		}

Modified: scummvm/trunk/engines/kyra/kyra.cpp
===================================================================
--- scummvm/trunk/engines/kyra/kyra.cpp	2006-03-24 18:33:47 UTC (rev 21442)
+++ scummvm/trunk/engines/kyra/kyra.cpp	2006-03-25 04:17:17 UTC (rev 21443)
@@ -276,7 +276,7 @@
 		if (!Common::File::exists(g->checkFile))
 			continue;
 
-		if (Common::md5_file(g->checkFile, md5sum, ConfMan.get("path").c_str(), kMD5FileSizeLimit)) {
+		if (Common::md5_file(g->checkFile, md5sum, NULL, kMD5FileSizeLimit)) {
 			for (int j = 0; j < 16; j++) {
 				sprintf(md5str + j*2, "%02x", (int)md5sum[j]);
 			}

Modified: scummvm/trunk/engines/lure/lure.cpp
===================================================================
--- scummvm/trunk/engines/lure/lure.cpp	2006-03-24 18:33:47 UTC (rev 21442)
+++ scummvm/trunk/engines/lure/lure.cpp	2006-03-25 04:17:17 UTC (rev 21443)
@@ -221,7 +221,7 @@
 		if (!Common::File::exists(g->checkFile))
 			continue;
 
-		if (Common::md5_file(g->checkFile, md5sum, ConfMan.get("path").c_str(), kMD5FileSizeLimit)) {
+		if (Common::md5_file(g->checkFile, md5sum, NULL, kMD5FileSizeLimit)) {
 			for (int j = 0; j < 16; j++) {
 				sprintf(md5str + j * 2, "%02x", (int)md5sum[j]);
 			}

Modified: scummvm/trunk/engines/scumm/he/script_v72he.cpp
===================================================================
--- scummvm/trunk/engines/scumm/he/script_v72he.cpp	2006-03-24 18:33:47 UTC (rev 21442)
+++ scummvm/trunk/engines/scumm/he/script_v72he.cpp	2006-03-25 04:17:17 UTC (rev 21443)
@@ -560,7 +560,7 @@
 
 	if (setFilePath) {
 		char filePath[256];
-		sprintf(filePath, "%s%s", _gameDataPath.c_str(), dst + r);
+		sprintf(filePath, "%s", dst + r);
 		if (!Common::File::exists(filePath)) {
 			sprintf(filePath, "%s%s", _saveFileMan->getSavePath(), dst + r);
 		}

Modified: scummvm/trunk/engines/scumm/he/script_v80he.cpp
===================================================================
--- scummvm/trunk/engines/scumm/he/script_v80he.cpp	2006-03-24 18:33:47 UTC (rev 21442)
+++ scummvm/trunk/engines/scumm/he/script_v80he.cpp	2006-03-25 04:17:17 UTC (rev 21443)
@@ -399,9 +399,15 @@
 
 void ScummEngine_v80he::o80_getFileSize() {
 	byte filename[256];
+	uint i;
 
 	copyScriptString(filename, sizeof(filename));
 
+	for (i = 0; i < strlen((const char *)filename); i++) {
+		if (filename[i] == '\\')
+			filename[i] = '/';
+	}
+
 	Common::File f;
 	if (!f.open((char *)filename)) {
 		push(-1);

Modified: scummvm/trunk/engines/scumm/plugin.cpp
===================================================================
--- scummvm/trunk/engines/scumm/plugin.cpp	2006-03-24 18:33:47 UTC (rev 21442)
+++ scummvm/trunk/engines/scumm/plugin.cpp	2006-03-25 04:17:17 UTC (rev 21443)
@@ -1595,7 +1595,7 @@
 			// Instead, use the fs.h code to get a list of all files in that 
 			// directory and simply check whether that filename is contained 
 			// in it. 
-			if (Common::File::exists(detectName, ConfMan.get("path").c_str())) {
+			if (Common::File::exists(detectName)) {
 				found = true;
 				break;
 			}
@@ -1630,7 +1630,7 @@
 	} else {
 		// Compute the MD5 of the file, and (if we succeeded) store a hex version
 		// of it in gameMD5 (useful to print it to the user in messages).
-		if (Common::md5_file(detectName, md5sum, ConfMan.get("path").c_str(), kMD5FileSizeLimit)) {
+		if (Common::md5_file(detectName, md5sum, NULL, kMD5FileSizeLimit)) {
 			for (int j = 0; j < 16; j++) {
 				sprintf(gameMD5 + j*2, "%02x", (int)md5sum[j]);
 			}


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.





More information about the Scummvm-git-logs mailing list