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

Tanoku at users.sourceforge.net Tanoku at users.sourceforge.net
Sat Aug 16 16:06:27 CEST 2008


Revision: 33941
          http://scummvm.svn.sourceforge.net/scummvm/?rev=33941&view=rev
Author:   Tanoku
Date:     2008-08-16 14:06:26 +0000 (Sat, 16 Aug 2008)

Log Message:
-----------
Added support for loading uncompressed/unpackaged themes.

Modified Paths:
--------------
    scummvm/branches/gsoc2008-gui/common/xmlparser.h
    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/scummclassic.zip
    scummvm/branches/gsoc2008-gui/gui/themes/scummodern.zip

Modified: scummvm/branches/gsoc2008-gui/common/xmlparser.h
===================================================================
--- scummvm/branches/gsoc2008-gui/common/xmlparser.h	2008-08-16 13:10:54 UTC (rev 33940)
+++ scummvm/branches/gsoc2008-gui/common/xmlparser.h	2008-08-16 14:06:26 UTC (rev 33941)
@@ -32,6 +32,7 @@
 #include "common/xmlparser.h"
 #include "common/stream.h"
 #include "common/file.h"
+#include "common/fs.h"
 
 #include "common/hashmap.h"
 #include "common/hash-str.h"
@@ -342,7 +343,7 @@
 	 *
 	 * @param filename Name of the file to load.
 	 */
-	bool loadFile(Common::String filename) {
+	bool loadFile(const Common::String &filename) {
 		Common::File *f = new Common::File;
 
 		if (!f->open(filename)) {
@@ -354,6 +355,19 @@
 		_text.loadStream(f);
 		return true;
 	}
+	
+	bool loadFile(const FilesystemNode &node) {
+		Common::File *f = new Common::File;
+		
+		if (!f->open(node)) {
+			delete f;
+			return false;
+		}
+		
+		_fileName = node.getName();
+		_text.loadStream(f);
+		return true;
+	}
 
 	/**
 	 * Loads a memory buffer into the parser.

Modified: scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.cpp	2008-08-16 13:10:54 UTC (rev 33940)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.cpp	2008-08-16 14:06:26 UTC (rev 33941)
@@ -191,7 +191,10 @@
 	for (ImagesMap::iterator i = _bitmaps.begin(); i != _bitmaps.end(); ++i)
 		ImageMan.unregisterSurface(i->_key);
 
-	ImageMan.remArchive(_themeFileName);
+	if (_themeFileName.hasSuffix(".zip"))
+		ImageMan.remArchive(_themeFileName);
+		
+	Common::File::resetDefaultDirectories();
 	
 	_themeEval->reset();
 	_themeOk = false;
@@ -370,7 +373,10 @@
 		if (ConfMan.hasKey("extrapath"))
 			Common::File::addDefaultDirectoryRecursive(ConfMan.get("extrapath"));
 		
-		ImageMan.addArchive(fileName);
+		if (fileName.hasSuffix(".zip"))
+			ImageMan.addArchive(fileName);
+		else 
+			Common::File::addDefaultDirectory(fileName);
 	}
 
 	if (fileName == "builtin") {
@@ -429,10 +435,11 @@
 	_themeName.clear();
 	
 	char fileNameBuffer[32];
+	char stxHeader[128];
 	int parseCount = 0;
 	
 #ifdef USE_ZLIB
-	unzFile zipFile = unzOpen(themeName.c_str());
+	unzFile zipFile = unzOpen((themeName).c_str());
 	
 	if (zipFile && unzGoToFirstFile(zipFile) == UNZ_OK) {
 		while (true) {
@@ -449,11 +456,12 @@
 				Common::MemoryReadStream *stream = new Common::MemoryReadStream(buffer, fileInfo.uncompressed_size+1, true);
 				
 				if (!strcmp(fileNameBuffer, "THEMERC")) {
-					char stxHeader[128];
 					stream->readLine(stxHeader, 128);
 
-					if (!themeConfigParseHeader(stxHeader, _themeName))
-						error("Corrupted 'THEMERC' file");
+					if (!themeConfigParseHeader(stxHeader, _themeName)) {
+						warning("Corrupted 'THEMERC' file in theme '%s'", _themeFileName.c_str());
+						return false;
+					}
 						
 					delete stream;
 					
@@ -484,13 +492,23 @@
 			
 			for (FSList::const_iterator i = fslist.begin(); i != fslist.end(); ++i) {
 				if (i->getName().hasSuffix(".stx")) {
+					parseCount++;
 					
+					if (parser()->loadFile(*i) == false || parser()->parse() == false) {
+						warning("Failed to parse STX file '%s'", i->getName().c_str());
+						return false;
+					}
 				} else if (i->getName() == "THEMERC") {
-					
+					Common::File f;
+					f.open(*i);
+					f.readLine(stxHeader, 128);
+
+					if (!themeConfigParseHeader(stxHeader, _themeName)) {
+						warning("Corrupted 'THEMERC' file in theme '%s'", _themeFileName.c_str());
+						return false;
+					}
 				}
-				
 			}
-			
 		}
 #ifdef USE_ZLIB
 	}

Modified: scummvm/branches/gsoc2008-gui/gui/newgui.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/newgui.cpp	2008-08-16 13:10:54 UTC (rev 33940)
+++ scummvm/branches/gsoc2008-gui/gui/newgui.cpp	2008-08-16 14:06:26 UTC (rev 33941)
@@ -92,8 +92,8 @@
 	if (themefile.compareToIgnoreCase("default") == 0)
 		themefile = "builtin";
 		
-	if (themefile != "builtin" && !themefile.hasSuffix(".zip"))
-		themefile += ".zip";
+//	if (themefile != "builtin" && !themefile.hasSuffix(".zip"))
+//		themefile += ".zip";
 		
 	ConfMan.registerDefault("gui_renderer", 2);
 	ThemeRenderer::GraphicsMode gfxMode = (ThemeRenderer::GraphicsMode)ConfMan.getInt("gui_renderer");

Modified: scummvm/branches/gsoc2008-gui/gui/theme.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/theme.cpp	2008-08-16 13:10:54 UTC (rev 33940)
+++ scummvm/branches/gsoc2008-gui/gui/theme.cpp	2008-08-16 14:06:26 UTC (rev 33941)
@@ -23,6 +23,7 @@
  */
 
 #include "gui/theme.h"
+#include "common/fs.h"
 #include "common/unzip.h"
 
 namespace GUI {
@@ -153,7 +154,10 @@
 	return tok.empty();
 }
 
-bool Theme::themeConfigUseable(const Common::String &filename, Common::String &themeName) {
+bool Theme::themeConfigUseable(const FilesystemNode &node, Common::String &themeName) {
+	char stxHeader[128];
+	bool foundHeader = false;
+	
 	if (ConfMan.hasKey("themepath"))
 		Common::File::addDefaultDirectory(ConfMan.get("themepath"));
 
@@ -164,38 +168,47 @@
 	if (ConfMan.hasKey("extrapath"))
 		Common::File::addDefaultDirectoryRecursive(ConfMan.get("extrapath"));
 		
+	if (node.getName().hasSuffix(".zip")) {		
 #ifdef USE_ZLIB
-	unzFile zipFile = unzOpen(filename.c_str());
-	char stxHeader[128];
-	bool foundHeader = false;
+		unzFile zipFile = unzOpen(node.getPath().c_str());
 	
-	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 (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;
+			if (themeConfigParseHeader(stxHeader, themeName))
+				foundHeader = true;
 
-		delete[] buffer;
-		buffer = 0;
-	}
-	unzClose(zipFile);
+			delete[] buffer;
+			buffer = 0;
+		}
+		unzClose(zipFile);
 #else
-	return false;
+		return false;
 #endif	
+	} else if (node.isDirectory()) {			
+		FilesystemNode headerfile = node.getChild("THEMERC");
+		if (!headerfile.exists() || !headerfile.isReadable() || headerfile.isDirectory())
+			return false;
+			
+		Common::File f;
+		f.open(headerfile);
+		f.readLine(stxHeader, 128);
 
+		if (themeConfigParseHeader(stxHeader, themeName))
+			foundHeader = true;
+	}
+
 	return foundHeader;
 }
 
-
-
 } // End of namespace GUI
 

Modified: scummvm/branches/gsoc2008-gui/gui/theme.h
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/theme.h	2008-08-16 13:10:54 UTC (rev 33940)
+++ scummvm/branches/gsoc2008-gui/gui/theme.h	2008-08-16 14:06:26 UTC (rev 33941)
@@ -305,7 +305,7 @@
 	bool isThemeLoadingRequired();
 	virtual ThemeEval *evaluator() = 0;
 
-	static bool themeConfigUseable(const Common::String &file, Common::String &themeName);
+	static bool themeConfigUseable(const FilesystemNode &node, Common::String &themeName);
 	static bool themeConfigParseHeader(Common::String header, Common::String &themeName);
 
 	virtual const Common::String &getThemeFileName() const = 0;

Modified: scummvm/branches/gsoc2008-gui/gui/themebrowser.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/themebrowser.cpp	2008-08-16 13:10:54 UTC (rev 33940)
+++ scummvm/branches/gsoc2008-gui/gui/themebrowser.cpp	2008-08-16 14:06:26 UTC (rev 33941)
@@ -146,16 +146,14 @@
 		return;
 
 	FSList fslist;
-	if (!node.getChildren(fslist, FilesystemNode::kListAll))
-		return;
-
-	for (FSList::const_iterator i = fslist.begin(); i != fslist.end(); ++i) {
-		if (i->isDirectory()) {
-			addDir(list, i->getPath(), level-1);
-		} else {
+	
+#ifdef USE_ZLIB
+	if (node.lookupFile(fslist, "*.zip", false, true, 0)) {
+		for (FSList::const_iterator i = fslist.begin(); i != fslist.end(); ++i) {
 			Entry th;
 			if (isTheme(*i, th)) {
 				bool add = true;
+				
 				for (ThList::const_iterator p = list.begin(); p != list.end(); ++p) {
 					if (p->name == th.name || p->file == th.file) {
 						add = false;
@@ -164,6 +162,26 @@
 				}
 
 				if (add)
+					list.push_back(th);	
+			}
+		}
+	}
+#endif
+
+	if (node.lookupFile(fslist, "THEMERC", false, true, 1)) {
+		for (FSList::const_iterator i = fslist.begin(); i != fslist.end(); ++i) {
+			Entry th;
+			if (isTheme(i->getParent(), th)) {
+				bool add = true;
+				
+				for (ThList::const_iterator p = list.begin(); p != list.end(); ++p) {
+					if (p->name == th.name || p->file == th.file) {
+						add = false;
+						break;
+					}
+				}
+
+				if (add)
 					list.push_back(th);
 			}
 		}
@@ -171,12 +189,17 @@
 }
 
 bool ThemeBrowser::isTheme(const FilesystemNode &node, Entry &out) {
-	out.file = node.getName();
+	out.file = node.getName();	
 	
-	if (!out.file.hasSuffix(".zip"))
+#ifdef USE_ZLIB
+	if (!out.file.hasSuffix(".zip") && !node.isDirectory())
 		return false;
+#else
+	if (!node.isDirectory())
+		return false;
+#endif
 		
-	if (!Theme::themeConfigUseable(out.file, out.name))
+	if (!Theme::themeConfigUseable(node, out.name))
 		return false;
 
 	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