ENGINES: Factor adding games to ConfMan
This commit is contained in:
parent
1de5aca585
commit
faa2534f46
7 changed files with 64 additions and 100 deletions
|
@ -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++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -271,6 +271,13 @@ public:
|
|||
PlainGameDescriptor findGame(const Common::String &gameName, const Plugin **plugin = NULL) const;
|
||||
DetectionResults detectGames(const Common::FSList &fslist) const;
|
||||
const PluginList &getPlugins() const;
|
||||
|
||||
/**
|
||||
* Create a target from the supplied game descriptor
|
||||
*
|
||||
* Returns the created target name.
|
||||
*/
|
||||
Common::String createTargetForGame(const GameDescriptor &game);
|
||||
};
|
||||
|
||||
/** Convenience shortcut for accessing the engine manager. */
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<Common::String> StringArray;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue