diff options
Diffstat (limited to 'gui/ThemeEngine.cpp')
-rw-r--r-- | gui/ThemeEngine.cpp | 63 |
1 files changed, 35 insertions, 28 deletions
diff --git a/gui/ThemeEngine.cpp b/gui/ThemeEngine.cpp index 82104eb7ae..098cb8e0ac 100644 --- a/gui/ThemeEngine.cpp +++ b/gui/ThemeEngine.cpp @@ -24,7 +24,6 @@ */ #include "common/system.h" -#include "common/events.h" #include "common/config-manager.h" #include "common/file.h" #include "common/fs.h" @@ -32,14 +31,13 @@ #include "common/tokenizer.h" #include "common/translation.h" -#include "graphics/colormasks.h" #include "graphics/cursorman.h" #include "graphics/fontman.h" #include "graphics/imagedec.h" #include "graphics/surface.h" #include "graphics/VectorRenderer.h" -#include "gui/launcher.h" +#include "gui/widget.h" #include "gui/ThemeEngine.h" #include "gui/ThemeEval.h" #include "gui/ThemeParser.h" @@ -373,8 +371,8 @@ const char *ThemeEngine::findModeConfigName(GraphicsMode mode) { bool ThemeEngine::init() { // reset everything and reload the graphics _initOk = false; - setGraphicsMode(_graphicsMode); _overlayFormat = _system->getOverlayFormat(); + setGraphicsMode(_graphicsMode); if (_screen.pixels && _backBuffer.pixels) { _initOk = true; @@ -393,7 +391,7 @@ bool ThemeEngine::init() { Common::FSNode node(_themeFile); if (node.isDirectory()) { _themeArchive = new Common::FSDirectory(node); - } else if (_themeFile.hasSuffix(".zip")) { + } else if (_themeFile.matchString("*.zip", true)) { // TODO: Also use "node" directly? // Look for the zip file via SearchMan Common::ArchiveMemberPtr member = SearchMan.getMember(_themeFile); @@ -499,10 +497,10 @@ void ThemeEngine::setGraphicsMode(GraphicsMode mode) { uint32 height = _system->getOverlayHeight(); _backBuffer.free(); - _backBuffer.create(width, height, _bytesPerPixel); + _backBuffer.create(width, height, _overlayFormat); _screen.free(); - _screen.create(width, height, _bytesPerPixel); + _screen.create(width, height, _overlayFormat); delete _vectorRenderer; _vectorRenderer = Graphics::createRenderer(mode); @@ -1477,20 +1475,23 @@ Common::String ThemeEngine::genLocalizedFontFilename(const Common::String &filen #ifndef USE_TRANSLATION return filename; #else - Common::String result; - bool pointPassed = false; - - for (const char *p = filename.c_str(); *p != 0; p++) { - if (!pointPassed && *p == '.') { - result += "-"; - result += TransMan.getCurrentCharset(); - result += *p; - - pointPassed = true; - } else { - result += *p; - } - } + // We will transform the font filename in the following way: + // name.bdf + // will become: + // name-charset.bdf + // Note that name should not contain any dot here! + + // In the first step we look for the dot. In case there is none we will + // return the normal filename. + Common::String::const_iterator dot = Common::find(filename.begin(), filename.end(), '.'); + if (dot == filename.end()) + return filename; + + // Put the translated font filename string back together. + Common::String result(filename.begin(), dot); + result += '-'; + result += TransMan.getCurrentCharset(); + result += dot; return result; #endif @@ -1502,6 +1503,12 @@ Common::String ThemeEngine::genLocalizedFontFilename(const Common::String &filen *********************************************************/ bool ThemeEngine::themeConfigParseHeader(Common::String header, Common::String &themeName) { + // Check that header is not corrupted + if ((byte)header[0] > 127) { + warning("Corrupted theme header found"); + return false; + } + header.trim(); if (header.empty()) @@ -1528,7 +1535,7 @@ bool ThemeEngine::themeConfigUsable(const Common::ArchiveMember &member, Common: Common::File stream; bool foundHeader = false; - if (member.getName().hasSuffix(".zip")) { + if (member.getName().matchString("*.zip", true)) { Common::Archive *zipArchive = Common::makeZipArchive(member.createReadStream()); if (zipArchive && zipArchive->hasFile("THEMERC")) { @@ -1550,7 +1557,7 @@ bool ThemeEngine::themeConfigUsable(const Common::FSNode &node, Common::String & Common::File stream; bool foundHeader = false; - if (node.getName().hasSuffix(".zip") && !node.isDirectory()) { + if (node.getName().matchString("*.zip", true) && !node.isDirectory()) { Common::Archive *zipArchive = Common::makeZipArchive(node); if (zipArchive && zipArchive->hasFile("THEMERC")) { // Open THEMERC from the ZIP file. @@ -1636,7 +1643,7 @@ void ThemeEngine::listUsableThemes(Common::Archive &archive, Common::List<ThemeD // If the name of the node object also contains // the ".zip" suffix, we will strip it. - if (td.id.hasSuffix(".zip")) { + if (td.id.matchString("*.zip", true)) { for (int j = 0; j < 4; ++j) td.id.deleteLastChar(); } @@ -1673,7 +1680,7 @@ void ThemeEngine::listUsableThemes(const Common::FSNode &node, Common::List<Them for (Common::FSList::iterator i = fileList.begin(); i != fileList.end(); ++i) { // We will only process zip files for now - if (!i->getPath().hasSuffix(".zip")) + if (!i->getPath().matchString("*.zip", true)) continue; td.name.clear(); @@ -1683,7 +1690,7 @@ void ThemeEngine::listUsableThemes(const Common::FSNode &node, Common::List<Them // If the name of the node object also contains // the ".zip" suffix, we will strip it. - if (td.id.hasSuffix(".zip")) { + if (td.id.matchString("*.zip", true)) { for (int j = 0; j < 4; ++j) td.id.deleteLastChar(); } @@ -1720,7 +1727,7 @@ Common::String ThemeEngine::getThemeFile(const Common::String &id) { Common::FSNode node(id); // If the given id is a full path we'll just use it - if (node.exists() && (node.isDirectory() || node.getName().hasSuffix(".zip"))) + if (node.exists() && (node.isDirectory() || node.getName().matchString("*.zip", true))) return id; // FIXME: @@ -1751,7 +1758,7 @@ Common::String ThemeEngine::getThemeId(const Common::String &filename) { if (!node.exists()) return "builtin"; - if (node.getName().hasSuffix(".zip")) { + if (node.getName().matchString("*.zip", true)) { Common::String id = node.getName(); for (int i = 0; i < 4; ++i) |