diff --git a/engines/advancedDetector.cpp b/engines/advancedDetector.cpp index ea439475e4f..d570b2655dc 100644 --- a/engines/advancedDetector.cpp +++ b/engines/advancedDetector.cpp @@ -198,7 +198,7 @@ DetectedGame AdvancedMetaEngineDetection::toDetectedGame(const ADDetectedGame &a return game; } -bool cleanupPirated(ADDetectedGames &matched) { +bool AdvancedMetaEngineDetection::cleanupPirated(ADDetectedGames &matched) const { // OKay, now let's sense presence of pirated games if (!matched.empty()) { for (uint j = 0; j < matched.size();) { diff --git a/engines/advancedDetector.h b/engines/advancedDetector.h index f2edff84401..7832779f2c6 100644 --- a/engines/advancedDetector.h +++ b/engines/advancedDetector.h @@ -428,6 +428,9 @@ protected: /** Convert an AD game description into the shared game description format. */ virtual DetectedGame toDetectedGame(const ADDetectedGame &adGame) const; + /** Check for pirated games in the given detected games */ + bool cleanupPirated(ADDetectedGames &matched) const; + friend class FileMapArchive; }; diff --git a/engines/ags/detection.cpp b/engines/ags/detection.cpp index 8bade671554..78ed984868d 100644 --- a/engines/ags/detection.cpp +++ b/engines/ags/detection.cpp @@ -168,6 +168,53 @@ AGSMetaEngineDetection::AGSMetaEngineDetection() : AdvancedMetaEngineDetection(A sizeof(AGS::AGSGameDescription), AGS::GAME_NAMES) { } +DetectedGames AGSMetaEngineDetection::detectGames(const Common::FSList &fslist) const { + 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 + ADDetectedGames matches = detectGame(fslist.begin()->getParent(), allFiles, Common::UNK_LANG, Common::kPlatformUnknown, ""); + + cleanupPirated(matches); + + bool foundKnownGames = false; + DetectedGames detectedGames; + for (uint i = 0; i < matches.size(); i++) { + DetectedGame game = toDetectedGame(matches[i]); + if (game.hasUnknownFiles) { + // Check the game is an AGS game + for (FilePropertiesMap::const_iterator it = game.matchedFiles.begin(); it != game.matchedFiles.end(); it++) { + Common::File f; + if (f.open(allFiles[it->_key]) && AGS3::isAGSFile(f)) { + detectedGames.push_back(game); + break; + } + } + } else { + detectedGames.push_back(game); + foundKnownGames = true; + } + } + + // If we didn't find a known game, also add a fallback detection + if (!foundKnownGames) { + // Use fallback detector if there were no matches by other means + ADDetectedGame fallbackDetectionResult = fallbackDetect(allFiles, fslist); + if (fallbackDetectionResult.desc) { + DetectedGame fallbackDetectedGame = toDetectedGame(fallbackDetectionResult); + fallbackDetectedGame.preferredTarget += "-fallback"; + + detectedGames.push_back(fallbackDetectedGame); + } + } + return detectedGames; +} + ADDetectedGame AGSMetaEngineDetection::fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const { // Set the default values for the fallback descriptor's ADGameDescription part. AGS::g_fallbackDesc.desc.language = Common::UNK_LANG; diff --git a/engines/ags/detection.h b/engines/ags/detection.h index 21aebb58a2c..63d72d9c14f 100644 --- a/engines/ags/detection.h +++ b/engines/ags/detection.h @@ -69,6 +69,8 @@ public: return "AGS Engine (C) Chris Jones"; } + DetectedGames detectGames(const Common::FSList &fslist) const override; + ADDetectedGame fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const override; GUI::OptionsContainerWidget *buildEngineOptionsWidgetStatic(GUI::GuiObject *boss, const Common::String &name, const Common::String &target) const override;