aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMax Horn2007-04-26 20:35:10 +0000
committerMax Horn2007-04-26 20:35:10 +0000
commit02fd340b8ca0d1d7509e9a4b0c9298a65ca2bef9 (patch)
tree82c6869effe3ef8a9652577fd97cd96a0de0efbd /common
parente9f8035b53797c6c58c0597041b94aa737a06857 (diff)
downloadscummvm-rg350-02fd340b8ca0d1d7509e9a4b0c9298a65ca2bef9.tar.gz
scummvm-rg350-02fd340b8ca0d1d7509e9a4b0c9298a65ca2bef9.tar.bz2
scummvm-rg350-02fd340b8ca0d1d7509e9a4b0c9298a65ca2bef9.zip
Patch #1697907: Small patches for AdvancedDetector
svn-id: r26600
Diffstat (limited to 'common')
-rw-r--r--common/advancedDetector.cpp69
1 files changed, 34 insertions, 35 deletions
diff --git a/common/advancedDetector.cpp b/common/advancedDetector.cpp
index 401284e4e3..6263ba8768 100644
--- a/common/advancedDetector.cpp
+++ b/common/advancedDetector.cpp
@@ -254,7 +254,7 @@ static ADGameDescList detectGame(const FSList *fslist, const Common::ADParams &p
IntMap filesSize;
IntMap allFiles;
- String tstr, tstr2;
+ String tstr;
uint i;
char md5str[32+1];
@@ -273,48 +273,50 @@ static ADGameDescList detectGame(const FSList *fslist, const Common::ADParams &p
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 @@ static ADGameDescList detectGame(const FSList *fslist, const Common::ADParams &p
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 @@ static ADGameDescList detectGame(const FSList *fslist, const Common::ADParams &p
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 @@ static ADGameDescList detectGame(const FSList *fslist, const Common::ADParams &p
}
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 @@ static ADGameDescList detectGame(const FSList *fslist, const Common::ADParams &p
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 @@ static ADGameDescList detectGame(const FSList *fslist, const Common::ADParams &p
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;
-
- 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();
- }
+ // 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();
+
+ if (!allFiles.contains(tstr)) {
+ if (testFile.open(tstr) || testFile.open(tstr + ".")) {
+ allFiles[tstr] = 1;
+ testFile.close();
}
}
}
@@ -461,12 +462,10 @@ static ADGameDescList detectGame(const FSList *fslist, const Common::ADParams &p
}
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;
}