Rest of patch #2982224: GSoC: Added unit test and unified error message display
svn-id: r48627
This commit is contained in:
parent
b928da4418
commit
f2ff555996
7 changed files with 187 additions and 16 deletions
|
@ -49,6 +49,7 @@
|
||||||
|
|
||||||
#include "gui/GuiManager.h"
|
#include "gui/GuiManager.h"
|
||||||
#include "gui/message.h"
|
#include "gui/message.h"
|
||||||
|
#include "gui/error.h"
|
||||||
|
|
||||||
#include "sound/audiocd.h"
|
#include "sound/audiocd.h"
|
||||||
|
|
||||||
|
@ -134,21 +135,12 @@ static Common::Error runGame(const EnginePlugin *plugin, OSystem &system, const
|
||||||
|
|
||||||
// Check for errors
|
// Check for errors
|
||||||
if (!engine || err != Common::kNoError) {
|
if (!engine || err != Common::kNoError) {
|
||||||
// TODO: Show an error dialog or so?
|
|
||||||
// TODO: Also take 'err' into consideration...
|
// TODO: An errorDialog for this and engine related errors is displayed already in the scummvm_main function
|
||||||
//GUI::MessageDialog alert("ScummVM could not find any game in the specified directory!");
|
// Is a separate dialog here still required?
|
||||||
//alert.runModal();
|
|
||||||
const char *errMsg = 0;
|
//GUI::displayErrorDialog("ScummVM could not find any game in the specified directory!");
|
||||||
switch (err) {
|
const char *errMsg = Common::errorToString(err);
|
||||||
case Common::kInvalidPathError:
|
|
||||||
errMsg = "Invalid game path";
|
|
||||||
break;
|
|
||||||
case Common::kNoGameDataFoundError:
|
|
||||||
errMsg = "Unable to locate game data";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
errMsg = "Unknown error";
|
|
||||||
}
|
|
||||||
|
|
||||||
warning("%s failed to instantiate engine: %s (target '%s', path '%s')",
|
warning("%s failed to instantiate engine: %s (target '%s', path '%s')",
|
||||||
plugin->getName(),
|
plugin->getName(),
|
||||||
|
@ -391,7 +383,8 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) {
|
||||||
|
|
||||||
// Did an error occur ?
|
// Did an error occur ?
|
||||||
if (result != Common::kNoError) {
|
if (result != Common::kNoError) {
|
||||||
// TODO: Show an informative error dialog if starting the selected game failed.
|
// Shows an informative error dialog if starting the selected game failed.
|
||||||
|
GUI::displayErrorDialog(result, "Error running game:");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quit unless an error occurred, or Return to launcher was requested
|
// Quit unless an error occurred, or Return to launcher was requested
|
||||||
|
@ -418,6 +411,7 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) {
|
||||||
// A dialog would be nicer, but we don't have any
|
// A dialog would be nicer, but we don't have any
|
||||||
// screen to draw on yet.
|
// screen to draw on yet.
|
||||||
warning("Could not find any engine capable of running the selected game");
|
warning("Could not find any engine capable of running the selected game");
|
||||||
|
GUI::displayErrorDialog("Could not find any engine capable of running the selected game");
|
||||||
}
|
}
|
||||||
|
|
||||||
// We will destroy the AudioCDManager singleton here to save some memory.
|
// We will destroy the AudioCDManager singleton here to save some memory.
|
||||||
|
|
72
common/error.cpp
Normal file
72
common/error.cpp
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
/* ScummVM - Graphic Adventure Engine
|
||||||
|
*
|
||||||
|
* ScummVM is the legal property of its developers, whose names
|
||||||
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||||
|
* file distributed with this source distribution.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
* $URL$
|
||||||
|
* $Id$
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "common/error.h"
|
||||||
|
#include "common/util.h"
|
||||||
|
|
||||||
|
namespace Common {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error Table: Maps error codes to their default descriptions
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct ErrorMessage {
|
||||||
|
Error error;
|
||||||
|
const char *errMsg;
|
||||||
|
};
|
||||||
|
|
||||||
|
static const ErrorMessage _errMsgTable[] = {
|
||||||
|
{ kInvalidPathError, "Invalid Path" },
|
||||||
|
{ kNoGameDataFoundError, "Game Data not found" },
|
||||||
|
{ kUnsupportedGameidError, "Game Id not supported" },
|
||||||
|
{ kUnsupportedColorMode, "Unsupported Color Mode" },
|
||||||
|
|
||||||
|
{ kReadPermissionDenied, "Read permission denied" },
|
||||||
|
{ kWritePermissionDenied, "Write permission denied" },
|
||||||
|
|
||||||
|
// The following three overlap a bit with kInvalidPathError and each other. Which to keep?
|
||||||
|
{ kPathDoesNotExist, "Path not exists" },
|
||||||
|
{ kPathNotDirectory, "Path not a directory" },
|
||||||
|
{ kPathNotFile, "Path not a file" },
|
||||||
|
|
||||||
|
{ kCreatingFileFailed, "Cannot create file" },
|
||||||
|
{ kReadingFailed, "Reading failed" },
|
||||||
|
{ kWritingFailed, "Writing data failed" },
|
||||||
|
|
||||||
|
{ kUnknownError, "Unknown Error" }
|
||||||
|
};
|
||||||
|
|
||||||
|
const char *errorToString(Error error) {
|
||||||
|
|
||||||
|
for (int i = 0; i < ARRAYSIZE(_errMsgTable); i++) {
|
||||||
|
if (error == _errMsgTable[i].error) {
|
||||||
|
return _errMsgTable[i].errMsg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Unknown Error";
|
||||||
|
}
|
||||||
|
|
||||||
|
} // End of namespace Common
|
|
@ -66,6 +66,14 @@ enum Error {
|
||||||
kUnknownError ///< Catch-all error, used if no other error code matches
|
kUnknownError ///< Catch-all error, used if no other error code matches
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps an error code to equivalent string description.
|
||||||
|
*
|
||||||
|
* @param error error code to be converted
|
||||||
|
* @return a pointer to string description of the error
|
||||||
|
*/
|
||||||
|
const char *errorToString(Error error);
|
||||||
|
|
||||||
} // End of namespace Common
|
} // End of namespace Common
|
||||||
|
|
||||||
#endif //COMMON_ERROR_H
|
#endif //COMMON_ERROR_H
|
||||||
|
|
|
@ -5,6 +5,7 @@ MODULE_OBJS := \
|
||||||
config-file.o \
|
config-file.o \
|
||||||
config-manager.o \
|
config-manager.o \
|
||||||
debug.o \
|
debug.o \
|
||||||
|
error.o \
|
||||||
EventDispatcher.o \
|
EventDispatcher.o \
|
||||||
EventRecorder.o \
|
EventRecorder.o \
|
||||||
file.o \
|
file.o \
|
||||||
|
|
45
gui/error.cpp
Normal file
45
gui/error.cpp
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
/* ScummVM - Graphic Adventure Engine
|
||||||
|
*
|
||||||
|
* ScummVM is the legal property of its developers, whose names
|
||||||
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||||
|
* file distributed with this source distribution.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
* $URL$
|
||||||
|
* $Id$
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "common/error.h"
|
||||||
|
#include "gui/message.h"
|
||||||
|
#include "gui/error.h"
|
||||||
|
|
||||||
|
namespace GUI {
|
||||||
|
|
||||||
|
void displayErrorDialog(const char *text) {
|
||||||
|
GUI::MessageDialog alert(text);
|
||||||
|
alert.runModal();
|
||||||
|
}
|
||||||
|
|
||||||
|
void displayErrorDialog(Common::Error error, const char *extraText) {
|
||||||
|
Common::String errorText(extraText);
|
||||||
|
errorText += " ";
|
||||||
|
errorText += Common::errorToString(error);
|
||||||
|
GUI::MessageDialog alert(errorText);
|
||||||
|
alert.runModal();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // End of namespace GUI
|
50
gui/error.h
Normal file
50
gui/error.h
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
/* ScummVM - Graphic Adventure Engine
|
||||||
|
*
|
||||||
|
* ScummVM is the legal property of its developers, whose names
|
||||||
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||||
|
* file distributed with this source distribution.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
* $URL$
|
||||||
|
* $Id$
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GUI_ERROR_H
|
||||||
|
#define GUI_ERROR_H
|
||||||
|
|
||||||
|
#include "common/error.h"
|
||||||
|
|
||||||
|
namespace GUI {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays an error dialog for some error code.
|
||||||
|
*
|
||||||
|
* @param error error code
|
||||||
|
* @param extraText extra text to be displayed in addition to default string description(optional)
|
||||||
|
*/
|
||||||
|
void displayErrorDialog(Common::Error error, const char *extraText = "");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays an error dialog for a given message.
|
||||||
|
*
|
||||||
|
* @param text message to be displayed
|
||||||
|
*/
|
||||||
|
void displayErrorDialog(const char *text);
|
||||||
|
|
||||||
|
} // End of namespace GUI
|
||||||
|
|
||||||
|
#endif //GUI_ERROR_H
|
|
@ -7,6 +7,7 @@ MODULE_OBJS := \
|
||||||
debugger.o \
|
debugger.o \
|
||||||
dialog.o \
|
dialog.o \
|
||||||
editable.o \
|
editable.o \
|
||||||
|
error.o \
|
||||||
EditTextWidget.o \
|
EditTextWidget.o \
|
||||||
GuiManager.o \
|
GuiManager.o \
|
||||||
launcher.o \
|
launcher.o \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue