[Scummvm-cvs-logs] SF.net SVN: scummvm:[33388] scummvm/trunk/common/advancedDetector.cpp

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Tue Jul 29 02:50:12 CEST 2008


Revision: 33388
          http://scummvm.svn.sourceforge.net/scummvm/?rev=33388&view=rev
Author:   fingolfin
Date:     2008-07-29 00:50:12 +0000 (Tue, 29 Jul 2008)

Log Message:
-----------
Changed advanced detector to *always* use the FSNode API for detection (i.e. killed second code path which used File::open trial&error directory 'scanning')

Modified Paths:
--------------
    scummvm/trunk/common/advancedDetector.cpp

Modified: scummvm/trunk/common/advancedDetector.cpp
===================================================================
--- scummvm/trunk/common/advancedDetector.cpp	2008-07-29 00:49:44 UTC (rev 33387)
+++ scummvm/trunk/common/advancedDetector.cpp	2008-07-29 00:50:12 UTC (rev 33388)
@@ -48,7 +48,7 @@
  * @param platform	restrict results to specified platform only
  * @return	list of ADGameDescription (or subclass) pointers corresponding to matched games
  */
-static ADGameDescList detectGame(const FSList *fslist, const Common::ADParams &params, Language language, Platform platform, const Common::String extra);
+static ADGameDescList detectGame(const FSList &fslist, const Common::ADParams &params, Language language, Platform platform, const Common::String extra);
 
 
 /**
@@ -194,7 +194,7 @@
 }
 
 GameList AdvancedMetaEngine::detectGames(const FSList &fslist) const {
-	ADGameDescList matches = detectGame(&fslist, params, Common::UNK_LANG, Common::kPlatformUnknown, "");
+	ADGameDescList matches = detectGame(fslist, params, Common::UNK_LANG, Common::kPlatformUnknown, "");
 	GameList detectedGames;
 
 	// Use fallback detector if there were no matches by other means
@@ -233,8 +233,22 @@
 
 	Common::String gameid = ConfMan.get("gameid");
 
-	ADGameDescList matches = detectGame(0, params, language, platform, extra);
+	Common::String path;
+	if (ConfMan.hasKey("path")) {
+		path = ConfMan.get("path");
+	} else {
+		path = ".";
+		warning("No path was provided. Assuming the data files are in the current directory");
+	}
+	FilesystemNode dir(path);
+	FSList files;
+	if (!dir.isDirectory() || !dir.getChildren(files, FilesystemNode::kListAll)) {
+		warning("Game data path does not exist or is not a directory (%s)", path.c_str());
+		return kNoGameDataFoundError;
+	}
 
+	ADGameDescList matches = detectGame(files, params, language, platform, extra);
+
 	if (params.singleid == NULL) {
 		for (uint i = 0; i < matches.size(); i++) {
 			if (matches[i]->gameid == gameid) {
@@ -287,7 +301,7 @@
 	printf("\n");
 }
 
-static ADGameDescList detectGame(const FSList *fslist, const Common::ADParams &params, Language language, Platform platform, const Common::String extra) {
+static ADGameDescList detectGame(const FSList &fslist, const Common::ADParams &params, Language language, Platform platform, const Common::String extra) {
 	StringSet filesList;
 
 	StringMap filesMD5;
@@ -319,57 +333,35 @@
 		}
 	}
 
-	// TODO/FIXME: Fingolfin says: It's not good that we have two different code paths here,
-	// one using a FSList, one using File::open, as that will lead to discrepancies and subtle
-	// problems caused by those.
-	if (fslist != 0) {
-		// Get the information of the existing files
-		for (FSList::const_iterator file = fslist->begin(); file != fslist->end(); ++file) {
-			if (file->isDirectory()) continue;
-			tstr = file->getName();
-			tstr.toLowercase();
+	// Get the information of the existing files
+	for (FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
+		if (file->isDirectory()) continue;
+		tstr = file->getName();
+		tstr.toLowercase();
 
-			// Strip any trailing dot
-			if (tstr.lastChar() == '.')
-				tstr.deleteLastChar();
+		// Strip any trailing dot
+		if (tstr.lastChar() == '.')
+			tstr.deleteLastChar();
 
-			allFiles[tstr] = true;
+		allFiles[tstr] = true;
 
-			debug(3, "+ %s", tstr.c_str());
+		debug(3, "+ %s", tstr.c_str());
 
-			if (!filesList.contains(tstr)) continue;
+		if (!filesList.contains(tstr)) continue;
 
-			if (!md5_file_string(*file, md5str, params.md5Bytes))
-				continue;
-			filesMD5[tstr] = md5str;
+		if (!md5_file_string(*file, md5str, params.md5Bytes))
+			continue;
+		filesMD5[tstr] = md5str;
 
-			debug(3, "> %s: %s", tstr.c_str(), md5str);
+		debug(3, "> %s: %s", tstr.c_str(), md5str);
 
-			if (testFile.open(file->getPath())) {
-				filesSize[tstr] = (int32)testFile.size();
-				testFile.close();
-			}
+		if (testFile.open(file->getPath())) {
+			filesSize[tstr] = (int32)testFile.size();
+			testFile.close();
 		}
-	} else {
-		// Get the information of the requested files
-		for (StringSet::const_iterator file = filesList.begin(); file != filesList.end(); ++file) {
-			tstr = file->_key;
-
-			debug(3, "+ %s", tstr.c_str());
-			if (!filesMD5.contains(tstr)) {
-				if (testFile.open(tstr) || testFile.open(tstr + ".")) {
-					filesSize[tstr] = (int32)testFile.size();
-					testFile.close();
-
-					if (md5_file_string(file->_key.c_str(), md5str, params.md5Bytes)) {
-						filesMD5[tstr] = md5str;
-						debug(3, "> %s: %s", tstr.c_str(), md5str);
-					}
-				}
-			}
-		}
 	}
 
+
 	ADGameDescList matched;
 	int maxFilesMatched = 0;
 


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