From cf1ebf29516bd74927fd7b632b72fd8973f72e98 Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Sat, 2 Dec 2017 17:14:22 +0100 Subject: ENGINES: Add unknown game variants to the game detector results --- base/commandLine.cpp | 38 ++++++++++++++++++++++++++++++-------- base/plugins.cpp | 20 +++++++++++++++----- 2 files changed, 45 insertions(+), 13 deletions(-) (limited to 'base') diff --git a/base/commandLine.cpp b/base/commandLine.cpp index 83c7b56171..8e701408ef 100644 --- a/base/commandLine.cpp +++ b/base/commandLine.cpp @@ -864,12 +864,20 @@ static GameList getGameList(const Common::FSNode &dir) { } // detect Games - GameList candidates(EngineMan.detectGames(files)); - Common::String dataPath = dir.getPath(); - // add game data path - for (GameList::iterator v = candidates.begin(); v != candidates.end(); ++v) { - (*v)["path"] = dataPath; + DetectionResults detectionResults = EngineMan.detectGames(files); + + if (detectionResults.foundUnknownGames()) { + Common::String report = detectionResults.generateUnknownGameReport(false, 80); + g_system->logMessage(LogMessageType::kInfo, report.c_str()); } + + DetectedGames detectedGames = detectionResults.listRecognizedGames(); + + GameList candidates; + for (uint i = 0; i < detectedGames.size(); i++) { + candidates.push_back(detectedGames[i].matchedGame); + } + return candidates; } @@ -1014,7 +1022,14 @@ static void runDetectorTest() { continue; } - GameList candidates(EngineMan.detectGames(files)); + DetectionResults detectionResults = EngineMan.detectGames(files); + DetectedGames detectedGames = detectionResults.listRecognizedGames(); + + GameList candidates; + for (uint i = 0; i < detectedGames.size(); i++) { + candidates.push_back(detectedGames[i].matchedGame); + } + bool gameidDiffers = false; GameList::iterator x; for (x = candidates.begin(); x != candidates.end(); ++x) { @@ -1092,7 +1107,14 @@ void upgradeTargets() { Common::Platform plat = Common::parsePlatform(dom.getVal("platform")); Common::String desc(dom.getVal("description")); - GameList candidates(EngineMan.detectGames(files)); + DetectionResults detectionResults = EngineMan.detectGames(files); + DetectedGames detectedGames = detectionResults.listRecognizedGames(); + + GameList candidates; + for (uint i = 0; i < detectedGames.size(); i++) { + candidates.push_back(detectedGames[i].matchedGame); + } + GameDescriptor *g = 0; // We proceed as follows: @@ -1100,7 +1122,7 @@ void upgradeTargets() { // * If there is a unique detector match, trust it. // * If there are multiple match, run over them comparing gameid, language and platform. // If we end up with a unique match, use it. Otherwise, skip. - if (candidates.size() == 0) { + if (candidates.empty()) { printf(" ... failed to detect game, skipping\n"); continue; } diff --git a/base/plugins.cpp b/base/plugins.cpp index 852786919b..02f6998ad9 100644 --- a/base/plugins.cpp +++ b/base/plugins.cpp @@ -22,6 +22,7 @@ #include "base/plugins.h" +#include "common/translation.h" #include "common/func.h" #include "common/debug.h" #include "common/config-manager.h" @@ -514,8 +515,9 @@ GameDescriptor EngineManager::findGameInLoadedPlugins(const Common::String &game return result; } -GameList EngineManager::detectGames(const Common::FSList &fslist, bool useUnknownGameDialog) const { - GameList candidates; +DetectionResults EngineManager::detectGames(const Common::FSList &fslist) const { + DetectedGames candidates; + Common::String path = fslist.begin()->getParent().getPath(); PluginList plugins; PluginList::const_iterator iter; PluginManager::instance().loadFirstPlugin(); @@ -524,17 +526,25 @@ GameList EngineManager::detectGames(const Common::FSList &fslist, bool useUnknow // Iterate over all known games and for each check if it might be // the game in the presented directory. for (iter = plugins.begin(); iter != plugins.end(); ++iter) { - candidates.push_back((*iter)->get().detectGames(fslist, useUnknownGameDialog)); + const MetaEngine &metaEngine = (*iter)->get(); + DetectedGames engineCandidates = metaEngine.detectGames(fslist); + + for (uint i = 0; i < engineCandidates.size(); i++) { + engineCandidates[i].engineName = metaEngine.getName(); + engineCandidates[i].matchedGame["path"] = path; + candidates.push_back(engineCandidates[i]); + } + } } while (PluginManager::instance().loadNextPlugin()); - return candidates; + + return DetectionResults(candidates); } const PluginList &EngineManager::getPlugins() const { return PluginManager::instance().getPlugins(PLUGIN_TYPE_ENGINE); } - // Music plugins #include "audio/musicplugin.h" -- cgit v1.2.3 From 8fb149e3c7603f023dfccf2b2056a9a2fda431c2 Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Sun, 6 May 2018 12:57:08 +0200 Subject: ENGINES: Change MetaEngine::findGame to return a plain game descriptor --- base/commandLine.cpp | 14 +++++++------- base/main.cpp | 9 ++++++--- base/plugins.cpp | 16 ++++++++-------- 3 files changed, 21 insertions(+), 18 deletions(-) (limited to 'base') diff --git a/base/commandLine.cpp b/base/commandLine.cpp index 8e701408ef..0755165094 100644 --- a/base/commandLine.cpp +++ b/base/commandLine.cpp @@ -714,10 +714,10 @@ static void listTargets() { // FIXME: At this point, we should check for a "gameid" override // to find the proper desc. In fact, the platform probably should // be taken into account, too. - Common::String gameid(name); - GameDescriptor g = EngineMan.findGame(gameid); - if (g.description().size() > 0) - description = g.description(); + const Common::String &gameid = name; + PlainGameDescriptor g = EngineMan.findGame(gameid); + if (g.description) + description = g.description; } targets.push_back(Common::String::format("%-20s %s", name.c_str(), description.c_str())); @@ -770,7 +770,7 @@ static Common::Error listSaves(const Common::String &target) { // Find the plugin that will handle the specified gameid const Plugin *plugin = nullptr; - GameDescriptor game = EngineMan.findGame(gameid, &plugin); + EngineMan.findGame(gameid, &plugin); if (!plugin) { // If the target was specified, treat this as an error, and otherwise skip it. @@ -1276,8 +1276,8 @@ bool processSettings(Common::String &command, Common::StringMap &settings, Commo // domain (i.e. a target) matching this argument, or alternatively // whether there is a gameid matching that name. if (!command.empty()) { - GameDescriptor gd = EngineMan.findGame(command); - if (ConfMan.hasGameDomain(command) || !gd.gameid().empty()) { + PlainGameDescriptor gd = EngineMan.findGame(command); + if (ConfMan.hasGameDomain(command) || gd.gameId) { bool idCameFromCommandLine = false; // WORKAROUND: Fix for bug #1719463: "DETECTOR: Launching diff --git a/base/main.cpp b/base/main.cpp index 8e783c9776..385b8f35a9 100644 --- a/base/main.cpp +++ b/base/main.cpp @@ -128,13 +128,13 @@ static const Plugin *detectPlugin() { printf("User picked target '%s' (gameid '%s')...\n", ConfMan.getActiveDomainName().c_str(), gameid.c_str()); printf(" Looking for a plugin supporting this gameid... "); - GameDescriptor game = EngineMan.findGame(gameid, &plugin); + PlainGameDescriptor game = EngineMan.findGame(gameid, &plugin); if (plugin == 0) { printf("failed\n"); warning("%s is an invalid gameid. Use the --list-games option to list supported gameid", gameid.c_str()); } else { - printf("%s\n Starting '%s'\n", plugin->getName(), game.description().c_str()); + printf("%s\n Starting '%s'\n", plugin->getName(), game.description); } return plugin; @@ -210,7 +210,10 @@ static Common::Error runGame(const Plugin *plugin, OSystem &system, const Common Common::String caption(ConfMan.get("description")); if (caption.empty()) { - caption = EngineMan.findGame(ConfMan.get("gameid")).description(); + PlainGameDescriptor game = EngineMan.findGame(ConfMan.get("gameid")); + if (game.description) { + caption = game.description; + } } if (caption.empty()) caption = ConfMan.getActiveDomainName(); // Use the domain (=target) name diff --git a/base/plugins.cpp b/base/plugins.cpp index 02f6998ad9..25dd3e1e0c 100644 --- a/base/plugins.cpp +++ b/base/plugins.cpp @@ -458,13 +458,13 @@ DECLARE_SINGLETON(EngineManager); * For the uncached version, we first try to find the plugin using the gameId * and only if we can't find it there, we loop through the plugins. **/ -GameDescriptor EngineManager::findGame(const Common::String &gameName, const Plugin **plugin) const { - GameDescriptor result; +PlainGameDescriptor EngineManager::findGame(const Common::String &gameName, const Plugin **plugin) const { + PlainGameDescriptor result; // First look for the game using the plugins in memory. This is critical // for calls coming from inside games result = findGameInLoadedPlugins(gameName, plugin); - if (!result.gameid().empty()) { + if (result.gameId) { return result; } @@ -472,7 +472,7 @@ GameDescriptor EngineManager::findGame(const Common::String &gameName, const Plu // by plugin if (PluginMan.loadPluginFromGameId(gameName)) { result = findGameInLoadedPlugins(gameName, plugin); - if (!result.gameid().empty()) { + if (result.gameId) { return result; } } @@ -481,7 +481,7 @@ GameDescriptor EngineManager::findGame(const Common::String &gameName, const Plu PluginMan.loadFirstPlugin(); do { result = findGameInLoadedPlugins(gameName, plugin); - if (!result.gameid().empty()) { + if (result.gameId) { // Update with new plugin file name PluginMan.updateConfigWithFileName(gameName); break; @@ -494,10 +494,10 @@ GameDescriptor EngineManager::findGame(const Common::String &gameName, const Plu /** * Find the game within the plugins loaded in memory **/ -GameDescriptor EngineManager::findGameInLoadedPlugins(const Common::String &gameName, const Plugin **plugin) const { +PlainGameDescriptor EngineManager::findGameInLoadedPlugins(const Common::String &gameName, const Plugin **plugin) const { // Find the GameDescriptor for this target const PluginList &plugins = getPlugins(); - GameDescriptor result; + PlainGameDescriptor result; if (plugin) *plugin = 0; @@ -506,7 +506,7 @@ GameDescriptor EngineManager::findGameInLoadedPlugins(const Common::String &game for (iter = plugins.begin(); iter != plugins.end(); ++iter) { result = (*iter)->get().findGame(gameName.c_str()); - if (!result.gameid().empty()) { + if (result.gameId) { if (plugin) *plugin = *iter; return result; -- cgit v1.2.3 From 643c24db75797728087999abd8acf1ecc83757fa Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Sun, 6 May 2018 13:09:52 +0200 Subject: ENGINES: Change MetaEngine::listSupportedGames to return plain game descriptors --- base/commandLine.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'base') diff --git a/base/commandLine.cpp b/base/commandLine.cpp index 0755165094..1c7916c48f 100644 --- a/base/commandLine.cpp +++ b/base/commandLine.cpp @@ -687,9 +687,9 @@ static void listGames() { const PluginList &plugins = EngineMan.getPlugins(); for (PluginList::const_iterator iter = plugins.begin(); iter != plugins.end(); ++iter) { - GameList list = (*iter)->get().getSupportedGames(); - for (GameList::iterator v = list.begin(); v != list.end(); ++v) { - printf("%-20s %s\n", v->gameid().c_str(), v->description().c_str()); + PlainGameList list = (*iter)->get().getSupportedGames(); + for (PlainGameList::iterator v = list.begin(); v != list.end(); ++v) { + printf("%-20s %s\n", v->gameId, v->description); } } } -- cgit v1.2.3 From 5aff87dc153f392cb14423efa78a96397789a6fd Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Sun, 3 Dec 2017 12:19:08 +0100 Subject: ENGINES: Turn GameDescriptor into a simple struct --- base/commandLine.cpp | 83 ++++++++++++++++++++++++++++++---------------------- base/plugins.cpp | 2 +- 2 files changed, 49 insertions(+), 36 deletions(-) (limited to 'base') diff --git a/base/commandLine.cpp b/base/commandLine.cpp index 1c7916c48f..e1539d7a3e 100644 --- a/base/commandLine.cpp +++ b/base/commandLine.cpp @@ -881,8 +881,17 @@ static GameList getGameList(const Common::FSNode &dir) { return candidates; } +namespace { + +static void addStringToConf(const Common::String &key, const Common::String &value, const Common::String &domain) { + if (!value.empty()) + ConfMan.set(key, value, domain); +} + +} // End of anonymous namespace + static bool addGameToConf(const GameDescriptor &gd) { - const Common::String &domain = gd.preferredtarget(); + const Common::String &domain = gd.preferredTarget; // If game has already been added, don't add if (ConfMan.hasGameDomain(domain)) @@ -891,18 +900,22 @@ static bool addGameToConf(const GameDescriptor &gd) { // Add the name domain ConfMan.addGameDomain(domain); - // Copy all non-empty key/value pairs into the new domain - for (GameDescriptor::const_iterator iter = gd.begin(); iter != gd.end(); ++iter) { - if (!iter->_value.empty() && iter->_key != "preferredtarget") - ConfMan.set(iter->_key, iter->_value, domain); - } + // Copy all non-empty relevant values into the new domain + // FIXME: Factor out + addStringToConf("gameid", gd.gameId, domain); + addStringToConf("description", gd.description, domain); + addStringToConf("language", Common::getLanguageCode(gd.language), domain); + addStringToConf("platform", Common::getPlatformCode(gd.platform), domain); + addStringToConf("path", gd.path, domain); + addStringToConf("extra", gd.extra, domain); + addStringToConf("guioptions", gd.getGUIOptions(), domain); // Display added game info printf("Game Added: \n GameID: %s\n Name: %s\n Language: %s\n Platform: %s\n", - gd.gameid().c_str(), - gd.description().c_str(), - Common::getLanguageDescription(gd.language()), - Common::getPlatformDescription(gd.platform())); + gd.gameId.c_str(), + gd.description.c_str(), + Common::getLanguageDescription(gd.language), + Common::getPlatformDescription(gd.platform)); return true; } @@ -916,7 +929,7 @@ static GameList recListGames(const Common::FSNode &dir, const Common::String &ga for (Common::FSList::const_iterator file = files.begin(); file != files.end(); ++file) { GameList rec = recListGames(*file, gameId, recursive); for (GameList::const_iterator game = rec.begin(); game != rec.end(); ++game) { - if (gameId.empty() || game->gameid().c_str() == gameId) + if (gameId.empty() || game->gameId == gameId) list.push_back(*game); } } @@ -946,23 +959,23 @@ static Common::String detectGames(const Common::String &path, const Common::Stri printf("ID Description Full Path\n"); printf("-------------- ---------------------------------------------------------- ---------------------------------------------------------\n"); for (GameList::iterator v = candidates.begin(); v != candidates.end(); ++v) { - printf("%-14s %-58s %s\n", v->gameid().c_str(), v->description().c_str(), (*v)["path"].c_str()); + printf("%-14s %-58s %s\n", v->gameId.c_str(), v->description.c_str(), v->path.c_str()); } - return candidates[0].gameid(); + return candidates[0].gameId; } static int recAddGames(const Common::FSNode &dir, const Common::String &game, bool recursive) { int count = 0; GameList list = getGameList(dir); for (GameList::iterator v = list.begin(); v != list.end(); ++v) { - if (v->gameid().c_str() != game && !game.empty()) { - printf("Found %s, only adding %s per --game option, ignoring...\n", v->gameid().c_str(), game.c_str()); + if (v->gameId != game && !game.empty()) { + printf("Found %s, only adding %s per --game option, ignoring...\n", v->gameId.c_str(), game.c_str()); } else if (!addGameToConf(*v)) { // TODO Is it reall the case that !addGameToConf iff already added? - printf("Found %s, but has already been added, skipping\n", v->gameid().c_str()); + printf("Found %s, but has already been added, skipping\n", v->gameId.c_str()); } else { - printf("Found %s, adding...\n", v->gameid().c_str()); + printf("Found %s, adding...\n", v->gameId.c_str()); count++; } } @@ -1033,7 +1046,7 @@ static void runDetectorTest() { bool gameidDiffers = false; GameList::iterator x; for (x = candidates.begin(); x != candidates.end(); ++x) { - gameidDiffers |= (scumm_stricmp(gameid.c_str(), x->gameid().c_str()) != 0); + gameidDiffers |= (scumm_stricmp(gameid.c_str(), x->gameId.c_str()) != 0); } if (candidates.empty()) { @@ -1056,10 +1069,10 @@ static void runDetectorTest() { for (x = candidates.begin(); x != candidates.end(); ++x) { printf(" gameid '%s', desc '%s', language '%s', platform '%s'\n", - x->gameid().c_str(), - x->description().c_str(), - Common::getLanguageCode(x->language()), - Common::getPlatformCode(x->platform())); + x->gameId.c_str(), + x->description.c_str(), + Common::getLanguageDescription(x->language), + Common::getPlatformDescription(x->platform)); } } int total = domains.size(); @@ -1131,7 +1144,7 @@ void upgradeTargets() { GameList::iterator x; int matchesFound = 0; for (x = candidates.begin(); x != candidates.end(); ++x) { - if (x->gameid() == gameid && x->language() == lang && x->platform() == plat) { + if (x->gameId == gameid && x->language == lang && x->platform == plat) { matchesFound++; g = &(*x); } @@ -1149,27 +1162,27 @@ void upgradeTargets() { // the target referred to by dom. We update several things // Always set the gameid explicitly (in case of legacy targets) - dom["gameid"] = g->gameid(); + dom["gameid"] = g->gameId; // Always set the GUI options. The user should not modify them, and engines might // gain more features over time, so we want to keep this list up-to-date. - if (g->contains("guioptions")) { - printf(" -> update guioptions to '%s'\n", (*g)["guioptions"].c_str()); - dom["guioptions"] = (*g)["guioptions"]; + if (!g->getGUIOptions().empty()) { + printf(" -> update guioptions to '%s'\n", g->getGUIOptions().c_str()); + dom["guioptions"] = g->getGUIOptions(); } else if (dom.contains("guioptions")) { dom.erase("guioptions"); } // Update the language setting but only if none has been set yet. - if (lang == Common::UNK_LANG && g->language() != Common::UNK_LANG) { - printf(" -> set language to '%s'\n", Common::getLanguageCode(g->language())); - dom["language"] = (*g)["language"]; + if (lang == Common::UNK_LANG && g->language != Common::UNK_LANG) { + printf(" -> set language to '%s'\n", Common::getLanguageCode(g->language)); + dom["language"] = Common::getLanguageCode(g->language); } // Update the platform setting but only if none has been set yet. - if (plat == Common::kPlatformUnknown && g->platform() != Common::kPlatformUnknown) { - printf(" -> set platform to '%s'\n", Common::getPlatformCode(g->platform())); - dom["platform"] = (*g)["platform"]; + if (plat == Common::kPlatformUnknown && g->platform != Common::kPlatformUnknown) { + printf(" -> set platform to '%s'\n", Common::getPlatformCode(g->platform)); + dom["platform"] = Common::getPlatformCode(g->platform); } // TODO: We could also update the description. But not everybody will want that. @@ -1178,8 +1191,8 @@ void upgradeTargets() { // should only be updated if the user explicitly requests this. #if 0 if (desc != g->description()) { - printf(" -> update desc from '%s' to\n '%s' ?\n", desc.c_str(), g->description().c_str()); - dom["description"] = (*g)["description"]; + printf(" -> update desc from '%s' to\n '%s' ?\n", desc.c_str(), g->description.c_str()); + dom["description"] = g->description; } #endif } diff --git a/base/plugins.cpp b/base/plugins.cpp index 25dd3e1e0c..61dae910f9 100644 --- a/base/plugins.cpp +++ b/base/plugins.cpp @@ -531,7 +531,7 @@ DetectionResults EngineManager::detectGames(const Common::FSList &fslist) const for (uint i = 0; i < engineCandidates.size(); i++) { engineCandidates[i].engineName = metaEngine.getName(); - engineCandidates[i].matchedGame["path"] = path; + engineCandidates[i].matchedGame.path = path; candidates.push_back(engineCandidates[i]); } -- cgit v1.2.3 From faa2534f46611a47913004b55aa0e5ed5b7e4b7a Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Sun, 4 Feb 2018 08:46:12 +0100 Subject: ENGINES: Factor adding games to ConfMan --- base/commandLine.cpp | 44 +++----------------------------------------- base/plugins.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 41 deletions(-) (limited to 'base') diff --git a/base/commandLine.cpp b/base/commandLine.cpp index e1539d7a3e..02c3d1c454 100644 --- a/base/commandLine.cpp +++ b/base/commandLine.cpp @@ -881,45 +881,6 @@ static GameList getGameList(const Common::FSNode &dir) { return candidates; } -namespace { - -static void addStringToConf(const Common::String &key, const Common::String &value, const Common::String &domain) { - if (!value.empty()) - ConfMan.set(key, value, domain); -} - -} // End of anonymous namespace - -static bool addGameToConf(const GameDescriptor &gd) { - const Common::String &domain = gd.preferredTarget; - - // If game has already been added, don't add - if (ConfMan.hasGameDomain(domain)) - return false; - - // Add the name domain - ConfMan.addGameDomain(domain); - - // Copy all non-empty relevant values into the new domain - // FIXME: Factor out - addStringToConf("gameid", gd.gameId, domain); - addStringToConf("description", gd.description, domain); - addStringToConf("language", Common::getLanguageCode(gd.language), domain); - addStringToConf("platform", Common::getPlatformCode(gd.platform), domain); - addStringToConf("path", gd.path, domain); - addStringToConf("extra", gd.extra, domain); - addStringToConf("guioptions", gd.getGUIOptions(), domain); - - // Display added game info - printf("Game Added: \n GameID: %s\n Name: %s\n Language: %s\n Platform: %s\n", - gd.gameId.c_str(), - gd.description.c_str(), - Common::getLanguageDescription(gd.language), - Common::getPlatformDescription(gd.platform)); - - return true; -} - static GameList recListGames(const Common::FSNode &dir, const Common::String &gameId, bool recursive) { GameList list = getGameList(dir); @@ -971,11 +932,12 @@ static int recAddGames(const Common::FSNode &dir, const Common::String &game, bo for (GameList::iterator v = list.begin(); v != list.end(); ++v) { if (v->gameId != game && !game.empty()) { printf("Found %s, only adding %s per --game option, ignoring...\n", v->gameId.c_str(), game.c_str()); - } else if (!addGameToConf(*v)) { - // TODO Is it reall the case that !addGameToConf iff already added? + } else if (ConfMan.hasGameDomain(v->preferredTarget)) { + // TODO Better check for game already added? printf("Found %s, but has already been added, skipping\n", v->gameId.c_str()); } else { printf("Found %s, adding...\n", v->gameId.c_str()); + EngineMan.createTargetForGame(*v); count++; } } diff --git a/base/plugins.cpp b/base/plugins.cpp index 61dae910f9..1bfb929950 100644 --- a/base/plugins.cpp +++ b/base/plugins.cpp @@ -545,6 +545,57 @@ const PluginList &EngineManager::getPlugins() const { return PluginManager::instance().getPlugins(PLUGIN_TYPE_ENGINE); } +namespace { + +void addStringToConf(const Common::String &key, const Common::String &value, const Common::String &domain) { + if (!value.empty()) + ConfMan.set(key, value, domain); +} + +} // End of anonymous namespace + +Common::String EngineManager::createTargetForGame(const GameDescriptor &game) { + // The auto detector or the user made a choice. + // Pick a domain name which does not yet exist (after all, we + // are *adding* a game to the config, not replacing). + Common::String domain = game.preferredTarget; + + assert(!domain.empty()); + if (ConfMan.hasGameDomain(domain)) { + int suffixN = 1; + Common::String gameid(domain); + + while (ConfMan.hasGameDomain(domain)) { + domain = gameid + Common::String::format("-%d", suffixN); + suffixN++; + } + } + + // Add the name domain + ConfMan.addGameDomain(domain); + + // Copy all non-empty relevant values into the new domain + addStringToConf("gameid", game.gameId, domain); + addStringToConf("description", game.description, domain); + addStringToConf("language", Common::getLanguageCode(game.language), domain); + addStringToConf("platform", Common::getPlatformCode(game.platform), domain); + addStringToConf("path", game.path, domain); + addStringToConf("extra", game.extra, domain); + addStringToConf("guioptions", game.getGUIOptions(), domain); + + // TODO: Setting the description field here has the drawback + // that the user does never notice when we upgrade our descriptions. + // It might be nice to leave this field empty, and only set it to + // a value when the user edits the description string. + // However, at this point, that's impractical. Once we have a method + // to query all backends for the proper & full description of a given + // game target, we can change this (currently, you can only query + // for the generic gameid description; it's not possible to obtain + // a description which contains extended information like language, etc.). + + return domain; +} + // Music plugins #include "audio/musicplugin.h" -- cgit v1.2.3 From 90b78c544657bf0fc41d6b86276a0873060345b5 Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Sun, 6 May 2018 15:51:03 +0200 Subject: ENGINES: Merge GameDescriptor and DetectedGame --- base/commandLine.cpp | 61 ++++++++++++++++++++++------------------------------ base/plugins.cpp | 4 ++-- 2 files changed, 28 insertions(+), 37 deletions(-) (limited to 'base') diff --git a/base/commandLine.cpp b/base/commandLine.cpp index 02c3d1c454..96548b9129 100644 --- a/base/commandLine.cpp +++ b/base/commandLine.cpp @@ -854,13 +854,13 @@ static void listAudioDevices() { } /** Display all games in the given directory, or current directory if empty */ -static GameList getGameList(const Common::FSNode &dir) { +static DetectedGames getGameList(const Common::FSNode &dir) { Common::FSList files; // Collect all files from directory if (!dir.getChildren(files, Common::FSNode::kListAll)) { printf("Path %s does not exist or is not a directory.\n", dir.getPath().c_str()); - return GameList(); + return DetectedGames(); } // detect Games @@ -871,25 +871,18 @@ static GameList getGameList(const Common::FSNode &dir) { g_system->logMessage(LogMessageType::kInfo, report.c_str()); } - DetectedGames detectedGames = detectionResults.listRecognizedGames(); - - GameList candidates; - for (uint i = 0; i < detectedGames.size(); i++) { - candidates.push_back(detectedGames[i].matchedGame); - } - - return candidates; + return detectionResults.listRecognizedGames(); } -static GameList recListGames(const Common::FSNode &dir, const Common::String &gameId, bool recursive) { - GameList list = getGameList(dir); +static DetectedGames recListGames(const Common::FSNode &dir, const Common::String &gameId, bool recursive) { + DetectedGames list = getGameList(dir); if (recursive) { Common::FSList files; dir.getChildren(files, Common::FSNode::kListDirectoriesOnly); for (Common::FSList::const_iterator file = files.begin(); file != files.end(); ++file) { - GameList rec = recListGames(*file, gameId, recursive); - for (GameList::const_iterator game = rec.begin(); game != rec.end(); ++game) { + DetectedGames rec = recListGames(*file, gameId, recursive); + for (DetectedGames::const_iterator game = rec.begin(); game != rec.end(); ++game) { if (gameId.empty() || game->gameId == gameId) list.push_back(*game); } @@ -904,7 +897,7 @@ static Common::String detectGames(const Common::String &path, const Common::Stri bool noPath = path.empty(); //Current directory Common::FSNode dir(path); - GameList candidates = recListGames(dir, gameId, recursive); + DetectedGames candidates = recListGames(dir, gameId, recursive); if (candidates.empty()) { printf("WARNING: ScummVM could not find any game in %s\n", dir.getPath().c_str()); @@ -919,7 +912,7 @@ static Common::String detectGames(const Common::String &path, const Common::Stri // TODO this is not especially pretty printf("ID Description Full Path\n"); printf("-------------- ---------------------------------------------------------- ---------------------------------------------------------\n"); - for (GameList::iterator v = candidates.begin(); v != candidates.end(); ++v) { + for (DetectedGames::const_iterator v = candidates.begin(); v != candidates.end(); ++v) { printf("%-14s %-58s %s\n", v->gameId.c_str(), v->description.c_str(), v->path.c_str()); } @@ -928,17 +921,25 @@ static Common::String detectGames(const Common::String &path, const Common::Stri static int recAddGames(const Common::FSNode &dir, const Common::String &game, bool recursive) { int count = 0; - GameList list = getGameList(dir); - for (GameList::iterator v = list.begin(); v != list.end(); ++v) { + DetectedGames list = getGameList(dir); + for (DetectedGames::const_iterator v = list.begin(); v != list.end(); ++v) { if (v->gameId != game && !game.empty()) { printf("Found %s, only adding %s per --game option, ignoring...\n", v->gameId.c_str(), game.c_str()); } else if (ConfMan.hasGameDomain(v->preferredTarget)) { // TODO Better check for game already added? printf("Found %s, but has already been added, skipping\n", v->gameId.c_str()); } else { - printf("Found %s, adding...\n", v->gameId.c_str()); - EngineMan.createTargetForGame(*v); + Common::String target = EngineMan.createTargetForGame(*v); count++; + + // Display added game info + printf("Game Added: \n Target: %s\n GameID: %s\n Name: %s\n Language: %s\n Platform: %s\n", + target.c_str(), + v->gameId.c_str(), + v->description.c_str(), + Common::getLanguageDescription(v->language), + Common::getPlatformDescription(v->platform) + ); } } @@ -998,15 +999,10 @@ static void runDetectorTest() { } DetectionResults detectionResults = EngineMan.detectGames(files); - DetectedGames detectedGames = detectionResults.listRecognizedGames(); - - GameList candidates; - for (uint i = 0; i < detectedGames.size(); i++) { - candidates.push_back(detectedGames[i].matchedGame); - } + DetectedGames candidates = detectionResults.listRecognizedGames(); bool gameidDiffers = false; - GameList::iterator x; + DetectedGames::const_iterator x; for (x = candidates.begin(); x != candidates.end(); ++x) { gameidDiffers |= (scumm_stricmp(gameid.c_str(), x->gameId.c_str()) != 0); } @@ -1083,14 +1079,9 @@ void upgradeTargets() { Common::String desc(dom.getVal("description")); DetectionResults detectionResults = EngineMan.detectGames(files); - DetectedGames detectedGames = detectionResults.listRecognizedGames(); - - GameList candidates; - for (uint i = 0; i < detectedGames.size(); i++) { - candidates.push_back(detectedGames[i].matchedGame); - } + DetectedGames candidates = detectionResults.listRecognizedGames(); - GameDescriptor *g = 0; + DetectedGame *g = 0; // We proceed as follows: // * If detection failed to produce candidates, skip. @@ -1103,7 +1094,7 @@ void upgradeTargets() { } if (candidates.size() > 1) { // Scan over all candidates, check if there is a unique match for gameid, language and platform - GameList::iterator x; + DetectedGames::iterator x; int matchesFound = 0; for (x = candidates.begin(); x != candidates.end(); ++x) { if (x->gameId == gameid && x->language == lang && x->platform == plat) { diff --git a/base/plugins.cpp b/base/plugins.cpp index 1bfb929950..40a4d77053 100644 --- a/base/plugins.cpp +++ b/base/plugins.cpp @@ -531,7 +531,7 @@ DetectionResults EngineManager::detectGames(const Common::FSList &fslist) const for (uint i = 0; i < engineCandidates.size(); i++) { engineCandidates[i].engineName = metaEngine.getName(); - engineCandidates[i].matchedGame.path = path; + engineCandidates[i].path = path; candidates.push_back(engineCandidates[i]); } @@ -554,7 +554,7 @@ void addStringToConf(const Common::String &key, const Common::String &value, con } // End of anonymous namespace -Common::String EngineManager::createTargetForGame(const GameDescriptor &game) { +Common::String EngineManager::createTargetForGame(const DetectedGame &game) { // The auto detector or the user made a choice. // Pick a domain name which does not yet exist (after all, we // are *adding* a game to the config, not replacing). -- cgit v1.2.3 From 1dcb8076db64420ab28722a73583f89b38314e71 Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Thu, 10 May 2018 09:26:26 +0200 Subject: ENGINES: Remove usage of C++11 extended initializer lists --- base/plugins.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'base') diff --git a/base/plugins.cpp b/base/plugins.cpp index 40a4d77053..023f2f3bb3 100644 --- a/base/plugins.cpp +++ b/base/plugins.cpp @@ -459,11 +459,9 @@ DECLARE_SINGLETON(EngineManager); * and only if we can't find it there, we loop through the plugins. **/ PlainGameDescriptor EngineManager::findGame(const Common::String &gameName, const Plugin **plugin) const { - PlainGameDescriptor result; - // First look for the game using the plugins in memory. This is critical // for calls coming from inside games - result = findGameInLoadedPlugins(gameName, plugin); + PlainGameDescriptor result = findGameInLoadedPlugins(gameName, plugin); if (result.gameId) { return result; } @@ -497,7 +495,6 @@ PlainGameDescriptor EngineManager::findGame(const Common::String &gameName, cons PlainGameDescriptor EngineManager::findGameInLoadedPlugins(const Common::String &gameName, const Plugin **plugin) const { // Find the GameDescriptor for this target const PluginList &plugins = getPlugins(); - PlainGameDescriptor result; if (plugin) *plugin = 0; @@ -505,14 +502,15 @@ PlainGameDescriptor EngineManager::findGameInLoadedPlugins(const Common::String PluginList::const_iterator iter; for (iter = plugins.begin(); iter != plugins.end(); ++iter) { - result = (*iter)->get().findGame(gameName.c_str()); - if (result.gameId) { + PlainGameDescriptor pgd = (*iter)->get().findGame(gameName.c_str()); + if (pgd.gameId) { if (plugin) *plugin = *iter; - return result; + return pgd; } } - return result; + + return PlainGameDescriptor::empty(); } DetectionResults EngineManager::detectGames(const Common::FSList &fslist) const { -- cgit v1.2.3