From 817d2078cca738af631380467a42b2e87e9c1d57 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 4 Nov 2008 19:49:26 +0000 Subject: Some cleanup / handle the case where the themepath is neither pointing to a dir nor to a .zip file svn-id: r34897 --- gui/ThemeEngine.cpp | 21 +++++++++++++-------- gui/ThemeEngine.h | 4 ++-- 2 files changed, 15 insertions(+), 10 deletions(-) (limited to 'gui') diff --git a/gui/ThemeEngine.cpp b/gui/ThemeEngine.cpp index df3f3af4f4..cbcd32fd4c 100644 --- a/gui/ThemeEngine.cpp +++ b/gui/ThemeEngine.cpp @@ -487,18 +487,19 @@ bool ThemeEngine::addDrawData(const Common::String &data, bool cached) { /********************************************************** * Theme XML loading *********************************************************/ -bool ThemeEngine::loadTheme(Common::String fileName) { +bool ThemeEngine::loadTheme(const Common::String &fileName) { unloadTheme(); - if (fileName != "builtin") + bool tryAgain = false; + if (fileName != "builtin") { ImageMan.addArchive(fileName); + if (!loadThemeXML(fileName)) { + warning("Could not parse custom theme '%s'. Falling back to default theme", fileName.c_str()); + tryAgain = true; // Fall back to default builtin theme + } + } - if (fileName == "builtin") { - if (!loadDefaultXML()) - error("Could not load default embedded theme"); - } else if (!loadThemeXML(fileName)) { - warning("Could not parse custom theme '%s'. Falling back to default theme", fileName.c_str()); - + if (fileName == "builtin" || tryAgain) { if (!loadDefaultXML()) // if we can't load the embedded theme, this is a complete failure error("Could not load default embedded theme"); } @@ -571,9 +572,13 @@ bool ThemeEngine::loadThemeXML(const Common::String &themeName) { #endif } else if (node.isDirectory()) { + warning("Don't know how to open theme '%s'", themeName.c_str()); archive = new Common::FSDirectory(node); } + if (!archive) + return false; + Common::File themercFile; // FIXME: Possibly dereferencing a NULL pointer here if the node's // name doesn't have a ".zip" suffix and the node is not a directory. diff --git a/gui/ThemeEngine.h b/gui/ThemeEngine.h index f164b8831c..0b054c53f5 100644 --- a/gui/ThemeEngine.h +++ b/gui/ThemeEngine.h @@ -476,8 +476,8 @@ public: return _initOk && _themeOk; } - /** Custom implementation of the GUI::Theme API, changed to use the XML parser. */ - bool loadTheme(Common::String themeName); + /** Load the them from the file with the specified name. */ + bool loadTheme(const Common::String &fileName); /** * Changes the active graphics mode of the GUI; may be used to either -- cgit v1.2.3