[Scummvm-git-logs] scummvm master -> cb02d7471d073ad3ddb4a3dba84aab16cce514f0

criezy criezy at scummvm.org
Wed Apr 25 20:40:25 CEST 2018


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
5907add148 BASE: Use --game to specify target for --list-saves command
cb02d7471d BASE: Allow listing save games for all targets


Commit: 5907add14821b4dc9b205157c1a90c76270d5541
    https://github.com/scummvm/scummvm/commit/5907add14821b4dc9b205157c1a90c76270d5541
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2018-04-25T19:40:20+01:00

Commit Message:
BASE: Use --game to specify target for --list-saves command

This change brings the --list-saves command syntax in line with
other commands.

Changed paths:
    README
    base/commandLine.cpp


diff --git a/README b/README
index afb153d..30f2b62 100644
--- a/README
+++ b/README
@@ -1463,7 +1463,7 @@ arguments -- see the next section.
   -h, --help               Display a brief help text and exit
   -z, --list-games         Display list of supported games and exit
   -t, --list-targets       Display list of configured targets and exit
-  --list-saves=TARGET      Display a list of saved games for the game (TARGET) specified
+  --list-saves             Display a list of saved games for the target specified with --game=TARGET
   -a, --add                Add all games from current or specified directory.
                            If --game=ID is passed only the game with id ID is
                            added. See also --detect.
@@ -2011,7 +2011,7 @@ Where 'xxx' is exact the saved game slot (i.e., 001) under ScummVM
    This switch may be used to display a list of the current saved games
    of the specified target game and their corresponding save slots.
 
-   Usage: --list-saves=[TARGET], where [TARGET] is the target game.
+   Usage: --list-saves --game=[TARGET], where [TARGET] is the target game.
 
    Engines which currently support --list-saves are:
 
diff --git a/base/commandLine.cpp b/base/commandLine.cpp
index f9090a8..0ef8996 100644
--- a/base/commandLine.cpp
+++ b/base/commandLine.cpp
@@ -68,7 +68,7 @@ static const char HELP_STRING[] =
 	"  -h, --help               Display a brief help text and exit\n"
 	"  -z, --list-games         Display list of supported games and exit\n"
 	"  -t, --list-targets       Display list of configured targets and exit\n"
-	"  --list-saves=TARGET      Display a list of saved games for the game (TARGET) specified\n"
+	"  --list-saves             Display a list of saved games for the target specified with --game=TARGET\n"
 	"  -a, --add                Add all games from current or specified directory.\n"
 	"                           If --game=ID is passed only the game with id ID is added. See also --detect\n"
 	"                           Use --path=PATH to specify a directory.\n"
@@ -458,13 +458,8 @@ Common::String parseCommandLine(Common::StringMap &settings, int argc, const cha
 			END_COMMAND
 #endif
 
-			DO_LONG_OPTION("list-saves")
-				// TODO: Make the argument optional. If no argument is given, list all saved games
-				// for all configured targets.
-				// TODO: Consider breaking the command line interface to pass the argument via the --game option
-				ensureFirstCommand(command, "list-saves");
-				command = "list-saves";
-			END_OPTION
+			DO_LONG_COMMAND("list-saves")
+			END_COMMAND
 
 			DO_OPTION('c', "config")
 			END_OPTION
@@ -734,9 +729,14 @@ static void listTargets() {
 }
 
 /** List all saves states for the given target. */
-static Common::Error listSaves(const char *target) {
+static Common::Error listSaves(const Common::String &target) {
 	Common::Error result = Common::kNoError;
 
+	// TODO: Make the target argument optional. If no argument is given, list all saved games
+	// for all configured targets.
+	if (target.empty())
+		usage("You must specify a target using --game=TARGET when using --list-saves.");
+
 	// FIXME HACK
 	g_system->initBackend();
 
@@ -762,7 +762,7 @@ static Common::Error listSaves(const char *target) {
 
 	if (!plugin) {
 		return Common::Error(Common::kEnginePluginNotFound,
-		                     Common::String::format("target '%s', gameid '%s", target, gameid.c_str()));
+		                     Common::String::format("target '%s', gameid '%s", target.c_str(), gameid.c_str()));
 	}
 
 	const MetaEngine &metaEngine = plugin->get<MetaEngine>();
@@ -770,14 +770,14 @@ static Common::Error listSaves(const char *target) {
 	if (!metaEngine.hasFeature(MetaEngine::kSupportsListSaves)) {
 		// TODO: Include more info about the target (desc, engine name, ...) ???
 		return Common::Error(Common::kEnginePluginNotSupportSaves,
-		                     Common::String::format("target '%s', gameid '%s", target, gameid.c_str()));
+		                     Common::String::format("target '%s', gameid '%s", target.c_str(), gameid.c_str()));
 	} else {
 		// Query the plugin for a list of saved games
-		SaveStateList saveList = metaEngine.listSaves(target);
+		SaveStateList saveList = metaEngine.listSaves(target.c_str());
 
 		if (saveList.size() > 0) {
 			// TODO: Include more info about the target (desc, engine name, ...) ???
-			printf("Save states for target '%s' (gameid '%s'):\n", target, gameid.c_str());
+			printf("Save states for target '%s' (gameid '%s'):\n", target.c_str(), gameid.c_str());
 			printf("  Slot Description                                           \n"
 				   "  ---- ------------------------------------------------------\n");
 
@@ -786,7 +786,7 @@ static Common::Error listSaves(const char *target) {
 				// TODO: Could also iterate over the full hashmap, printing all key-value pairs
 			}
 		} else {
-			printf("There are no save states for target '%s' (gameid '%s'):\n", target, gameid.c_str());
+			printf("There are no save states for target '%s' (gameid '%s'):\n", target.c_str(), gameid.c_str());
 		}
 	}
 
@@ -1165,7 +1165,7 @@ bool processSettings(Common::String &command, Common::StringMap &settings, Commo
 		listGames();
 		return true;
 	} else if (command == "list-saves") {
-		err = listSaves(settings["list-saves"].c_str());
+		err = listSaves(settings["game"]);
 		return true;
 	} else if (command == "list-themes") {
 		listThemes();


Commit: cb02d7471d073ad3ddb4a3dba84aab16cce514f0
    https://github.com/scummvm/scummvm/commit/cb02d7471d073ad3ddb4a3dba84aab16cce514f0
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2018-04-25T19:40:20+01:00

Commit Message:
BASE: Allow listing save games for all targets

Changed paths:
    README
    base/commandLine.cpp


diff --git a/README b/README
index 30f2b62..9657bbe 100644
--- a/README
+++ b/README
@@ -1463,7 +1463,8 @@ arguments -- see the next section.
   -h, --help               Display a brief help text and exit
   -z, --list-games         Display list of supported games and exit
   -t, --list-targets       Display list of configured targets and exit
-  --list-saves             Display a list of saved games for the target specified with --game=TARGET
+  --list-saves             Display a list of saved games for the target specified
+                           with --game=TARGET, or all targets if none is specified
   -a, --add                Add all games from current or specified directory.
                            If --game=ID is passed only the game with id ID is
                            added. See also --detect.
@@ -2009,7 +2010,8 @@ Where 'xxx' is exact the saved game slot (i.e., 001) under ScummVM
 --list-saves:
 
    This switch may be used to display a list of the current saved games
-   of the specified target game and their corresponding save slots.
+   of the specified target game and their corresponding save slots. If no
+   target is specified, it lists saved games for all known target.
 
    Usage: --list-saves --game=[TARGET], where [TARGET] is the target game.
 
diff --git a/base/commandLine.cpp b/base/commandLine.cpp
index 0ef8996..83c7b56 100644
--- a/base/commandLine.cpp
+++ b/base/commandLine.cpp
@@ -68,7 +68,8 @@ static const char HELP_STRING[] =
 	"  -h, --help               Display a brief help text and exit\n"
 	"  -z, --list-games         Display list of supported games and exit\n"
 	"  -t, --list-targets       Display list of configured targets and exit\n"
-	"  --list-saves             Display a list of saved games for the target specified with --game=TARGET\n"
+	"  --list-saves             Display a list of saved games for the target specified\n"
+	"                           with --game=TARGET, or all targets if none is specified\n"
 	"  -a, --add                Add all games from current or specified directory.\n"
 	"                           If --game=ID is passed only the game with id ID is added. See also --detect\n"
 	"                           Use --path=PATH to specify a directory.\n"
@@ -732,67 +733,94 @@ static void listTargets() {
 static Common::Error listSaves(const Common::String &target) {
 	Common::Error result = Common::kNoError;
 
-	// TODO: Make the target argument optional. If no argument is given, list all saved games
-	// for all configured targets.
-	if (target.empty())
-		usage("You must specify a target using --game=TARGET when using --list-saves.");
+	// If no target is specified, list save games for all known targets
+	Common::Array<Common::String> targets;
+	if (!target.empty())
+		targets.push_back(target);
+	else {
+		const Common::ConfigManager::DomainMap &domains = ConfMan.getGameDomains();
+		Common::ConfigManager::DomainMap::const_iterator iter;
+
+		targets.reserve(domains.size());
+		for (iter = domains.begin(); iter != domains.end(); ++iter)
+			targets.push_back(iter->_key);
+	}
 
 	// FIXME HACK
 	g_system->initBackend();
 
-	// Grab the "target" domain, if any
-	const Common::ConfigManager::Domain *domain = ConfMan.getDomain(target);
-
-	// Set up the game domain as newly active domain, so
-	// target specific savepath will be checked
 	Common::String oldDomain = ConfMan.getActiveDomainName();
-	ConfMan.setActiveDomain(target);
-
-	// Grab the gameid from the domain resp. use the target as gameid
-	Common::String gameid;
-	if (domain)
-		gameid = domain->getVal("gameid");
-	if (gameid.empty())
-		gameid = target;
-	gameid.toLowercase(); // Normalize it to lower case
-
-	// Find the plugin that will handle the specified gameid
-	const Plugin *plugin = nullptr;
-	GameDescriptor game = EngineMan.findGame(gameid, &plugin);
-
-	if (!plugin) {
-		return Common::Error(Common::kEnginePluginNotFound,
-		                     Common::String::format("target '%s', gameid '%s", target.c_str(), gameid.c_str()));
-	}
 
-	const MetaEngine &metaEngine = plugin->get<MetaEngine>();
+	bool atLeastOneFound = false;
+	for (Common::Array<Common::String>::const_iterator i = targets.begin(), end = targets.end(); i != end; ++i) {
+		// Grab the "target" domain, if any
+		const Common::ConfigManager::Domain *domain = ConfMan.getDomain(*i);
+
+		// Set up the game domain as newly active domain, so
+		// target specific savepath will be checked
+		ConfMan.setActiveDomain(*i);
+
+		// Grab the gameid from the domain resp. use the target as gameid
+		Common::String gameid;
+		if (domain)
+			gameid = domain->getVal("gameid");
+		if (gameid.empty())
+			gameid = *i;
+		gameid.toLowercase(); // Normalize it to lower case
+
+		// Find the plugin that will handle the specified gameid
+		const Plugin *plugin = nullptr;
+		GameDescriptor game = EngineMan.findGame(gameid, &plugin);
+
+		if (!plugin) {
+			// If the target was specified, treat this as an error, and otherwise skip it.
+			if (!target.empty())
+				return Common::Error(Common::kEnginePluginNotFound,
+				                     Common::String::format("target '%s', gameid '%s", i->c_str(), gameid.c_str()));
+			printf("Plugin could not be loaded for target '%s', gameid '%s", i->c_str(), gameid.c_str());
+			continue;
+		}
+
+		const MetaEngine &metaEngine = plugin->get<MetaEngine>();
+
+		if (!metaEngine.hasFeature(MetaEngine::kSupportsListSaves)) {
+			// If the target was specified, treat this as an error, and otherwise skip it.
+			if (!target.empty())
+				// TODO: Include more info about the target (desc, engine name, ...) ???
+				return Common::Error(Common::kEnginePluginNotSupportSaves,
+				                     Common::String::format("target '%s', gameid '%s", i->c_str(), gameid.c_str()));
+			continue;
+		}
 
-	if (!metaEngine.hasFeature(MetaEngine::kSupportsListSaves)) {
-		// TODO: Include more info about the target (desc, engine name, ...) ???
-		return Common::Error(Common::kEnginePluginNotSupportSaves,
-		                     Common::String::format("target '%s', gameid '%s", target.c_str(), gameid.c_str()));
-	} else {
 		// Query the plugin for a list of saved games
-		SaveStateList saveList = metaEngine.listSaves(target.c_str());
+		SaveStateList saveList = metaEngine.listSaves(i->c_str());
 
 		if (saveList.size() > 0) {
 			// TODO: Include more info about the target (desc, engine name, ...) ???
-			printf("Save states for target '%s' (gameid '%s'):\n", target.c_str(), gameid.c_str());
+			if (atLeastOneFound)
+				printf("\n");
+			printf("Save states for target '%s' (gameid '%s'):\n", i->c_str(), gameid.c_str());
 			printf("  Slot Description                                           \n"
-				   "  ---- ------------------------------------------------------\n");
+					   "  ---- ------------------------------------------------------\n");
 
 			for (SaveStateList::const_iterator x = saveList.begin(); x != saveList.end(); ++x) {
 				printf("  %-4d %s\n", x->getSaveSlot(), x->getDescription().c_str());
 				// TODO: Could also iterate over the full hashmap, printing all key-value pairs
 			}
+			atLeastOneFound = true;
 		} else {
-			printf("There are no save states for target '%s' (gameid '%s'):\n", target.c_str(), gameid.c_str());
+			// If the target was specified, indicate no save games were found for it. Otherwise just skip it.
+			if (!target.empty())
+				printf("There are no save states for target '%s' (gameid '%s'):\n", i->c_str(), gameid.c_str());
 		}
 	}
 
 	// Revert to the old active domain
 	ConfMan.setActiveDomain(oldDomain);
 
+	if (!atLeastOneFound && target.empty())
+		printf("No save states could be found.\n");
+
 	return result;
 }
 





More information about the Scummvm-git-logs mailing list