diff options
-rw-r--r-- | gui/ThemeEngine.cpp | 11 | ||||
-rw-r--r-- | gui/theme.cpp | 33 | ||||
-rw-r--r-- | gui/theme.h | 5 |
3 files changed, 19 insertions, 30 deletions
diff --git a/gui/ThemeEngine.cpp b/gui/ThemeEngine.cpp index 2839155589..42ffbcbc02 100644 --- a/gui/ThemeEngine.cpp +++ b/gui/ThemeEngine.cpp @@ -411,7 +411,7 @@ bool ThemeEngine::addFont(const Common::String &fontId, const Common::String &fi _texts[textId]->_fontPtr = FontMan.getFontByName(file); if (!_texts[textId]->_fontPtr) { - _texts[textId]->_fontPtr = loadFont(file.c_str()); + _texts[textId]->_fontPtr = loadFont(file); if (!_texts[textId]->_fontPtr) error("Couldn't load %s font '%s'", fontId.c_str(), file.c_str()); @@ -473,8 +473,7 @@ bool ThemeEngine::loadTheme(Common::String fileName) { if (fileName == "builtin") { if (!loadDefaultXML()) error("Could not load default embeded theme"); - } - else if (!loadThemeXML(fileName)) { + } else if (!loadThemeXML(fileName)) { warning("Could not parse custom theme '%s'. Falling back to default theme", fileName.c_str()); if (!loadDefaultXML()) // if we can't load the embeded theme, this is a complete failure @@ -545,7 +544,7 @@ bool ThemeEngine::loadThemeXML(Common::String themeName) { if (zipFile.isOpen() && zipFile.listMembers(zipContents)) { for (Common::ArchiveMemberList::iterator za = zipContents.begin(); za != zipContents.end(); ++za) { - if (!failed && matchString((*za)->getName().c_str(), "*.stx")) { + if (!failed && (*za)->getName().hasSuffix(".stx")) { if (parser()->loadStream((*za)->open()) == false) { warning("Failed to load stream for zipped file '%s'", fileNameBuffer); failed = true; @@ -562,7 +561,7 @@ bool ThemeEngine::loadThemeXML(Common::String themeName) { Common::SeekableReadStream *stream = (*za)->open(); stxHeader = stream->readLine(); - if (!themeConfigParseHeader(stxHeader.c_str(), _themeName)) { + if (!themeConfigParseHeader(stxHeader, _themeName)) { warning("Corrupted 'THEMERC' file in theme '%s'", _themeFileName.c_str()); failed = true; } @@ -601,7 +600,7 @@ bool ThemeEngine::loadThemeXML(Common::String themeName) { f.open(*i); stxHeader = f.readLine(); - if (!themeConfigParseHeader(stxHeader.c_str(), _themeName)) { + if (!themeConfigParseHeader(stxHeader, _themeName)) { warning("Corrupted 'THEMERC' file in theme '%s'", _themeFileName.c_str()); failed = true; } diff --git a/gui/theme.cpp b/gui/theme.cpp index d15f3aabd4..8e05ca8479 100644 --- a/gui/theme.cpp +++ b/gui/theme.cpp @@ -33,9 +33,9 @@ Theme::Theme() : _loadedThemeX(0), _loadedThemeY(0) {} Theme::~Theme() {} -const Graphics::Font *Theme::loadFont(const char *filename) { +const Graphics::Font *Theme::loadFont(const Common::String &filename) { const Graphics::NewFont *font = 0; - Common::String cacheFilename = genCacheFilename(filename); + Common::String cacheFilename = genCacheFilename(filename.c_str()); Common::File fontFile; if (!cacheFilename.empty()) { @@ -45,7 +45,7 @@ const Graphics::Font *Theme::loadFont(const char *filename) { return font; #ifdef USE_ZLIB - Common::ZipArchive zipArchive(getThemeFileName().c_str()); + Common::ZipArchive zipArchive(getThemeFileName()); Common::SeekableReadStream *stream(zipArchive.openFile(cacheFilename)); if (stream) { font = Graphics::NewFont::loadFromCache(*stream); @@ -63,7 +63,7 @@ const Graphics::Font *Theme::loadFont(const char *filename) { #ifdef USE_ZLIB if (!font) { - Common::ZipArchive zipArchive(getThemeFileName().c_str()); + Common::ZipArchive zipArchive(getThemeFileName()); Common::SeekableReadStream *stream(zipArchive.openFile(filename)); if (stream) { @@ -76,7 +76,7 @@ const Graphics::Font *Theme::loadFont(const char *filename) { if (font) { if (!cacheFilename.empty()) { if (!Graphics::NewFont::cacheFontData(*font, cacheFilename)) { - warning("Couldn't create cache file for font '%s'", filename); + warning("Couldn't create cache file for font '%s'", filename.c_str()); } } } @@ -133,35 +133,26 @@ bool Theme::themeConfigParseHeader(Common::String header, Common::String &themeN } bool Theme::themeConfigUseable(const Common::FSNode &node, Common::String &themeName) { - Common::String stxHeader; + Common::File stream; bool foundHeader = false; if (node.getName().hasSuffix(".zip")) { #ifdef USE_ZLIB Common::ZipArchive zipArchive(node); if (zipArchive.hasFile("THEMERC")) { - Common::File stream; stream.open("THEMERC", zipArchive); - stxHeader = stream.readLine(); - // TODO: Read first line of file. How? - if (themeConfigParseHeader(stxHeader.c_str(), themeName)) - foundHeader = true; } -#else - return false; #endif - } else if (node.isDirectory()) { Common::FSNode headerfile = node.getChild("THEMERC"); if (!headerfile.exists() || !headerfile.isReadable() || headerfile.isDirectory()) return false; - - // TODO: File or FilePtr? - Common::File f; - f.open(headerfile); - stxHeader = f.readLine(); - if (themeConfigParseHeader(stxHeader.c_str(), themeName)) - foundHeader = true; + stream.open(headerfile); + } + + if (stream.isOpen()) { + Common::String stxHeader = stream.readLine(); + foundHeader = themeConfigParseHeader(stxHeader, themeName); } return foundHeader; diff --git a/gui/theme.h b/gui/theme.h index c4080f884e..09455ea590 100644 --- a/gui/theme.h +++ b/gui/theme.h @@ -334,9 +334,9 @@ public: * @see kThemeImages */ virtual const Graphics::Surface *getImageSurface(const kThemeImages n) const { return 0; } -protected: - const Graphics::Font *loadFont(const char *filename); +protected: + const Graphics::Font *loadFont(const Common::String &filename); Common::String genCacheFilename(const char *filename); public: @@ -344,7 +344,6 @@ public: (_loadedThemeY != g_system->getOverlayHeight())); } private: - static const char *_defaultConfigINI; int _loadedThemeX, _loadedThemeY; }; } // end of namespace GUI |