diff options
author | Max Horn | 2011-06-14 18:02:09 +0200 |
---|---|---|
committer | Max Horn | 2011-06-14 18:52:11 +0200 |
commit | 879c3c78177ee2ff95c0d22f82d3448877d6fa98 (patch) | |
tree | 7a51efd1a5a77fbb89791b1a9a3ec2f5a87c1656 | |
parent | 64e523141fa619c1632dcb2b215cfd85c41ef5a1 (diff) | |
download | scummvm-rg350-879c3c78177ee2ff95c0d22f82d3448877d6fa98.tar.gz scummvm-rg350-879c3c78177ee2ff95c0d22f82d3448877d6fa98.tar.bz2 scummvm-rg350-879c3c78177ee2ff95c0d22f82d3448877d6fa98.zip |
DETECTOR: Pass allFiles to AdvancedMetaEngine::fallbackDetect()
Also reorder the parameters of composeFileHashMap, placing the "return value"
first.
-rw-r--r-- | engines/advancedDetector.cpp | 43 | ||||
-rw-r--r-- | engines/advancedDetector.h | 13 | ||||
-rw-r--r-- | engines/agi/detection.cpp | 4 | ||||
-rw-r--r-- | engines/made/detection.cpp | 4 | ||||
-rw-r--r-- | engines/sci/detection.cpp | 5 | ||||
-rw-r--r-- | engines/scumm/detection.cpp | 7 | ||||
-rw-r--r-- | engines/teenagent/detection.cpp | 4 | ||||
-rw-r--r-- | engines/tinsel/detection.cpp | 4 | ||||
-rw-r--r-- | engines/tucker/detection.cpp | 2 |
9 files changed, 46 insertions, 40 deletions
diff --git a/engines/advancedDetector.cpp b/engines/advancedDetector.cpp index 9a05e8513d..c9f4f38b77 100644 --- a/engines/advancedDetector.cpp +++ b/engines/advancedDetector.cpp @@ -127,12 +127,22 @@ bool cleanupPirated(ADGameDescList &matched) { GameList AdvancedMetaEngine::detectGames(const Common::FSList &fslist) const { - ADGameDescList matches = detectGame(fslist, Common::UNK_LANG, Common::kPlatformUnknown, ""); + ADGameDescList matches; GameList detectedGames; + FileMap allFiles; + + if (fslist.empty()) + return detectedGames; + + // Compose a hashmap of all files in fslist. + composeFileHashMap(allFiles, fslist, (_maxScanDepth == 0 ? 1 : _maxScanDepth)); + + // Run the detector on this + matches = detectGame(fslist.begin()->getParent(), allFiles, Common::UNK_LANG, Common::kPlatformUnknown, ""); if (matches.empty()) { // Use fallback detector if there were no matches by other means - const ADGameDescription *fallbackDesc = fallbackDetect(fslist); + const ADGameDescription *fallbackDesc = fallbackDetect(allFiles, fslist); if (fallbackDesc != 0) { GameDescriptor desc(toGameDescriptor(*fallbackDesc, _gameids)); updateGameDescriptor(desc, fallbackDesc); @@ -196,7 +206,15 @@ Common::Error AdvancedMetaEngine::createInstance(OSystem *syst, Engine **engine) return Common::kNoGameDataFoundError; } - ADGameDescList matches = detectGame(files, language, platform, extra); + if (files.empty()) + return Common::kNoGameDataFoundError; + + // Compose a hashmap of all files in fslist. + FileMap allFiles; + composeFileHashMap(allFiles, files, (_maxScanDepth == 0 ? 1 : _maxScanDepth)); + + // Run the detector on this + ADGameDescList matches = detectGame(files.begin()->getParent(), allFiles, language, platform, extra); if (cleanupPirated(matches)) return Common::kNoGameDataFoundError; @@ -215,7 +233,7 @@ Common::Error AdvancedMetaEngine::createInstance(OSystem *syst, Engine **engine) if (agdDesc == 0) { // Use fallback detector if there were no matches by other means - agdDesc = fallbackDetect(files); + agdDesc = fallbackDetect(allFiles, files); if (agdDesc != 0) { // Seems we found a fallback match. But first perform a basic // sanity check: the gameid must match. @@ -270,7 +288,7 @@ static void reportUnknown(const Common::FSNode &path, const SizeMD5Map &filesSiz g_system->logMessage(LogMessageType::kInfo, report.c_str()); } -void AdvancedMetaEngine::composeFileHashMap(const Common::FSList &fslist, FileMap &allFiles, int depth) const { +void AdvancedMetaEngine::composeFileHashMap(FileMap &allFiles, const Common::FSList &fslist, int depth) const { if (depth <= 0) return; @@ -297,7 +315,7 @@ void AdvancedMetaEngine::composeFileHashMap(const Common::FSList &fslist, FileMa if (!file->getChildren(files, Common::FSNode::kListAll)) continue; - composeFileHashMap(files, allFiles, depth - 1); + composeFileHashMap(allFiles, files, depth - 1); } Common::String tstr = file->getName(); @@ -310,24 +328,17 @@ void AdvancedMetaEngine::composeFileHashMap(const Common::FSList &fslist, FileMa } } -ADGameDescList AdvancedMetaEngine::detectGame(const Common::FSList &fslist, Common::Language language, Common::Platform platform, const Common::String &extra) const { - FileMap allFiles; +ADGameDescList AdvancedMetaEngine::detectGame(const Common::FSNode &parent, const FileMap &allFiles, Common::Language language, Common::Platform platform, const Common::String &extra) const { SizeMD5Map filesSizeMD5; const ADGameFileDescription *fileDesc; const ADGameDescription *g; const byte *descPtr; - if (fslist.empty()) - return ADGameDescList(); - Common::FSNode parent = fslist.begin()->getParent(); debug(3, "Starting detection in dir '%s'", parent.getPath().c_str()); - // First we compose a hashmap of all files in fslist. - composeFileHashMap(fslist, allFiles, (_maxScanDepth == 0 ? 1 : _maxScanDepth)); - - // Check which files are included in some ADGameDescription *and* present - // in fslist. Compute MD5s and file sizes for these files. + // Check which files are included in some ADGameDescription *and* are present. + // Compute MD5s and file sizes for these files. for (descPtr = _gameDescriptors; ((const ADGameDescription *)descPtr)->gameid != 0; descPtr += _descItemSize) { g = (const ADGameDescription *)descPtr; diff --git a/engines/advancedDetector.h b/engines/advancedDetector.h index 976f17ce35..c48e4a9815 100644 --- a/engines/advancedDetector.h +++ b/engines/advancedDetector.h @@ -230,31 +230,30 @@ protected: // To be implemented by subclasses virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const = 0; + typedef Common::HashMap<Common::String, Common::FSNode, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> FileMap; + /** * An (optional) generic fallback detect function which is invoked * if both the regular MD5 based detection as well as the file * based fallback failed to detect anything. */ - virtual const ADGameDescription *fallbackDetect(const Common::FSList &fslist) const { + virtual const ADGameDescription *fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const { return 0; } protected: - typedef Common::HashMap<Common::String, Common::FSNode, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> FileMap; - /** * Detect games in specified directory. * Parameters language and platform are used to pass on values * specified by the user. This is used to restrict search scope. * - * @param fslist FSList to scan or NULL for scanning all specified - * default directories. + * @param allFiles list of all present files, as computed by composeFileHashMap * @param language restrict results to specified language * @param platform restrict results to specified platform * @param extra restrict results to specified extra string (only if kADFlagUseExtraAsHint is set) * @return list of ADGameDescription pointers corresponding to matched games */ - ADGameDescList detectGame(const Common::FSList &fslist, Common::Language language, Common::Platform platform, const Common::String &extra) const; + ADGameDescList detectGame(const Common::FSNode &parent, const FileMap &allFiles, Common::Language language, Common::Platform platform, const Common::String &extra) const; /** * Iterates over all ADFileBasedFallback records inside _fileBasedFallback. @@ -275,7 +274,7 @@ protected: * Compose a hashmap of all files in fslist. * Includes nifty stuff like removing trailing dots and ignoring case. */ - void composeFileHashMap(const Common::FSList &fslist, FileMap &allFiles, int depth) const; + void composeFileHashMap(FileMap &allFiles, const Common::FSList &fslist, int depth) const; }; #endif diff --git a/engines/agi/detection.cpp b/engines/agi/detection.cpp index 427ffef1ad..21ff5deb2c 100644 --- a/engines/agi/detection.cpp +++ b/engines/agi/detection.cpp @@ -155,7 +155,7 @@ public: virtual void removeSaveState(const char *target, int slot) const; SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const; - const ADGameDescription *fallbackDetect(const Common::FSList &fslist) const; + const ADGameDescription *fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const; }; bool AgiMetaEngine::hasFeature(MetaEngineFeature f) const { @@ -293,7 +293,7 @@ SaveStateDescriptor AgiMetaEngine::querySaveMetaInfos(const char *target, int sl return SaveStateDescriptor(); } -const ADGameDescription *AgiMetaEngine::fallbackDetect(const Common::FSList &fslist) const { +const ADGameDescription *AgiMetaEngine::fallbackDetect(const FileMap &allFilesXXX, const Common::FSList &fslist) const { typedef Common::HashMap<Common::String, int32> IntMap; IntMap allFiles; bool matchedUsingFilenames = false; diff --git a/engines/made/detection.cpp b/engines/made/detection.cpp index fcbee9cb32..e8c948af4e 100644 --- a/engines/made/detection.cpp +++ b/engines/made/detection.cpp @@ -542,7 +542,7 @@ public: virtual bool hasFeature(MetaEngineFeature f) const; virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const; - const ADGameDescription *fallbackDetect(const Common::FSList &fslist) const; + const ADGameDescription *fallbackDetect(const Common::FSList &fslist, const FileMap &allFiles) const; }; @@ -564,7 +564,7 @@ bool MadeMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGame return gd != 0; } -const ADGameDescription *MadeMetaEngine::fallbackDetect(const Common::FSList &fslist) const { +const ADGameDescription *MadeMetaEngine::fallbackDetect(const Common::FSList &fslist, const FileMap &allFiles) const { // Set the default values for the fallback descriptor's ADGameDescription part. Made::g_fallbackDesc.desc.language = Common::UNK_LANG; Made::g_fallbackDesc.desc.platform = Common::kPlatformPC; diff --git a/engines/sci/detection.cpp b/engines/sci/detection.cpp index 8d53ce9937..7bc9699e9b 100644 --- a/engines/sci/detection.cpp +++ b/engines/sci/detection.cpp @@ -390,7 +390,7 @@ public: } virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *gd) const; - const ADGameDescription *fallbackDetect(const Common::FSList &fslist) const; + const ADGameDescription *fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const; virtual bool hasFeature(MetaEngineFeature f) const; virtual SaveStateList listSaves(const char *target) const; virtual int getMaximumSaveSlot() const; @@ -418,7 +418,7 @@ Common::Language charToScummVMLanguage(const char c) { } } -const ADGameDescription *SciMetaEngine::fallbackDetect(const Common::FSList &fslist) const { +const ADGameDescription *SciMetaEngine::fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const { bool foundResMap = false; bool foundRes000 = false; @@ -430,6 +430,7 @@ const ADGameDescription *SciMetaEngine::fallbackDetect(const Common::FSList &fsl s_fallbackDesc.gameid = "sci"; // First grab all filenames + // TODO: Consider using allFiles instead of fslist for (Common::FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) { if (file->isDirectory()) continue; diff --git a/engines/scumm/detection.cpp b/engines/scumm/detection.cpp index 4b673ad8ff..e5c5906404 100644 --- a/engines/scumm/detection.cpp +++ b/engines/scumm/detection.cpp @@ -431,7 +431,7 @@ static void computeGameSettingsFromMD5(const Common::FSList &fslist, const GameF } } -static void composeFileHashMap(const Common::FSList &fslist, DescMap &fileMD5Map, int depth, const char **globs) { +static void composeFileHashMap(DescMap &fileMD5Map, const Common::FSList &fslist, int depth, const char **globs) { if (depth <= 0) return; @@ -459,9 +459,8 @@ static void composeFileHashMap(const Common::FSList &fslist, DescMap &fileMD5Map continue; Common::FSList files; - if (file->getChildren(files, Common::FSNode::kListAll)) { - composeFileHashMap(files, fileMD5Map, depth - 1, globs); + composeFileHashMap(fileMD5Map, files, depth - 1, globs); } } } @@ -472,7 +471,7 @@ static void detectGames(const Common::FSList &fslist, Common::List<DetectorResul DetectorResult dr; // Dive one level down since mac indy3/loom has its files split into directories. See Bug #1438631 - composeFileHashMap(fslist, fileMD5Map, 2, directoryGlobs); + composeFileHashMap(fileMD5Map, fslist, 2, directoryGlobs); // Iterate over all filename patterns. for (const GameFilenamePattern *gfp = gameFilenamesTable; gfp->gameid; ++gfp) { diff --git a/engines/teenagent/detection.cpp b/engines/teenagent/detection.cpp index b965e616f1..72a338664b 100644 --- a/engines/teenagent/detection.cpp +++ b/engines/teenagent/detection.cpp @@ -117,10 +117,6 @@ public: return desc != 0; } -// virtual const ADGameDescription *fallbackDetect(const Common::FSList &fslist) const { -// return 0; -// } - static Common::String generateGameStateFileName(const char *target, int slot) { return Common::String::format("%s.%02d", target, slot); } diff --git a/engines/tinsel/detection.cpp b/engines/tinsel/detection.cpp index 6a221da0eb..9c52305a1c 100644 --- a/engines/tinsel/detection.cpp +++ b/engines/tinsel/detection.cpp @@ -89,7 +89,7 @@ public: } virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const; - const ADGameDescription *fallbackDetect(const Common::FSList &fslist) const; + const ADGameDescription *fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const; virtual bool hasFeature(MetaEngineFeature f) const; virtual SaveStateList listSaves(const char *target) const; @@ -175,7 +175,7 @@ typedef Common::Array<const ADGameDescription*> ADGameDescList; * Fallback detection scans the list of Discworld 2 targets to see if it can detect an installation * where the files haven't been renamed (i.e. don't have the '1' just before the extension) */ -const ADGameDescription *TinselMetaEngine::fallbackDetect(const Common::FSList &fslist) const { +const ADGameDescription *TinselMetaEngine::fallbackDetect(const FileMap &allFilesXXX, const Common::FSList &fslist) const { Common::String extra; FileMap allFiles; SizeMD5Map filesSizeMD5; diff --git a/engines/tucker/detection.cpp b/engines/tucker/detection.cpp index d7d829e1da..4a3313e3f7 100644 --- a/engines/tucker/detection.cpp +++ b/engines/tucker/detection.cpp @@ -145,7 +145,7 @@ public: return desc != 0; } - virtual const ADGameDescription *fallbackDetect(const Common::FSList &fslist) const { + virtual const ADGameDescription *fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const { for (Common::FSList::const_iterator d = fslist.begin(); d != fslist.end(); ++d) { Common::FSList audiofslist; if (d->isDirectory() && d->getName().equalsIgnoreCase("audio") && d->getChildren(audiofslist, Common::FSNode::kListFilesOnly)) { |