Finished theme loading support.

Added "themerc" file to default theme.

svn-id: r33851
This commit is contained in:
Vicent Marti 2008-08-13 23:07:26 +00:00
parent 80e059f2bb
commit c4f2a691ce
6 changed files with 84 additions and 38 deletions

@ -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);
delete stream;
return false;
}
if (!strcmp(fileNameBuffer, "THEMERC")) {
char stxHeader[128];
stream->readLine(stxHeader, 128);
parseCount++;
}
if (!themeConfigParseHeader(stxHeader, _themeName))
error("Corrupted 'THEMERC' file");
delete stream;
} 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;
}
}
}
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
}

@ -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;

@ -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 true;
return foundHeader;
}
} // End of namespace GUI

@ -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;

@ -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;
}

Binary file not shown.