From 3a574199b0b3e848d786d71a50a1107536507479 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 18 Apr 2011 18:19:53 +0200 Subject: COMMON: Cleanup names/handling of some error codes --- base/commandLine.cpp | 29 +++++++++++++++-------------- base/main.cpp | 11 ++++++----- common/error.cpp | 12 ++++++++---- common/error.h | 5 ++--- 4 files changed, 31 insertions(+), 26 deletions(-) diff --git a/base/commandLine.cpp b/base/commandLine.cpp index f920dd0170..7c482d3057 100644 --- a/base/commandLine.cpp +++ b/base/commandLine.cpp @@ -641,29 +641,30 @@ static Common::Error listSaves(const char *target) { GameDescriptor game = EngineMan.findGame(gameid, &plugin); if (!plugin) { - warning("Could not find any plugin to handle target '%s' (gameid '%s')", target, gameid.c_str()); - return Common::kPluginNotFound; + return Common::Error(Common::kEnginePluginNotFound, + Common::String::format("target '%s', gameid '%s", target, gameid.c_str())); } if (!(*plugin)->hasFeature(MetaEngine::kSupportsListSaves)) { // TODO: Include more info about the target (desc, engine name, ...) ??? - printf("ScummVM does not support listing save states for target '%s' (gameid '%s') .\n", target, gameid.c_str()); - result = Common::kPluginNotSupportSaves; + return Common::Error(Common::kEnginePluginNotSupportSaves, + Common::String::format("target '%s', gameid '%s", target, gameid.c_str())); } else { // Query the plugin for a list of savegames SaveStateList saveList = (*plugin)->listSaves(target); - // TODO: Include more info about the target (desc, engine name, ...) ??? - printf("Saves for target '%s' (gameid '%s'):\n", target, gameid.c_str()); - printf(" Slot Description \n" - " ---- ------------------------------------------------------\n"); - - if (saveList.size() == 0) - result = Common::kNoSavesError; + 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(" Slot Description \n" + " ---- ------------------------------------------------------\n"); - for (SaveStateList::const_iterator x = saveList.begin(); x != saveList.end(); ++x) { - printf(" %-4s %s\n", x->save_slot().c_str(), x->description().c_str()); - // TODO: Could also iterate over the full hashmap, printing all key-value pairs + for (SaveStateList::const_iterator x = saveList.begin(); x != saveList.end(); ++x) { + printf(" %-4s %s\n", x->save_slot().c_str(), x->description().c_str()); + // 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()); } } diff --git a/base/main.cpp b/base/main.cpp index 4dfed0f08c..13359031f6 100644 --- a/base/main.cpp +++ b/base/main.cpp @@ -111,13 +111,12 @@ static const EnginePlugin *detectPlugin() { if (plugin == 0) { printf("failed\n"); warning("%s is an invalid gameid. Use the --list-games option to list supported gameid", gameid.c_str()); - return 0; } else { printf("%s\n", plugin->getName()); - } - // FIXME: Do we really need this one? - printf(" Starting '%s'\n", game.description().c_str()); + // FIXME: Do we really need this one? + printf(" Starting '%s'\n", game.description().c_str()); + } return plugin; } @@ -352,8 +351,10 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) { // TODO: deal with settings that require plugins to be loaded res = Base::processSettings(command, settings); - if (res.getCode() != Common::kArgumentNotProcessed) + if (res.getCode() != Common::kArgumentNotProcessed) { + warning("%s", res.getDesc().c_str()); return res.getCode(); + } // Init the backend. Must take place after all config data (including // the command line params) was read. diff --git a/common/error.cpp b/common/error.cpp index 86557ee2dc..8fa58e2259 100644 --- a/common/error.cpp +++ b/common/error.cpp @@ -66,11 +66,15 @@ static String errorToString(ErrorCode errorCode) { case kWritingFailed: return _s("Writing data failed"); - case kUnknownError: - case kPluginNotFound: - case kPluginNotSupportSaves: - case kNoSavesError: + case kEnginePluginNotFound: + return _s("Could not find suitable engine plugin"); + case kEnginePluginNotSupportSaves: + return _s("Engine plugin does not support save states"); + case kArgumentNotProcessed: + return _s("Command line argument not processed"); + + case kUnknownError: default: return _s("Unknown error"); } diff --git a/common/error.h b/common/error.h index 5c19761d6c..1ffbba723a 100644 --- a/common/error.h +++ b/common/error.h @@ -63,9 +63,8 @@ enum ErrorCode { kWritingFailed, ///< Failure to write data -- disk full? // The following are used by --list-saves - kPluginNotFound, ///< Failed to find plugin to handle target - kPluginNotSupportSaves, ///< Failed if plugin does not support saves - kNoSavesError, ///< There are no saves to show + kEnginePluginNotFound, ///< Failed to find plugin to handle target + kEnginePluginNotSupportSaves, ///< Failed if plugin does not support listing save states kArgumentNotProcessed, ///< Used in command line parsing -- cgit v1.2.3