From 76915424962c1288cbd8859bf1a4d401f2769cbd Mon Sep 17 00:00:00 2001 From: Sven Hesse Date: Wed, 27 Jun 2012 04:05:12 +0200 Subject: DETECTOR: Rename SizeMD5(Map) to ADFileProperties(Map) --- engines/advancedDetector.cpp | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/engines/advancedDetector.cpp b/engines/advancedDetector.cpp index ac06e74e0a..272032d66a 100644 --- a/engines/advancedDetector.cpp +++ b/engines/advancedDetector.cpp @@ -308,14 +308,21 @@ Common::Error AdvancedMetaEngine::createInstance(OSystem *syst, Engine **engine) return Common::kNoError; } -struct SizeMD5 { - int size; +/** + * A record describing the properties of a file. Used on the existing + * files while detecting a game. + */ +struct ADFileProperties { + int32 size; Common::String md5; }; -typedef Common::HashMap SizeMD5Map; +/** + * A map of all relevant existing files in a game directory while detecting. + */ +typedef Common::HashMap ADFilePropertiesMap; -static void reportUnknown(const Common::FSNode &path, const SizeMD5Map &filesSizeMD5) { +static void reportUnknown(const Common::FSNode &path, const ADFilePropertiesMap &filesProps) { // TODO: This message should be cleaned up / made more specific. // For example, we should specify at least which engine triggered this. // @@ -327,7 +334,7 @@ static void reportUnknown(const Common::FSNode &path, const SizeMD5Map &filesSiz report += _("of the game you tried to add and its version/language/etc.:"); report += "\n"; - for (SizeMD5Map::const_iterator file = filesSizeMD5.begin(); file != filesSizeMD5.end(); ++file) + for (ADFilePropertiesMap::const_iterator file = filesProps.begin(); file != filesProps.end(); ++file) report += Common::String::format(" {\"%s\", 0, \"%s\", %d},\n", file->_key.c_str(), file->_value.md5.c_str(), file->_value.size); report += "\n"; @@ -376,7 +383,7 @@ void AdvancedMetaEngine::composeFileHashMap(FileMap &allFiles, const Common::FSL } ADGameDescList AdvancedMetaEngine::detectGame(const Common::FSNode &parent, const FileMap &allFiles, Common::Language language, Common::Platform platform, const Common::String &extra) const { - SizeMD5Map filesSizeMD5; + ADFilePropertiesMap filesProps; const ADGameFileDescription *fileDesc; const ADGameDescription *g; @@ -391,9 +398,9 @@ ADGameDescList AdvancedMetaEngine::detectGame(const Common::FSNode &parent, cons for (fileDesc = g->filesDescriptions; fileDesc->fileName; fileDesc++) { Common::String fname = fileDesc->fileName; - SizeMD5 tmp; + ADFileProperties tmp; - if (filesSizeMD5.contains(fname)) + if (filesProps.contains(fname)) continue; // FIXME/TODO: We don't handle the case that a file is listed as a regular @@ -406,7 +413,7 @@ ADGameDescList AdvancedMetaEngine::detectGame(const Common::FSNode &parent, cons tmp.md5 = macResMan.computeResForkMD5AsString(_md5Bytes); tmp.size = macResMan.getResForkDataSize(); debug(3, "> '%s': '%s'", fname.c_str(), tmp.md5.c_str()); - filesSizeMD5[fname] = tmp; + filesProps[fname] = tmp; } } else { if (allFiles.contains(fname)) { @@ -422,7 +429,7 @@ ADGameDescList AdvancedMetaEngine::detectGame(const Common::FSNode &parent, cons } debug(3, "> '%s': '%s'", fname.c_str(), tmp.md5.c_str()); - filesSizeMD5[fname] = tmp; + filesProps[fname] = tmp; } } } @@ -456,19 +463,19 @@ ADGameDescList AdvancedMetaEngine::detectGame(const Common::FSNode &parent, cons for (fileDesc = g->filesDescriptions; fileDesc->fileName; fileDesc++) { Common::String tstr = fileDesc->fileName; - if (!filesSizeMD5.contains(tstr)) { + if (!filesProps.contains(tstr)) { fileMissing = true; allFilesPresent = false; break; } - if (fileDesc->md5 != NULL && fileDesc->md5 != filesSizeMD5[tstr].md5) { - debug(3, "MD5 Mismatch. Skipping (%s) (%s)", fileDesc->md5, filesSizeMD5[tstr].md5.c_str()); + if (fileDesc->md5 != NULL && fileDesc->md5 != filesProps[tstr].md5) { + debug(3, "MD5 Mismatch. Skipping (%s) (%s)", fileDesc->md5, filesProps[tstr].md5.c_str()); fileMissing = true; break; } - if (fileDesc->fileSize != -1 && fileDesc->fileSize != filesSizeMD5[tstr].size) { + if (fileDesc->fileSize != -1 && fileDesc->fileSize != filesProps[tstr].size) { debug(3, "Size Mismatch. Skipping"); fileMissing = true; break; @@ -514,8 +521,8 @@ ADGameDescList AdvancedMetaEngine::detectGame(const Common::FSNode &parent, cons // We didn't find a match if (matched.empty()) { - if (!filesSizeMD5.empty() && gotAnyMatchesWithAllFiles) { - reportUnknown(parent, filesSizeMD5); + if (!filesProps.empty() && gotAnyMatchesWithAllFiles) { + reportUnknown(parent, filesProps); } // Filename based fallback -- cgit v1.2.3 From 5ca480aa2e5ffdb0e8fc753aff06e676358dfcfc Mon Sep 17 00:00:00 2001 From: Sven Hesse Date: Wed, 27 Jun 2012 04:07:32 +0200 Subject: DETECTOR: Move ADFileProperties(Map) into advancedDetector.h --- engines/advancedDetector.cpp | 15 --------------- engines/advancedDetector.h | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/engines/advancedDetector.cpp b/engines/advancedDetector.cpp index 272032d66a..248b8cc432 100644 --- a/engines/advancedDetector.cpp +++ b/engines/advancedDetector.cpp @@ -22,7 +22,6 @@ #include "common/debug.h" #include "common/util.h" -#include "common/hash-str.h" #include "common/file.h" #include "common/macresman.h" #include "common/md5.h" @@ -308,20 +307,6 @@ Common::Error AdvancedMetaEngine::createInstance(OSystem *syst, Engine **engine) return Common::kNoError; } -/** - * A record describing the properties of a file. Used on the existing - * files while detecting a game. - */ -struct ADFileProperties { - int32 size; - Common::String md5; -}; - -/** - * A map of all relevant existing files in a game directory while detecting. - */ -typedef Common::HashMap ADFilePropertiesMap; - static void reportUnknown(const Common::FSNode &path, const ADFilePropertiesMap &filesProps) { // TODO: This message should be cleaned up / made more specific. // For example, we should specify at least which engine triggered this. diff --git a/engines/advancedDetector.h b/engines/advancedDetector.h index 45a9f183e8..0c3f53f0c5 100644 --- a/engines/advancedDetector.h +++ b/engines/advancedDetector.h @@ -26,6 +26,8 @@ #include "engines/metaengine.h" #include "engines/engine.h" +#include "common/hash-str.h" + #include "common/gui_options.h" // FIXME: Temporary hack? namespace Common { @@ -45,6 +47,20 @@ struct ADGameFileDescription { int32 fileSize; ///< Size of the described file. Set to -1 to ignore. }; +/** + * A record describing the properties of a file. Used on the existing + * files while detecting a game. + */ +struct ADFileProperties { + int32 size; + Common::String md5; +}; + +/** + * A map of all relevant existing files in a game directory while detecting. + */ +typedef Common::HashMap ADFilePropertiesMap; + /** * A shortcut to produce an empty ADGameFileDescription record. Used to mark * the end of a list of these. -- cgit v1.2.3 From 63e13c5d2c48c0a9aba72a0f63dc4aa515972da5 Mon Sep 17 00:00:00 2001 From: Sven Hesse Date: Wed, 27 Jun 2012 04:25:38 +0200 Subject: DETECTOR: Move size reading and MD5 creating into a new method getFileProperties() --- engines/advancedDetector.cpp | 59 +++++++++++++++++++++++--------------------- engines/advancedDetector.h | 3 +++ 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/engines/advancedDetector.cpp b/engines/advancedDetector.cpp index 248b8cc432..af011bee4d 100644 --- a/engines/advancedDetector.cpp +++ b/engines/advancedDetector.cpp @@ -367,6 +367,34 @@ void AdvancedMetaEngine::composeFileHashMap(FileMap &allFiles, const Common::FSL } } +bool AdvancedMetaEngine::getFileProperties(const Common::FSNode &parent, const FileMap &allFiles, const ADGameDescription &game, const Common::String fname, ADFileProperties &fileProps) const { + // FIXME/TODO: We don't handle the case that a file is listed as a regular + // file and as one with resource fork. + + if (game.flags & ADGF_MACRESFORK) { + Common::MacResManager macResMan; + + if (!macResMan.open(parent, fname)) + return false; + + fileProps.md5 = macResMan.computeResForkMD5AsString(_md5Bytes); + fileProps.size = macResMan.getResForkDataSize(); + return true; + } + + if (!allFiles.contains(fname)) + return false; + + Common::File testFile; + + if (!testFile.open(allFiles[fname])) + return false; + + fileProps.size = (int32)testFile.size(); + fileProps.md5 = Common::computeStreamMD5AsString(testFile, _md5Bytes); + return true; +} + ADGameDescList AdvancedMetaEngine::detectGame(const Common::FSNode &parent, const FileMap &allFiles, Common::Language language, Common::Platform platform, const Common::String &extra) const { ADFilePropertiesMap filesProps; @@ -388,34 +416,9 @@ ADGameDescList AdvancedMetaEngine::detectGame(const Common::FSNode &parent, cons if (filesProps.contains(fname)) continue; - // FIXME/TODO: We don't handle the case that a file is listed as a regular - // file and as one with resource fork. - - if (g->flags & ADGF_MACRESFORK) { - Common::MacResManager macResMan; - - if (macResMan.open(parent, fname)) { - tmp.md5 = macResMan.computeResForkMD5AsString(_md5Bytes); - tmp.size = macResMan.getResForkDataSize(); - debug(3, "> '%s': '%s'", fname.c_str(), tmp.md5.c_str()); - filesProps[fname] = tmp; - } - } else { - if (allFiles.contains(fname)) { - debug(3, "+ %s", fname.c_str()); - - Common::File testFile; - - if (testFile.open(allFiles[fname])) { - tmp.size = (int32)testFile.size(); - tmp.md5 = Common::computeStreamMD5AsString(testFile, _md5Bytes); - } else { - tmp.size = -1; - } - - debug(3, "> '%s': '%s'", fname.c_str(), tmp.md5.c_str()); - filesProps[fname] = tmp; - } + if (getFileProperties(parent, allFiles, *g, fname, tmp)) { + debug(3, "> '%s': '%s'", fname.c_str(), tmp.md5.c_str()); + filesProps[fname] = tmp; } } } diff --git a/engines/advancedDetector.h b/engines/advancedDetector.h index 0c3f53f0c5..91cb54c396 100644 --- a/engines/advancedDetector.h +++ b/engines/advancedDetector.h @@ -314,6 +314,9 @@ protected: * Includes nifty stuff like removing trailing dots and ignoring case. */ void composeFileHashMap(FileMap &allFiles, const Common::FSList &fslist, int depth) const; + + /** Get the properties (size and MD5) of this file. */ + bool getFileProperties(const Common::FSNode &parent, const FileMap &allFiles, const ADGameDescription &game, const Common::String fname, ADFileProperties &fileProps) const; }; #endif -- cgit v1.2.3 From 2c760cb15e27de29ef9262cb6e2a102d8dbe3935 Mon Sep 17 00:00:00 2001 From: Sven Hesse Date: Wed, 27 Jun 2012 04:42:36 +0200 Subject: DETECTOR: Make detectGameFilebased() return a list of MD5s and file sizes Since we need a FSNode parent for Mac resource forks, we need to change signature of detectGameFilebased(), too. --- engines/advancedDetector.cpp | 12 +++++++++++- engines/advancedDetector.h | 4 +++- engines/cge/detection.cpp | 2 +- engines/gob/detection/detection.cpp | 2 +- engines/mohawk/detection.cpp | 2 +- engines/toon/detection.cpp | 2 +- engines/touche/detection.cpp | 2 +- 7 files changed, 19 insertions(+), 7 deletions(-) diff --git a/engines/advancedDetector.cpp b/engines/advancedDetector.cpp index af011bee4d..727134fad8 100644 --- a/engines/advancedDetector.cpp +++ b/engines/advancedDetector.cpp @@ -519,7 +519,7 @@ ADGameDescList AdvancedMetaEngine::detectGame(const Common::FSNode &parent, cons return matched; } -const ADGameDescription *AdvancedMetaEngine::detectGameFilebased(const FileMap &allFiles, const ADFileBasedFallback *fileBasedFallback) const { +const ADGameDescription *AdvancedMetaEngine::detectGameFilebased(const FileMap &allFiles, const Common::FSList &fslist, const ADFileBasedFallback *fileBasedFallback, ADFilePropertiesMap *filesProps) const { const ADFileBasedFallback *ptr; const char* const* filenames; @@ -549,6 +549,16 @@ const ADGameDescription *AdvancedMetaEngine::detectGameFilebased(const FileMap & maxNumMatchedFiles = numMatchedFiles; debug(4, "and overridden"); + + if (filesProps) { + for (filenames = ptr->filenames; *filenames; ++filenames) { + ADFileProperties tmp; + + if (getFileProperties(fslist.begin()->getParent(), allFiles, *agdesc, *filenames, tmp)) + (*filesProps)[*filenames] = tmp; + } + } + } } } diff --git a/engines/advancedDetector.h b/engines/advancedDetector.h index 91cb54c396..3e18a6aa18 100644 --- a/engines/advancedDetector.h +++ b/engines/advancedDetector.h @@ -302,9 +302,11 @@ protected: * In case of a tie, the entry coming first in the list is chosen. * * @param allFiles a map describing all present files + * @param fslist a list of nodes for all present files * @param fileBasedFallback a list of ADFileBasedFallback records, zero-terminated + * @param filesProps if not 0, return a map of properties for all detected files here */ - const ADGameDescription *detectGameFilebased(const FileMap &allFiles, const ADFileBasedFallback *fileBasedFallback) const; + const ADGameDescription *detectGameFilebased(const FileMap &allFiles, const Common::FSList &fslist, const ADFileBasedFallback *fileBasedFallback, ADFilePropertiesMap *filesProps = 0) const; // TODO void updateGameDescriptor(GameDescriptor &desc, const ADGameDescription *realDesc) const; diff --git a/engines/cge/detection.cpp b/engines/cge/detection.cpp index f723ec8fbd..eda4edd520 100644 --- a/engines/cge/detection.cpp +++ b/engines/cge/detection.cpp @@ -108,7 +108,7 @@ public: } virtual const ADGameDescription *fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const { - return detectGameFilebased(allFiles, CGE::fileBasedFallback); + return detectGameFilebased(allFiles, fslist, CGE::fileBasedFallback); } virtual const char *getName() const { diff --git a/engines/gob/detection/detection.cpp b/engines/gob/detection/detection.cpp index bcfd5dacfa..9400001636 100644 --- a/engines/gob/detection/detection.cpp +++ b/engines/gob/detection/detection.cpp @@ -40,7 +40,7 @@ public: } virtual const ADGameDescription *fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const { - return detectGameFilebased(allFiles, Gob::fileBased); + return detectGameFilebased(allFiles, fslist, Gob::fileBased); } virtual const char *getName() const { diff --git a/engines/mohawk/detection.cpp b/engines/mohawk/detection.cpp index f0c657897d..5664929948 100644 --- a/engines/mohawk/detection.cpp +++ b/engines/mohawk/detection.cpp @@ -167,7 +167,7 @@ public: } virtual const ADGameDescription *fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const { - return detectGameFilebased(allFiles, Mohawk::fileBased); + return detectGameFilebased(allFiles, fslist, Mohawk::fileBased); } virtual const char *getName() const { diff --git a/engines/toon/detection.cpp b/engines/toon/detection.cpp index 8234934972..9c50c20ef8 100644 --- a/engines/toon/detection.cpp +++ b/engines/toon/detection.cpp @@ -133,7 +133,7 @@ public: } virtual const ADGameDescription *fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const { - return detectGameFilebased(allFiles, Toon::fileBasedFallback); + return detectGameFilebased(allFiles, fslist, Toon::fileBasedFallback); } virtual const char *getName() const { diff --git a/engines/touche/detection.cpp b/engines/touche/detection.cpp index 35dd54776f..2566597e6c 100644 --- a/engines/touche/detection.cpp +++ b/engines/touche/detection.cpp @@ -135,7 +135,7 @@ public: } virtual const ADGameDescription *fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const { - const ADGameDescription *matchedDesc = detectGameFilebased(allFiles, Touche::fileBasedFallback); + const ADGameDescription *matchedDesc = detectGameFilebased(allFiles, fslist, Touche::fileBasedFallback); if (matchedDesc) { // We got a match Common::String report = Common::String::format(_("Your game version has been detected using " -- cgit v1.2.3 From 9e7ece4ebe06bb66d1408189b44ba2aa9d0d6f42 Mon Sep 17 00:00:00 2001 From: Sven Hesse Date: Wed, 27 Jun 2012 04:48:57 +0200 Subject: DETECTOR: Make reportUnknown() available for AdvancedMetaEngine classes to use --- engines/advancedDetector.cpp | 2 +- engines/advancedDetector.h | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/engines/advancedDetector.cpp b/engines/advancedDetector.cpp index 727134fad8..9beba6ce4a 100644 --- a/engines/advancedDetector.cpp +++ b/engines/advancedDetector.cpp @@ -307,7 +307,7 @@ Common::Error AdvancedMetaEngine::createInstance(OSystem *syst, Engine **engine) return Common::kNoError; } -static void reportUnknown(const Common::FSNode &path, const ADFilePropertiesMap &filesProps) { +void AdvancedMetaEngine::reportUnknown(const Common::FSNode &path, const ADFilePropertiesMap &filesProps) const { // TODO: This message should be cleaned up / made more specific. // For example, we should specify at least which engine triggered this. // diff --git a/engines/advancedDetector.h b/engines/advancedDetector.h index 3e18a6aa18..8c19d03691 100644 --- a/engines/advancedDetector.h +++ b/engines/advancedDetector.h @@ -308,6 +308,12 @@ protected: */ const ADGameDescription *detectGameFilebased(const FileMap &allFiles, const Common::FSList &fslist, const ADFileBasedFallback *fileBasedFallback, ADFilePropertiesMap *filesProps = 0) const; + /** + * Log and print a report that we found an unknown game variant, together with the file + * names, sizes and MD5 sums. + */ + void reportUnknown(const Common::FSNode &path, const ADFilePropertiesMap &filesProps) const; + // TODO void updateGameDescriptor(GameDescriptor &desc, const ADGameDescription *realDesc) const; -- cgit v1.2.3 From 02375fa1e62aef578117e98c864d83939cac7229 Mon Sep 17 00:00:00 2001 From: Sven Hesse Date: Wed, 27 Jun 2012 04:53:39 +0200 Subject: GOB: Report unknown game variant when using the file based fallback detector --- engines/gob/detection/detection.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/engines/gob/detection/detection.cpp b/engines/gob/detection/detection.cpp index 9400001636..14da54637b 100644 --- a/engines/gob/detection/detection.cpp +++ b/engines/gob/detection/detection.cpp @@ -40,7 +40,14 @@ public: } virtual const ADGameDescription *fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const { - return detectGameFilebased(allFiles, fslist, Gob::fileBased); + ADFilePropertiesMap filesProps; + + const ADGameDescription *game = detectGameFilebased(allFiles, fslist, Gob::fileBased, &filesProps); + if (!game) + return 0; + + reportUnknown(fslist.begin()->getParent(), filesProps); + return game; } virtual const char *getName() const { -- cgit v1.2.3 From 18fc453b97e4b67e5e4bd6522c8b8dd05d289910 Mon Sep 17 00:00:00 2001 From: Sven Hesse Date: Wed, 27 Jun 2012 04:56:19 +0200 Subject: TOUCHE: Report unknown game variant when using the file based fallback detector Given the message Touche prints when it found a game, printing the MD5 sums of the files was probably what it expected the AdvancedDetector would do in the filebase fallback detector. This may have been true in the past, but it's not what it does anymore, rendering the message pointless. This fixes it by calling the now accessable reportUnknown method. --- engines/touche/detection.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/engines/touche/detection.cpp b/engines/touche/detection.cpp index 2566597e6c..e4bbe0c4c1 100644 --- a/engines/touche/detection.cpp +++ b/engines/touche/detection.cpp @@ -135,19 +135,13 @@ public: } virtual const ADGameDescription *fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const { - const ADGameDescription *matchedDesc = detectGameFilebased(allFiles, fslist, Touche::fileBasedFallback); - - if (matchedDesc) { // We got a match - Common::String report = Common::String::format(_("Your game version has been detected using " - "filename matching as a variant of %s."), matchedDesc->gameid); - report += "\n"; - report += _("If this is an original and unmodified version, please report any"); - report += "\n"; - report += _("information previously printed by ScummVM to the team."); - report += "\n"; - g_system->logMessage(LogMessageType::kInfo, report.c_str()); - } + ADFilePropertiesMap filesProps; + + const ADGameDescription *matchedDesc = detectGameFilebased(allFiles, fslist, Touche::fileBasedFallback, &filesProps); + if (!matchedDesc) + return 0; + reportUnknown(fslist.begin()->getParent(), filesProps); return matchedDesc; } -- cgit v1.2.3