[Scummvm-cvs-logs] SF.net SVN: scummvm:[43613] scummvm/trunk/engines/sci/detection.cpp

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Sat Aug 22 00:25:55 CEST 2009


Revision: 43613
          http://scummvm.svn.sourceforge.net/scummvm/?rev=43613&view=rev
Author:   lordhoto
Date:     2009-08-21 22:25:55 +0000 (Fri, 21 Aug 2009)

Log Message:
-----------
Fix use of default directories in SCI detection code. So far all our detection code was based on FSNode, but since SCI seems to call engine internal code for detection which operates via File, there was the need to use File::addDefaultDirectory to have it working. The problem here is that the default directories are not reset after game detection, since the caller code assumes it's all done via FSNode. A simple change to use SearchMan, which is used internally by File, to add the default directory and removing it later on in the SCI detection code fixed the issue. Of course that is still slightly of a HACK, but it is much nicer than to rewrite engine internal code to use FSNode, just to be usable for game detection. I added a possible solution to remove the HACK as sourcecode comment.

Modified Paths:
--------------
    scummvm/trunk/engines/sci/detection.cpp

Modified: scummvm/trunk/engines/sci/detection.cpp
===================================================================
--- scummvm/trunk/engines/sci/detection.cpp	2009-08-21 20:50:57 UTC (rev 43612)
+++ scummvm/trunk/engines/sci/detection.cpp	2009-08-21 22:25:55 UTC (rev 43613)
@@ -3130,11 +3130,17 @@
 		if (filename.contains("resource.map") || filename.contains("resmap.000")) {
 			// HACK: resource.map is located in the same directory as the other resource files,
 			// therefore add the directory here, so that the game files can be opened later on
-			// TODO/FIXME: This should be removed, as it will cause problems with game detection:
-			// if we got a game A, and then try to detect another game B, adding a default
-			// directory here means that game A's files will be opened first. We need to rewrite
-			// all the functions that access game files to use FSNodes instead
-			Common::File::addDefaultDirectory(file->getParent().getPath());
+			// We now add the parent directory temporary to our SearchMan so the engine code
+			// used in the detection can access all files via Common::File without any problems.
+			// In all branches returning from this function, we need to have a call to
+			// SearchMan.remove to remove it from the default directory pool again.
+			//
+			// A proper solution to remove this hack would be to have the code, which is needed
+			// for detection, to operate on Stream objects, so they can be easily called from
+			// the detection code. This might be easily to achieve through refactoring the
+			// code needed for detection.
+			assert(!SearchMan.hasArchive("SCI_detection"));
+			SearchMan.addDirectory("SCI_detection", file->getParent());
 			foundResMap = true;
 		}
 
@@ -3165,8 +3171,10 @@
 	}
 
 	// If these files aren't found, it can't be SCI
-	if (!foundResMap && !foundRes000)
+	if (!foundResMap && !foundRes000) {
+		SearchMan.remove("SCI_detection");
 		return 0;
+	}
 
 	// Set some defaults
 	s_fallbackDesc.desc.extra = "";
@@ -3184,6 +3192,7 @@
 	SegManager *segManager = new SegManager(resMgr, version, hasOldScriptHeader);
 	if (!script_instantiate(resMgr, segManager, version, hasOldScriptHeader, 0)) {
 		warning("fallbackDetect(): Could not instantiate script 0");
+		SearchMan.remove("SCI_detection");
 		return 0;
 	}
 	reg_t game_obj = script_lookup_export(segManager, 0, 0);
@@ -3199,6 +3208,8 @@
 	printf("version number, from the game's executable:\n");
 	printf("Version: %s\n\n", exeVersionString.empty() ? "not found" : exeVersionString.c_str());
 
+	SearchMan.remove("SCI_detection");
+
 	return (const ADGameDescription *)&s_fallbackDesc;
 }
 


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