From bb20579bee4d86e05699107f19882294178deb64 Mon Sep 17 00:00:00 2001 From: Abhinav Chennubhotla <51199011+PhoenixFlame101@users.noreply.github.com> Date: Mon, 19 Jun 2023 12:01:19 +0530 Subject: [PATCH] BASE: Add dumpAllDetectionEntries() to commandLine - Add virtual function dumpDetectionEntries() to MetaEngine - Glk, Sky and SCUMM do not have proper definitions for dumpDetectionEntries() - Add md5PropToGameFile() to extract prefixes for md5s - AdvancedDetector writes content of DAT file to STDOUT --- base/commandLine.cpp | 3 +- engines/advancedDetector.cpp | 58 ++++++++++++++++++++++++++++++++++++ engines/advancedDetector.h | 2 ++ engines/glk/detection.h | 2 ++ engines/metaengine.h | 3 ++ engines/scumm/detection.cpp | 2 ++ engines/sky/detection.cpp | 2 ++ 7 files changed, 70 insertions(+), 2 deletions(-) diff --git a/base/commandLine.cpp b/base/commandLine.cpp index 81b4e75bcf6..83a51829147 100644 --- a/base/commandLine.cpp +++ b/base/commandLine.cpp @@ -1424,12 +1424,11 @@ static void listAudioDevices() { } /** Dump MD5s from detection entries into STDOUT */ -/** WIP: Current only creates a metaengine instance for each engine */ static void dumpAllDetectionEntries() { - // We need to create one file for each engine const PluginList &plugins = EngineMan.getPlugins(); for (PluginList::const_iterator iter = plugins.begin(); iter != plugins.end(); iter++) { const MetaEngineDetection &metaEngine = (*iter)->get(); + metaEngine.dumpDetectionEntries(); } } diff --git a/engines/advancedDetector.cpp b/engines/advancedDetector.cpp index 18a602a71d6..78072188760 100644 --- a/engines/advancedDetector.cpp +++ b/engines/advancedDetector.cpp @@ -545,6 +545,32 @@ static MD5Properties gameFileToMD5Props(const ADGameFileDescription *fileEntry, return ret; } +const char *md5PropToGameFile(MD5Properties flags) { + switch (flags & kMD5MacMask) { + case kMD5MacDataFork: { + if (flags & kMD5Tail) + return "dt"; + return "d"; + } + + case kMD5MacResOrDataFork: { + if (flags & kMD5Tail) + return "mt"; + return "m"; + } + + case kMD5MacResFork: { + if (flags & kMD5Tail) + return "rt"; + return "r"; + } + + default: { + return ""; + } + } +} + static bool getFilePropertiesIntern(uint md5Bytes, const AdvancedMetaEngine::FileMap &allFiles, MD5Properties md5prop, const Common::String &fname, FileProperties &fileProps); bool AdvancedMetaEngineDetection::getFileProperties(const FileMap &allFiles, MD5Properties md5prop, const Common::String &fname, FileProperties &fileProps) const { @@ -626,6 +652,38 @@ static bool getFilePropertiesIntern(uint md5Bytes, const AdvancedMetaEngine::Fil return true; } +void AdvancedMetaEngineDetection::dumpDetectionEntries() const { + const byte *descPtr; + + debug("scummvm ("); + // debug("version %s", commitHash); + // debug("date %s", date); + debug("\tauthor scummvm"); + debug(")\n"); + for (descPtr = _gameDescriptors; ((const ADGameDescription *)descPtr)->gameId != nullptr; descPtr += _descItemSize) { + auto g = ((const ADGameDescription *)descPtr); + auto gameid = g->gameId; + + debug("game ("); + debug("\tname %s", gameid); + // debug("\tsourcefile %s"); // Not necessary for now + // debug("\tromof %s"); // Not sure where i get this from + for (auto fileDesc = g->filesDescriptions; fileDesc->fileName; fileDesc++) { + Common::String fname = fileDesc->fileName; + int64 fsize = fileDesc->fileSize; + Common::String md5 = fileDesc->md5; + MD5Properties md5prop = gameFileToMD5Props(fileDesc, g->flags); + auto md5Prefix = Common::String(md5PropToGameFile(md5prop)); + Common::String key = fname.c_str(); + if (md5Prefix != "") + key = Common::String::format("%s:%s", md5Prefix.c_str(), fname.c_str()); + + debug("\trom ( name %s size %ld md5-%d %s )", fname.c_str(), fsize, _md5Bytes, key.c_str()); + } + debug(")\n"); + } +} + ADDetectedGames AdvancedMetaEngineDetection::detectGame(const Common::FSNode &parent, const FileMap &allFiles, Common::Language language, Common::Platform platform, const Common::String &extra, uint32 skipADFlags, bool skipIncomplete) { FilePropertiesMap filesProps; ADDetectedGames matched; diff --git a/engines/advancedDetector.h b/engines/advancedDetector.h index b7a4e5f9671..c639f94be15 100644 --- a/engines/advancedDetector.h +++ b/engines/advancedDetector.h @@ -403,6 +403,8 @@ public: return count; } + void dumpDetectionEntries() const override final; + protected: /** * A hashmap of files and their MD5 checksums. diff --git a/engines/glk/detection.h b/engines/glk/detection.h index 025c0b43167..ca637ca0213 100644 --- a/engines/glk/detection.h +++ b/engines/glk/detection.h @@ -69,6 +69,8 @@ public: void detectClashes() const; uint getMD5Bytes() const override; + + void dumpDetectionEntries() const override final {} }; namespace Glk { diff --git a/engines/metaengine.h b/engines/metaengine.h index 625f53be55e..ea960f604a8 100644 --- a/engines/metaengine.h +++ b/engines/metaengine.h @@ -170,6 +170,9 @@ public: return -1; } + /** Returns formatted data from game descriptor for dumping into a file */ + virtual void dumpDetectionEntries() const = 0; + /** * The default version of this method will just parse the options string from * the config manager. However it also allows the meta engine to post process diff --git a/engines/scumm/detection.cpp b/engines/scumm/detection.cpp index 0ee4ac7fc96..de9f65065a5 100644 --- a/engines/scumm/detection.cpp +++ b/engines/scumm/detection.cpp @@ -96,6 +96,8 @@ public: } Common::String parseAndCustomizeGuiOptions(const Common::String &optionsString, const Common::String &domain) const override; + + void dumpDetectionEntries() const override final {} }; PlainGameList ScummMetaEngineDetection::getSupportedGames() const { diff --git a/engines/sky/detection.cpp b/engines/sky/detection.cpp index 021f5df93b9..148c51ef99f 100644 --- a/engines/sky/detection.cpp +++ b/engines/sky/detection.cpp @@ -73,6 +73,8 @@ public: return 0; } + void dumpDetectionEntries() const override final {} + int getGameVariantCount() const override { int entries = 0; for (const SkyVersion *sv = skyVersions; sv->dinnerTableEntries; ++sv)