From 9e651592ec9d58d8f5c0d2dea0e351bf048d2743 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 6 Jun 2007 18:35:37 +0000 Subject: Adv detector: Merged upgradeTargetIfNecessary() into detectGameForEngineCreation() svn-id: r27144 --- common/advancedDetector.cpp | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) (limited to 'common/advancedDetector.cpp') diff --git a/common/advancedDetector.cpp b/common/advancedDetector.cpp index 24e884a164..da65c30411 100644 --- a/common/advancedDetector.cpp +++ b/common/advancedDetector.cpp @@ -72,27 +72,6 @@ GameList gameIDList(const Common::ADParams ¶ms) { return GameList(params.list); } -static void upgradeTargetIfNecessary(const Common::ADParams ¶ms) { - if (params.obsoleteList == 0) - return; - - const char *gameid = ConfMan.get("gameid").c_str(); - - for (const Common::ADObsoleteGameID *o = params.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; - } - } -} - GameDescriptor findGameID( const char *gameid, const Common::ADParams ¶ms @@ -221,10 +200,24 @@ PluginError detectGameForEngineCreation( const Common::ADParams ¶ms ) { - upgradeTargetIfNecessary(params); - Common::String gameid = ConfMan.get("gameid"); + if (params.obsoleteList != 0) { + for (const Common::ADObsoleteGameID *o = params.obsoleteList; o->from; ++o) { + if (!scumm_stricmp(gameid.c_str(), 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)) { -- cgit v1.2.3 From add3243e5e564bb730ac57af2fd9ce15e6d54309 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Mon, 11 Jun 2007 08:38:23 +0000 Subject: Fix for bug #1719463: "DETECTOR: Launching undefined target adds launcher entry" svn-id: r27352 --- common/advancedDetector.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'common/advancedDetector.cpp') diff --git a/common/advancedDetector.cpp b/common/advancedDetector.cpp index da65c30411..f0f77ee26e 100644 --- a/common/advancedDetector.cpp +++ b/common/advancedDetector.cpp @@ -212,7 +212,12 @@ PluginError detectGameForEngineCreation( ConfMan.set("platform", Common::getPlatformCode(o->platform)); warning("Target upgraded from %s to %s", o->from, o->to); - ConfMan.flushToDisk(); + + if (ConfMan.hasKey("id_came_from_command_line")) { + warning("Target came from command line. Skipping save"); + } else { + ConfMan.flushToDisk(); + } break; } } -- cgit v1.2.3 From 6e5b70f5e9f8690b467ea8837e727e1048838788 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Tue, 12 Jun 2007 12:22:25 +0000 Subject: Patch #1733764: "Fallback detection patch". GSoC student. svn-id: r27375 --- common/advancedDetector.cpp | 136 ++++++++++++++++++++++++++++++-------------- 1 file changed, 92 insertions(+), 44 deletions(-) (limited to 'common/advancedDetector.cpp') diff --git a/common/advancedDetector.cpp b/common/advancedDetector.cpp index f0f77ee26e..7d7cadbade 100644 --- a/common/advancedDetector.cpp +++ b/common/advancedDetector.cpp @@ -72,6 +72,32 @@ GameList gameIDList(const Common::ADParams ¶ms) { return GameList(params.list); } +static void upgradeTargetIfNecessary(const Common::ADParams ¶ms) { + if (params.obsoleteList == 0) + return; + + const char *gameid = ConfMan.get("gameid").c_str(); + + for (const Common::ADObsoleteGameID *o = params.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); + + if (ConfMan.hasKey("id_came_from_command_line")) { + warning("Target came from command line. Skipping save"); + } else { + ConfMan.flushToDisk(); + } + break; + } + } +} + GameDescriptor findGameID( const char *gameid, const Common::ADParams ¶ms @@ -110,6 +136,24 @@ static GameDescriptor toGameDescriptor(const ADGameDescription &g, const PlainGa return gd; } +// Almost identical to the toGameDescriptor function that takes a ADGameDescription and PlainGameDescriptor. +// Just a little fine tuning about accessing variables. +// Used because of fallback detection and the dynamic string content it needs. +static GameDescriptor toGameDescriptor(const EncapsulatedADGameDesc &g, const PlainGameDescriptor *sg) { + const char *title = 0; + + while (sg->gameid) { + if (!scumm_stricmp(g.getGameID(), sg->gameid)) + title = sg->description; + sg++; + } + + assert(g.realDesc); + GameDescriptor gd(g.getGameID(), title, g.realDesc->language, g.realDesc->platform); + gd.updateDesc(g.getExtra()); + return gd; +} + /** * Generate a preferred target value as * GAMEID-PLAFORM-LANG @@ -134,38 +178,49 @@ static String generatePreferredTarget(const String &id, const ADGameDescription return res; } +static void updateGameDescriptor(GameDescriptor &desc, const ADGameDescription *realDesc, const Common::ADParams ¶ms) { + if (params.singleid != NULL) { + desc["preferredtarget"] = desc["gameid"]; + desc["gameid"] = params.singleid; + } + + if (params.flags & kADFlagAugmentPreferredTarget) { + if (!desc.contains("preferredtarget")) + desc["preferredtarget"] = desc["gameid"]; + + desc["preferredtarget"] = generatePreferredTarget(desc["preferredtarget"], realDesc); + } +} + GameList detectAllGames( const FSList &fslist, const Common::ADParams ¶ms ) { ADGameDescList matches = detectGame(&fslist, params, Common::UNK_LANG, Common::kPlatformUnknown); - GameList detectedGames; - for (uint i = 0; i < matches.size(); i++) { - GameDescriptor desc(toGameDescriptor(*matches[i], params.list)); - - if (params.singleid != NULL) { - desc["preferredtarget"] = desc["gameid"]; - desc["gameid"] = params.singleid; - } - if (params.flags & kADFlagAugmentPreferredTarget) { - if (!desc.contains("preferredtarget")) - desc["preferredtarget"] = desc["gameid"]; - - desc["preferredtarget"] = generatePreferredTarget(desc["preferredtarget"], matches[i]); + // Use fallback detector if there were no matches by other means + if (matches.empty() && params.fallbackDetectFunc != NULL) { + EncapsulatedADGameDesc fallbackDesc = (*params.fallbackDetectFunc)(&fslist); + if (fallbackDesc.realDesc != 0) { + GameDescriptor desc(toGameDescriptor(fallbackDesc, params.list)); + updateGameDescriptor(desc, fallbackDesc.realDesc, params); + detectedGames.push_back(desc); } - + } else for (uint i = 0; i < matches.size(); i++) { // Otherwise use the found matches + GameDescriptor desc(toGameDescriptor(*matches[i], params.list)); + updateGameDescriptor(desc, matches[i], params); detectedGames.push_back(desc); } return detectedGames; } -const ADGameDescription *detectBestMatchingGame( +EncapsulatedADGameDesc detectBestMatchingGame( const Common::ADParams ¶ms ) { const ADGameDescription *agdDesc = 0; + EncapsulatedADGameDesc result; Common::Language language = Common::UNK_LANG; Common::Platform platform = Common::kPlatformUnknown; @@ -189,39 +244,29 @@ const ADGameDescription *detectBestMatchingGame( agdDesc = matches[0]; } - if (agdDesc != 0) { - debug(2, "Running %s", toGameDescriptor(*agdDesc, params.list).description().c_str()); + if (agdDesc != 0) { // Check if we found a match without fallback detection + result = EncapsulatedADGameDesc(agdDesc); + } else if (params.fallbackDetectFunc != NULL) { // Use fallback detector if there were no matches by other means + EncapsulatedADGameDesc fallbackDesc = (*params.fallbackDetectFunc)(NULL); + if (fallbackDesc.realDesc != 0 && (params.singleid != NULL || fallbackDesc.getGameID() == gameid)) { + result = fallbackDesc; // Found a fallback match + } + } + + if (result.realDesc != 0) { + debug(2, "Running %s", toGameDescriptor(result, params.list).description().c_str()); } - return agdDesc; + return result; } PluginError detectGameForEngineCreation( const Common::ADParams ¶ms ) { - Common::String gameid = ConfMan.get("gameid"); + upgradeTargetIfNecessary(params); - if (params.obsoleteList != 0) { - for (const Common::ADObsoleteGameID *o = params.obsoleteList; o->from; ++o) { - if (!scumm_stricmp(gameid.c_str(), 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); - - if (ConfMan.hasKey("id_came_from_command_line")) { - warning("Target came from command line. Skipping save"); - } else { - ConfMan.flushToDisk(); - } - break; - } - } - } + Common::String gameid = ConfMan.get("gameid"); FSList fslist; FilesystemNode dir(ConfMan.get("path")); @@ -241,6 +286,14 @@ PluginError detectGameForEngineCreation( } } + // Use fallback detector if there were no matches by other means + if (params.fallbackDetectFunc != NULL) { + EncapsulatedADGameDesc fallbackDesc = (*params.fallbackDetectFunc)(&fslist); + if (fallbackDesc.realDesc != 0 && (params.singleid != NULL || fallbackDesc.getGameID() == gameid)) { + return kNoError; + } + } + return kNoGameDataFoundError; } @@ -491,11 +544,6 @@ static ADGameDescList detectGame(const FSList *fslist, const Common::ADParams &p } } - // If we still haven't got a match, try to use the fallback callback :-) - if (matched.empty() && params.fallbackDetectFunc != 0) { - matched = (*params.fallbackDetectFunc)(fslist); - } - return matched; } -- cgit v1.2.3 From d6e47d5fd322cf7cb61bee94b946096ecef64abb Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 15 Jun 2007 17:36:41 +0000 Subject: ADV detector: Refactored findGameID() a bit, making it possible to use it outside the AdvancedDetector framework; also made it generate somewhat more user friendly desc for obsolete game IDs svn-id: r27424 --- common/advancedDetector.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'common/advancedDetector.cpp') diff --git a/common/advancedDetector.cpp b/common/advancedDetector.cpp index 7d7cadbade..6b4d3f685e 100644 --- a/common/advancedDetector.cpp +++ b/common/advancedDetector.cpp @@ -100,25 +100,31 @@ static void upgradeTargetIfNecessary(const Common::ADParams ¶ms) { GameDescriptor findGameID( const char *gameid, - const Common::ADParams ¶ms + const PlainGameDescriptor *list, + const Common::ADObsoleteGameID *obsoleteList ) { - const PlainGameDescriptor *g = params.list; - while (g->gameid) { - if (0 == scumm_stricmp(gameid, g->gameid)) - return GameDescriptor(*g); - g++; - } - - if (params.obsoleteList != 0) { - const Common::ADObsoleteGameID *o = params.obsoleteList; + // First search the list of supported game IDs for a match. + const PlainGameDescriptor *g = findPlainGameDescriptor(gameid, list); + if (g) + return GameDescriptor(*g); + + // If we didn't find the gameid in the main list, check if it + // is an obsolete game id. + if (obsoleteList != 0) { + const Common::ADObsoleteGameID *o = obsoleteList; while (o->from) { if (0 == scumm_stricmp(gameid, o->from)) { - return GameDescriptor(gameid, "Obsolete game ID"); + g = findPlainGameDescriptor(o->to, list); + if (g && g->description) + return GameDescriptor(gameid, "Obsolete game ID (" + Common::String(g->description) + ")"); + else + return GameDescriptor(gameid, "Obsolete game ID"); } o++; } } + // No match found return GameDescriptor(); } -- cgit v1.2.3 From 0a7bb215d9d4888c7106b41f6ca2ee46e09bca70 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 15 Jun 2007 17:37:28 +0000 Subject: Added a FIXME comment to the adv. detector code regarding (not) using FSNode/FSList svn-id: r27425 --- common/advancedDetector.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'common/advancedDetector.cpp') diff --git a/common/advancedDetector.cpp b/common/advancedDetector.cpp index 6b4d3f685e..a342ed910a 100644 --- a/common/advancedDetector.cpp +++ b/common/advancedDetector.cpp @@ -338,6 +338,9 @@ static ADGameDescList detectGame(const FSList *fslist, const Common::ADParams &p } } + // TODO/FIXME: Fingolfin says: It's not good that we have two different code paths here, + // one using a FSList, one using File::open, as that will lead to discrepancies and subtle + // problems caused by those. if (fslist != 0) { // Get the information of the existing files for (FSList::const_iterator file = fslist->begin(); file != fslist->end(); ++file) { -- cgit v1.2.3