From 7b63eadb50e55575abf501922e8aab8846e2bcf1 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sun, 2 Apr 2006 21:06:49 +0000 Subject: Move handling of --list-targets and --list-games to a later point (after plugin & config file loading), to make them work properly again. svn-id: r21569 --- base/gameDetector.cpp | 54 +++++--------------------------------------- base/gameDetector.h | 2 +- base/main.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 68 insertions(+), 50 deletions(-) (limited to 'base') diff --git a/base/gameDetector.cpp b/base/gameDetector.cpp index 57de0871e4..e10ad0e694 100644 --- a/base/gameDetector.cpp +++ b/base/gameDetector.cpp @@ -252,49 +252,6 @@ GameDetector::GameDetector() { _plugin = 0; } -/** List all supported game IDs, i.e. all games which any loaded plugin supports. */ -void listGames() { - const PluginList &plugins = PluginManager::instance().getPlugins(); - - printf("Game ID Full Title \n" - "-------------------- ------------------------------------------------------\n"); - - PluginList::const_iterator iter = plugins.begin(); - for (iter = plugins.begin(); iter != plugins.end(); ++iter) { - GameList list = (*iter)->getSupportedGames(); - for (GameList::iterator v = list.begin(); v != list.end(); ++v) { - printf("%-20s %s\n", v->gameid.c_str(), v->description.c_str()); - } - } -} - -/** List all targets which are configured in the config file. */ -void listTargets() { - using namespace Common; - const ConfigManager::DomainMap &domains = ConfMan.getGameDomains(); - - printf("Target Description \n" - "-------------------- ------------------------------------------------------\n"); - - ConfigManager::DomainMap::const_iterator iter = domains.begin(); - for (iter = domains.begin(); iter != domains.end(); ++iter) { - String name(iter->_key); - String description(iter->_value.get("description")); - - if (description.empty()) { - // 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. - String gameid(name); - GameDescriptor g = GameDetector::findGame(gameid); - if (g.description.size() > 0) - description = g.description; - } - - printf("%-20s %s\n", name.c_str(), description.c_str()); - } -} - GameDescriptor GameDetector::findGame(const String &gameName, const Plugin **plugin) { // Find the GameDescriptor for this target const PluginList &plugins = PluginManager::instance().getPlugins(); @@ -372,7 +329,7 @@ GameDescriptor GameDetector::findGame(const String &gameName, const Plugin **plu } -void GameDetector::parseCommandLine(Common::StringMap &settings, int argc, char **argv) { +Common::String GameDetector::parseCommandLine(Common::StringMap &settings, int argc, char **argv) { const char *s, *s2; // argv[0] contains the name of the executable. @@ -415,13 +372,11 @@ void GameDetector::parseCommandLine(Common::StringMap &settings, int argc, char END_OPTION DO_OPTION_CMD('t', "list-targets") - listTargets(); - exit(0); + return "list-targets"; END_OPTION DO_OPTION_CMD('z', "list-games") - listGames(); - exit(0); + return "list-games"; END_OPTION @@ -576,6 +531,9 @@ unknownOption: usage("Unrecognized option '%s'", argv[i]); } } + + + return Common::String::emptyString; } diff --git a/base/gameDetector.h b/base/gameDetector.h index ab891b325a..5299e3cbe5 100644 --- a/base/gameDetector.h +++ b/base/gameDetector.h @@ -69,7 +69,7 @@ class GameDetector { public: GameDetector(); - static void parseCommandLine(Common::StringMap &settings, int argc, char **argv); + static Common::String parseCommandLine(Common::StringMap &settings, int argc, char **argv); void processSettings(Common::StringMap &settings); bool detectMain(); diff --git a/base/main.cpp b/base/main.cpp index 01b00a9eaa..a15380a28c 100644 --- a/base/main.cpp +++ b/base/main.cpp @@ -142,6 +142,49 @@ const char *gScummVMFeatures = "" #endif ; +/** List all supported game IDs, i.e. all games which any loaded plugin supports. */ +void listGames() { + const PluginList &plugins = PluginManager::instance().getPlugins(); + + printf("Game ID Full Title \n" + "-------------------- ------------------------------------------------------\n"); + + PluginList::const_iterator iter = plugins.begin(); + for (iter = plugins.begin(); iter != plugins.end(); ++iter) { + GameList list = (*iter)->getSupportedGames(); + for (GameList::iterator v = list.begin(); v != list.end(); ++v) { + printf("%-20s %s\n", v->gameid.c_str(), v->description.c_str()); + } + } +} + +/** List all targets which are configured in the config file. */ +void listTargets() { + using namespace Common; + const ConfigManager::DomainMap &domains = ConfMan.getGameDomains(); + + printf("Target Description \n" + "-------------------- ------------------------------------------------------\n"); + + ConfigManager::DomainMap::const_iterator iter = domains.begin(); + for (iter = domains.begin(); iter != domains.end(); ++iter) { + String name(iter->_key); + String description(iter->_value.get("description")); + + if (description.empty()) { + // 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. + String gameid(name); + GameDescriptor g = GameDetector::findGame(gameid); + if (g.description.size() > 0) + description = g.description; + } + + printf("%-20s %s\n", name.c_str(), description.c_str()); + } +} + static void setupDummyPalette(OSystem &system) { // FIXME - mouse cursors are currently always set via 8 bit data. // Thus for now we need to setup a dummy palette. On the long run, we might @@ -271,6 +314,7 @@ extern "C" int scummvm_main(GameDetector &detector, int argc, char *argv[]) { extern "C" int scummvm_main(int argc, char *argv[]) { #endif Common::String specialDebug; + Common::String command; bool running = true; // Verify that the backend has been initialized (i.e. g_system has been set). @@ -279,7 +323,7 @@ extern "C" int scummvm_main(int argc, char *argv[]) { // Parse the command line Common::StringMap settings; - GameDetector::parseCommandLine(settings, argc, argv); + command = GameDetector::parseCommandLine(settings, argc, argv); // Load the config file (possibly overriden via command line): if (settings.contains("config")) { @@ -303,6 +347,22 @@ extern "C" int scummvm_main(int argc, char *argv[]) { // Load the plugins PluginManager::instance().loadPlugins(); + + + // Handle commands passed via the command line (like --list-targets and + // --list-games). This must be done after the config file and the plugins + // have been loaded. + // FIXME: The way are are doing this is rather arbitrary at this time. + // E.g. --version and --help are very similar, but are still handled + // inside parseCommandLine. This should be unified. + if (command == "list-targets") { + listTargets(); + exit(0); + } else if (command == "list-games") { + listGames(); + exit(0); + } + // Process the command line settings #ifndef _WIN32_WCE -- cgit v1.2.3