From 82ab3056fa52f78309ae3271114dbec28ceb9684 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Wed, 29 Feb 2012 16:48:25 +0100 Subject: ENGINES: Implement per-game options caching in AdvancedDetector via GUIO flags. --- engines/advancedDetector.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'engines/advancedDetector.cpp') diff --git a/engines/advancedDetector.cpp b/engines/advancedDetector.cpp index 081a97b9f1..dc7f7e007c 100644 --- a/engines/advancedDetector.cpp +++ b/engines/advancedDetector.cpp @@ -167,6 +167,25 @@ GameList AdvancedMetaEngine::detectGames(const Common::FSList &fslist) const { return detectedGames; } +const ExtraGuiOptions AdvancedMetaEngine::getExtraGuiOptions(const Common::String &target) const { + if (!_extraGuiOptions) + return ExtraGuiOptions(); + + // Query the GUI options + const Common::String guiOptionsString = ConfMan.get("guioptions", target); + const Common::String guiOptions = parseGameGUIOptions(guiOptionsString); + + ExtraGuiOptions options; + + // Add all the applying extra GUI options. + for (const ADExtraGuiOptionsMap *entry = _extraGuiOptions; entry->guioFlag; ++entry) { + if (guiOptions.contains(entry->guioFlag)) + options.push_back(entry->option); + } + + return options; +} + Common::Error AdvancedMetaEngine::createInstance(OSystem *syst, Engine **engine) const { assert(engine); @@ -562,8 +581,9 @@ GameDescriptor AdvancedMetaEngine::findGame(const char *gameid) const { return GameDescriptor(); } -AdvancedMetaEngine::AdvancedMetaEngine(const void *descs, uint descItemSize, const PlainGameDescriptor *gameids) - : _gameDescriptors((const byte *)descs), _descItemSize(descItemSize), _gameids(gameids) { +AdvancedMetaEngine::AdvancedMetaEngine(const void *descs, uint descItemSize, const PlainGameDescriptor *gameids, const ADExtraGuiOptionsMap *extraGuiOptions) + : _gameDescriptors((const byte *)descs), _descItemSize(descItemSize), _gameids(gameids), + _extraGuiOptions(extraGuiOptions) { _md5Bytes = 5000; _singleid = NULL; -- cgit v1.2.3 From 6a49d3eadd7555a4f5f539ceb73fdfe370fce9da Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Sat, 31 Mar 2012 13:55:03 +0300 Subject: ENGINES: Return all available custom GUI options if no target is specified This is used to set default settings for all custom game options when an engine starts --- engines/advancedDetector.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'engines/advancedDetector.cpp') diff --git a/engines/advancedDetector.cpp b/engines/advancedDetector.cpp index dc7f7e007c..ac06e74e0a 100644 --- a/engines/advancedDetector.cpp +++ b/engines/advancedDetector.cpp @@ -171,12 +171,21 @@ const ExtraGuiOptions AdvancedMetaEngine::getExtraGuiOptions(const Common::Strin if (!_extraGuiOptions) return ExtraGuiOptions(); + ExtraGuiOptions options; + + // If there isn't any target specified, return all available GUI options. + // Only used when an engine starts in order to set option defaults. + if (target.empty()) { + for (const ADExtraGuiOptionsMap *entry = _extraGuiOptions; entry->guioFlag; ++entry) + options.push_back(entry->option); + + return options; + } + // Query the GUI options const Common::String guiOptionsString = ConfMan.get("guioptions", target); const Common::String guiOptions = parseGameGUIOptions(guiOptionsString); - ExtraGuiOptions options; - // Add all the applying extra GUI options. for (const ADExtraGuiOptionsMap *entry = _extraGuiOptions; entry->guioFlag; ++entry) { if (guiOptions.contains(entry->guioFlag)) -- cgit v1.2.3 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(-) (limited to 'engines/advancedDetector.cpp') 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 --------------- 1 file changed, 15 deletions(-) (limited to 'engines/advancedDetector.cpp') 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. -- 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 +++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 28 deletions(-) (limited to 'engines/advancedDetector.cpp') 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; } } } -- 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 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'engines/advancedDetector.cpp') 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; + } + } + } } } -- 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/advancedDetector.cpp') 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. // -- cgit v1.2.3