From 0f3e1bfeb6ca73d95afffef8544fe3adfa31d63e Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Tue, 30 Nov 2021 23:46:41 +0100 Subject: [PATCH] AD: Add full path entries' path components to globs This lets us avoid adding globs to the engines when they're used only for detection. --- engines/advancedDetector.cpp | 44 +++++++++++++++++++++++++++++++++++- engines/advancedDetector.h | 2 ++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/engines/advancedDetector.cpp b/engines/advancedDetector.cpp index 20bfd02cde1..46e2199fb35 100644 --- a/engines/advancedDetector.cpp +++ b/engines/advancedDetector.cpp @@ -29,6 +29,7 @@ #include "common/punycode.h" #include "common/system.h" #include "common/textconsole.h" +#include "common/tokenizer.h" #include "common/translation.h" #include "gui/EventRecorder.h" #include "gui/gui-manager.h" @@ -817,10 +818,30 @@ void AdvancedMetaEngineDetection::preprocessDescriptions() { _globsMap.setVal(*glob, true); } - // Check if the detection entries have only files from the blacklist + // Now scan all detection entries for (const byte *descPtr = _gameDescriptors; ((const ADGameDescription *)descPtr)->gameId != nullptr; descPtr += _descItemSize) { const ADGameDescription *g = (const ADGameDescription *)descPtr; + // Scan for potential directory globs + for (const ADGameFileDescription *fileDesc = g->filesDescriptions; fileDesc->fileName; fileDesc++) { + if (strchr(fileDesc->fileName, '/')) { + if (!_matchFullPaths) + warning("Path component detected in entry for '%s' in engine '%s' but no _matchFullPaths is set", + g->gameId, getEngineId()); + + Common::StringTokenizer tok(fileDesc->fileName, "/"); + + while (!tok.empty()) { + Common::String component = tok.nextToken(); + + if (!tok.empty()) { // If it is not the last component + _globsMap.setVal(component, true); + } + } + } + } + + // Check if the detection entry have only files from the blacklist if (isEntryGrayListed(g)) { debug(0, "WARNING: Detection entry for '%s' in engine '%s' contains only blacklisted names. Add more files to the entry (%s)", g->gameId, getEngineId(), g->filesDescriptions[0].md5); @@ -828,6 +849,27 @@ void AdvancedMetaEngineDetection::preprocessDescriptions() { } } +Common::StringArray AdvancedMetaEngineDetection::getPathsFromEntry(const ADGameDescription *g) { + Common::StringArray result; + + for (const ADGameFileDescription *fileDesc = g->filesDescriptions; fileDesc->fileName; fileDesc++) { + if (!strchr(fileDesc->fileName, '/')) + continue; + + Common::StringTokenizer tok(fileDesc->fileName, "/"); + + while (!tok.empty()) { + Common::String component = tok.nextToken(); + + if (!tok.empty()) { // If it is not the last component + result.push_back(component); + } + } + } + + return result; +} + bool AdvancedMetaEngineDetection::isEntryGrayListed(const ADGameDescription *g) const { bool grayIsPresent = false, nonGrayIsPresent = false; diff --git a/engines/advancedDetector.h b/engines/advancedDetector.h index c9e560a947c..3144eeb4de6 100644 --- a/engines/advancedDetector.h +++ b/engines/advancedDetector.h @@ -383,6 +383,8 @@ public: */ const ExtraGuiOptions getExtraGuiOptions(const Common::String &target) const override; + static Common::StringArray getPathsFromEntry(const ADGameDescription *g); + protected: /** * A hashmap of files and their MD5 checksums.