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 --- gui/launcher.cpp | 54 +----------------------------------------------------- gui/launcher.h | 2 -- gui/massadd.cpp | 5 +---- gui/massadd.h | 1 + 4 files changed, 3 insertions(+), 59 deletions(-) (limited to 'gui') diff --git a/gui/launcher.cpp b/gui/launcher.cpp index 4edd3527f4..67a62ad61e 100644 --- a/gui/launcher.cpp +++ b/gui/launcher.cpp @@ -376,58 +376,6 @@ void LauncherDialog::addGame() { } while (looping); } -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 - -Common::String addGameToConf(const GameDescriptor &result) { - // 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 = result.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 - // FIXME: Factor out - addStringToConf("gameid", result.gameId, domain); - addStringToConf("description", result.description, domain); - addStringToConf("language", Common::getLanguageCode(result.language), domain); - addStringToConf("platform", Common::getPlatformCode(result.platform), domain); - addStringToConf("path", result.path, domain); - addStringToConf("extra", result.extra, domain); - addStringToConf("guioptions", result.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 ot 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; -} - void LauncherDialog::removeGame(int item) { MessageDialog alert(_("Do you really want to remove this game configuration?"), _("Yes"), _("No")); @@ -623,7 +571,7 @@ bool LauncherDialog::doGameDetection(const Common::String &path) { if (0 <= idx && idx < (int)candidates.size()) { const GameDescriptor &result = candidates[idx].matchedGame; - Common::String domain = addGameToConf(result); + Common::String domain = EngineMan.createTargetForGame(result); // Display edit dialog for the new entry EditGameDialog editDialog(domain); diff --git a/gui/launcher.h b/gui/launcher.h index 08413fe3d2..9f0a1c8e95 100644 --- a/gui/launcher.h +++ b/gui/launcher.h @@ -38,8 +38,6 @@ class StaticTextWidget; class EditTextWidget; class SaveLoadChooser; -Common::String addGameToConf(const GameDescriptor &result); - class LauncherDialog : public Dialog { typedef Common::String String; typedef Common::Array StringArray; diff --git a/gui/massadd.cpp b/gui/massadd.cpp index 7c54c503a3..56b15ecfd7 100644 --- a/gui/massadd.cpp +++ b/gui/massadd.cpp @@ -28,10 +28,7 @@ #include "common/taskbar.h" #include "common/translation.h" -#include "gui/launcher.h" // For addGameToConf() #include "gui/massadd.h" -#include "gui/widget.h" -#include "gui/widgets/list.h" #ifndef DISABLE_MASS_ADD namespace GUI { @@ -149,7 +146,7 @@ void MassAddDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data debug(1, " Added gameid '%s', desc '%s'\n", iter->gameId.c_str(), iter->description.c_str()); - iter->gameId = addGameToConf(*iter); + iter->gameId = EngineMan.createTargetForGame(*iter); } // Write everything to disk diff --git a/gui/massadd.h b/gui/massadd.h index 58071cda0a..b954c87161 100644 --- a/gui/massadd.h +++ b/gui/massadd.h @@ -24,6 +24,7 @@ #define MASSADD_DIALOG_H #include "gui/dialog.h" +#include "gui/widgets/list.h" #include "common/fs.h" #include "common/hashmap.h" #include "common/stack.h" -- cgit v1.2.3