aboutsummaryrefslogtreecommitdiff
path: root/common/unzip.cpp
diff options
context:
space:
mode:
authorMax Horn2008-09-23 09:39:37 +0000
committerMax Horn2008-09-23 09:39:37 +0000
commitbfdff06e327ee4660f69ffb576dc24662a6c7362 (patch)
treee8108fc26bde0dc237747803112c987aa0ddfecb /common/unzip.cpp
parent939ba5294f5367c91e178a7b06db0266840f79f3 (diff)
downloadscummvm-rg350-bfdff06e327ee4660f69ffb576dc24662a6c7362.tar.gz
scummvm-rg350-bfdff06e327ee4660f69ffb576dc24662a6c7362.tar.bz2
scummvm-rg350-bfdff06e327ee4660f69ffb576dc24662a6c7362.zip
Moved ZipArchive implementation into unzip.cpp, added new ZipArchive::isOpen method
svn-id: r34630
Diffstat (limited to 'common/unzip.cpp')
-rw-r--r--common/unzip.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/common/unzip.cpp b/common/unzip.cpp
index 93fb60f41c..135dc2f7a7 100644
--- a/common/unzip.cpp
+++ b/common/unzip.cpp
@@ -1213,4 +1213,81 @@ extern int ZEXPORT unzGetGlobalComment (unzFile file, char *szComment, uLong uSi
return (int)uReadThis;
}
+/*
+class ZipArchiveMember : public ArchiveMember {
+ unzFile _zipFile;
+
+public:
+ ZipArchiveMember(FilesystemNode &node) : _node(node) {
+ }
+
+ String getName() const {
+ ...
+ }
+
+ SeekableReadStream *open() {
+ ...
+ }
+};
+*/
+
+ZipArchive::ZipArchive(const Common::String &name) {
+ _zipFile = unzOpen(name.c_str());
+}
+
+ZipArchive::~ZipArchive() {
+ unzClose(_zipFile);
+}
+
+bool ZipArchive::hasFile(const Common::String &name) {
+ return (_zipFile && unzLocateFile(_zipFile, name.c_str(), 2) == UNZ_OK);
+}
+
+int ZipArchive::getAllNames(Common::StringList &list) {
+ return 0;
+}
+
+/*
+int ZipArchive::listMembers(Common::ArchiveMemberList &list) {
+ if (!_zipFile)
+ return 0;
+
+ int matches = 0;
+ int err = unzGoToFirstFile(_zipFile);
+
+ while (err == UNZ_OK) {
+ char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
+ unzGetCurrentFileInfo(_zipFile, NULL,
+ szCurrentFileName, sizeof(szCurrentFileName)-1,
+ NULL, 0, NULL, 0);
+
+ szCurrentFileName
+ matches++;
+ err = unzGoToNextFile(file);
+ }
+ return 0;
+}
+*/
+
+Common::SeekableReadStream *ZipArchive::openFile(const Common::String &name) {
+ if (!_zipFile)
+ return 0;
+
+ unzLocateFile(_zipFile, name.c_str(), 2);
+
+ unz_file_info fileInfo;
+ unzOpenCurrentFile(_zipFile);
+ unzGetCurrentFileInfo(_zipFile, &fileInfo, NULL, 0, NULL, 0, NULL, 0);
+ byte *buffer = (byte *)calloc(fileInfo.uncompressed_size+1, 1);
+ assert(buffer);
+ unzReadCurrentFile(_zipFile, buffer, fileInfo.uncompressed_size);
+ unzCloseCurrentFile(_zipFile);
+ return new Common::MemoryReadStream(buffer, fileInfo.uncompressed_size+1, true);
+
+ // FIXME: instead of reading all into a memory stream, we could
+ // instead create a new ZipStream class. But then we have to be
+ // careful to handle the case where the client code opens multiple
+ // files in the archive and tries to use them indepenendtly.
+}
+
#endif