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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Tue Sep 23 11:42:39 CEST 2008


Revision: 34631
          http://scummvm.svn.sourceforge.net/scummvm/?rev=34631&view=rev
Author:   fingolfin
Date:     2008-09-23 09:42:38 +0000 (Tue, 23 Sep 2008)

Log Message:
-----------
ImageManager: renamed remArchive() to removeArchive(); switched to using a SearchSet + ZipArchive to access ZIP files (code is much simpler now yet more flexible, yay)

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

Modified: scummvm/trunk/graphics/imageman.cpp
===================================================================
--- scummvm/trunk/graphics/imageman.cpp	2008-09-23 09:39:37 UTC (rev 34630)
+++ scummvm/trunk/graphics/imageman.cpp	2008-09-23 09:42:38 UTC (rev 34631)
@@ -26,14 +26,13 @@
 #include "graphics/imageman.h"
 #include "graphics/surface.h"
 
+#include "common/unzip.h"
+
 DECLARE_SINGLETON(Graphics::ImageManager);
 
 namespace Graphics {
-ImageManager::ImageManager() : _surfaces()
-#ifdef USE_ZLIB
-, _archives()
-#endif
-{
+
+ImageManager::ImageManager() {
 }
 
 ImageManager::~ImageManager() {
@@ -44,36 +43,21 @@
 		*pos = 0;
 	}
 	_surfaces.clear();
-#ifdef USE_ZLIB
-	for (ZipIterator pos2 = _archives.begin(); pos2 != _archives.end(); ++pos2) {
-		unzClose(pos2->file);
-	}
-	_archives.clear();
-#endif
 }
 
 bool ImageManager::addArchive(const Common::String &name) {
 #ifdef USE_ZLIB
-	unzFile newFile = unzOpen(name.c_str());
-	if (!newFile)
+	ZipArchive *arch = new ZipArchive(name);
+	if (!arch || !arch->isOpen())
 		return false;
-	Archive arch;
-	arch.file = newFile;
-	arch.filename = name;
-	_archives.push_back(arch);
+	_archives.add(name, Common::ArchivePtr(arch));
 #endif
 	return true;
 }
 
-void ImageManager::remArchive(const Common::String &name) {
+void ImageManager::removeArchive(const Common::String &name) {
 #ifdef USE_ZLIB
-	for (ZipIterator pos = _archives.begin(); pos != _archives.end(); ++pos) {
-		if (pos->filename.compareToIgnoreCase(name) == 0) {
-			unzClose(pos->file);
-			_archives.erase(pos);
-			break;
-		}
-	}
+	_archives.remove(name);
 #endif
 }
 
@@ -86,40 +70,22 @@
 	if (!newHandle)
 		return false;
 
-	if (!surf) {
+	if (!surf)
 		surf = ImageDecoder::loadFile(name);
-		if (!surf) {
-#ifdef USE_ZLIB
-			ZipIterator file = _archives.end();
-			for (ZipIterator pos = _archives.begin(); pos != _archives.end(); ++pos) {
-				if (unzLocateFile(pos->file, name.c_str(), 2) == UNZ_OK) {
-					file = pos;
-					break;
-				}
-			}
 
-			if (file == _archives.end())
-				return false;
-
-			unz_file_info fileInfo;
-			unzOpenCurrentFile(file->file);
-			unzGetCurrentFileInfo(file->file, &fileInfo, NULL, 0, NULL, 0, NULL, 0);
-			uint8 *buffer = new uint8[fileInfo.uncompressed_size];
-			assert(buffer);
-			unzReadCurrentFile(file->file, buffer, fileInfo.uncompressed_size);
-			unzCloseCurrentFile(file->file);
-			Common::MemoryReadStream stream(buffer, fileInfo.uncompressed_size);
-			surf = ImageDecoder::loadFile(stream);
-			delete[] buffer;
-
-			if (!surf)
-				return false;
-#else
-			return false;
-#endif
+#ifdef USE_ZLIB
+	if (!surf) {
+		Common::SeekableReadStream *stream = _archives.openFile(name);
+		if (stream) {
+			surf = ImageDecoder::loadFile(*stream);
+			delete stream;
 		}
 	}
+#endif
 
+	if (!surf)
+		return false;
+
 	newHandle->surface = surf;
 	newHandle->name = name;
 	_surfaces.push_back(newHandle);

Modified: scummvm/trunk/graphics/imageman.h
===================================================================
--- scummvm/trunk/graphics/imageman.h	2008-09-23 09:39:37 UTC (rev 34630)
+++ scummvm/trunk/graphics/imageman.h	2008-09-23 09:42:38 UTC (rev 34631)
@@ -26,12 +26,14 @@
 #define GRAPHICS_IMAGEMAN_H
 
 #include "common/scummsys.h"
+
+#include "common/archive.h"
 #include "common/singleton.h"
 #include "common/str.h"
 #include "common/list.h"
-#include "common/unzip.h"
 
 namespace Graphics {
+
 struct Surface;
 
 class ImageManager : public Common::Singleton<ImageManager> {
@@ -53,7 +55,7 @@
 	 *
 	 * @param name the name of the archive
 	 */
-	void remArchive(const Common::String &name);
+	void removeArchive(const Common::String &name);
 
 	/**
 	 * registers a surface to the ImageManager.
@@ -93,20 +95,11 @@
 		Surface *surface;
 	};
 	typedef Common::List<Entry*>::iterator Iterator;
-#ifdef USE_ZLIB
-	struct Archive {
-		unzFile file;
-		Common::String filename;
-	};
-	typedef Common::List<Archive>::iterator ZipIterator;
-#endif
 
 	Iterator searchHandle(const Common::String &name);
 
 	Common::List<Entry*> _surfaces;
-#ifdef USE_ZLIB
-	Common::List<Archive> _archives;
-#endif
+	Common::SearchSet _archives;
 };
 
 } // end of namespace Graphics

Modified: scummvm/trunk/gui/ThemeModern.cpp
===================================================================
--- scummvm/trunk/gui/ThemeModern.cpp	2008-09-23 09:39:37 UTC (rev 34630)
+++ scummvm/trunk/gui/ThemeModern.cpp	2008-09-23 09:42:38 UTC (rev 34631)
@@ -120,7 +120,7 @@
 	for (int i = 0; i < kImageHandlesMax; ++i) {
 		ImageMan.unregisterSurface(_imageHandles[i]);
 	}
-	ImageMan.remArchive(_stylefile + ".zip");
+	ImageMan.removeArchive(_stylefile + ".zip");
 }
 
 bool ThemeModern::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