[Scummvm-cvs-logs] SF.net SVN: scummvm:[33851] scummvm/branches/gsoc2008-gui/gui

Tanoku at users.sourceforge.net Tanoku at users.sourceforge.net
Thu Aug 14 01:07:27 CEST 2008


Revision: 33851
          http://scummvm.svn.sourceforge.net/scummvm/?rev=33851&view=rev
Author:   Tanoku
Date:     2008-08-13 23:07:26 +0000 (Wed, 13 Aug 2008)

Log Message:
-----------
Finished theme loading support.
Added "themerc" file to default theme.

Modified Paths:
--------------
    scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.cpp
    scummvm/branches/gsoc2008-gui/gui/newgui.cpp
    scummvm/branches/gsoc2008-gui/gui/theme.cpp
    scummvm/branches/gsoc2008-gui/gui/theme.h
    scummvm/branches/gsoc2008-gui/gui/themebrowser.cpp
    scummvm/branches/gsoc2008-gui/gui/themes/scummodern.zip

Modified: scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.cpp	2008-08-13 22:20:18 UTC (rev 33850)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.cpp	2008-08-13 23:07:26 UTC (rev 33851)
@@ -383,7 +383,6 @@
 		}
 	}
 	
-	_themeName = "DEBUG - A Theme name";
 	_themeOk = true;
 	return true;
 }
@@ -412,9 +411,10 @@
 
 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 @@
 			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 @@
 			
 				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
 }
 

Modified: scummvm/branches/gsoc2008-gui/gui/newgui.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/newgui.cpp	2008-08-13 22:20:18 UTC (rev 33850)
+++ scummvm/branches/gsoc2008-gui/gui/newgui.cpp	2008-08-13 23:07:26 UTC (rev 33851)
@@ -93,6 +93,9 @@
 	Common::String themefile(ConfMan.get("gui_theme"));
 	if (themefile.compareToIgnoreCase("default") == 0)
 		themefile = "builtin";
+		
+	if (!themefile.hasSuffix(".zip"))
+		themefile += ".zip";
 
 	loadNewTheme(themefile);
 	_themeChange = false;

Modified: scummvm/branches/gsoc2008-gui/gui/theme.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/theme.cpp	2008-08-13 22:20:18 UTC (rev 33850)
+++ scummvm/branches/gsoc2008-gui/gui/theme.cpp	2008-08-13 23:07:26 UTC (rev 33851)
@@ -133,7 +133,27 @@
 	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 @@
 
 	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
 

Modified: scummvm/branches/gsoc2008-gui/gui/theme.h
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/theme.h	2008-08-13 22:20:18 UTC (rev 33850)
+++ scummvm/branches/gsoc2008-gui/gui/theme.h	2008-08-13 23:07:26 UTC (rev 33851)
@@ -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 @@
 	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;

Modified: scummvm/branches/gsoc2008-gui/gui/themebrowser.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/themebrowser.cpp	2008-08-13 22:20:18 UTC (rev 33850)
+++ scummvm/branches/gsoc2008-gui/gui/themebrowser.cpp	2008-08-13 23:07:26 UTC (rev 33851)
@@ -91,7 +91,7 @@
 
 	// 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 @@
 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;
 }
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list