[Scummvm-cvs-logs] SF.net SVN: scummvm: [24201] scummvm/trunk/gui

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Sun Oct 8 14:00:28 CEST 2006


Revision: 24201
          http://svn.sourceforge.net/scummvm/?rev=24201&view=rev
Author:   lordhoto
Date:     2006-10-08 05:00:19 -0700 (Sun, 08 Oct 2006)

Log Message:
-----------
- added auto detection of the Theme style to use
- fixed a bug which would lead to a crash when loading the modern theme config with the classic theme

Modified Paths:
--------------
    scummvm/trunk/gui/ThemeClassic.cpp
    scummvm/trunk/gui/ThemeNew.cpp
    scummvm/trunk/gui/newgui.cpp
    scummvm/trunk/gui/theme.cpp
    scummvm/trunk/gui/theme.h

Modified: scummvm/trunk/gui/ThemeClassic.cpp
===================================================================
--- scummvm/trunk/gui/ThemeClassic.cpp	2006-10-08 11:03:46 UTC (rev 24200)
+++ scummvm/trunk/gui/ThemeClassic.cpp	2006-10-08 12:00:19 UTC (rev 24201)
@@ -25,8 +25,8 @@
 #define THEME_VERSION 1
 
 namespace GUI {
-ThemeClassic::ThemeClassic(OSystem *system) : Theme() {
-	_stylefile = "classic";
+ThemeClassic::ThemeClassic(OSystem *system, const Common::String &config, const Common::ConfigFile *cfg) : Theme() {
+	_stylefile = config;
 	_system = system;
 	_initOk = false;
 	_font = 0;
@@ -37,7 +37,10 @@
 #endif
 	_font = 0;
 
-	loadConfigFile(_stylefile);
+	if (cfg)
+		_configFile = *cfg;
+	else
+		loadConfigFile(_stylefile);
 }
 
 ThemeClassic::~ThemeClassic() {
@@ -625,8 +628,8 @@
 
 void ThemeClassic::setupConfig() {
 	if (_configFile.hasSection("theme")) {
-		loadConfig();
-		return;
+		if (loadConfig())
+			return;
 	}
 
 	static const uint8 colors[][3] = {
@@ -646,6 +649,10 @@
 	if (atoi(temp.c_str()) != THEME_VERSION) {
 		// TODO: improve this detection and handle it nicer
 		warning("Theme config uses a different version (you have: '%s', needed is: '%d')", temp.c_str(), THEME_VERSION);
+		_configFile.clear();
+
+		// force a theme reload here
+		loadTheme(_defaultConfig);
 		return false;
 	}
 
@@ -653,6 +660,10 @@
 	_configFile.getKey("type", "theme", temp);
 	if (0 != temp.compareToIgnoreCase("classic")) {
 		warning("Theme config is not for the classic style theme");
+		_configFile.clear();
+
+		// force a theme reload here
+		loadTheme(_defaultConfig);
 		return false;
 	}
 

Modified: scummvm/trunk/gui/ThemeNew.cpp
===================================================================
--- scummvm/trunk/gui/ThemeNew.cpp	2006-10-08 11:03:46 UTC (rev 24200)
+++ scummvm/trunk/gui/ThemeNew.cpp	2006-10-08 12:00:19 UTC (rev 24201)
@@ -55,7 +55,7 @@
 
 #pragma mark -
 
-ThemeNew::ThemeNew(OSystem *system, const Common::String &stylefile) : Theme(), _system(system), _screen(), _initOk(false),
+ThemeNew::ThemeNew(OSystem *system, const Common::String &stylefile, const Common::ConfigFile *cfg) : Theme(), _system(system), _screen(), _initOk(false),
 _lastUsedBitMask(0), _forceRedraw(false), _imageHandles(0), _images(0), _colors(), _fonts(), _cursor(0), _gradientFactors() {
 	_stylefile = stylefile;
 	_initOk = false;
@@ -71,9 +71,13 @@
 		clearAll();
 	}
 
-	if (!loadConfigFile(stylefile)) {
-		warning("Can not find theme config file '%s'", (stylefile + ".ini").c_str());
-		return;
+	if (cfg) {
+		_configFile = *cfg;
+	} else {
+		if (!loadConfigFile(stylefile)) {
+			warning("Can not find theme config file '%s'", (stylefile + ".ini").c_str());
+			return;
+		}
 	}
 
 	ImageMan.addArchive(stylefile + ".zip");

Modified: scummvm/trunk/gui/newgui.cpp
===================================================================
--- scummvm/trunk/gui/newgui.cpp	2006-10-08 11:03:46 UTC (rev 24200)
+++ scummvm/trunk/gui/newgui.cpp	2006-10-08 12:00:19 UTC (rev 24201)
@@ -85,6 +85,7 @@
 // Constructor
 NewGui::NewGui() : _needRedraw(false),
 	_stateIsSaved(false), _cursorAnimateCounter(0), _cursorAnimateTimer(0) {
+	_theme = 0;
 
 	_system = g_system;
 	_lastScreenChangeID = _system->getScreenChangeID();
@@ -99,17 +100,28 @@
 	ConfMan.registerDefault("gui_theme", "default");
 	Common::String style(ConfMan.get("gui_theme"));
 	// The default theme for now is the 'modern' theme.
-	if (scumm_stricmp(style.c_str(), "default") == 0)
+	if (style.compareToIgnoreCase("default") == 0)
 		style = "modern";
 
-	if (scumm_stricmp(style.c_str(), "classic") == 0) {
-#endif
-		_theme = new ThemeClassic(_system);
-#ifndef DISABLE_FANCY_THEMES
+	Common::String styleType;
+	Common::ConfigFile cfg;
+
+	if (Theme::themeConfigUseable(style, "", &styleType, &cfg)) {
+		if (0 == styleType.compareToIgnoreCase("classic"))
+			_theme = new ThemeClassic(_system, style, &cfg);
+		else if (0 == styleType.compareToIgnoreCase("modern"))
+			_theme = new ThemeNew(_system, style, &cfg);
+		else
+			warning("Unsupported theme type '%s'", styleType.c_str());
 	} else {
-		_theme = new ThemeNew(_system, style.c_str());
+		warning("Config '%s' is NOT usable for themes or not found", style.c_str());
 	}
+	cfg.clear();
 #endif
+	
+	if (!_theme)
+		_theme = new ThemeClassic(_system);
+
 	assert(_theme);
 
 	// Init the theme

Modified: scummvm/trunk/gui/theme.cpp
===================================================================
--- scummvm/trunk/gui/theme.cpp	2006-10-08 11:03:46 UTC (rev 24200)
+++ scummvm/trunk/gui/theme.cpp	2006-10-08 12:00:19 UTC (rev 24201)
@@ -187,4 +187,70 @@
 	return true;
 }
 
+bool Theme::themeConfigUseable(const String &stylefile, const String &style, String *cStyle, Common::ConfigFile *cfg) {
+	if (ConfMan.hasKey("themepath"))
+		Common::File::addDefaultDirectory(ConfMan.get("themepath"));
+
+#ifdef DATA_PATH
+	Common::File::addDefaultDirectoryRecursive(DATA_PATH);
+#endif
+
+	if (ConfMan.hasKey("extrapath"))
+		Common::File::addDefaultDirectoryRecursive(ConfMan.get("extrapath"));
+
+	Common::File file;
+	Common::ConfigFile configFile;
+	if (!cfg && (cStyle || !style.empty()))
+		cfg = &configFile;
+
+	if (!file.open(stylefile + ".ini")) {
+#ifdef USE_ZLIB
+		// Maybe find a nicer solution to this
+		unzFile zipFile = unzOpen((stylefile + ".zip").c_str());
+		if (zipFile && unzLocateFile(zipFile, (stylefile + ".ini").c_str(), 2) == UNZ_OK) {
+			if (!style.empty() || cStyle || cfg) {
+				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);
+				if (!cfg->loadFromStream(stream)) {
+					unzClose(zipFile);
+					return false;
+				}
+				delete [] buffer;
+				buffer = 0;
+			}
+		} else {
+			unzClose(zipFile);
+			return false;
+		}
+		unzClose(zipFile);
+#else
+		return false;
+#endif
+	}
+
+	if (!style.empty() || cStyle || cfg) {
+		if (file.isOpen()) {
+			if (!cfg->loadFromStream(file))
+				return false;
+			file.close();
+		}
+
+		Common::String temp;
+		cfg->getKey("type", "theme", temp);
+		if (cStyle)
+			*cStyle = temp;
+		if (0 != temp.compareToIgnoreCase(style) && !style.empty())
+			return false;
+	}
+
+	return true;
+}
+
 } // End of namespace GUI

Modified: scummvm/trunk/gui/theme.h
===================================================================
--- scummvm/trunk/gui/theme.h	2006-10-08 11:03:46 UTC (rev 24200)
+++ scummvm/trunk/gui/theme.h	2006-10-08 12:00:19 UTC (rev 24201)
@@ -212,6 +212,7 @@
 
 	Eval *_evaluator;
 
+	static bool themeConfigUseable(const String &file, const String &style="", String *cStyle=0, Common::ConfigFile *cfg=0);
 protected:
 	bool loadConfigFile(const String &file);
 	void getColorFromConfig(const String &name, OverlayColor &col);
@@ -236,7 +237,7 @@
 
 class ThemeClassic : public Theme {
 public:
-	ThemeClassic(OSystem *system);
+	ThemeClassic(OSystem *system, const Common::String &config = "classic", const Common::ConfigFile *cfg = 0);
 	virtual ~ThemeClassic();
 
 	bool init();
@@ -329,7 +330,7 @@
 class ThemeNew : public Theme {
 	typedef Common::String String;
 public:
-	ThemeNew(OSystem *system, const String &stylefile);
+	ThemeNew(OSystem *system, const String &stylefile, const Common::ConfigFile *cfg = 0);
 	virtual ~ThemeNew();
 
 	bool init();


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