aboutsummaryrefslogtreecommitdiff
path: root/base
diff options
context:
space:
mode:
authorBastien Bouclet2018-02-04 08:46:12 +0100
committerBastien Bouclet2018-05-10 09:04:23 +0200
commitfaa2534f46611a47913004b55aa0e5ed5b7e4b7a (patch)
tree80d25039401ee215536ff853c043bfd2e62c4ca6 /base
parent1de5aca585af3e04a64a4f287dd348c0e7b4b967 (diff)
downloadscummvm-rg350-faa2534f46611a47913004b55aa0e5ed5b7e4b7a.tar.gz
scummvm-rg350-faa2534f46611a47913004b55aa0e5ed5b7e4b7a.tar.bz2
scummvm-rg350-faa2534f46611a47913004b55aa0e5ed5b7e4b7a.zip
ENGINES: Factor adding games to ConfMan
Diffstat (limited to 'base')
-rw-r--r--base/commandLine.cpp44
-rw-r--r--base/plugins.cpp51
2 files changed, 54 insertions, 41 deletions
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"