aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVicent Marti2008-08-13 23:07:26 +0000
committerVicent Marti2008-08-13 23:07:26 +0000
commitc4f2a691ce3feed23b28ba8b657e94baa9d2301b (patch)
tree4a1212087e6bccc2bf02e5a34cd1cac2b5265eb8
parent80e059f2bb61f58e02d44d9dd125d23627d38b83 (diff)
downloadscummvm-rg350-c4f2a691ce3feed23b28ba8b657e94baa9d2301b.tar.gz
scummvm-rg350-c4f2a691ce3feed23b28ba8b657e94baa9d2301b.tar.bz2
scummvm-rg350-c4f2a691ce3feed23b28ba8b657e94baa9d2301b.zip
Finished theme loading support.
Added "themerc" file to default theme. svn-id: r33851
-rw-r--r--gui/ThemeRenderer.cpp39
-rw-r--r--gui/newgui.cpp3
-rw-r--r--gui/theme.cpp54
-rw-r--r--gui/theme.h4
-rw-r--r--gui/themebrowser.cpp22
-rw-r--r--gui/themes/scummodern.zipbin114585 -> 87340 bytes
6 files changed, 84 insertions, 38 deletions
diff --git a/gui/ThemeRenderer.cpp b/gui/ThemeRenderer.cpp
index 00a07909b0..f323807903 100644
--- a/gui/ThemeRenderer.cpp
+++ b/gui/ThemeRenderer.cpp
@@ -383,7 +383,6 @@ bool ThemeRenderer::loadTheme(Common::String fileName) {
}
}
- _themeName = "DEBUG - A Theme name";
_themeOk = true;
return true;
}
@@ -412,9 +411,10 @@ bool ThemeRenderer::loadDefaultXML() {
bool ThemeRenderer::loadThemeXML(Common::String themeName) {
assert(_parser);
+ _themeName.clear();
#ifdef USE_ZLIB
- unzFile zipFile = unzOpen((themeName + ".zip").c_str());
+ unzFile zipFile = unzOpen(themeName.c_str());
char fileNameBuffer[32];
int parseCount = 0;
@@ -424,7 +424,7 @@ bool ThemeRenderer::loadThemeXML(Common::String themeName) {
unzOpenCurrentFile(zipFile);
unzGetCurrentFileInfo(zipFile, &fileInfo, fileNameBuffer, 32, NULL, 0, NULL, 0);
- if (matchString(fileNameBuffer, "*.stx")) {
+ if (matchString(fileNameBuffer, "*.stx") || !strcmp(fileNameBuffer, "THEMERC")) {
uint8 *buffer = new uint8[fileInfo.uncompressed_size+1];
assert(buffer);
memset(buffer, 0, (fileInfo.uncompressed_size+1)*sizeof(uint8));
@@ -432,31 +432,38 @@ bool ThemeRenderer::loadThemeXML(Common::String themeName) {
Common::MemoryReadStream *stream = new Common::MemoryReadStream(buffer, fileInfo.uncompressed_size+1, true);
- if (parser()->loadStream(stream) == false || parser()->parse() == false) {
- warning("Failed to load stream for zipped file '%s'", fileNameBuffer);
- unzClose(zipFile);
+ if (!strcmp(fileNameBuffer, "THEMERC")) {
+ char stxHeader[128];
+ stream->readLine(stxHeader, 128);
+
+ if (!themeConfigParseHeader(stxHeader, _themeName))
+ error("Corrupted 'THEMERC' file");
+
delete stream;
- return false;
+
+ } else {
+ parseCount++;
+
+ if (parser()->loadStream(stream) == false || parser()->parse() == false) {
+ warning("Failed to load stream for zipped file '%s'", fileNameBuffer);
+ unzClose(zipFile);
+ delete stream;
+ return false;
+ }
}
-
- parseCount++;
- }
+ }
unzCloseCurrentFile(zipFile);
if (unzGoToNextFile(zipFile) != UNZ_OK)
break;
}
- } else if (parser()->loadFile(themeName + ".stx") && parser()->parse()) {
- parseCount++;
- } else {
- warning("No theme files for '%s' found.", themeName.c_str());
}
unzClose(zipFile);
- return (parseCount > 0);
+ return (parseCount > 0 && _themeName.empty() == false);
#else
- return (parser()->loadFile(themeName + ".stx") && parser()->parse());
+ return false;
#endif
}
diff --git a/gui/newgui.cpp b/gui/newgui.cpp
index f4d20920dd..945c944b93 100644
--- a/gui/newgui.cpp
+++ b/gui/newgui.cpp
@@ -93,6 +93,9 @@ NewGui::NewGui() : _redrawStatus(kRedrawDisabled),
Common::String themefile(ConfMan.get("gui_theme"));
if (themefile.compareToIgnoreCase("default") == 0)
themefile = "builtin";
+
+ if (!themefile.hasSuffix(".zip"))
+ themefile += ".zip";
loadNewTheme(themefile);
_themeChange = false;
diff --git a/gui/theme.cpp b/gui/theme.cpp
index e61fc1993d..3e77919ba9 100644
--- a/gui/theme.cpp
+++ b/gui/theme.cpp
@@ -133,7 +133,27 @@ bool Theme::isThemeLoadingRequired() {
return true;
}
-bool Theme::themeConfigUseable(const Common::String &filename) {
+bool Theme::themeConfigParseHeader(Common::String header, Common::String &themeName) {
+ header.trim();
+
+ if (header[0] != '[' || header.lastChar() != ']')
+ return false;
+
+ header.deleteChar(0);
+ header.deleteLastChar();
+
+ Common::StringTokenizer tok(header, ":");
+
+ if (tok.nextToken() != SCUMMVM_THEME_VERSION_STR)
+ return false;
+
+ themeName = tok.nextToken();
+ Common::String author = tok.nextToken();
+
+ return tok.empty();
+}
+
+bool Theme::themeConfigUseable(const Common::String &filename, Common::String &themeName) {
if (ConfMan.hasKey("themepath"))
Common::File::addDefaultDirectory(ConfMan.get("themepath"));
@@ -143,11 +163,39 @@ bool Theme::themeConfigUseable(const Common::String &filename) {
if (ConfMan.hasKey("extrapath"))
Common::File::addDefaultDirectoryRecursive(ConfMan.get("extrapath"));
+
+#ifdef USE_ZLIB
+ unzFile zipFile = unzOpen(filename.c_str());
+ char stxHeader[128];
+ bool foundHeader = false;
+
+ if (zipFile && unzLocateFile(zipFile, "THEMERC", 2) == UNZ_OK) {
+ unz_file_info fileInfo;
+ unzOpenCurrentFile(zipFile);
+ unzGetCurrentFileInfo(zipFile, &fileInfo, NULL, 0, NULL, 0, NULL, 0);
+ uint8 *buffer = new uint8[fileInfo.uncompressed_size+1];
+ assert(buffer);
+ memset(buffer, 0, (fileInfo.uncompressed_size+1)*sizeof(uint8));
+ unzReadCurrentFile(zipFile, buffer, fileInfo.uncompressed_size);
+ unzCloseCurrentFile(zipFile);
+ Common::MemoryReadStream stream(buffer, fileInfo.uncompressed_size+1);
+ stream.readLine(stxHeader, 128);
+
+ if (themeConfigParseHeader(stxHeader, themeName))
+ foundHeader = true;
+
+ delete[] buffer;
+ buffer = 0;
+ }
+ unzClose(zipFile);
+#else
+ return false;
+#endif
+ return foundHeader;
+}
- return true;
-}
} // End of namespace GUI
diff --git a/gui/theme.h b/gui/theme.h
index 72495b3a22..4c1ab2e195 100644
--- a/gui/theme.h
+++ b/gui/theme.h
@@ -35,6 +35,7 @@
#include "graphics/fontman.h"
#define THEME_VERSION 23
+#define SCUMMVM_THEME_VERSION_STR "SCUMMVM_THEME_V23"
namespace GUI {
@@ -304,7 +305,8 @@ public:
bool isThemeLoadingRequired();
virtual ThemeEval *evaluator() = 0;
- static bool themeConfigUseable(const Common::String &file);
+ static bool themeConfigUseable(const Common::String &file, Common::String &themeName);
+ static bool themeConfigParseHeader(Common::String header, Common::String &themeName);
virtual const Common::String &getThemeFileName() const = 0;
virtual const Common::String &getThemeName() const = 0;
diff --git a/gui/themebrowser.cpp b/gui/themebrowser.cpp
index f4039c6cff..2f1ab48f2d 100644
--- a/gui/themebrowser.cpp
+++ b/gui/themebrowser.cpp
@@ -91,7 +91,7 @@ void ThemeBrowser::updateListing() {
// classic is always build in
Entry th;
- th.name = "Modern Development Theme (Builtin) - WIP";
+ th.name = "ScummVM Modern Theme (Builtin Version)";
th.file = "builtin";
_themes.push_back(th);
@@ -173,26 +173,12 @@ void ThemeBrowser::addDir(ThList &list, const Common::String &dir, int level) {
bool ThemeBrowser::isTheme(const FilesystemNode &node, Entry &out) {
out.file = node.getName();
- if (!out.file.hasSuffix(".zip") && !out.file.hasSuffix(".stx"))
+ if (!out.file.hasSuffix(".zip"))
return false;
-
- for (int i = out.file.size()-1; out.file[i] != '.' && i > 0; --i) {
- out.file.deleteLastChar();
- }
- out.file.deleteLastChar();
-
- if (out.file.empty())
+
+ if (!Theme::themeConfigUseable(out.file, out.name))
return false;
-// TODO: Check if theme is usable.
-// if (!Theme::themeConfigUseable(out.file, "", &type, &cfg))
-// return false;
-
-// if (cfg.hasKey("name", "theme"))
-// cfg.getKey("name", "theme", out.name);
-// else
- out.name = out.file;
-
return true;
}
diff --git a/gui/themes/scummodern.zip b/gui/themes/scummodern.zip
index 940377a713..bbd750a1fa 100644
--- a/gui/themes/scummodern.zip
+++ b/gui/themes/scummodern.zip
Binary files differ