ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

commandLine.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 // FIXME: Avoid using printf
00024 #define FORBIDDEN_SYMBOL_EXCEPTION_printf
00025 
00026 #define FORBIDDEN_SYMBOL_EXCEPTION_exit
00027 
00028 #include <limits.h>
00029 
00030 #include "engines/metaengine.h"
00031 #include "base/commandLine.h"
00032 #include "base/plugins.h"
00033 #include "base/version.h"
00034 
00035 #include "common/config-manager.h"
00036 #include "common/fs.h"
00037 #include "common/rendermode.h"
00038 #include "common/stack.h"
00039 #include "common/system.h"
00040 #include "common/textconsole.h"
00041 
00042 #include "gui/ThemeEngine.h"
00043 
00044 #include "audio/musicplugin.h"
00045 
00046 #include "graphics/renderer.h" // ResidualVM
00047 
00048 #define DETECTOR_TESTING_HACK
00049 #define UPGRADE_ALL_TARGETS_HACK
00050 
00051 namespace Base {
00052 
00053 #ifndef DISABLE_COMMAND_LINE
00054 
00055 static const char USAGE_STRING[] =
00056     "%s: %s\n"
00057     "Usage: %s [OPTIONS]... [GAME]\n"
00058     "\n"
00059     "Try '%s --help' for more options.\n"
00060 ;
00061 
00062 // DONT FIXME: DO NOT ORDER ALPHABETICALLY, THIS IS ORDERED BY IMPORTANCE/CATEGORY! :)
00063 #if defined(__SYMBIAN32__) || defined(ANDROID) || defined(__DS__) || defined(__3DS__)
00064 static const char HELP_STRING[] = "NoUsageString"; // save more data segment space
00065 #else
00066 static const char HELP_STRING[] =
00067     "ResidualVM - A 3D game interpreter\n"
00068     "Usage: %s [OPTIONS]... [GAME]\n"
00069     "  -v, --version            Display ResidualVM version information and exit\n"
00070     "  -h, --help               Display a brief help text and exit\n"
00071     "  -z, --list-games         Display list of supported games and exit\n"
00072     "  -t, --list-targets       Display list of configured targets and exit\n"
00073     "  --list-saves             Display a list of saved games for the target specified\n"
00074     "                           with --game=TARGET, or all targets if none is specified\n"
00075     "  -a, --add                Add all games from current or specified directory.\n"
00076     "                           If --game=ID is passed only the game with id ID is added. See also --detect\n"
00077     "                           Use --path=PATH to specify a directory.\n"
00078     "  --detect                 Display a list of games with their ID from current or\n"
00079     "                           specified directory without adding it to the config.\n"
00080     "                           Use --path=PATH to specify a directory.\n"
00081     "  --game=ID                In combination with --add or --detect only adds or attempts to\n"
00082     "                           detect the game with id ID.\n"
00083     "  --auto-detect            Display a list of games from current or specified directory\n"
00084     "                           and start the first one. Use --path=PATH to specify a directory.\n"
00085     "  --recursive              In combination with --add or --detect recurse down all subdirectories\n"
00086 #if defined(WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
00087     "  --console                Enable the console window (default:enabled)\n"
00088 #endif
00089     "\n"
00090     "  -c, --config=CONFIG      Use alternate configuration file\n"
00091     "  -p, --path=PATH          Path to where the game is installed\n"
00092     "  -x, --save-slot[=NUM]    Save game slot to load (default: autosave)\n"
00093     "  -f, --fullscreen         Force full-screen mode\n"
00094     "  -F, --no-fullscreen      Force windowed mode\n"
00095     "  --gui-theme=THEME        Select GUI theme\n"
00096     "  --themepath=PATH         Path to where GUI themes are stored\n"
00097     "  --list-themes            Display list of all usable GUI themes\n"
00098     "  -e, --music-driver=MODE  Select music driver (see README for details)\n"
00099     "  --list-audio-devices     List all available audio devices\n"
00100     "  -q, --language=LANG      Select language (en,de,fr,it,pt,es,jp,zh,kr,se,gb,\n"
00101     "                           hb,ru,cz)\n"
00102     "  -m, --music-volume=NUM   Set the music volume, 0-255 (default: 192)\n"
00103     "  -s, --sfx-volume=NUM     Set the sfx volume, 0-255 (default: 192)\n"
00104     "  -r, --speech-volume=NUM  Set the speech volume, 0-255 (default: 192)\n"
00105     "  --midi-gain=NUM          Set the gain for MIDI playback, 0-1000 (default:\n"
00106     "                           100) (only supported by some MIDI drivers)\n"
00107     "  -n, --subtitles          Enable subtitles (use with games that have voice)\n"
00108     "  -b, --boot-param=NUM     Pass number to the boot script (boot param)\n"
00109     "  -d, --debuglevel=NUM     Set debug verbosity level\n"
00110     "  --debugflags=FLAGS       Enable engine specific debug flags\n"
00111     "                           (separated by commas)\n"
00112     "  --debug-channels-only    Show only the specified debug channels\n"
00113     "  -u, --dump-scripts       Enable script dumping if a directory called 'dumps'\n"
00114     "                           exists in the current directory\n"
00115     "\n"
00116     "  --cdrom=DRIVE            CD drive to play CD audio from; can either be a\n"
00117     "                           drive, path, or numeric index (default: 0 = best\n"
00118     "                           choice drive)\n"
00119     "  --joystick[=NUM]         Enable joystick input (default: 0 = first joystick)\n"
00120     "  --platform=WORD          Specify platform of game (allowed values: 2gs, 3do,\n"
00121     "                           acorn, amiga, atari, c64, fmtowns, nes, mac, pc, pc98,\n"
00122     "                           pce, segacd, wii, windows)\n"
00123     "  --savepath=PATH          Path to where saved games are stored\n"
00124     "  --extrapath=PATH         Extra path to additional game data\n"
00125     "  --soundfont=FILE         Select the SoundFont for MIDI playback (only\n"
00126     "                           supported by some MIDI drivers)\n"
00127     "  --multi-midi             Enable combination AdLib and native MIDI\n"
00128     "  --native-mt32            True Roland MT-32 (disable GM emulation)\n"
00129     "  --enable-gs              Enable Roland GS mode for MIDI playback\n"
00130     "  --output-rate=RATE       Select output sample rate in Hz (e.g. 22050)\n"
00131     "  --opl-driver=DRIVER      Select AdLib (OPL) emulator (db, mame)\n"
00132     "  --talkspeed=NUM          Set talk speed for games (default: 179)\n"
00133     "  --show-fps               Set the turn on display FPS info\n"
00134     "  --no-show-fps            Set the turn off display FPS info\n"
00135     "  --renderer=RENDERER      Select renderer (software, opengl, opengl_shaders)\n"
00136     "  --aspect-ratio           Enable aspect ratio correction\n"
00137     "  --bpp=NUM                Select number of bits per pixel, 0 (auto-detect), 16, 32\n"
00138     "                           (default: 0) (only supported by software renderer)\n"
00139     "  --[no-]dirtyrects        Enable dirty rectangles optimisation in software renderer\n"
00140     "                           (default: enabled)\n"
00141 #ifdef ENABLE_EVENTRECORDER
00142     "  --record-mode=MODE       Specify record mode for event recorder (record, playback,\n"
00143     "                           passthrough [default])\n"
00144     "  --record-file-name=FILE  Specify record file name\n"
00145     "  --disable-display        Disable any gfx output. Used for headless events\n"
00146     "                           playback by Event Recorder\n"
00147 #endif
00148     "\n"
00149 #ifdef ENABLE_GRIM
00150     "  --dimuse-tempo=NUM       Set internal Digital iMuse tempo (10 - 100) per second\n"
00151     "                           (default: 10)\n"
00152 #endif
00153     "  --engine-speed=NUM       Set frame per second limit (0 - 100), 0 = no limit\n"
00154     "                           (default: 60)\n"
00155 ;
00156 #endif
00157 
00158 static const char *s_appName = "residualvm";
00159 
00160 static void NORETURN_PRE usage(const char *s, ...) GCC_PRINTF(1, 2) NORETURN_POST;
00161 
00162 static void usage(const char *s, ...) {
00163     char buf[STRINGBUFLEN];
00164     va_list va;
00165 
00166     va_start(va, s);
00167     vsnprintf(buf, STRINGBUFLEN, s, va);
00168     va_end(va);
00169 
00170 #if !(defined(__SYMBIAN32__) || defined(__DS__))
00171     printf(USAGE_STRING, s_appName, buf, s_appName, s_appName);
00172 #endif
00173     exit(1);
00174 }
00175 
00176 static void ensureFirstCommand(const Common::String &existingCommand, const char *newCommand) {
00177     if (!existingCommand.empty())
00178         usage("--%s: Cannot accept more than one command (already found --%s).", newCommand, existingCommand.c_str());
00179 }
00180 
00181 #endif // DISABLE_COMMAND_LINE
00182 
00183 
00184 void registerDefaults() {
00185 
00186     // Graphics
00187     ConfMan.registerDefault("fullscreen", false);
00188     ConfMan.registerDefault("filtering", false);
00189     ConfMan.registerDefault("show_fps", false);
00190     ConfMan.registerDefault("aspect_ratio", false);
00191     ConfMan.registerDefault("dirtyrects", true);
00192     ConfMan.registerDefault("bpp", 0);
00193 
00194     // Sound & Music
00195     ConfMan.registerDefault("music_volume", 192);
00196     ConfMan.registerDefault("sfx_volume", 192);
00197     ConfMan.registerDefault("speech_volume", 192);
00198 
00199     ConfMan.registerDefault("music_mute", false);
00200     ConfMan.registerDefault("sfx_mute", false);
00201     ConfMan.registerDefault("speech_mute", false);
00202     ConfMan.registerDefault("mute", false);
00203 
00204     ConfMan.registerDefault("multi_midi", false);
00205     ConfMan.registerDefault("native_mt32", false);
00206     ConfMan.registerDefault("enable_gs", false);
00207     ConfMan.registerDefault("midi_gain", 100);
00208 
00209     ConfMan.registerDefault("music_driver", "auto");
00210     ConfMan.registerDefault("mt32_device", "null");
00211     ConfMan.registerDefault("gm_device", "null");
00212 
00213     ConfMan.registerDefault("cdrom", 0);
00214 
00215     ConfMan.registerDefault("enable_unsupported_game_warning", true);
00216 
00217     // Game specific
00218     ConfMan.registerDefault("path", "");
00219     ConfMan.registerDefault("platform", Common::kPlatformDOS);
00220     ConfMan.registerDefault("language", "en");
00221     ConfMan.registerDefault("subtitles", false);
00222     ConfMan.registerDefault("boot_param", 0);
00223     ConfMan.registerDefault("dump_scripts", false);
00224     ConfMan.registerDefault("save_slot", -1);
00225     ConfMan.registerDefault("autosave_period", 5 * 60); // By default, trigger autosave every 5 minutes
00226 
00227     ConfMan.registerDefault("talkspeed", 179);
00228 
00229 #ifdef ENABLE_GRIM
00230     ConfMan.registerDefault("dimuse_tempo", 10);
00231 #endif
00232     ConfMan.registerDefault("engine_speed", 60);
00233 
00234     // Miscellaneous
00235     ConfMan.registerDefault("joystick_num", -1);
00236     ConfMan.registerDefault("confirm_exit", false);
00237     ConfMan.registerDefault("disable_sdl_parachute", false);
00238 
00239     ConfMan.registerDefault("disable_display", false);
00240     ConfMan.registerDefault("record_mode", "none");
00241     ConfMan.registerDefault("record_file_name", "record.bin");
00242 
00243     ConfMan.registerDefault("gui_saveload_chooser", "grid");
00244     ConfMan.registerDefault("gui_saveload_last_pos", "0");
00245 
00246     ConfMan.registerDefault("gui_browser_show_hidden", false);
00247     ConfMan.registerDefault("gui_browser_native", true);
00248     ConfMan.registerDefault("game", "");
00249 
00250 #ifdef USE_FLUIDSYNTH
00251     // The settings are deliberately stored the same way as in Qsynth. The
00252     // FluidSynth music driver is responsible for transforming them into
00253     // their appropriate values.
00254     ConfMan.registerDefault("fluidsynth_chorus_activate", true);
00255     ConfMan.registerDefault("fluidsynth_chorus_nr", 3);
00256     ConfMan.registerDefault("fluidsynth_chorus_level", 100);
00257     ConfMan.registerDefault("fluidsynth_chorus_speed", 30);
00258     ConfMan.registerDefault("fluidsynth_chorus_depth", 80);
00259     ConfMan.registerDefault("fluidsynth_chorus_waveform", "sine");
00260 
00261     ConfMan.registerDefault("fluidsynth_reverb_activate", true);
00262     ConfMan.registerDefault("fluidsynth_reverb_roomsize", 20);
00263     ConfMan.registerDefault("fluidsynth_reverb_damping", 0);
00264     ConfMan.registerDefault("fluidsynth_reverb_width", 1);
00265     ConfMan.registerDefault("fluidsynth_reverb_level", 90);
00266 
00267     ConfMan.registerDefault("fluidsynth_misc_interpolation", "4th");
00268 #endif
00269 }
00270 
00271 //
00272 // Various macros used by the command line parser.
00273 //
00274 
00275 #ifndef DISABLE_COMMAND_LINE
00276 
00277 // Use this for options which have an *optional* value
00278 #define DO_OPTION_OPT(shortCmd, longCmd, defaultVal) \
00279     if (isLongCmd ? (!strcmp(s + 2, longCmd) || !memcmp(s + 2, longCmd"=", sizeof(longCmd"=") - 1)) : (tolower(s[1]) == shortCmd)) { \
00280         s += 2; \
00281         if (isLongCmd) { \
00282             s += sizeof(longCmd) - 1; \
00283             if (*s == '=') \
00284                 s++; \
00285         } \
00286         const char *option = s; \
00287         if (*s == '\0' && !isLongCmd) { option = s2; i++; } \
00288         if (!option || *option == '\0') option = defaultVal; \
00289         if (option) settings[longCmd] = option;
00290 
00291 // Use this for options which have a required (string) value
00292 #define DO_OPTION(shortCmd, longCmd) \
00293     DO_OPTION_OPT(shortCmd, longCmd, 0) \
00294     if (!option) usage("Option '%s' requires an argument", argv[isLongCmd ? i : i-1]);
00295 
00296 // Use this for options which have a required integer value
00297 // (we don't check ERANGE because WinCE doesn't support errno, so we're stuck just rejecting LONG_MAX/LONG_MIN..)
00298 #define DO_OPTION_INT(shortCmd, longCmd) \
00299     DO_OPTION(shortCmd, longCmd) \
00300     char *endptr; \
00301     long int retval = strtol(option, &endptr, 0); \
00302     if (*endptr != '\0' || retval == LONG_MAX || retval == LONG_MIN) \
00303         usage("--%s: Invalid number '%s'", longCmd, option);
00304 
00305 // Use this for boolean options; this distinguishes between "-x" and "-X",
00306 // resp. between "--some-option" and "--no-some-option".
00307 #define DO_OPTION_BOOL(shortCmd, longCmd) \
00308     if (isLongCmd ? (!strcmp(s + 2, longCmd) || !strcmp(s + 2, "no-" longCmd)) : (tolower(s[1]) == shortCmd)) { \
00309         bool boolValue = (Common::isLower(s[1]) != 0); \
00310         s += 2; \
00311         if (isLongCmd) { \
00312             boolValue = !strcmp(s, longCmd); \
00313             s += boolValue ? (sizeof(longCmd) - 1) : (sizeof("no-" longCmd) - 1); \
00314         } \
00315         if (*s != '\0') goto unknownOption; \
00316         const char *option = boolValue ? "true" : "false"; \
00317         settings[longCmd] = option;
00318 
00319 // Use this for options which never have a value, i.e. for 'commands', like "--help".
00320 #define DO_COMMAND(shortCmd, longCmd) \
00321     if (isLongCmd ? (!strcmp(s + 2, longCmd)) : (tolower(s[1]) == shortCmd)) { \
00322         s += 2; \
00323         if (isLongCmd) \
00324             s += sizeof(longCmd) - 1; \
00325         if (*s != '\0') goto unknownOption; \
00326         ensureFirstCommand(command, longCmd); \
00327         command = longCmd;
00328 
00329 
00330 #define DO_LONG_OPTION_OPT(longCmd, d)  DO_OPTION_OPT(0, longCmd, d)
00331 #define DO_LONG_OPTION(longCmd)         DO_OPTION(0, longCmd)
00332 #define DO_LONG_OPTION_INT(longCmd)     DO_OPTION_INT(0, longCmd)
00333 #define DO_LONG_OPTION_BOOL(longCmd)    DO_OPTION_BOOL(0, longCmd)
00334 #define DO_LONG_COMMAND(longCmd)        DO_COMMAND(0, longCmd)
00335 
00336 // End an option handler
00337 #define END_OPTION \
00338         continue; \
00339     }
00340 
00341 // End an option handler
00342 #define END_COMMAND \
00343         continue; \
00344     }
00345 
00346 
00347 Common::String parseCommandLine(Common::StringMap &settings, int argc, const char * const *argv) {
00348     const char *s, *s2;
00349     Common::String command;
00350 
00351     if (!argv)
00352         return command;
00353 
00354     // argv[0] contains the name of the executable.
00355     if (argv[0]) {
00356         s = strrchr(argv[0], '/');
00357         s_appName = s ? (s + 1) : argv[0];
00358     }
00359 
00360     // We store all command line settings into a string map.
00361 
00362     // Iterate over all command line arguments and parse them into our string map.
00363     for (int i = 1; i < argc; ++i) {
00364         s = argv[i];
00365         s2 = (i < argc-1) ? argv[i+1] : 0;
00366 
00367         if (s[0] != '-') {
00368             // The argument doesn't start with a dash, so it's not an option.
00369             // Hence it must be the target name. We currently enforce that
00370             // this always comes last.
00371             if (i != argc - 1)
00372                 usage("Stray argument '%s'", s);
00373 
00374             // We defer checking whether this is a valid target to a later point.
00375             return s;
00376         } else {
00377             // On MacOS X prior to 10.9 the OS is sometimes adding a -psn_X_XXXXXX argument (where X are digits)
00378             // to pass the process serial number. We need to ignore it to avoid an error.
00379             // When using XCode it also adds -NSDocumentRevisionsDebugMode YES argument if XCode option
00380             // "Allow debugging when using document Versions Browser" is on (which is the default).
00381 #ifdef MACOSX
00382             if (strncmp(s, "-psn_", 5) == 0)
00383                 continue;
00384             if (strcmp(s, "-NSDocumentRevisionsDebugMode") == 0) {
00385                 ++i; // Also skip the YES that follows
00386                 continue;
00387             }
00388 #endif
00389 
00390             bool isLongCmd = (s[0] == '-' && s[1] == '-');
00391 
00392             DO_COMMAND('h', "help")
00393             END_COMMAND
00394 
00395             DO_COMMAND('v', "version")
00396             END_COMMAND
00397 
00398             DO_COMMAND('t', "list-targets")
00399             END_COMMAND
00400 
00401             DO_COMMAND('z', "list-games")
00402             END_COMMAND
00403 
00404             DO_COMMAND('a', "add")
00405             END_COMMAND
00406 
00407             DO_LONG_COMMAND("detect")
00408             END_COMMAND
00409 
00410             DO_LONG_COMMAND("auto-detect")
00411             END_COMMAND
00412 
00413 #ifdef DETECTOR_TESTING_HACK
00414             // HACK FIXME TODO: This command is intentionally *not* documented!
00415             DO_LONG_COMMAND("test-detector")
00416             END_COMMAND
00417 #endif
00418 
00419 #ifdef UPGRADE_ALL_TARGETS_HACK
00420             // HACK FIXME TODO: This command is intentionally *not* documented!
00421             DO_LONG_COMMAND("upgrade-targets")
00422             END_COMMAND
00423 #endif
00424 
00425             DO_LONG_COMMAND("list-saves")
00426             END_COMMAND
00427 
00428             DO_OPTION('c', "config")
00429             END_OPTION
00430 
00431             DO_OPTION_INT('b', "boot-param")
00432             END_OPTION
00433 
00434             DO_OPTION_OPT('d', "debuglevel", "0")
00435             END_OPTION
00436 
00437             DO_LONG_OPTION("debugflags")
00438             END_OPTION
00439 
00440             DO_LONG_OPTION_BOOL("debug-channels-only")
00441             END_OPTION
00442 
00443             DO_OPTION('e', "music-driver")
00444             END_OPTION
00445 
00446             DO_LONG_COMMAND("list-audio-devices")
00447             END_COMMAND
00448 
00449             DO_LONG_OPTION_INT("output-rate")
00450             END_OPTION
00451 
00452             DO_OPTION_BOOL('f', "fullscreen")
00453             END_OPTION
00454 
00455             DO_LONG_OPTION_BOOL("filtering")
00456             END_OPTION
00457 
00458 #ifdef ENABLE_EVENTRECORDER
00459             DO_LONG_OPTION_INT("disable-display")
00460             END_OPTION
00461 
00462             DO_LONG_OPTION("record-mode")
00463             END_OPTION
00464 
00465             DO_LONG_OPTION("record-file-name")
00466             END_OPTION
00467 #endif
00468 
00469             DO_LONG_OPTION("opl-driver")
00470             END_OPTION
00471 
00472             DO_OPTION_INT('m', "music-volume")
00473             END_OPTION
00474 
00475             DO_OPTION_BOOL('n', "subtitles")
00476             END_OPTION
00477 
00478             DO_OPTION('p', "path")
00479                 Common::FSNode path(option);
00480                 if (!path.exists()) {
00481                     usage("Non-existent game path '%s'", option);
00482                 } else if (!path.isReadable()) {
00483                     usage("Non-readable game path '%s'", option);
00484                 }
00485             END_OPTION
00486 
00487             DO_OPTION('q', "language")
00488                 if (Common::parseLanguage(option) == Common::UNK_LANG)
00489                     usage("Unrecognized language '%s'", option);
00490             END_OPTION
00491 
00492             DO_OPTION_INT('s', "sfx-volume")
00493             END_OPTION
00494 
00495             DO_OPTION_INT('r', "speech-volume")
00496             END_OPTION
00497 
00498             DO_LONG_OPTION_INT("midi-gain")
00499             END_OPTION
00500 
00501             DO_OPTION_BOOL('u', "dump-scripts")
00502             END_OPTION
00503 
00504             DO_OPTION_OPT('x', "save-slot", "0")
00505             END_OPTION
00506 
00507             DO_LONG_OPTION_INT("cdrom")
00508             END_OPTION
00509 
00510             DO_LONG_OPTION_OPT("joystick", "0")
00511                 settings["joystick_num"] = option;
00512                 settings.erase("joystick");
00513             END_OPTION
00514 
00515             DO_LONG_OPTION("platform")
00516                 int platform = Common::parsePlatform(option);
00517                 if (platform == Common::kPlatformUnknown)
00518                     usage("Unrecognized platform '%s'", option);
00519             END_OPTION
00520 
00521             DO_LONG_OPTION("soundfont")
00522                 Common::FSNode path(option);
00523                 if (!path.exists()) {
00524                     usage("Non-existent soundfont path '%s'", option);
00525                 } else if (!path.isReadable()) {
00526                     usage("Non-readable soundfont path '%s'", option);
00527                 }
00528             END_OPTION
00529 
00530             DO_LONG_OPTION_BOOL("disable-sdl-parachute")
00531             END_OPTION
00532 
00533             DO_LONG_OPTION_BOOL("multi-midi")
00534             END_OPTION
00535 
00536             DO_LONG_OPTION_BOOL("native-mt32")
00537             END_OPTION
00538 
00539             DO_LONG_OPTION_BOOL("enable-gs")
00540             END_OPTION
00541 
00542             DO_LONG_OPTION_BOOL("aspect-ratio")
00543             END_OPTION
00544 
00545             DO_LONG_OPTION_INT("bpp")
00546             END_OPTION
00547 
00548             DO_LONG_OPTION_BOOL("dirtyrects")
00549             END_OPTION
00550 
00551             DO_LONG_OPTION("gamma")
00552             END_OPTION
00553 // ResidualVM specific start
00554             DO_LONG_OPTION("renderer")
00555                 Graphics::RendererType renderer = Graphics::parseRendererTypeCode(option);
00556                 if (renderer == Graphics::kRendererTypeDefault)
00557                     usage("Unrecognized renderer type '%s'", option);
00558             END_OPTION
00559 
00560             DO_LONG_OPTION_BOOL("show-fps")
00561 // ResidualVM specific end
00562             END_OPTION
00563 
00564             DO_LONG_OPTION("savepath")
00565                 Common::FSNode path(option);
00566                 if (!path.exists()) {
00567                     usage("Non-existent saved games path '%s'", option);
00568                 } else if (!path.isWritable()) {
00569                     usage("Non-writable saved games path '%s'", option);
00570                 }
00571             END_OPTION
00572 
00573             DO_LONG_OPTION("extrapath")
00574                 Common::FSNode path(option);
00575                 if (!path.exists()) {
00576                     usage("Non-existent extra path '%s'", option);
00577                 } else if (!path.isReadable()) {
00578                     usage("Non-readable extra path '%s'", option);
00579                 }
00580             END_OPTION
00581 
00582             DO_LONG_OPTION_INT("talkspeed")
00583             END_OPTION
00584 
00585             DO_LONG_OPTION("gui-theme")
00586             END_OPTION
00587 
00588             DO_LONG_OPTION("game")
00589             END_OPTION
00590 
00591             DO_LONG_OPTION_BOOL("recursive")
00592             END_OPTION
00593 
00594             DO_LONG_OPTION("themepath")
00595                 Common::FSNode path(option);
00596                 if (!path.exists()) {
00597                     usage("Non-existent theme path '%s'", option);
00598                 } else if (!path.isReadable()) {
00599                     usage("Non-readable theme path '%s'", option);
00600                 }
00601             END_OPTION
00602 
00603             DO_LONG_COMMAND("list-themes")
00604             END_COMMAND
00605 
00606             DO_LONG_OPTION("target-md5")
00607             END_OPTION
00608 
00609 #ifdef ENABLE_GRIM
00610             DO_LONG_OPTION_INT("dimuse-tempo")
00611             END_OPTION
00612 #endif
00613 
00614 
00615             DO_LONG_OPTION_INT("engine-speed")
00616             END_OPTION
00617 
00618             DO_LONG_OPTION("speech-mode")
00619             END_OPTION
00620 
00621 #ifdef IPHONE
00622             // This is automatically set when launched from the Springboard.
00623             DO_LONG_OPTION_OPT("launchedFromSB", 0)
00624             END_OPTION
00625 #endif
00626 
00627 #if defined(WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
00628             // Optional console window on Windows (default: enabled)
00629             DO_LONG_OPTION_BOOL("console")
00630             END_OPTION
00631 #endif
00632 
00633 unknownOption:
00634             // If we get till here, the option is unhandled and hence unknown.
00635             usage("Unrecognized option '%s'", argv[i]);
00636         }
00637     }
00638 
00639     return command;
00640 }
00641 
00643 static void listGames() {
00644     printf("Game ID              Full Title                                            \n"
00645            "-------------------- ------------------------------------------------------\n");
00646 
00647     const PluginList &plugins = EngineMan.getPlugins();
00648     for (PluginList::const_iterator iter = plugins.begin(); iter != plugins.end(); ++iter) {
00649         PlainGameList list = (*iter)->get<MetaEngine>().getSupportedGames();
00650         for (PlainGameList::iterator v = list.begin(); v != list.end(); ++v) {
00651             printf("%-20s %s\n", v->gameId, v->description);
00652         }
00653     }
00654 }
00655 
00657 static void listTargets() {
00658     printf("Target               Description                                           \n"
00659            "-------------------- ------------------------------------------------------\n");
00660 
00661     using namespace Common;
00662     const ConfigManager::DomainMap &domains = ConfMan.getGameDomains();
00663     ConfigManager::DomainMap::const_iterator iter;
00664 
00665     Common::Array<Common::String> targets;
00666     targets.reserve(domains.size());
00667 
00668     for (iter = domains.begin(); iter != domains.end(); ++iter) {
00669         Common::String name(iter->_key);
00670         Common::String description(iter->_value.getVal("description"));
00671 
00672         if (description.empty()) {
00673             // FIXME: At this point, we should check for a "gameid" override
00674             // to find the proper desc. In fact, the platform probably should
00675             // be taken into account, too.
00676             const Common::String &gameid = name;
00677             PlainGameDescriptor g = EngineMan.findGame(gameid);
00678             if (g.description)
00679                 description = g.description;
00680         }
00681 
00682         targets.push_back(Common::String::format("%-20s %s", name.c_str(), description.c_str()));
00683     }
00684 
00685     Common::sort(targets.begin(), targets.end());
00686 
00687     for (Common::Array<Common::String>::const_iterator i = targets.begin(), end = targets.end(); i != end; ++i)
00688         printf("%s\n", i->c_str());
00689 }
00690 
00692 static Common::Error listSaves(const Common::String &target) {
00693     Common::Error result = Common::kNoError;
00694 
00695     // If no target is specified, list save games for all known targets
00696     Common::Array<Common::String> targets;
00697     if (!target.empty())
00698         targets.push_back(target);
00699     else {
00700         const Common::ConfigManager::DomainMap &domains = ConfMan.getGameDomains();
00701         Common::ConfigManager::DomainMap::const_iterator iter;
00702 
00703         targets.reserve(domains.size());
00704         for (iter = domains.begin(); iter != domains.end(); ++iter)
00705             targets.push_back(iter->_key);
00706     }
00707 
00708     // FIXME HACK
00709     g_system->initBackend();
00710 
00711     Common::String oldDomain = ConfMan.getActiveDomainName();
00712 
00713     bool atLeastOneFound = false;
00714     for (Common::Array<Common::String>::const_iterator i = targets.begin(), end = targets.end(); i != end; ++i) {
00715         // Grab the "target" domain, if any
00716         const Common::ConfigManager::Domain *domain = ConfMan.getDomain(*i);
00717 
00718         // Set up the game domain as newly active domain, so
00719         // target specific savepath will be checked
00720         ConfMan.setActiveDomain(*i);
00721 
00722         // Grab the gameid from the domain resp. use the target as gameid
00723         Common::String gameid;
00724         if (domain)
00725             gameid = domain->getVal("gameid");
00726         if (gameid.empty())
00727             gameid = *i;
00728         gameid.toLowercase(); // Normalize it to lower case
00729 
00730         // Find the plugin that will handle the specified gameid
00731         const Plugin *plugin = nullptr;
00732         EngineMan.findGame(gameid, &plugin);
00733 
00734         if (!plugin) {
00735             // If the target was specified, treat this as an error, and otherwise skip it.
00736             if (!target.empty())
00737                 return Common::Error(Common::kEnginePluginNotFound,
00738                                      Common::String::format("target '%s', gameid '%s", i->c_str(), gameid.c_str()));
00739             printf("Plugin could not be loaded for target '%s', gameid '%s", i->c_str(), gameid.c_str());
00740             continue;
00741         }
00742 
00743         const MetaEngine &metaEngine = plugin->get<MetaEngine>();
00744 
00745         if (!metaEngine.hasFeature(MetaEngine::kSupportsListSaves)) {
00746             // If the target was specified, treat this as an error, and otherwise skip it.
00747             if (!target.empty())
00748                 // TODO: Include more info about the target (desc, engine name, ...) ???
00749                 return Common::Error(Common::kEnginePluginNotSupportSaves,
00750                                      Common::String::format("target '%s', gameid '%s", i->c_str(), gameid.c_str()));
00751             continue;
00752         }
00753 
00754         // Query the plugin for a list of saved games
00755         SaveStateList saveList = metaEngine.listSaves(i->c_str());
00756 
00757         if (saveList.size() > 0) {
00758             // TODO: Include more info about the target (desc, engine name, ...) ???
00759             if (atLeastOneFound)
00760                 printf("\n");
00761             printf("Save states for target '%s' (gameid '%s'):\n", i->c_str(), gameid.c_str());
00762             printf("  Slot Description                                           \n"
00763                        "  ---- ------------------------------------------------------\n");
00764 
00765             for (SaveStateList::const_iterator x = saveList.begin(); x != saveList.end(); ++x) {
00766                 printf("  %-4d %s\n", x->getSaveSlot(), x->getDescription().c_str());
00767                 // TODO: Could also iterate over the full hashmap, printing all key-value pairs
00768             }
00769             atLeastOneFound = true;
00770         } else {
00771             // If the target was specified, indicate no save games were found for it. Otherwise just skip it.
00772             if (!target.empty())
00773                 printf("There are no save states for target '%s' (gameid '%s'):\n", i->c_str(), gameid.c_str());
00774         }
00775     }
00776 
00777     // Revert to the old active domain
00778     ConfMan.setActiveDomain(oldDomain);
00779 
00780     if (!atLeastOneFound && target.empty())
00781         printf("No save states could be found.\n");
00782 
00783     return result;
00784 }
00785 
00787 static void listThemes() {
00788     typedef Common::List<GUI::ThemeEngine::ThemeDescriptor> ThList;
00789     ThList thList;
00790     GUI::ThemeEngine::listUsableThemes(thList);
00791 
00792     printf("Theme          Description\n");
00793     printf("-------------- ------------------------------------------------\n");
00794 
00795     for (ThList::const_iterator i = thList.begin(); i != thList.end(); ++i)
00796         printf("%-14s %s\n", i->id.c_str(), i->name.c_str());
00797 }
00798 
00800 static void listAudioDevices() {
00801     PluginList pluginList = MusicMan.getPlugins();
00802 
00803     printf("ID                             Description\n");
00804     printf("------------------------------ ------------------------------------------------\n");
00805 
00806     for (PluginList::const_iterator i = pluginList.begin(), iend = pluginList.end(); i != iend; ++i) {
00807         const MusicPluginObject &musicObject = (*i)->get<MusicPluginObject>();
00808         MusicDevices deviceList = musicObject.getDevices();
00809         for (MusicDevices::iterator j = deviceList.begin(), jend = deviceList.end(); j != jend; ++j) {
00810             printf("%-30s %s\n", Common::String::format("\"%s\"", j->getCompleteId().c_str()).c_str(), j->getCompleteName().c_str());
00811         }
00812     }
00813 }
00814 
00816 static DetectedGames getGameList(const Common::FSNode &dir) {
00817     Common::FSList files;
00818 
00819     // Collect all files from directory
00820     if (!dir.getChildren(files, Common::FSNode::kListAll)) {
00821         printf("Path %s does not exist or is not a directory.\n", dir.getPath().c_str());
00822         return DetectedGames();
00823     }
00824 
00825     // detect Games
00826     DetectionResults detectionResults = EngineMan.detectGames(files);
00827 
00828     if (detectionResults.foundUnknownGames()) {
00829         Common::String report = detectionResults.generateUnknownGameReport(false, 80);
00830         g_system->logMessage(LogMessageType::kInfo, report.c_str());
00831     }
00832 
00833     return detectionResults.listRecognizedGames();
00834 }
00835 
00836 static DetectedGames recListGames(const Common::FSNode &dir, const Common::String &gameId, bool recursive) {
00837     DetectedGames list = getGameList(dir);
00838 
00839     if (recursive) {
00840         Common::FSList files;
00841         dir.getChildren(files, Common::FSNode::kListDirectoriesOnly);
00842         for (Common::FSList::const_iterator file = files.begin(); file != files.end(); ++file) {
00843             DetectedGames rec = recListGames(*file, gameId, recursive);
00844             for (DetectedGames::const_iterator game = rec.begin(); game != rec.end(); ++game) {
00845                 if (gameId.empty() || game->gameId == gameId)
00846                     list.push_back(*game);
00847             }
00848         }
00849     }
00850 
00851     return list;
00852 }
00853 
00855 static Common::String detectGames(const Common::String &path, const Common::String &gameId, bool recursive) {
00856     bool noPath = path.empty();
00857     //Current directory
00858     Common::FSNode dir(path);
00859     DetectedGames candidates = recListGames(dir, gameId, recursive);
00860 
00861     if (candidates.empty()) {
00862         printf("WARNING: ResidualVM could not find any game in %s\n", dir.getPath().c_str());
00863         if (noPath) {
00864             printf("WARNING: Consider using --path=<path> to specify a directory\n");
00865         }
00866         if (!recursive) {
00867             printf("WARNING: Consider using --recursive to search inside subdirectories\n");
00868         }
00869         return Common::String();
00870     }
00871     // TODO this is not especially pretty
00872     printf("ID             Description                                                Full Path\n");
00873     printf("-------------- ---------------------------------------------------------- ---------------------------------------------------------\n");
00874     for (DetectedGames::const_iterator v = candidates.begin(); v != candidates.end(); ++v) {
00875         printf("%-14s %-58s %s\n", v->gameId.c_str(), v->description.c_str(), v->path.c_str());
00876     }
00877 
00878     return candidates[0].gameId;
00879 }
00880 
00881 static int recAddGames(const Common::FSNode &dir, const Common::String &game, bool recursive) {
00882     int count = 0;
00883     DetectedGames list = getGameList(dir);
00884     for (DetectedGames::const_iterator v = list.begin(); v != list.end(); ++v) {
00885         if (v->gameId != game && !game.empty()) {
00886             printf("Found %s, only adding %s per --game option, ignoring...\n", v->gameId.c_str(), game.c_str());
00887         } else if (ConfMan.hasGameDomain(v->preferredTarget)) {
00888             // TODO Better check for game already added?
00889             printf("Found %s, but has already been added, skipping\n", v->gameId.c_str());
00890         } else {
00891             Common::String target = EngineMan.createTargetForGame(*v);
00892             count++;
00893 
00894             // Display added game info
00895             printf("Game Added: \n  Target:   %s\n  GameID:   %s\n  Name:     %s\n  Language: %s\n  Platform: %s\n",
00896                    target.c_str(),
00897                    v->gameId.c_str(),
00898                    v->description.c_str(),
00899                    Common::getLanguageDescription(v->language),
00900                    Common::getPlatformDescription(v->platform)
00901             );
00902         }
00903     }
00904 
00905     if (recursive) {
00906         Common::FSList files;
00907         if (dir.getChildren(files, Common::FSNode::kListDirectoriesOnly)) {
00908             for (Common::FSList::const_iterator file = files.begin(); file != files.end(); ++file) {
00909                 count += recAddGames(*file, game, recursive);
00910             }
00911         }
00912     }
00913 
00914     return count;
00915 }
00916 
00917 static bool addGames(const Common::String &path, const Common::String &game, bool recursive) {
00918     //Current directory
00919     Common::FSNode dir(path);
00920     int added = recAddGames(dir, game, recursive);
00921     printf("Added %d games\n", added);
00922     if (added == 0 && !recursive) {
00923         printf("Consider using --recursive to search inside subdirectories\n");
00924     }
00925     ConfMan.flushToDisk();
00926     return true;
00927 }
00928 
00929 #ifdef DETECTOR_TESTING_HACK
00930 static void runDetectorTest() {
00931     // HACK: The following code can be used to test the detection code of our
00932     // engines. Basically, it loops over all targets, and calls the detector
00933     // for the given path. It then prints out the result and also checks
00934     // whether the result agrees with the settings of the target.
00935 
00936     const Common::ConfigManager::DomainMap &domains = ConfMan.getGameDomains();
00937     Common::ConfigManager::DomainMap::const_iterator iter = domains.begin();
00938     int success = 0, failure = 0;
00939     for (iter = domains.begin(); iter != domains.end(); ++iter) {
00940         Common::String name(iter->_key);
00941         Common::String gameid(iter->_value.getVal("gameid"));
00942         Common::String path(iter->_value.getVal("path"));
00943         printf("Looking at target '%s', gameid '%s', path '%s' ...\n",
00944                 name.c_str(), gameid.c_str(), path.c_str());
00945         if (path.empty()) {
00946             printf(" ... no path specified, skipping\n");
00947             continue;
00948         }
00949         if (gameid.empty()) {
00950             gameid = name;
00951         }
00952 
00953         Common::FSNode dir(path);
00954         Common::FSList files;
00955         if (!dir.getChildren(files, Common::FSNode::kListAll)) {
00956             printf(" ... invalid path, skipping\n");
00957             continue;
00958         }
00959 
00960         DetectionResults detectionResults = EngineMan.detectGames(files);
00961         DetectedGames candidates = detectionResults.listRecognizedGames();
00962 
00963         bool gameidDiffers = false;
00964         DetectedGames::const_iterator x;
00965         for (x = candidates.begin(); x != candidates.end(); ++x) {
00966             gameidDiffers |= (scumm_stricmp(gameid.c_str(), x->gameId.c_str()) != 0);
00967         }
00968 
00969         if (candidates.empty()) {
00970             printf(" FAILURE: No games detected\n");
00971             failure++;
00972         } else if (candidates.size() > 1) {
00973             if (gameidDiffers) {
00974                 printf(" WARNING: Multiple games detected, some/all with wrong gameid\n");
00975             } else {
00976                 printf(" WARNING: Multiple games detected, but all have matching gameid\n");
00977             }
00978             failure++;
00979         } else if (gameidDiffers) {
00980             printf(" FAILURE: Wrong gameid detected\n");
00981             failure++;
00982         } else {
00983             printf(" SUCCESS: Game was detected correctly\n");
00984             success++;
00985         }
00986 
00987         for (x = candidates.begin(); x != candidates.end(); ++x) {
00988             printf("    gameid '%s', desc '%s', language '%s', platform '%s'\n",
00989                    x->gameId.c_str(),
00990                    x->description.c_str(),
00991                    Common::getLanguageDescription(x->language),
00992                    Common::getPlatformDescription(x->platform));
00993         }
00994     }
00995     int total = domains.size();
00996     printf("Detector test run: %d fail, %d success, %d skipped, out of %d\n",
00997             failure, success, total - failure - success, total);
00998 }
00999 #endif
01000 
01001 #ifdef UPGRADE_ALL_TARGETS_HACK
01002 void upgradeTargets() {
01003     // HACK: The following upgrades all your targets to the latest and
01004     // greatest. Right now that means updating the guioptions and (optionally)
01005     // also the game descriptions.
01006     // Basically, it loops over all targets, and calls the detector for the
01007     // given path. It then compares the result with the settings of the target.
01008     // If the basics seem to match, it updates the guioptions.
01009 
01010     printf("Upgrading all your existing targets\n");
01011 
01012     Common::ConfigManager::DomainMap::iterator iter = ConfMan.beginGameDomains();
01013     for (; iter != ConfMan.endGameDomains(); ++iter) {
01014         Common::ConfigManager::Domain &dom = iter->_value;
01015         Common::String name(iter->_key);
01016         Common::String gameid(dom.getVal("gameid"));
01017         Common::String path(dom.getVal("path"));
01018         printf("Looking at target '%s', gameid '%s' ...\n",
01019                 name.c_str(), gameid.c_str());
01020         if (path.empty()) {
01021             printf(" ... no path specified, skipping\n");
01022             continue;
01023         }
01024         if (gameid.empty()) {
01025             gameid = name;
01026         }
01027         gameid.toLowercase(); // TODO: Is this paranoia? Maybe we should just assume all lowercase, always?
01028 
01029         Common::FSNode dir(path);
01030         Common::FSList files;
01031         if (!dir.getChildren(files, Common::FSNode::kListAll)) {
01032             printf(" ... invalid path, skipping\n");
01033             continue;
01034         }
01035 
01036         Common::Language lang = Common::parseLanguage(dom.getVal("language"));
01037         Common::Platform plat = Common::parsePlatform(dom.getVal("platform"));
01038         Common::String desc(dom.getVal("description"));
01039 
01040         DetectionResults detectionResults = EngineMan.detectGames(files);
01041         DetectedGames candidates = detectionResults.listRecognizedGames();
01042 
01043         DetectedGame *g = 0;
01044 
01045         // We proceed as follows:
01046         // * If detection failed to produce candidates, skip.
01047         // * If there is a unique detector match, trust it.
01048         // * If there are multiple match, run over them comparing gameid, language and platform.
01049         //   If we end up with a unique match, use it. Otherwise, skip.
01050         if (candidates.empty()) {
01051             printf(" ... failed to detect game, skipping\n");
01052             continue;
01053         }
01054         if (candidates.size() > 1) {
01055             // Scan over all candidates, check if there is a unique match for gameid, language and platform
01056             DetectedGames::iterator x;
01057             int matchesFound = 0;
01058             for (x = candidates.begin(); x != candidates.end(); ++x) {
01059                 if (x->gameId == gameid && x->language == lang && x->platform == plat) {
01060                     matchesFound++;
01061                     g = &(*x);
01062                 }
01063             }
01064             if (matchesFound != 1) {
01065                 printf(" ... detected multiple games, could not establish unique match, skipping\n");
01066                 continue;
01067             }
01068         } else {
01069             // Unique match -> use it
01070             g = &candidates[0];
01071         }
01072 
01073         // At this point, g points to a GameDescriptor which we can use to update
01074         // the target referred to by dom. We update several things
01075 
01076         // Always set the gameid explicitly (in case of legacy targets)
01077         dom["gameid"] = g->gameId;
01078 
01079         // Always set the GUI options. The user should not modify them, and engines might
01080         // gain more features over time, so we want to keep this list up-to-date.
01081         if (!g->getGUIOptions().empty()) {
01082             printf("  -> update guioptions to '%s'\n", g->getGUIOptions().c_str());
01083             dom["guioptions"] = g->getGUIOptions();
01084         } else if (dom.contains("guioptions")) {
01085             dom.erase("guioptions");
01086         }
01087 
01088         // Update the language setting but only if none has been set yet.
01089         if (lang == Common::UNK_LANG && g->language != Common::UNK_LANG) {
01090             printf("  -> set language to '%s'\n", Common::getLanguageCode(g->language));
01091             dom["language"] = Common::getLanguageCode(g->language);
01092         }
01093 
01094         // Update the platform setting but only if none has been set yet.
01095         if (plat == Common::kPlatformUnknown && g->platform != Common::kPlatformUnknown) {
01096             printf("  -> set platform to '%s'\n", Common::getPlatformCode(g->platform));
01097             dom["platform"] = Common::getPlatformCode(g->platform);
01098         }
01099 
01100         // TODO: We could also update the description. But not everybody will want that.
01101         // Esp. because for some games (e.g. the combined Zak/Loom FM-TOWNS demo etc.)
01102         // ScummVM still generates an incorrect description string. So, the description
01103         // should only be updated if the user explicitly requests this.
01104 #if 0
01105         if (desc != g->description()) {
01106             printf("  -> update desc from '%s' to\n                      '%s' ?\n", desc.c_str(), g->description.c_str());
01107             dom["description"] = g->description;
01108         }
01109 #endif
01110     }
01111 
01112     // Finally, save our changes to disk
01113     ConfMan.flushToDisk();
01114 }
01115 #endif
01116 
01117 #else // DISABLE_COMMAND_LINE
01118 
01119 
01120 Common::String parseCommandLine(Common::StringMap &settings, int argc, const char * const *argv) {
01121     return Common::String();
01122 }
01123 
01124 
01125 #endif // DISABLE_COMMAND_LINE
01126 
01127 
01128 bool processSettings(Common::String &command, Common::StringMap &settings, Common::Error &err) {
01129     err = Common::kNoError;
01130 
01131 #ifndef DISABLE_COMMAND_LINE
01132 
01133     // Handle commands passed via the command line (like --list-targets and
01134     // --list-games). This must be done after the config file and the plugins
01135     // have been loaded.
01136     if (command == "list-targets") {
01137         listTargets();
01138         return true;
01139     } else if (command == "list-games") {
01140         listGames();
01141         return true;
01142     } else if (command == "list-saves") {
01143         err = listSaves(settings["game"]);
01144         return true;
01145     } else if (command == "list-themes") {
01146         listThemes();
01147         return true;
01148     } else if (command == "list-audio-devices") {
01149         listAudioDevices();
01150         return true;
01151     } else if (command == "version") {
01152         printf("%s\n", gScummVMFullVersion);
01153         printf("Features compiled in: %s\n", gScummVMFeatures);
01154         return true;
01155     } else if (command == "help") {
01156         printf(HELP_STRING, s_appName);
01157         return true;
01158     } else if (command == "auto-detect") {
01159         bool resursive = settings["recursive"] == "true";
01160         // If auto-detects fails (returns an empty ID) return true to close ScummVM.
01161         // If we get a non-empty ID, we store it in command so that it gets processed together with the
01162         // other command line options below.
01163         if (resursive) {
01164             printf("ERROR: Autodetection not supported with --recursive; are you sure you didn't want --detect?\n");
01165             err = Common::kUnknownError;
01166             return true;
01167             // There is not a particularly good technical reason for this.
01168             // From an UX point of view, however, it might get confusing.
01169             // Consider removing this if consensus says otherwise.
01170         } else {
01171             command = detectGames(settings["path"], settings["game"], resursive);
01172             if (command.empty()) {
01173                 err = Common::kNoGameDataFoundError;
01174                 return true;
01175             }
01176         }
01177     } else if (command == "detect") {
01178         detectGames(settings["path"], settings["game"], settings["recursive"] == "true");
01179         return true;
01180     } else if (command == "add") {
01181         addGames(settings["path"], settings["game"], settings["recursive"] == "true");
01182         return true;
01183     }
01184 #ifdef DETECTOR_TESTING_HACK
01185     else if (command == "test-detector") {
01186         runDetectorTest();
01187         return true;
01188     }
01189 #endif
01190 #ifdef UPGRADE_ALL_TARGETS_HACK
01191     else if (command == "upgrade-targets") {
01192         upgradeTargets();
01193         return true;
01194     }
01195 #endif
01196 
01197 #endif // DISABLE_COMMAND_LINE
01198 
01199 
01200     // If a target was specified, check whether there is either a game
01201     // domain (i.e. a target) matching this argument, or alternatively
01202     // whether there is a gameid matching that name.
01203     if (!command.empty()) {
01204         PlainGameDescriptor gd = EngineMan.findGame(command);
01205         if (ConfMan.hasGameDomain(command) || gd.gameId) {
01206             bool idCameFromCommandLine = false;
01207 
01208             // WORKAROUND: Fix for bug #1719463: "DETECTOR: Launching
01209             // undefined target adds launcher entry"
01210             //
01211             // We designate gameids which come strictly from command line
01212             // so AdvancedDetector will not save config file with invalid
01213             // gameid in case target autoupgrade was performed
01214             if (!ConfMan.hasGameDomain(command)) {
01215                 idCameFromCommandLine = true;
01216             }
01217 
01218             ConfMan.setActiveDomain(command);
01219 
01220             if (idCameFromCommandLine)
01221                 ConfMan.set("id_came_from_command_line", "1");
01222 
01223         } else {
01224 #ifndef DISABLE_COMMAND_LINE
01225             usage("Unrecognized game target '%s'", command.c_str());
01226 #endif // DISABLE_COMMAND_LINE
01227         }
01228     }
01229 
01230 
01231     // Finally, store the command line settings into the config manager.
01232     for (Common::StringMap::const_iterator x = settings.begin(); x != settings.end(); ++x) {
01233         Common::String key(x->_key);
01234         Common::String value(x->_value);
01235 
01236         // Replace any "-" in the key by "_" (e.g. change "save-slot" to "save_slot").
01237         for (Common::String::iterator c = key.begin(); c != key.end(); ++c)
01238             if (*c == '-')
01239                 *c = '_';
01240 
01241         // Store it into ConfMan.
01242         ConfMan.set(key, value, Common::ConfigManager::kTransientDomain);
01243     }
01244 
01245     return false;
01246 }
01247 
01248 } // End of namespace Base


Generated on Sat May 18 2019 05:00:58 for ResidualVM by doxygen 1.7.1
curved edge   curved edge