aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--base/main.cpp26
-rw-r--r--common/error.cpp72
-rw-r--r--common/error.h8
-rw-r--r--common/module.mk1
-rw-r--r--gui/error.cpp45
-rw-r--r--gui/error.h50
-rw-r--r--gui/module.mk1
7 files changed, 187 insertions, 16 deletions
diff --git a/base/main.cpp b/base/main.cpp
index 71a5f96382..fb456f38a2 100644
--- a/base/main.cpp
+++ b/base/main.cpp
@@ -49,6 +49,7 @@
#include "gui/GuiManager.h"
#include "gui/message.h"
+#include "gui/error.h"
#include "sound/audiocd.h"
@@ -134,21 +135,12 @@ static Common::Error runGame(const EnginePlugin *plugin, OSystem &system, const
// Check for errors
if (!engine || err != Common::kNoError) {
- // TODO: Show an error dialog or so?
- // TODO: Also take 'err' into consideration...
- //GUI::MessageDialog alert("ScummVM could not find any game in the specified directory!");
- //alert.runModal();
- const char *errMsg = 0;
- switch (err) {
- case Common::kInvalidPathError:
- errMsg = "Invalid game path";
- break;
- case Common::kNoGameDataFoundError:
- errMsg = "Unable to locate game data";
- break;
- default:
- errMsg = "Unknown error";
- }
+
+ // TODO: An errorDialog for this and engine related errors is displayed already in the scummvm_main function
+ // Is a separate dialog here still required?
+
+ //GUI::displayErrorDialog("ScummVM could not find any game in the specified directory!");
+ const char *errMsg = Common::errorToString(err);
warning("%s failed to instantiate engine: %s (target '%s', path '%s')",
plugin->getName(),
@@ -391,7 +383,8 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) {
// Did an error occur ?
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
@@ -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
// screen to draw on yet.
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.
diff --git a/common/error.cpp b/common/error.cpp
new file mode 100644
index 0000000000..d51774fd3e
--- /dev/null
+++ b/common/error.cpp
@@ -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
diff --git a/common/error.h b/common/error.h
index 30142926ca..c4d383e508 100644
--- a/common/error.h
+++ b/common/error.h
@@ -66,6 +66,14 @@ enum Error {
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
#endif //COMMON_ERROR_H
diff --git a/common/module.mk b/common/module.mk
index 1209718a86..2bbb1eda76 100644
--- a/common/module.mk
+++ b/common/module.mk
@@ -5,6 +5,7 @@ MODULE_OBJS := \
config-file.o \
config-manager.o \
debug.o \
+ error.o \
EventDispatcher.o \
EventRecorder.o \
file.o \
diff --git a/gui/error.cpp b/gui/error.cpp
new file mode 100644
index 0000000000..fbe09c5a02
--- /dev/null
+++ b/gui/error.cpp
@@ -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
diff --git a/gui/error.h b/gui/error.h
new file mode 100644
index 0000000000..a55f555bed
--- /dev/null
+++ b/gui/error.h
@@ -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
diff --git a/gui/module.mk b/gui/module.mk
index e97a6eb741..9bf1a08d4b 100644
--- a/gui/module.mk
+++ b/gui/module.mk
@@ -7,6 +7,7 @@ MODULE_OBJS := \
debugger.o \
dialog.o \
editable.o \
+ error.o \
EditTextWidget.o \
GuiManager.o \
launcher.o \