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

Tanoku at users.sourceforge.net Tanoku at users.sourceforge.net
Sat Oct 18 03:27:33 CEST 2008


Revision: 34815
          http://scummvm.svn.sourceforge.net/scummvm/?rev=34815&view=rev
Author:   Tanoku
Date:     2008-10-18 01:27:33 +0000 (Sat, 18 Oct 2008)

Log Message:
-----------
ImageManager: Added support for generic archives (zips and folders).
Theme Font Loading: Added support for generic archives.
ThemeEngine: Removed dependency on Common::File and File::AddDefaultPath for image and font loading.

Modified Paths:
--------------
    scummvm/trunk/graphics/imageman.cpp
    scummvm/trunk/gui/ThemeEngine.cpp
    scummvm/trunk/gui/theme.cpp
    scummvm/trunk/gui/theme.h

Modified: scummvm/trunk/graphics/imageman.cpp
===================================================================
--- scummvm/trunk/graphics/imageman.cpp	2008-10-18 00:29:23 UTC (rev 34814)
+++ scummvm/trunk/graphics/imageman.cpp	2008-10-18 01:27:33 UTC (rev 34815)
@@ -46,19 +46,33 @@
 }
 
 bool ImageManager::addArchive(const Common::String &name) {
+	Common::Archive *arch = 0;
+
+	if (name.hasSuffix(".zip")) {
 #ifdef USE_ZLIB
-	Common::ZipArchive *arch = new Common::ZipArchive(name);
-	if (!arch || !arch->isOpen())
+		Common::ZipArchive *zip = new Common::ZipArchive(name);
+		if (!zip || !zip->isOpen())
+			return false;
+
+		arch = zip;
+#else
 		return false;
+#endif
+	} else {
+		Common::FSDirectory *dir = new Common::FSDirectory(name);
+		if (!dir || !dir->getFSNode().isDirectory())	
+			return false;
+
+		arch = dir;
+	}
+
 	_archives.add(name, Common::ArchivePtr(arch));
-#endif
 	return true;
 }
 
 void ImageManager::removeArchive(const Common::String &name) {
-#ifdef USE_ZLIB
-	_archives.remove(name);
-#endif
+	if (_archives.hasArchive(name))
+		_archives.remove(name);
 }
 
 bool ImageManager::registerSurface(const Common::String &name, Surface *surf) {
@@ -73,7 +87,6 @@
 	if (!surf)
 		surf = ImageDecoder::loadFile(name);
 
-#ifdef USE_ZLIB
 	if (!surf) {
 		Common::SeekableReadStream *stream = _archives.openFile(name);
 		if (stream) {
@@ -81,7 +94,6 @@
 			delete stream;
 		}
 	}
-#endif
 
 	if (!surf)
 		return false;

Modified: scummvm/trunk/gui/ThemeEngine.cpp
===================================================================
--- scummvm/trunk/gui/ThemeEngine.cpp	2008-10-18 00:29:23 UTC (rev 34814)
+++ scummvm/trunk/gui/ThemeEngine.cpp	2008-10-18 01:27:33 UTC (rev 34815)
@@ -251,10 +251,7 @@
 	for (ImagesMap::iterator i = _bitmaps.begin(); i != _bitmaps.end(); ++i)
 		ImageMan.unregisterSurface(i->_key);
 
-	if (_themeFileName.hasSuffix(".zip"))
-		ImageMan.removeArchive(_themeFileName);
-		
-	Common::File::resetDefaultDirectories();
+	ImageMan.removeArchive(_themeFileName);
 	
 	_themeEval->reset();
 	_themeOk = false;
@@ -463,12 +460,8 @@
 bool ThemeEngine::loadTheme(Common::String fileName) {
 	unloadTheme();
 
-	if (fileName != "builtin") {
-		if (fileName.hasSuffix(".zip"))
-			ImageMan.addArchive(fileName);
-		else 
-			Common::File::addDefaultDirectory(fileName);
-	}
+	if (fileName != "builtin")
+		ImageMan.addArchive(fileName);
 
 	if (fileName == "builtin") {
 		if (!loadDefaultXML())

Modified: scummvm/trunk/gui/theme.cpp
===================================================================
--- scummvm/trunk/gui/theme.cpp	2008-10-18 00:29:23 UTC (rev 34814)
+++ scummvm/trunk/gui/theme.cpp	2008-10-18 01:27:33 UTC (rev 34815)
@@ -33,26 +33,51 @@
 
 Theme::~Theme() {}
 
+const Graphics::Font *Theme::loadFontFromArchive(const Common::String &filename) {
+	Common::Archive *arch = 0;
+	const Graphics::NewFont *font = 0;
+
+	if (getThemeFileName().hasSuffix(".zip")) {
+#ifdef USE_ZLIB
+		Common::ZipArchive *zip = new Common::ZipArchive(getThemeFileName());
+		if (!zip || !zip->isOpen())
+			return 0;
+
+		arch = zip;
+#else
+		return 0;
+#endif
+	} else {
+		Common::FSDirectory *dir = new Common::FSDirectory(getThemeFileName());
+		if (!dir || !dir->getFSNode().isDirectory())	
+			return 0;
+
+		arch = dir;
+	}
+
+	Common::SeekableReadStream *stream(arch->openFile(filename));
+	if (stream) {
+		font = Graphics::NewFont::loadFromCache(*stream);
+		delete stream;
+	}
+
+	delete arch;
+	return font;
+}
+
 const Graphics::Font *Theme::loadFont(const Common::String &filename) {
-	const Graphics::NewFont *font = 0;
+	const Graphics::Font *font = 0;
 	Common::String cacheFilename = genCacheFilename(filename.c_str());
 	Common::File fontFile;
 
 	if (!cacheFilename.empty()) {
 		if (fontFile.open(cacheFilename))
 			font = Graphics::NewFont::loadFromCache(fontFile);
+
 		if (font)
 			return font;
 
-#ifdef USE_ZLIB
-		Common::ZipArchive zipArchive(getThemeFileName());
-		Common::SeekableReadStream *stream(zipArchive.openFile(cacheFilename));
-		if (stream) {
-			font = Graphics::NewFont::loadFromCache(*stream);
-			delete stream;
-		}
-#endif
-		if (font)
+		if ((font = loadFontFromArchive(cacheFilename)))
 			return font;
 	}
 
@@ -61,21 +86,13 @@
 		font = Graphics::NewFont::loadFont(fontFile);
 	}
 
-#ifdef USE_ZLIB
 	if (!font) {
-		Common::ZipArchive zipArchive(getThemeFileName());
-		
-		Common::SeekableReadStream *stream(zipArchive.openFile(filename));
-		if (stream) {
-			font = Graphics::NewFont::loadFont(*stream);
-			delete stream;
-		}
+		font = loadFontFromArchive(filename);
 	}
-#endif
 
 	if (font) {
 		if (!cacheFilename.empty()) {
-			if (!Graphics::NewFont::cacheFontData(*font, cacheFilename)) {
+			if (!Graphics::NewFont::cacheFontData(*(Graphics::NewFont*)font, cacheFilename)) {
 				warning("Couldn't create cache file for font '%s'", filename.c_str());
 			}
 		}

Modified: scummvm/trunk/gui/theme.h
===================================================================
--- scummvm/trunk/gui/theme.h	2008-10-18 00:29:23 UTC (rev 34814)
+++ scummvm/trunk/gui/theme.h	2008-10-18 01:27:33 UTC (rev 34815)
@@ -337,6 +337,7 @@
 
 protected:
 	const Graphics::Font *loadFont(const Common::String &filename);
+	const Graphics::Font *loadFontFromArchive(const Common::String &filename);
 	Common::String genCacheFilename(const char *filename);
 
 public:


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