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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Thu Apr 26 22:35:14 CEST 2007


Revision: 26600
          http://scummvm.svn.sourceforge.net/scummvm/?rev=26600&view=rev
Author:   fingolfin
Date:     2007-04-26 13:35:10 -0700 (Thu, 26 Apr 2007)

Log Message:
-----------
Patch #1697907: Small patches for AdvancedDetector

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

Modified: scummvm/trunk/common/advancedDetector.cpp
===================================================================
--- scummvm/trunk/common/advancedDetector.cpp	2007-04-26 20:26:49 UTC (rev 26599)
+++ scummvm/trunk/common/advancedDetector.cpp	2007-04-26 20:35:10 UTC (rev 26600)
@@ -254,7 +254,7 @@
 	IntMap filesSize;
 	IntMap allFiles;
 
-	String tstr, tstr2;
+	String tstr;
 	
 	uint i;
 	char md5str[32+1];
@@ -273,48 +273,50 @@
 		for (fileDesc = g->filesDescriptions; fileDesc->fileName; fileDesc++) {
 			tstr = String(fileDesc->fileName);
 			tstr.toLowercase();
-			tstr2 = tstr + ".";
 			filesList[tstr] = true;
-			filesList[tstr2] = true;
 		}
 	}
-	
+
 	if (fslist != 0) {
+		// Get the information of the existing files
 		for (FSList::const_iterator file = fslist->begin(); file != fslist->end(); ++file) {
 			Common::File f;
 
 			if (file->isDirectory()) continue;
 			tstr = file->name();
 			tstr.toLowercase();
-			tstr2 = tstr + ".";
 
-			allFiles[tstr] = allFiles[tstr2] = 1;
+			// Strip the trailing dot
+			if (tstr.lastChar() == '.')
+				tstr.deleteLastChar();
 
+			allFiles[tstr] = 1;
+
 			debug(3, "+ %s", tstr.c_str());
 
-			if (!filesList.contains(tstr) && !filesList.contains(tstr2)) continue;
+			if (!filesList.contains(tstr)) continue;
 
 			if (!md5_file_string(*file, md5str, params.md5Bytes))
 				continue;
-			filesMD5[tstr] = filesMD5[tstr2] = md5str;
+			filesMD5[tstr] = md5str;
 
 			debug(3, "> %s: %s", tstr.c_str(), md5str);
 
 			if (f.open(file->path())) {
-				filesSize[tstr] = filesSize[tstr2] = (int32)f.size();
+				filesSize[tstr] = (int32)f.size();
 				f.close();
 			}
 		}
 	} else {
+		// Get the information of the requested files
 		File testFile;
 
 		for (StringSet::const_iterator file = filesList.begin(); file != filesList.end(); ++file) {
 			tstr = file->_key;
-			tstr.toLowercase();
 
 			debug(3, "+ %s", tstr.c_str());
 			if (!filesMD5.contains(tstr)) {
-				if (testFile.open(file->_key)) {
+				if (testFile.open(tstr) || testFile.open(tstr + ".")) {
 					filesSize[tstr] = (int32)testFile.size();
 					testFile.close();
 
@@ -330,6 +332,7 @@
 	ADGameDescList matched;
 	int maxFilesMatched = 0;
 
+	// MD5 based matching
 	for (i = 0, descPtr = params.descs; ((const ADGameDescription *)descPtr)->gameid != 0; descPtr += params.descItemSize, ++i) {
 		g = (const ADGameDescription *)descPtr;
 		fileMissing = false;
@@ -341,18 +344,17 @@
 			continue;
 		}
 
-		// Try to open all files for this game
+		// Try to match all files for this game
 		for (fileDesc = g->filesDescriptions; fileDesc->fileName; fileDesc++) {
 			tstr = fileDesc->fileName;
 			tstr.toLowercase();
-			tstr2 = tstr + ".";
 
-			if (!filesMD5.contains(tstr) && !filesMD5.contains(tstr2)) {
+			if (!filesMD5.contains(tstr)) {
 				fileMissing = true;
 				break;
 			}
 			if (fileDesc->md5 != NULL) {
-				if (strcmp(fileDesc->md5, filesMD5[tstr].c_str()) && strcmp(fileDesc->md5, filesMD5[tstr2].c_str())) {
+				if (strcmp(fileDesc->md5, filesMD5[tstr].c_str())) {
 					debug(3, "MD5 Mismatch. Skipping (%s) (%s)", fileDesc->md5, filesMD5[tstr].c_str());
 					fileMissing = true;
 					break;
@@ -360,7 +362,7 @@
 			}
 
 			if (fileDesc->fileSize != -1) {
-				if (fileDesc->fileSize != filesSize[tstr] && fileDesc->fileSize != filesSize[tstr2]) {
+				if (fileDesc->fileSize != filesSize[tstr]) {
 					debug(3, "Size Mismatch. Skipping");
 					fileMissing = true;
 					break;
@@ -378,7 +380,7 @@
 			int curFilesMatched = 0;
 			for (fileDesc = g->filesDescriptions; fileDesc->fileName; fileDesc++)
 				curFilesMatched++;
-			
+
 			if (curFilesMatched > maxFilesMatched) {
 				debug(2, " ... new best match, removing all previous candidates");
 				maxFilesMatched = curFilesMatched;
@@ -416,26 +418,25 @@
 		printf("\n");
 	}
 
+	// Filename based fallback
 	if (params.fileBasedFallback != 0) {
 		const ADFileBasedFallback *ptr = params.fileBasedFallback;
 		const char* const* filenames = 0;
 
 		// First we create list of files required for detection.
-		if (allFiles.empty()) {
-			File testFile;
+		// The filenames can be different than the MD5 based match ones.
+		File testFile;
 
-			for (; ptr->desc; ptr++) {
-				filenames = ptr->filenames;
-				for (; *filenames; filenames++) {
-					tstr = String(*filenames);
-					tstr.toLowercase();
+		for (; ptr->desc; ptr++) {
+			filenames = ptr->filenames;
+			for (; *filenames; filenames++) {
+				tstr = String(*filenames);
+				tstr.toLowercase();
 
-					if (!allFiles.contains(tstr)) {
-						if (testFile.open(tstr)) {
-							tstr2 = tstr + ".";
-							allFiles[tstr] = allFiles[tstr2] = 1;
-							testFile.close();
-						}
+				if (!allFiles.contains(tstr)) {
+					if (testFile.open(tstr) || testFile.open(tstr + ".")) {
+						allFiles[tstr] = 1;
+						testFile.close();
 					}
 				}
 			}
@@ -461,12 +462,10 @@
 				}
 
 				tstr = String(*filenames);
-
 				tstr.toLowercase();
-				tstr2 = tstr + ".";
 
 				debug(3, "++ %s", *filenames);
-				if (!allFiles.contains(tstr) && !allFiles.contains(tstr2)) {
+				if (!allFiles.contains(tstr)) {
 					fileMissing = true;
 					continue;
 				}


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