aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2008-09-23 09:42:38 +0000
committerMax Horn2008-09-23 09:42:38 +0000
commitc1c9c895a37e79fe679154f3c725402732ff6162 (patch)
tree72951cf854b418ff84ca20516758e4c698e5eaf3
parentbfdff06e327ee4660f69ffb576dc24662a6c7362 (diff)
downloadscummvm-rg350-c1c9c895a37e79fe679154f3c725402732ff6162.tar.gz
scummvm-rg350-c1c9c895a37e79fe679154f3c725402732ff6162.tar.bz2
scummvm-rg350-c1c9c895a37e79fe679154f3c725402732ff6162.zip
ImageManager: renamed remArchive() to removeArchive(); switched to using a SearchSet + ZipArchive to access ZIP files (code is much simpler now yet more flexible, yay)
svn-id: r34631
-rw-r--r--graphics/imageman.cpp74
-rw-r--r--graphics/imageman.h17
-rw-r--r--gui/ThemeModern.cpp2
3 files changed, 26 insertions, 67 deletions
diff --git a/graphics/imageman.cpp b/graphics/imageman.cpp
index 83ffc40c99..38eb397dd6 100644
--- a/graphics/imageman.cpp
+++ b/graphics/imageman.cpp
@@ -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 @@ ImageManager::~ImageManager() {
*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,39 +70,21 @@ bool ImageManager::registerSurface(const Common::String &name, Surface *surf) {
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
+ 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;
diff --git a/graphics/imageman.h b/graphics/imageman.h
index c3b56c311f..f555b4c844 100644
--- a/graphics/imageman.h
+++ b/graphics/imageman.h
@@ -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 @@ public:
*
* @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 @@ private:
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
diff --git a/gui/ThemeModern.cpp b/gui/ThemeModern.cpp
index f6752f433c..fa8c29e616 100644
--- a/gui/ThemeModern.cpp
+++ b/gui/ThemeModern.cpp
@@ -120,7 +120,7 @@ ThemeModern::~ThemeModern() {
for (int i = 0; i < kImageHandlesMax; ++i) {
ImageMan.unregisterSurface(_imageHandles[i]);
}
- ImageMan.remArchive(_stylefile + ".zip");
+ ImageMan.removeArchive(_stylefile + ".zip");
}
bool ThemeModern::init() {