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 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) (limited to 'base/commandLine.cpp') 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; } -- 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 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'base/commandLine.cpp') 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 -- 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/commandLine.cpp') 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 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 35 deletions(-) (limited to 'base/commandLine.cpp') 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 } -- 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 +++----------------------------------------- 1 file changed, 3 insertions(+), 41 deletions(-) (limited to 'base/commandLine.cpp') 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++; } } -- 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 ++++++++++++++++++++++------------------------------ 1 file changed, 26 insertions(+), 35 deletions(-) (limited to 'base/commandLine.cpp') 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) { -- cgit v1.2.3