diff options
Diffstat (limited to 'common/advancedDetector.cpp')
| -rw-r--r-- | common/advancedDetector.cpp | 172 |
1 files changed, 169 insertions, 3 deletions
diff --git a/common/advancedDetector.cpp b/common/advancedDetector.cpp index b2107b85f2..9ddae9368c 100644 --- a/common/advancedDetector.cpp +++ b/common/advancedDetector.cpp @@ -22,18 +22,184 @@ #include "common/stdafx.h" +#include "base/plugins.h" + #include "common/util.h" #include "common/hash-str.h" #include "common/file.h" #include "common/md5.h" #include "common/advancedDetector.h" +#include "common/config-manager.h" namespace Common { -bool ADTrue() { - return true; +PluginError real_ADVANCED_DETECTOR_ENGINE_CREATE( + DetectedGameList (*detectFunc)(const FSList &fslist), + const Common::ADObsoleteGameID *obsoleteList + ) { + const char *gameid = ConfMan.get("gameid").c_str(); + + if (obsoleteList != 0) { + for (const Common::ADObsoleteGameID *o = obsoleteList; o->from; ++o) { + if (!scumm_stricmp(gameid, o->from)) { + gameid = o->to; + ConfMan.set("gameid", o->to); + + if (o->platform != Common::kPlatformUnknown) + ConfMan.set("platform", Common::getPlatformCode(o->platform)); + + warning("Target upgraded from %s to %s", o->from, o->to); + ConfMan.flushToDisk(); + break; + } + } + } + + FSList fslist; + FilesystemNode dir(ConfMan.get("path")); + if (!dir.listDir(fslist, FilesystemNode::kListFilesOnly)) { + return kInvalidPathError; + } + + DetectedGameList detectedGames = detectFunc(fslist); + + for (uint i = 0; i < detectedGames.size(); i++) { + if (detectedGames[i].gameid == gameid) { + return kNoError; + } + } + + return kNoGameDataFoundError; +} + +GameList real_ADVANCED_DETECTOR_GAMEID_LIST(const PlainGameDescriptor *list) { + GameList games; + const PlainGameDescriptor *g = list; + while (g->gameid) { + games.push_back(*g); + g++; + } + return games; } +GameDescriptor real_ADVANCED_DETECTOR_FIND_GAMEID( + const char *gameid, + const PlainGameDescriptor *list, + const Common::ADObsoleteGameID *obsoleteList + ) { + const PlainGameDescriptor *g = list; + while (g->gameid) { + if (0 == scumm_stricmp(gameid, g->gameid)) + return *g; + g++; + } + + GameDescriptor gs; + if (obsoleteList != 0) { + const Common::ADObsoleteGameID *o = obsoleteList; + while (o->from) { + if (0 == scumm_stricmp(gameid, o->from)) { + gs.gameid = gameid; + gs.description = "Obsolete game ID"; + return gs; + } + o++; + } + } else + return *g; + return gs; +} + +DetectedGame toDetectedGame(const ADGameDescription &g, const PlainGameDescriptor *sg) { + const char *title = 0; + + while (sg->gameid) { + if (!scumm_stricmp(g.name, sg->gameid)) + title = sg->description; + sg++; + } + + DetectedGame dg(g.name, title, g.language, g.platform); + dg.updateDesc(g.extra); + return dg; +} + +DetectedGameList real_ADVANCED_DETECTOR_DETECT_GAMES_FUNCTION( + const FSList &fslist, + const byte *descs, + const int descItemSize, + const int descItemCount, + const int md5Bytes, + const PlainGameDescriptor *list + ) { + DetectedGameList detectedGames; + Common::AdvancedDetector AdvDetector; + Common::ADList matches; + Common::ADGameDescList descList; + + for (int i = 0; i < descItemCount; i++) + descList.push_back((const ADGameDescription *)(descs + i * descItemSize)); + + AdvDetector.registerGameDescriptions(descList); + AdvDetector.setFileMD5Bytes(md5Bytes); + + matches = AdvDetector.detectGame(&fslist, Common::UNK_LANG, Common::kPlatformUnknown); + + for (uint i = 0; i < matches.size(); i++) + detectedGames.push_back(toDetectedGame(*(const ADGameDescription *)(descs + matches[i] * descItemSize), list)); + + return detectedGames; +} + +int real_ADVANCED_DETECTOR_DETECT_INIT_GAME( + const byte *descs, + const int descItemSize, + const int descItemCount, + const int md5Bytes, + const PlainGameDescriptor *list + ) { + int gameNumber = -1; + + DetectedGameList detectedGames; + Common::AdvancedDetector AdvDetector; + Common::ADList matches; + Common::ADGameDescList descList; + + Common::Language language = Common::UNK_LANG; + Common::Platform platform = Common::kPlatformUnknown; + + if (ConfMan.hasKey("language")) + language = Common::parseLanguage(ConfMan.get("language")); + if (ConfMan.hasKey("platform")) + platform = Common::parsePlatform(ConfMan.get("platform")); + + Common::String gameid = ConfMan.get("gameid"); + + for (int i = 0; i < descItemCount; i++) + descList.push_back((const ADGameDescription *)(descs + i * descItemSize)); + + AdvDetector.registerGameDescriptions(descList); + AdvDetector.setFileMD5Bytes(md5Bytes); + + matches = AdvDetector.detectGame(0, language, platform); + + for (uint i = 0; i < matches.size(); i++) { + if (toDetectedGame(*(const ADGameDescription *)(descs + matches[i] * descItemSize), list).gameid == gameid) { + gameNumber = matches[i]; + break; + } + } + + if (gameNumber >= descItemCount || gameNumber == -1) { + error("TODO invalid gameNumber %d (max. expected value: %d)", gameNumber, descItemCount ); + } + + debug(2, "Running %s", toDetectedGame(*(const ADGameDescription *)(descs + gameNumber * descItemSize), list).description.c_str()); + + return gameNumber; +} + + AdvancedDetector::AdvancedDetector() { _fileMD5Bytes = 0; } @@ -84,7 +250,7 @@ ADList AdvancedDetector::detectGame(const FSList *fslist, Language language, Pla } } - if (fslist != NULL) { + if (fslist != 0) { for (FSList::const_iterator file = fslist->begin(); file != fslist->end(); ++file) { if (file->isDirectory()) continue; tstr = file->name(); |
