BASE: Fix auto-detect command to detect and start game

There were several issues.

The first one was introduced recently and caused the preferred target
to be used as a game ID, which resulted in an error when this is not
a valid game ID. Thus this fixes bug #9754.

The other issues were here since the auto-detect command was added and
caused other command line options, suh as the path, to be lost. This
usually resulted in a failure to start the game as the data files could
not be found (unless the ID happened to be the same name as a target
previously added). This also caused a reappearance of the old bug
This commit is contained in:
Thierry Crozat 2017-05-02 23:59:23 +01:00
parent bfd2b487eb
commit ee0ac26621

View File

@ -855,11 +855,11 @@ static bool addGameToConf(const GameDescriptor &gd) {
return true;
}
/** Display all games in the given directory, add it to config according to input */
static bool detectGames(Common::String path, bool addToConfig) {
/** Display all games in the given directory, return ID of first detected game */
static Common::String detectGames(Common::String path) {
GameList candidates = getGameList(path);
if (candidates.empty())
return false;
return Common::String();
// Print all the candidate found
printf("ID Description\n");
@ -868,11 +868,7 @@ static bool detectGames(Common::String path, bool addToConfig) {
printf("%-20s %s\n", v->gameid().c_str(), v->description().c_str());
}
if (addToConfig) {
Common::String domain = candidates[0].preferredtarget();
ConfMan.setActiveDomain(domain);
}
return true;
return candidates[0].gameid();
}
/** Add one of the games in the given directory, or current directory if empty */
@ -1194,11 +1190,15 @@ bool processSettings(Common::String &command, Common::StringMap &settings, Commo
printf(HELP_STRING, s_appName);
return true;
} else if (command == "auto-detect") {
// If auto-detects succeed, we want to return false so that the game is started
return !detectGames(settings["path"], true);
//return true;
// If auto-detects fails (returns an empty ID) return true to close ScummVM.
// If we get a non-empty ID, we store it in command so that it gets processed together with the
// other command line options below.
command = detectGames(settings["path"]);
if (command.empty())
return true;
} else if (command == "detect") {
detectGames(settings["path"], false);
// Ignore the return value of detectGame.
detectGames(settings["path"]);
return true;
} else if (command == "add") {
addGame(settings["path"]);