aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorVicent Marti2008-09-29 19:23:36 +0000
committerVicent Marti2008-09-29 19:23:36 +0000
commit60ad4bd0d94321cdd78bcf79a507981f17d6ee43 (patch)
tree041ac12b1682b2d75beef7c90345a019b80a10f0 /common
parentc8f42a39737dbd50cbdc4cad7c6a6c89ca0efe69 (diff)
parent1776c75566603d4ecba657e4d4cd67a769ddb43d (diff)
downloadscummvm-rg350-60ad4bd0d94321cdd78bcf79a507981f17d6ee43.tar.gz
scummvm-rg350-60ad4bd0d94321cdd78bcf79a507981f17d6ee43.tar.bz2
scummvm-rg350-60ad4bd0d94321cdd78bcf79a507981f17d6ee43.zip
- Merged 75 revisions from trunk.
- Fixed new conflicts. - Changed Theme loading to use the new ZipArchive class. - Implemented ZipArchive::getAllNames() Original log message from SVNMerge.py ================================ Merged revisions 34605,34613-34615,34617,34619-34624,34627-34628,34630-34639,34642-34649,34656-34661,34663-34664,34671-34672,34674-34676,34678-34685 via svnmerge from https://tanoku@scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk ........ r34605 | Tanoku | 2008-09-20 12:32:59 +0200 (Sat, 20 Sep 2008) | 1 line Fixed "empty control statement" warning in FSDirectory::matchPattern(). ........ r34613 | lordhoto | 2008-09-20 16:53:31 +0200 (Sat, 20 Sep 2008) | 2 lines Updated theme file version, to reflect latest addition of new required entries/files. ........ r34614 | wjpalenstijn | 2008-09-20 17:03:37 +0200 (Sat, 20 Sep 2008) | 1 line fix drawing order in saveload choosers (draw container before contents) ........ r34615 | fingolfin | 2008-09-20 17:53:17 +0200 (Sat, 20 Sep 2008) | 1 line Little readability tweak ........ r34617 | fingolfin | 2008-09-20 18:10:29 +0200 (Sat, 20 Sep 2008) | 1 line Fix for bug #2120602: 5ALL: Starting the launcher with -f triggers assertion ........ r34619 | eriktorbjorn | 2008-09-20 18:21:27 +0200 (Sat, 20 Sep 2008) | 4 lines I think this is the correct fix for bug #2081347 ("MM: Charset out of bounds!"). If I understand correctly, version <= 2 games only have one (hard- coded) font, so when that's initialised we can set _curId to 0. ........ r34620 | marcus_c | 2008-09-20 18:38:50 +0200 (Sat, 20 Sep 2008) | 1 line game.h is now in engines, not base. ........ r34621 | marcus_c | 2008-09-20 18:47:31 +0200 (Sat, 20 Sep 2008) | 5 lines In the CD filesystem, nothing can be opened for writing, so just short-circuit any call to openForWriting(). Also, directories and non-existing files can't be opened for reading either, so just return 0 for those. ........ r34622 | sev | 2008-09-21 12:23:22 +0200 (Sun, 21 Sep 2008) | 2 lines Patch #2054467: CRUISE: 64bits fixes ........ r34623 | sev | 2008-09-21 13:17:22 +0200 (Sun, 21 Sep 2008) | 2 lines Add recent patch contributors. Reflect current ScummVM team in the credits ........ r34624 | sev | 2008-09-21 13:18:16 +0200 (Sun, 21 Sep 2008) | 2 lines Reflect current team ........ r34627 | lordhoto | 2008-09-22 19:33:30 +0200 (Mon, 22 Sep 2008) | 1 line Fixed full screen toggling via alt+enter. ........ r34628 | fingolfin | 2008-09-22 22:55:27 +0200 (Mon, 22 Sep 2008) | 1 line Fix comments for random() funcs (thanks to salty-horse for pointing this out) ........ r34630 | fingolfin | 2008-09-23 11:39:37 +0200 (Tue, 23 Sep 2008) | 1 line Moved ZipArchive implementation into unzip.cpp, added new ZipArchive::isOpen method ........ r34631 | fingolfin | 2008-09-23 11:42:38 +0200 (Tue, 23 Sep 2008) | 1 line ImageManager: renamed remArchive() to removeArchive(); switched to using a SearchSet + ZipArchive to access ZIP files (code is much simpler now yet more flexible, yay) ........ r34632 | fingolfin | 2008-09-23 11:50:03 +0200 (Tue, 23 Sep 2008) | 1 line Moved ZipArchive to namespace Common; moved unzip internals from unzip.h to unzip.cpp (to be cleaned up) ........ r34633 | fingolfin | 2008-09-23 12:08:45 +0200 (Tue, 23 Sep 2008) | 1 line cleanup ........ r34634 | fingolfin | 2008-09-23 12:10:29 +0200 (Tue, 23 Sep 2008) | 1 line Perform error checking when reading from a ZIP file ........ r34635 | fingolfin | 2008-09-23 13:43:57 +0200 (Tue, 23 Sep 2008) | 1 line Fix for bug #1917981: Game crash when finishing Indy3 demo. At the same time, added a new paranoia check ........ r34636 | Kirben | 2008-09-23 14:34:02 +0200 (Tue, 23 Sep 2008) | 1 line Add another French Windows version of Putt-Putt Enters the Race. ........ r34637 | lordhoto | 2008-09-23 18:40:41 +0200 (Tue, 23 Sep 2008) | 2 lines Fix for bug #2120780 "GUI: gui-theme command-line option ignored", '-f' and '-g' command line switch behavior. ........ r34638 | john_doe | 2008-09-24 01:16:47 +0200 (Wed, 24 Sep 2008) | 1 line Improved updateScreenAndWait; the mouse cursor is less jerky now in some scenes in Manhole:N&E ........ r34639 | thebluegr | 2008-09-24 09:26:45 +0200 (Wed, 24 Sep 2008) | 1 line Readded missing special case for the storm animation in ITE. Fixes bug #2125675 - "ITE: Game locks up in storm clouds scene" ........ r34642 | fingolfin | 2008-09-24 22:29:29 +0200 (Wed, 24 Sep 2008) | 1 line Changed Common::String to use a MemoryPool for its refcounts ........ r34643 | fingolfin | 2008-09-24 22:31:14 +0200 (Wed, 24 Sep 2008) | 1 line cleanup ........ r34644 | fingolfin | 2008-09-24 22:35:31 +0200 (Wed, 24 Sep 2008) | 1 line Changed builtin Common::String capacity to 24 (on 32 bit systems), to make sizeof(String) 32; reduces overall memory req by 200k on my system; overall # of mallocs after this + the refcount memory pool change is almost unchanged ........ r34645 | sev | 2008-09-25 00:44:01 +0200 (Thu, 25 Sep 2008) | 2 lines Fix bugs #1981081: "ITE: No blinking disk icon" and #1971729: "IHNM: No Animation of Disk Icon" ........ r34646 | fingolfin | 2008-09-25 10:06:18 +0200 (Thu, 25 Sep 2008) | 1 line SCUMM: Added a new ActorHE class, as well as a virtual Actor::prepareDrawActorCostume() method ........ r34647 | fingolfin | 2008-09-25 10:19:51 +0200 (Thu, 25 Sep 2008) | 1 line SCUMM: Moved Actor::drawActorToBackBuf to class ActorHE ........ r34648 | fingolfin | 2008-09-25 12:11:06 +0200 (Thu, 25 Sep 2008) | 1 line SCUMM: Moved more stuf from class Actor to ActorHE ........ r34649 | fingolfin | 2008-09-25 12:14:50 +0200 (Thu, 25 Sep 2008) | 1 line cleanup ........ r34656 | eriktorbjorn | 2008-09-27 19:25:40 +0200 (Sat, 27 Sep 2008) | 2 lines Fixed typos. ........ r34657 | eriktorbjorn | 2008-09-27 19:47:22 +0200 (Sat, 27 Sep 2008) | 2 lines Allow quitting or returning to the launcher while cutscenes are playing. ........ r34658 | eriktorbjorn | 2008-09-27 19:51:22 +0200 (Sat, 27 Sep 2008) | 2 lines Slight simplification of last commit. ........ r34659 | fingolfin | 2008-09-27 20:32:01 +0200 (Sat, 27 Sep 2008) | 1 line Modified Common::SearchSet to take signed integer priorities, for convenience (so that one can add archives with less-than-default priority) ........ r34660 | fingolfin | 2008-09-27 20:34:24 +0200 (Sat, 27 Sep 2008) | 1 line Fixed a nasty bug in SearchManager::addDirectory; made the 'char' constructor of Common::String explicit, to avoid such bugs in the future ........ r34661 | drmccoy | 2008-09-27 22:04:04 +0200 (Sat, 27 Sep 2008) | 2 lines Added a spanish floppy version of Lost in Time, as supplied by goodoldgeorg in bug report #2105220 ........ r34663 | fingolfin | 2008-09-28 01:00:46 +0200 (Sun, 28 Sep 2008) | 1 line Changed Common::File to use SearchMan ........ r34664 | fingolfin | 2008-09-28 01:27:01 +0200 (Sun, 28 Sep 2008) | 1 line SCUMM: Use FilesystemNode::openForReading instead of Common::File::open(FilesystemNode) in the detector ........ r34671 | john_doe | 2008-09-28 22:02:01 +0200 (Sun, 28 Sep 2008) | 1 line Return 32000 in sfGetCdTime instead of 0; this fixes the Manhole intro/credits (until the function is actually implemented) ........ r34672 | sev | 2008-09-28 23:07:41 +0200 (Sun, 28 Sep 2008) | 2 lines Add Italian C64 Zak ........ r34674 | sev | 2008-09-28 23:53:14 +0200 (Sun, 28 Sep 2008) | 2 lines Fix bug #2043489: DRASCULA: Cannot disable speech ........ r34675 | sev | 2008-09-29 00:07:16 +0200 (Mon, 29 Sep 2008) | 3 lines - Renamed withVoices to _subtitlesDisabled as it reflect the true meaning. - Allowed to disable subtitles from options dialogs including RTL. ........ r34676 | sev | 2008-09-29 00:19:11 +0200 (Mon, 29 Sep 2008) | 2 lines Use better "silence" without clicks when speech is disabled. ........ r34678 | fingolfin | 2008-09-29 12:29:01 +0200 (Mon, 29 Sep 2008) | 1 line Added FIXME to GP2x port ........ r34679 | fingolfin | 2008-09-29 12:30:31 +0200 (Mon, 29 Sep 2008) | 1 line Add priority parameter to the SearchMan API ........ r34680 | fingolfin | 2008-09-29 12:32:06 +0200 (Mon, 29 Sep 2008) | 1 line File::open no longer falls back to searching the current dir (if this causes any regressions, please report them; don't work around them, don't revert this change, without discussing it first) ........ r34681 | fingolfin | 2008-09-29 12:49:36 +0200 (Mon, 29 Sep 2008) | 1 line Don't subclass ArjFile from Common::File (there seems to be no good reason for it). BTW, this code is an abomination and should be replaced by an Archive/SearchSet approach ........ r34682 | fingolfin | 2008-09-29 13:01:25 +0200 (Mon, 29 Sep 2008) | 1 line Added const qualifiers ........ r34683 | fingolfin | 2008-09-29 13:02:11 +0200 (Mon, 29 Sep 2008) | 1 line SCUMM HE: Fixed leak in Win32ResExtractor::extractResource_, use _filename instead of File::name ........ r34684 | fingolfin | 2008-09-29 13:03:10 +0200 (Mon, 29 Sep 2008) | 1 line Added const qualifiers ........ r34685 | fingolfin | 2008-09-29 13:07:39 +0200 (Mon, 29 Sep 2008) | 1 line Don't use File::name() needlessly (i.e. if you still know which file you just opened :) ........ svn-id: r34687
Diffstat (limited to 'common')
-rw-r--r--common/archive.cpp29
-rw-r--r--common/archive.h20
-rw-r--r--common/file.cpp39
-rw-r--r--common/str.cpp27
-rw-r--r--common/str.h4
-rw-r--r--common/system.h2
-rw-r--r--common/unarj.cpp6
-rw-r--r--common/unarj.h8
-rw-r--r--common/unzip.cpp556
-rw-r--r--common/unzip.h326
-rw-r--r--common/util.h8
-rw-r--r--common/xmlparser.h4
12 files changed, 499 insertions, 530 deletions
diff --git a/common/archive.cpp b/common/archive.cpp
index 7e17fdca32..49e43a5973 100644
--- a/common/archive.cpp
+++ b/common/archive.cpp
@@ -26,6 +26,7 @@
#include "common/archive.h"
#include "common/fs.h"
#include "common/util.h"
+#include "common/system.h"
namespace Common {
@@ -231,7 +232,7 @@ void SearchSet::insert(const Node &node) {
_list.insert(it, node);
}
-void SearchSet::add(const String& name, ArchivePtr archive, uint priority) {
+void SearchSet::add(const String& name, ArchivePtr archive, int priority) {
if (find(name) == _list.end()) {
Node node = { priority, name, archive };
insert(node);
@@ -256,7 +257,7 @@ void SearchSet::clear() {
_list.clear();
}
-void SearchSet::setPriority(const String& name, uint priority) {
+void SearchSet::setPriority(const String& name, int priority) {
ArchiveList::iterator it = find(name);
if (it == _list.end()) {
warning("SearchSet::setPriority: archive '%s' is not present", name.c_str());
@@ -328,17 +329,29 @@ SeekableReadStream *SearchSet::openFile(const String &name) {
DECLARE_SINGLETON(SearchManager);
-void SearchManager::addArchive(const String &name, ArchivePtr archive) {
- add(name, archive);
+SearchManager::SearchManager() {
+ clear(); // Force a reset
}
-void SearchManager::addDirectory(const String &name, const String &directory) {
- addDirectoryRecursive(name, 1);
+void SearchManager::addArchive(const String &name, ArchivePtr archive, int priority) {
+ add(name, archive, priority);
}
-void SearchManager::addDirectoryRecursive(const String &name, const String &directory, int depth) {
- add(name, SharedPtr<FSDirectory>(new FSDirectory(directory, depth)));
+void SearchManager::addDirectory(const String &name, const String &directory, int priority) {
+ addDirectoryRecursive(name, directory, 1, priority);
}
+void SearchManager::addDirectoryRecursive(const String &name, const String &directory, int depth, int priority) {
+ add(name, ArchivePtr(new FSDirectory(directory, depth)), priority);
+}
+
+void SearchManager::clear() {
+ SearchSet::clear();
+
+ // Always keep system specific archives in the SearchManager.
+ // But we give them a lower priority than the default priority (which is 0),
+ // so that archives added by client code are searched first.
+ g_system->addSysArchivesToSearchSet(*this, -1);
+}
} // namespace Common
diff --git a/common/archive.h b/common/archive.h
index 89ea6a5ce2..246d9da8cf 100644
--- a/common/archive.h
+++ b/common/archive.h
@@ -153,7 +153,7 @@ public:
*/
class SearchSet : public Archive {
struct Node {
- uint _priority;
+ int _priority;
String _name;
ArchivePtr _arc;
};
@@ -169,7 +169,7 @@ public:
/**
* Add a new archive to the searchable set.
*/
- void add(const String& name, ArchivePtr archive, uint priority = 0);
+ void add(const String& name, ArchivePtr archive, int priority = 0);
/**
* Remove an archive from the searchable set.
@@ -184,12 +184,12 @@ public:
/**
* Empties the searchable set.
*/
- void clear();
+ virtual void clear();
/**
* Change the order of searches.
*/
- void setPriority(const String& name, uint priority);
+ void setPriority(const String& name, int priority);
virtual bool hasFile(const String &name);
virtual int matchPattern(StringList &list, const String &pattern);
@@ -205,22 +205,28 @@ public:
class SearchManager : public Singleton<SearchManager>, public SearchSet {
public:
+ SearchManager();
+
/**
* Add an existing Archive. This is meant to support searching in system-specific
* archives, namely the MACOSX/IPHONE bundles.
*/
- void addArchive(const String &name, ArchivePtr archive);
+ void addArchive(const String &name, ArchivePtr archive, int priority = 0);
/**
* Create and add a FSDirectory by name
*/
- void addDirectory(const String &name, const String &directory);
+ void addDirectory(const String &name, const String &directory, int priority = 0);
/**
* Create and add a FSDirectory and its subdirectories by name
*/
- void addDirectoryRecursive(const String &name, const String &directory, int depth = 4);
+ void addDirectoryRecursive(const String &name, const String &directory, int depth = 4, int priority = 0);
+ /**
+ * TODO
+ */
+ virtual void clear();
};
/** Shortcut for accessing the search manager. */
diff --git a/common/file.cpp b/common/file.cpp
index cf396a32cd..6558dfea33 100644
--- a/common/file.cpp
+++ b/common/file.cpp
@@ -31,9 +31,6 @@
namespace Common {
-static Common::SearchSet *s_searchSet = 0;
-
-
void File::addDefaultDirectory(const String &directory) {
FilesystemNode dir(directory);
addDefaultDirectoryRecursive(dir, 1);
@@ -52,18 +49,12 @@ void File::addDefaultDirectoryRecursive(const FilesystemNode &dir, int level) {
if (level <= 0 || !dir.exists() || !dir.isDirectory())
return;
- if (!s_searchSet) {
- s_searchSet = new Common::SearchSet();
- g_system->addSysArchivesToSearchSet(*s_searchSet);
- }
-
Common::ArchivePtr dataArchive(new Common::FSDirectory(dir, level));
- s_searchSet->add(dir.getPath(), dataArchive, 1);
+ SearchMan.add(dir.getPath(), dataArchive);
}
void File::resetDefaultDirectories() {
- delete s_searchSet;
- s_searchSet = 0;
+ SearchMan.clear();
}
File::File()
@@ -82,23 +73,18 @@ bool File::open(const String &filename) {
_name.clear();
clearIOFailed();
- if (s_searchSet && s_searchSet->hasFile(filename)) {
+ if (SearchMan.hasFile(filename)) {
debug(3, "Opening hashed: %s", filename.c_str());
- _handle = s_searchSet->openFile(filename);
- } else if (s_searchSet && s_searchSet->hasFile(filename + ".")) {
+ _handle = SearchMan.openFile(filename);
+ } else if (SearchMan.hasFile(filename + ".")) {
// WORKAROUND: Bug #1458388: "SIMON1: Game Detection fails"
// sometimes instead of "GAMEPC" we get "GAMEPC." (note trailing dot)
debug(3, "Opening hashed: %s.", filename.c_str());
- _handle = s_searchSet->openFile(filename);
- } else {
- // Last resort: try the current directory
- FilesystemNode file(filename);
- if (file.exists() && !file.isDirectory())
- _handle = file.openForReading();
+ _handle = SearchMan.openFile(filename + ".");
}
if (_handle == NULL)
- debug(2, "File %s not opened", filename.c_str());
+ debug(2, "File::open: '%s' not found", filename.c_str());
else
_name = filename;
@@ -127,7 +113,7 @@ bool File::open(const FilesystemNode &node) {
_handle = node.openForReading();
if (_handle == NULL)
- debug(2, "File %s not found", filename.c_str());
+ debug(2, "File::open: '%s' not found", node.getPath().c_str());
else
_name = filename;
@@ -135,17 +121,12 @@ bool File::open(const FilesystemNode &node) {
}
bool File::exists(const String &filename) {
- if (s_searchSet && s_searchSet->hasFile(filename)) {
+ if (SearchMan.hasFile(filename)) {
return true;
- } else if (s_searchSet && s_searchSet->hasFile(filename + ".")) {
+ } else if (SearchMan.hasFile(filename + ".")) {
// WORKAROUND: Bug #1458388: "SIMON1: Game Detection fails"
// sometimes instead of "GAMEPC" we get "GAMEPC." (note trailing dot)
return true;
- } else {
- // Last resort: try the current directory
- FilesystemNode file(filename);
- if (file.exists() && !file.isDirectory())
- return true;
}
return false;
diff --git a/common/str.cpp b/common/str.cpp
index a415e376c9..6c48738533 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -26,6 +26,13 @@
#include "common/hash-str.h"
#include "common/util.h"
+#include "common/memorypool.h"
+
+#if !defined(__SYMBIAN32__)
+#include <new>
+#endif
+
+
namespace Common {
#if !(defined(PALMOS_ARM) || defined(PALMOS_DEBUG) || defined(__GP32__))
@@ -34,6 +41,9 @@ const String String::emptyString;
const char *String::emptyString = "";
#endif
+
+MemoryPool *g_refCountPool = 0; // FIXME: This is never freed right now
+
static uint32 computeCapacity(uint32 len) {
// By default, for the capacity we use the next multiple of 32
return ((len + 32 - 1) & ~0x1F);
@@ -79,15 +89,17 @@ void String::initWithCStr(const char *str, uint32 len) {
}
String::String(const String &str)
- : _size(str._size), _str(str.isStorageIntern() ? _storage : str._str) {
+ : _size(str._size) {
if (str.isStorageIntern()) {
// String in internal storage: just copy it
- memcpy(_storage, str._storage, sizeof(_storage));
+ memcpy(_storage, str._storage, _builtinCapacity);
+ _str = _storage;
} else {
// String in external storage: use refcount mechanism
str.incRefCount();
_extern._refCount = str._extern._refCount;
_extern._capacity = str._extern._capacity;
+ _str = str._str;
}
assert(_str != 0);
}
@@ -178,7 +190,11 @@ void String::ensureCapacity(uint32 new_size, bool keep_old) {
void String::incRefCount() const {
assert(!isStorageIntern());
if (_extern._refCount == 0) {
- _extern._refCount = new int(2);
+ if (g_refCountPool == 0)
+ g_refCountPool = new MemoryPool(sizeof(int));
+
+ _extern._refCount = (int *)g_refCountPool->malloc();
+ *_extern._refCount = 2;
} else {
++(*_extern._refCount);
}
@@ -194,7 +210,10 @@ void String::decRefCount(int *oldRefCount) {
if (!oldRefCount || *oldRefCount <= 0) {
// The ref count reached zero, so we free the string storage
// and the ref count storage.
- delete oldRefCount;
+ if (oldRefCount) {
+ assert(g_refCountPool);
+ g_refCountPool->free(oldRefCount);
+ }
free(_str);
// Even though _str points to a freed memory block now,
diff --git a/common/str.h b/common/str.h
index 20914c1f1f..c3e773c3e4 100644
--- a/common/str.h
+++ b/common/str.h
@@ -54,7 +54,7 @@ protected:
* than 8 makes no sense, since that's the size of member _extern
* (on 32 bit machines; 12 bytes on systems with 64bit pointers).
*/
- static const uint32 _builtinCapacity = 32;
+ static const uint32 _builtinCapacity = 32 - sizeof(uint32) - sizeof(char*);
/**
* Length of the string. Stored to avoid having to call strlen
@@ -112,7 +112,7 @@ public:
String(const String &str);
/** Construct a string consisting of the given character. */
- String(char c);
+ explicit String(char c);
~String();
diff --git a/common/system.h b/common/system.h
index cb9dbedad7..176e53ddb4 100644
--- a/common/system.h
+++ b/common/system.h
@@ -917,7 +917,7 @@ public:
* @param s the SearchSet to which the system specific dirs, if any, are added
* @param priority the priority with which those dirs are added
*/
- virtual void addSysArchivesToSearchSet(Common::SearchSet &s, uint priority = 0) {}
+ virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0) {}
/**
* Open the default config file for reading, by returning a suitable
diff --git a/common/unarj.cpp b/common/unarj.cpp
index 244a296efb..00f51ac252 100644
--- a/common/unarj.cpp
+++ b/common/unarj.cpp
@@ -324,15 +324,15 @@ uint32 ArjFile::read(void *dataPtr, uint32 dataSize) {
return _uncompressed->read(dataPtr, dataSize);
}
-bool ArjFile::eos() {
+bool ArjFile::eos() const {
return _uncompressed->eos();
}
-int32 ArjFile::pos() {
+int32 ArjFile::pos() const {
return _uncompressed->pos();
}
-int32 ArjFile::size() {
+int32 ArjFile::size() const {
return _uncompressed->size();
}
diff --git a/common/unarj.h b/common/unarj.h
index 52e0d13948..d16d748ad3 100644
--- a/common/unarj.h
+++ b/common/unarj.h
@@ -85,7 +85,7 @@ struct ArjHeader {
typedef HashMap<String, int, IgnoreCase_Hash, IgnoreCase_EqualTo> ArjFilesMap;
-class ArjFile : public File {
+class ArjFile : public SeekableReadStream, public NonCopyable {
public:
ArjFile();
~ArjFile();
@@ -98,9 +98,9 @@ public:
void close();
uint32 read(void *dataPtr, uint32 dataSize);
- bool eos();
- int32 pos();
- int32 size();
+ bool eos() const;
+ int32 pos() const;
+ int32 size() const;
bool seek(int32 offset, int whence = SEEK_SET);
bool isOpen() { return _isOpen; }
diff --git a/common/unzip.cpp b/common/unzip.cpp
index 93fb60f41c..27001519a1 100644
--- a/common/unzip.cpp
+++ b/common/unzip.cpp
@@ -28,14 +28,51 @@
Read unzip.h for more info
*/
+/* unzip.h -- IO for uncompress .zip files using zlib
+ Version 0.15 beta, Mar 19th, 1998,
+
+ Copyright (C) 1998 Gilles Vollant
+
+ This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
+ WinZip, InfoZip tools and compatible.
+ Encryption and multi volume ZipFile (span) are not supported.
+ Old compressions used by old PKZip 1.x are not supported
+
+ THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE
+ CAN CHANGE IN FUTURE VERSION !!
+ I WAIT FEEDBACK at mail info@winimage.com
+ Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
+
+ Condition of use and distribution are the same than zlib :
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+
+
+*/
+/* for more info about .ZIP format, see
+ ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip
+ PkWare has also a specification at :
+ ftp://ftp.pkware.com/probdesc.zip */
+
+
#include "common/scummsys.h"
#ifdef USE_ZLIB
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
#ifdef __SYMBIAN32__
#include <zlib\zlib.h>
#else
@@ -45,24 +82,213 @@
#include "common/unzip.h"
#include "common/file.h"
-#ifdef STDC
-# include <stddef.h>
-# include <string.h>
-# include <stdlib.h>
-#endif
-#ifdef NO_ERRNO_H
- extern int errno;
+#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
+/* like the STRICT of WIN32, we define a pointer that cannot be converted
+ from (void*) without cast */
+typedef struct TagunzFile__ { int unused; } unzFile__;
+typedef unzFile__ *unzFile;
#else
-# include <errno.h>
+typedef voidp unzFile;
#endif
-#ifndef local
-# define local static
-#endif
-/* compile with -Dlocal if your debugger can't find static symbols */
+#define UNZ_OK (0)
+#define UNZ_END_OF_LIST_OF_FILE (-100)
+#define UNZ_ERRNO (Z_ERRNO)
+#define UNZ_EOF (0)
+#define UNZ_PARAMERROR (-102)
+#define UNZ_BADZIPFILE (-103)
+#define UNZ_INTERNALERROR (-104)
+#define UNZ_CRCERROR (-105)
+
+/* tm_unz contain date/time info */
+typedef struct {
+ uInt tm_sec; /* seconds after the minute - [0,59] */
+ uInt tm_min; /* minutes after the hour - [0,59] */
+ uInt tm_hour; /* hours since midnight - [0,23] */
+ uInt tm_mday; /* day of the month - [1,31] */
+ uInt tm_mon; /* months since January - [0,11] */
+ uInt tm_year; /* years - [1980..2044] */
+} tm_unz;
+
+/* unz_global_info structure contain global data about the ZIPfile
+ These data comes from the end of central dir */
+typedef struct {
+ uLong number_entry; /* total number of entries in
+ the central dir on this disk */
+ uLong size_comment; /* size of the global comment of the zipfile */
+} unz_global_info;
+
+
+/* unz_file_info contain information about a file in the zipfile */
+typedef struct {
+ uLong version; /* version made by 2 bytes */
+ uLong version_needed; /* version needed to extract 2 bytes */
+ uLong flag; /* general purpose bit flag 2 bytes */
+ uLong compression_method; /* compression method 2 bytes */
+ uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
+ uLong crc; /* crc-32 4 bytes */
+ uLong compressed_size; /* compressed size 4 bytes */
+ uLong uncompressed_size; /* uncompressed size 4 bytes */
+ uLong size_filename; /* filename length 2 bytes */
+ uLong size_file_extra; /* extra field length 2 bytes */
+ uLong size_file_comment; /* file comment length 2 bytes */
+
+ uLong disk_num_start; /* disk number start 2 bytes */
+ uLong internal_fa; /* internal file attributes 2 bytes */
+ uLong external_fa; /* external file attributes 4 bytes */
+
+ tm_unz tmu_date;
+} unz_file_info;
+
+int unzStringFileNameCompare(const char* fileName1,
+ const char* fileName2,
+ int iCaseSensitivity);
+/*
+ Compare two filename (fileName1,fileName2).
+ If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
+ If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
+ or strcasecmp)
+ If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
+ (like 1 on Unix, 2 on Windows)
+*/
+
+
+unzFile unzOpen(const char *path);
+/*
+ Open a Zip file. path contain the full pathname (by example,
+ on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer
+ "zlib/zlib111.zip".
+ If the zipfile cannot be opened (file don't exist or in not valid), the
+ return value is NULL.
+ Else, the return value is a unzFile Handle, usable with other function
+ of this unzip package.
+*/
+
+int unzClose(unzFile file);
+/*
+ Close a ZipFile opened with unzipOpen.
+ If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
+ these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
+ return UNZ_OK if there is no problem. */
+
+int unzGetGlobalInfo(unzFile file,
+ unz_global_info *pglobal_info);
+/*
+ Write info about the ZipFile in the *pglobal_info structure.
+ No preparation of the structure is needed
+ return UNZ_OK if there is no problem. */
+
+
+int unzGetGlobalComment(unzFile file, char *szComment, uLong uSizeBuf);
+/*
+ Get the global comment string of the ZipFile, in the szComment buffer.
+ uSizeBuf is the size of the szComment buffer.
+ return the number of byte copied or an error code <0
+*/
+
+
+/***************************************************************************/
+/* Unzip package allow you browse the directory of the zipfile */
+
+int unzGoToFirstFile(unzFile file);
+/*
+ Set the current file of the zipfile to the first file.
+ return UNZ_OK if there is no problem
+*/
+
+int unzGoToNextFile(unzFile file);
+/*
+ Set the current file of the zipfile to the next file.
+ return UNZ_OK if there is no problem
+ return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
+*/
+
+int unzLocateFile(unzFile file, const char *szFileName, int iCaseSensitivity);
+/*
+ Try locate the file szFileName in the zipfile.
+ For the iCaseSensitivity signification, see unzStringFileNameCompare
+
+ return value :
+ UNZ_OK if the file is found. It becomes the current file.
+ UNZ_END_OF_LIST_OF_FILE if the file is not found
+*/
+
+
+int unzGetCurrentFileInfo(unzFile file,
+ unz_file_info *pfile_info,
+ char *szFileName,
+ uLong fileNameBufferSize,
+ void *extraField,
+ uLong extraFieldBufferSize,
+ char *szComment,
+ uLong commentBufferSize);
+/*
+ Get Info about the current file
+ if pfile_info!=NULL, the *pfile_info structure will contain somes info about
+ the current file
+ if szFileName!=NULL, the filemane string will be copied in szFileName
+ (fileNameBufferSize is the size of the buffer)
+ if extraField!=NULL, the extra field information will be copied in extraField
+ (extraFieldBufferSize is the size of the buffer).
+ This is the Central-header version of the extra field
+ if szComment!=NULL, the comment string of the file will be copied in szComment
+ (commentBufferSize is the size of the buffer)
+*/
+
+/***************************************************************************/
+/* for reading the content of the current zipfile, you can open it, read data
+ from it, and close it (you can close it before reading all the file)
+ */
+
+int unzOpenCurrentFile(unzFile file);
+/*
+ Open for reading data the current file in the zipfile.
+ If there is no error, the return value is UNZ_OK.
+*/
+int unzCloseCurrentFile(unzFile file);
+/*
+ Close the file in zip opened with unzOpenCurrentFile
+ Return UNZ_CRCERROR if all the file was read but the CRC is not good
+*/
+
+
+int unzReadCurrentFile(unzFile file, voidp buf, unsigned len);
+/*
+ Read bytes from the current file (opened by unzOpenCurrentFile)
+ buf contain buffer where data must be copied
+ len the size of buf.
+
+ return the number of byte copied if somes bytes are copied
+ return 0 if the end of file was reached
+ return <0 with error code if there is an error
+ (UNZ_ERRNO for IO error, or zLib error for uncompress error)
+*/
+z_off_t unztell(unzFile file);
+/*
+ Give the current position in uncompressed data
+*/
+
+int unzeof(unzFile file);
+/*
+ return 1 if the end of file was reached, 0 elsewhere
+*/
+
+int unzGetLocalExtrafield(unzFile file, voidp buf, unsigned len);
+/*
+ Read extra field from the current file (opened by unzOpenCurrentFile)
+ This is the local-header version of the extra field (sometimes, there is
+ more info in the local-header version than in the central-header)
+
+ if buf==NULL, it return the size of the local extra field
+
+ if buf!=NULL, len is the size of the buffer, the extra header is copied in
+ buf.
+ the return value is the number of bytes copied in buf, or (if <0)
+ the error code
+*/
#if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) && \
!defined(CASESENSITIVITYDEFAULT_NO)
@@ -78,45 +304,22 @@
#define UNZ_MAXFILENAMEINZIP (256)
#endif
-#ifndef ALLOC
-# define ALLOC(size) (malloc(size))
-#endif
-#ifndef TRYFREE
-# define TRYFREE(p) {if (p) free(p);}
-#endif
-
#define SIZECENTRALDIRITEM (0x2e)
#define SIZEZIPLOCALHEADER (0x1e)
-/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
-
-#ifndef SEEK_CUR
-#define SEEK_CUR 1
-#endif
-
-#ifndef SEEK_END
-#define SEEK_END 2
-#endif
-
-#ifndef SEEK_SET
-#define SEEK_SET 0
-#endif
-
const char unz_copyright[] =
" unzip 0.15 Copyright 1998 Gilles Vollant ";
/* unz_file_info_interntal contain internal info about a file in zipfile*/
-typedef struct unz_file_info_internal_s
-{
+typedef struct {
uLong offset_curfile;/* relative offset of local header 4 bytes */
} unz_file_info_internal;
/* file_in_zip_read_info_s contain internal information about a file in zipfile,
when reading and decompress it */
-typedef struct
-{
+typedef struct {
char *read_buffer; /* internal buffer for compressed data */
z_stream stream; /* zLib stream structure for inflate */
@@ -139,8 +342,7 @@ typedef struct
/* unz_s contain internal information about the zipfile
*/
-typedef struct
-{
+typedef struct {
Common::File file; /* io structore of the zipfile */
unz_global_info gi; /* public global information */
uLong byte_before_the_zipfile; /* byte before the zipfile, (>0 for sfx)*/
@@ -166,14 +368,11 @@ typedef struct
*/
-/*local int unzlocal_getByte(Common::File &fin, int *pi)
-{
+/*static int unzlocal_getByte(Common::File &fin, int *pi) {
unsigned char c = fin.readByte();
*pi = (int)c;
return UNZ_OK;
- }
- else
- {
+ } else {
if (fin.ioFailed())
return UNZ_ERRNO;
else
@@ -185,37 +384,14 @@ typedef struct
/* ===========================================================================
Reads a long in LSB order from the given gz_stream. Sets
*/
-local int unzlocal_getShort (Common::File &fin, uLong *pX)
-{
+static int unzlocal_getShort(Common::File &fin, uLong *pX) {
*pX = fin.readUint16LE();
- return UNZ_OK;
+ return fin.ioFailed() ? UNZ_ERRNO : UNZ_OK;
}
-local int unzlocal_getLong (Common::File &fin, uLong *pX)
-{
+static int unzlocal_getLong(Common::File &fin, uLong *pX) {
*pX = fin.readUint32LE();
- return UNZ_OK;
-}
-
-/* My own strcmpi / strcasecmp */
-local int strcmpcasenosensitive_internal (const char* fileName1, const char* fileName2) {
- for (;;)
- {
- char c1=*(fileName1++);
- char c2=*(fileName2++);
- if ((c1>='a') && (c1<='z'))
- c1 -= 0x20;
- if ((c2>='a') && (c2<='z'))
- c2 -= 0x20;
- if (c1=='\0')
- return ((c2=='\0') ? 0 : -1);
- if (c2=='\0')
- return 1;
- if (c1<c2)
- return -1;
- if (c1>c2)
- return 1;
- }
+ return fin.ioFailed() ? UNZ_ERRNO : UNZ_OK;
}
@@ -225,10 +401,6 @@ local int strcmpcasenosensitive_internal (const char* fileName1, const char* fil
#define CASESENSITIVITYDEFAULTVALUE 1
#endif
-#ifndef STRCMPCASENOSENTIVEFUNCTION
-#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal
-#endif
-
/*
Compare two filename (fileName1,fileName2).
If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
@@ -238,15 +410,14 @@ local int strcmpcasenosensitive_internal (const char* fileName1, const char* fil
(like 1 on Unix, 2 on Windows)
*/
-extern int ZEXPORT unzStringFileNameCompare (const char* fileName1, const char* fileName2, int iCaseSensitivity)
-{
+int unzStringFileNameCompare(const char* fileName1, const char* fileName2, int iCaseSensitivity) {
if (iCaseSensitivity==0)
iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
if (iCaseSensitivity==1)
return strcmp(fileName1,fileName2);
- return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2);
+ return scumm_stricmp(fileName1,fileName2);
}
#define BUFREADCOMMENT (0x400)
@@ -255,8 +426,7 @@ extern int ZEXPORT unzStringFileNameCompare (const char* fileName1, const char*
Locate the Central directory of a zipfile (at the end, just before
the global comment)
*/
-local uLong unzlocal_SearchCentralDir(Common::File &fin)
-{
+static uLong unzlocal_SearchCentralDir(Common::File &fin) {
unsigned char* buf;
uLong uSizeFile;
uLong uBackRead;
@@ -270,13 +440,12 @@ local uLong unzlocal_SearchCentralDir(Common::File &fin)
if (uMaxBack>uSizeFile)
uMaxBack = uSizeFile;
- buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
+ buf = (unsigned char*)malloc(BUFREADCOMMENT+4);
if (buf==NULL)
return 0;
uBackRead = 4;
- while (uBackRead<uMaxBack)
- {
+ while (uBackRead<uMaxBack) {
uLong uReadSize,uReadPos ;
int i;
if (uBackRead+BUFREADCOMMENT>uMaxBack)
@@ -305,7 +474,7 @@ local uLong unzlocal_SearchCentralDir(Common::File &fin)
if (uPosFound!=0)
break;
}
- TRYFREE(buf);
+ free(buf);
return uPosFound;
}
@@ -318,8 +487,7 @@ local uLong unzlocal_SearchCentralDir(Common::File &fin)
Else, the return value is a unzFile Handle, usable with other function
of this unzip package.
*/
-extern unzFile ZEXPORT unzOpen (const char *path)
-{
+unzFile unzOpen(const char *path) {
unz_s *us = new unz_s;
uLong central_pos,uL;
@@ -408,8 +576,7 @@ extern unzFile ZEXPORT unzOpen (const char *path)
If there is files inside the .Zip opened with unzipOpenCurrentFile (see later),
these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
return UNZ_OK if there is no problem. */
-extern int ZEXPORT unzClose (unzFile file)
-{
+int unzClose(unzFile file) {
unz_s* s;
if (file==NULL)
return UNZ_PARAMERROR;
@@ -428,8 +595,7 @@ extern int ZEXPORT unzClose (unzFile file)
Write info about the ZipFile in the *pglobal_info structure.
No preparation of the structure is needed
return UNZ_OK if there is no problem. */
-extern int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info *pglobal_info)
-{
+int unzGetGlobalInfo (unzFile file, unz_global_info *pglobal_info) {
unz_s* s;
if (file==NULL)
return UNZ_PARAMERROR;
@@ -442,8 +608,7 @@ extern int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info *pglobal_info
/*
Translate date/time from Dos format to tm_unz (readable more easilty)
*/
-local void unzlocal_DosDateToTmuDate (uLong ulDosDate, tm_unz* ptm)
-{
+static void unzlocal_DosDateToTmuDate (uLong ulDosDate, tm_unz* ptm) {
uLong uDate;
uDate = (uLong)(ulDosDate>>16);
ptm->tm_mday = (uInt)(uDate&0x1f) ;
@@ -458,7 +623,7 @@ local void unzlocal_DosDateToTmuDate (uLong ulDosDate, tm_unz* ptm)
/*
Get Info about the current file in the zipfile, with internal only info
*/
-local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file,
+static int unzlocal_GetCurrentFileInfoInternal(unzFile file,
unz_file_info *pfile_info,
unz_file_info_internal
*pfile_info_internal,
@@ -467,9 +632,9 @@ local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file,
void *extraField,
uLong extraFieldBufferSize,
char *szComment,
- uLong commentBufferSize));
+ uLong commentBufferSize);
-local int unzlocal_GetCurrentFileInfoInternal (unzFile file,
+static int unzlocal_GetCurrentFileInfoInternal(unzFile file,
unz_file_info *pfile_info,
unz_file_info_internal *pfile_info_internal,
char *szFileName, uLong fileNameBufferSize,
@@ -492,8 +657,7 @@ local int unzlocal_GetCurrentFileInfoInternal (unzFile file,
/* we check the magic */
- if (err==UNZ_OK)
- {
+ if (err==UNZ_OK) {
if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK)
err=UNZ_ERRNO;
else if (uMagic!=0x02014b50)
@@ -548,15 +712,12 @@ local int unzlocal_GetCurrentFileInfoInternal (unzFile file,
err=UNZ_ERRNO;
lSeek+=file_info.size_filename;
- if ((err==UNZ_OK) && (szFileName!=NULL))
- {
+ if ((err==UNZ_OK) && (szFileName!=NULL)) {
uLong uSizeRead ;
- if (file_info.size_filename<fileNameBufferSize)
- {
+ if (file_info.size_filename<fileNameBufferSize) {
*(szFileName+file_info.size_filename)='\0';
uSizeRead = file_info.size_filename;
- }
- else
+ } else
uSizeRead = fileNameBufferSize;
if ((file_info.size_filename>0) && (fileNameBufferSize>0))
@@ -566,16 +727,14 @@ local int unzlocal_GetCurrentFileInfoInternal (unzFile file,
}
- if ((err==UNZ_OK) && (extraField!=NULL))
- {
+ if ((err==UNZ_OK) && (extraField!=NULL)) {
uLong uSizeRead ;
if (file_info.size_file_extra<extraFieldBufferSize)
uSizeRead = file_info.size_file_extra;
else
uSizeRead = extraFieldBufferSize;
- if (lSeek!=0)
- {
+ if (lSeek!=0) {
s->file.seek(lSeek, SEEK_CUR);
if (s->file.ioFailed())
lSeek=0;
@@ -591,19 +750,15 @@ local int unzlocal_GetCurrentFileInfoInternal (unzFile file,
lSeek+=file_info.size_file_extra;
- if ((err==UNZ_OK) && (szComment!=NULL))
- {
+ if ((err==UNZ_OK) && (szComment!=NULL)) {
uLong uSizeRead ;
- if (file_info.size_file_comment<commentBufferSize)
- {
+ if (file_info.size_file_comment<commentBufferSize) {
*(szComment+file_info.size_file_comment)='\0';
uSizeRead = file_info.size_file_comment;
- }
- else
+ } else
uSizeRead = commentBufferSize;
- if (lSeek!=0)
- {
+ if (lSeek!=0) {
s->file.seek(lSeek, SEEK_CUR);
if (s->file.ioFailed())
lSeek=0;
@@ -614,8 +769,7 @@ local int unzlocal_GetCurrentFileInfoInternal (unzFile file,
if (s->file.read(szComment,(uInt)uSizeRead)!=uSizeRead)
err=UNZ_ERRNO;
lSeek+=file_info.size_file_comment - uSizeRead;
- }
- else
+ } else
lSeek+=file_info.size_file_comment;
if ((err==UNZ_OK) && (pfile_info!=NULL))
@@ -634,7 +788,7 @@ local int unzlocal_GetCurrentFileInfoInternal (unzFile file,
No preparation of the structure is needed
return UNZ_OK if there is no problem.
*/
-extern int ZEXPORT unzGetCurrentFileInfo (unzFile file,
+int unzGetCurrentFileInfo(unzFile file,
unz_file_info *pfile_info,
char *szFileName, uLong fileNameBufferSize,
void *extraField, uLong extraFieldBufferSize,
@@ -650,8 +804,7 @@ extern int ZEXPORT unzGetCurrentFileInfo (unzFile file,
Set the current file of the zipfile to the first file.
return UNZ_OK if there is no problem
*/
-extern int ZEXPORT unzGoToFirstFile (unzFile file)
-{
+int unzGoToFirstFile(unzFile file) {
int err=UNZ_OK;
unz_s* s;
if (file==NULL)
@@ -672,8 +825,7 @@ extern int ZEXPORT unzGoToFirstFile (unzFile file)
return UNZ_OK if there is no problem
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
*/
-extern int ZEXPORT unzGoToNextFile (unzFile file)
-{
+int unzGoToNextFile(unzFile file) {
unz_s* s;
int err;
@@ -704,8 +856,7 @@ extern int ZEXPORT unzGoToNextFile (unzFile file)
UNZ_OK if the file is found. It becomes the current file.
UNZ_END_OF_LIST_OF_FILE if the file is not found
*/
-extern int ZEXPORT unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity)
-{
+int unzLocateFile(unzFile file, const char *szFileName, int iCaseSensitivity) {
unz_s* s;
int err;
@@ -729,8 +880,7 @@ extern int ZEXPORT unzLocateFile (unzFile file, const char *szFileName, int iCas
err = unzGoToFirstFile(file);
- while (err == UNZ_OK)
- {
+ while (err == UNZ_OK) {
char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
unzGetCurrentFileInfo(file,NULL,
szCurrentFileName,sizeof(szCurrentFileName)-1,
@@ -754,10 +904,9 @@ extern int ZEXPORT unzLocateFile (unzFile file, const char *szFileName, int iCas
store in *piSizeVar the size of extra info in local header
(filename and size of extra field data)
*/
-local int unzlocal_CheckCurrentFileCoherencyHeader (unz_s* s, uInt* piSizeVar,
+static int unzlocal_CheckCurrentFileCoherencyHeader(unz_s* s, uInt* piSizeVar,
uLong *poffset_local_extrafield,
- uInt *psize_local_extrafield)
-{
+ uInt *psize_local_extrafield) {
uLong uMagic,uData,uFlags;
uLong size_filename;
uLong size_extra_field;
@@ -773,8 +922,7 @@ local int unzlocal_CheckCurrentFileCoherencyHeader (unz_s* s, uInt* piSizeVar,
return UNZ_ERRNO;
- if (err==UNZ_OK)
- {
+ if (err==UNZ_OK) {
if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK)
err=UNZ_ERRNO;
else if (uMagic!=0x04034b50)
@@ -843,8 +991,7 @@ local int unzlocal_CheckCurrentFileCoherencyHeader (unz_s* s, uInt* piSizeVar,
Open for reading data the current file in the zipfile.
If there is no error and the file is opened, the return value is UNZ_OK.
*/
-extern int ZEXPORT unzOpenCurrentFile (unzFile file)
-{
+int unzOpenCurrentFile (unzFile file) {
int err=UNZ_OK;
int Store;
uInt iSizeVar;
@@ -866,19 +1013,19 @@ extern int ZEXPORT unzOpenCurrentFile (unzFile file)
&offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
return UNZ_BADZIPFILE;
- pfile_in_zip_read_info = (file_in_zip_read_info_s*) ALLOC(sizeof(file_in_zip_read_info_s));
+ pfile_in_zip_read_info = (file_in_zip_read_info_s*) malloc(sizeof(file_in_zip_read_info_s));
if (pfile_in_zip_read_info==NULL)
return UNZ_INTERNALERROR;
- pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE);
+ pfile_in_zip_read_info->read_buffer=(char*)malloc(UNZ_BUFSIZE);
pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;
pfile_in_zip_read_info->pos_local_extrafield=0;
if (pfile_in_zip_read_info->read_buffer==NULL)
{
- TRYFREE(pfile_in_zip_read_info);
+ free(pfile_in_zip_read_info);
return UNZ_INTERNALERROR;
}
@@ -938,8 +1085,7 @@ extern int ZEXPORT unzOpenCurrentFile (unzFile file)
return <0 with error code if there is an error
(UNZ_ERRNO for IO error, or zLib error for uncompress error)
*/
-extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len)
-{
+int unzReadCurrentFile(unzFile file, voidp buf, unsigned len) {
int err=UNZ_OK;
uInt iRead = 0;
unz_s* s;
@@ -1051,8 +1197,7 @@ extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len)
/*
Give the current position in uncompressed data
*/
-extern z_off_t ZEXPORT unztell (unzFile file)
-{
+z_off_t unztell(unzFile file) {
unz_s* s;
file_in_zip_read_info_s* pfile_in_zip_read_info;
if (file==NULL)
@@ -1070,8 +1215,7 @@ extern z_off_t ZEXPORT unztell (unzFile file)
/*
return 1 if the end of file was reached, 0 elsewhere
*/
-extern int ZEXPORT unzeof (unzFile file)
-{
+int unzeof(unzFile file) {
unz_s* s;
file_in_zip_read_info_s* pfile_in_zip_read_info;
if (file==NULL)
@@ -1102,8 +1246,7 @@ extern int ZEXPORT unzeof (unzFile file)
the return value is the number of bytes copied in buf, or (if <0)
the error code
*/
-extern int ZEXPORT unzGetLocalExtrafield (unzFile file,voidp buf,unsigned len)
-{
+int unzGetLocalExtrafield(unzFile file, voidp buf, unsigned len) {
unz_s* s;
file_in_zip_read_info_s* pfile_in_zip_read_info;
uInt read_now;
@@ -1146,8 +1289,7 @@ extern int ZEXPORT unzGetLocalExtrafield (unzFile file,voidp buf,unsigned len)
Close the file in zip opened with unzipOpenCurrentFile
Return UNZ_CRCERROR if all the file was read but the CRC is not good
*/
-extern int ZEXPORT unzCloseCurrentFile (unzFile file)
-{
+int unzCloseCurrentFile(unzFile file) {
int err=UNZ_OK;
unz_s* s;
@@ -1167,13 +1309,13 @@ extern int ZEXPORT unzCloseCurrentFile (unzFile file)
}
- TRYFREE(pfile_in_zip_read_info->read_buffer);
+ free(pfile_in_zip_read_info->read_buffer);
pfile_in_zip_read_info->read_buffer = NULL;
if (pfile_in_zip_read_info->stream_initialised)
inflateEnd(&pfile_in_zip_read_info->stream);
pfile_in_zip_read_info->stream_initialised = 0;
- TRYFREE(pfile_in_zip_read_info);
+ free(pfile_in_zip_read_info);
s->pfile_in_zip_read=NULL;
@@ -1186,8 +1328,7 @@ extern int ZEXPORT unzCloseCurrentFile (unzFile file)
uSizeBuf is the size of the szComment buffer.
return the number of byte copied or an error code <0
*/
-extern int ZEXPORT unzGetGlobalComment (unzFile file, char *szComment, uLong uSizeBuf)
-{
+int unzGetGlobalComment(unzFile file, char *szComment, uLong uSizeBuf) {
unz_s* s;
uLong uReadThis ;
if (file==NULL)
@@ -1213,4 +1354,111 @@ extern int ZEXPORT unzGetGlobalComment (unzFile file, char *szComment, uLong uSi
return (int)uReadThis;
}
+
+namespace Common {
+
+
+/*
+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::isOpen() const {
+ return _zipFile != 0;
+}
+
+bool ZipArchive::hasFile(const Common::String &name) {
+ return (_zipFile && unzLocateFile(_zipFile, name.c_str(), 2) == UNZ_OK);
+}
+
+int ZipArchive::getAllNames(Common::StringList &list) {
+ if (!_zipFile)
+ return 0;
+
+ if (unzGoToFirstFile(_zipFile) != UNZ_OK)
+ return 0;
+
+ char fileNameBuffer[UNZ_MAXFILENAMEINZIP+1];
+ list.clear();
+
+ do {
+ unzOpenCurrentFile(_zipFile);
+ unzGetCurrentFileInfo(_zipFile, 0, fileNameBuffer, UNZ_MAXFILENAMEINZIP+1, 0, 0, 0, 0);
+
+ list.push_back(Common::String(fileNameBuffer));
+
+ unzCloseCurrentFile(_zipFile);
+
+ } while (unzGoToNextFile(_zipFile) == UNZ_OK);
+
+ return list.size();
+}
+
+/*
+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.
+}
+
+} // End of namespace Common
+
+
#endif
diff --git a/common/unzip.h b/common/unzip.h
index 43faaf4a74..e4eb754eee 100644
--- a/common/unzip.h
+++ b/common/unzip.h
@@ -22,332 +22,34 @@
* $Id$
*/
-/* unzip.h -- IO for uncompress .zip files using zlib
- Version 0.15 beta, Mar 19th, 1998,
-
- Copyright (C) 1998 Gilles Vollant
-
- This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
- WinZip, InfoZip tools and compatible.
- Encryption and multi volume ZipFile (span) are not supported.
- Old compressions used by old PKZip 1.x are not supported
-
- THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE
- CAN CHANGE IN FUTURE VERSION !!
- I WAIT FEEDBACK at mail info@winimage.com
- Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
-
- Condition of use and distribution are the same than zlib :
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-
-
-*/
-/* for more info about .ZIP format, see
- ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip
- PkWare has also a specification at :
- ftp://ftp.pkware.com/probdesc.zip */
-
-#ifndef _unz_H
-#define _unz_H
+#ifndef COMMON_UNZIP_H
+#define COMMON_UNZIP_H
#ifdef USE_ZLIB
#include "common/scummsys.h"
#include "common/archive.h"
-#include "common/stream.h"
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifdef __SYMBIAN32__
-#include <zlib\zlib.h>
-#else
-#include <zlib.h>
-#endif
-
-#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
-/* like the STRICT of WIN32, we define a pointer that cannot be converted
- from (void*) without cast */
-typedef struct TagunzFile__ { int unused; } unzFile__;
-typedef unzFile__ *unzFile;
-#else
-typedef voidp unzFile;
-#endif
-
-
-#define UNZ_OK (0)
-#define UNZ_END_OF_LIST_OF_FILE (-100)
-#define UNZ_ERRNO (Z_ERRNO)
-#define UNZ_EOF (0)
-#define UNZ_PARAMERROR (-102)
-#define UNZ_BADZIPFILE (-103)
-#define UNZ_INTERNALERROR (-104)
-#define UNZ_CRCERROR (-105)
-
-/* tm_unz contain date/time info */
-typedef struct tm_unz_s
-{
- uInt tm_sec; /* seconds after the minute - [0,59] */
- uInt tm_min; /* minutes after the hour - [0,59] */
- uInt tm_hour; /* hours since midnight - [0,23] */
- uInt tm_mday; /* day of the month - [1,31] */
- uInt tm_mon; /* months since January - [0,11] */
- uInt tm_year; /* years - [1980..2044] */
-} tm_unz;
-
-/* unz_global_info structure contain global data about the ZIPfile
- These data comes from the end of central dir */
-typedef struct unz_global_info_s
-{
- uLong number_entry; /* total number of entries in
- the central dir on this disk */
- uLong size_comment; /* size of the global comment of the zipfile */
-} unz_global_info;
-
-
-/* unz_file_info contain information about a file in the zipfile */
-typedef struct unz_file_info_s
-{
- uLong version; /* version made by 2 bytes */
- uLong version_needed; /* version needed to extract 2 bytes */
- uLong flag; /* general purpose bit flag 2 bytes */
- uLong compression_method; /* compression method 2 bytes */
- uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
- uLong crc; /* crc-32 4 bytes */
- uLong compressed_size; /* compressed size 4 bytes */
- uLong uncompressed_size; /* uncompressed size 4 bytes */
- uLong size_filename; /* filename length 2 bytes */
- uLong size_file_extra; /* extra field length 2 bytes */
- uLong size_file_comment; /* file comment length 2 bytes */
-
- uLong disk_num_start; /* disk number start 2 bytes */
- uLong internal_fa; /* internal file attributes 2 bytes */
- uLong external_fa; /* external file attributes 4 bytes */
-
- tm_unz tmu_date;
-} unz_file_info;
-
-extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
- const char* fileName2,
- int iCaseSensitivity));
-/*
- Compare two filename (fileName1,fileName2).
- If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
- If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
- or strcasecmp)
- If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
- (like 1 on Unix, 2 on Windows)
-*/
-
-
-extern unzFile ZEXPORT unzOpen OF((const char *path));
-/*
- Open a Zip file. path contain the full pathname (by example,
- on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer
- "zlib/zlib111.zip".
- If the zipfile cannot be opened (file don't exist or in not valid), the
- return value is NULL.
- Else, the return value is a unzFile Handle, usable with other function
- of this unzip package.
-*/
-
-extern int ZEXPORT unzClose OF((unzFile file));
-/*
- Close a ZipFile opened with unzipOpen.
- If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
- these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
- return UNZ_OK if there is no problem. */
-extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
- unz_global_info *pglobal_info));
-/*
- Write info about the ZipFile in the *pglobal_info structure.
- No preparation of the structure is needed
- return UNZ_OK if there is no problem. */
+typedef void *unzFile;
+namespace Common {
-extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
- char *szComment,
- uLong uSizeBuf));
-/*
- Get the global comment string of the ZipFile, in the szComment buffer.
- uSizeBuf is the size of the szComment buffer.
- return the number of byte copied or an error code <0
-*/
-
-
-/***************************************************************************/
-/* Unzip package allow you browse the directory of the zipfile */
-
-extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
-/*
- Set the current file of the zipfile to the first file.
- return UNZ_OK if there is no problem
-*/
-
-extern int ZEXPORT unzGoToNextFile OF((unzFile file));
-/*
- Set the current file of the zipfile to the next file.
- return UNZ_OK if there is no problem
- return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
-*/
-
-extern int ZEXPORT unzLocateFile OF((unzFile file,
- const char *szFileName,
- int iCaseSensitivity));
-/*
- Try locate the file szFileName in the zipfile.
- For the iCaseSensitivity signification, see unzStringFileNameCompare
-
- return value :
- UNZ_OK if the file is found. It becomes the current file.
- UNZ_END_OF_LIST_OF_FILE if the file is not found
-*/
-
-
-extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
- unz_file_info *pfile_info,
- char *szFileName,
- uLong fileNameBufferSize,
- void *extraField,
- uLong extraFieldBufferSize,
- char *szComment,
- uLong commentBufferSize));
-/*
- Get Info about the current file
- if pfile_info!=NULL, the *pfile_info structure will contain somes info about
- the current file
- if szFileName!=NULL, the filemane string will be copied in szFileName
- (fileNameBufferSize is the size of the buffer)
- if extraField!=NULL, the extra field information will be copied in extraField
- (extraFieldBufferSize is the size of the buffer).
- This is the Central-header version of the extra field
- if szComment!=NULL, the comment string of the file will be copied in szComment
- (commentBufferSize is the size of the buffer)
-*/
-
-/***************************************************************************/
-/* for reading the content of the current zipfile, you can open it, read data
- from it, and close it (you can close it before reading all the file)
- */
-
-extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
-/*
- Open for reading data the current file in the zipfile.
- If there is no error, the return value is UNZ_OK.
-*/
-
-extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
-/*
- Close the file in zip opened with unzOpenCurrentFile
- Return UNZ_CRCERROR if all the file was read but the CRC is not good
-*/
-
-
-extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
- voidp buf,
- unsigned len));
-/*
- Read bytes from the current file (opened by unzOpenCurrentFile)
- buf contain buffer where data must be copied
- len the size of buf.
-
- return the number of byte copied if somes bytes are copied
- return 0 if the end of file was reached
- return <0 with error code if there is an error
- (UNZ_ERRNO for IO error, or zLib error for uncompress error)
-*/
-
-extern z_off_t ZEXPORT unztell OF((unzFile file));
-/*
- Give the current position in uncompressed data
-*/
-
-extern int ZEXPORT unzeof OF((unzFile file));
-/*
- return 1 if the end of file was reached, 0 elsewhere
-*/
-
-extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
- voidp buf,
- unsigned len));
-/*
- Read extra field from the current file (opened by unzOpenCurrentFile)
- This is the local-header version of the extra field (sometimes, there is
- more info in the local-header version than in the central-header)
-
- if buf==NULL, it return the size of the local extra field
-
- if buf!=NULL, len is the size of the buffer, the extra header is copied in
- buf.
- the return value is the number of bytes copied in buf, or (if <0)
- the error code
-*/
-
-#ifdef __cplusplus
-}
-#endif
-
-
-class ZipArchive : Common::Archive {
- unzFile _zipFile;
+class ZipArchive : public Archive {
+ void *_zipFile;
public:
- ZipArchive(const Common::String &name) {
- _zipFile = unzOpen(name.c_str());
- }
- ~ZipArchive() {
- unzClose(_zipFile);
- }
-
- virtual bool hasFile(const Common::String &name) {
- return (_zipFile && unzLocateFile(_zipFile, name.c_str(), 2) == UNZ_OK);
- }
-
- virtual int getAllNames(Common::StringList &list) {
- // TODO
- return 0;
- }
-
- virtual Common::SeekableReadStream *openFile(const Common::String &name) {
- if (!_zipFile)
- return 0;
+ ZipArchive(const String &name);
+ ~ZipArchive();
- unzLocateFile(_zipFile, name.c_str(), 2);
+ bool isOpen() const;
- 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.
- }
+ virtual bool hasFile(const String &name);
+ virtual int getAllNames(StringList &list);
+ virtual Common::SeekableReadStream *openFile(const Common::String &name);
};
+} // End of namespace Common
+
#endif // USE_ZLIB
#endif /* _unz_H */
diff --git a/common/util.h b/common/util.h
index 32f07181c4..573004c437 100644
--- a/common/util.h
+++ b/common/util.h
@@ -106,20 +106,20 @@ public:
/**
* Generates a random unsigned integer in the interval [0, max].
* @param max the upper bound
- * @return a random number in the interval [0, max].
+ * @return a random number in the interval [0, max]
*/
uint getRandomNumber(uint max);
/**
- * Generates a random unsigned integer in the interval [0, 1].
+ * Generates a random bit, i.e. either 0 or 1.
* Identical to getRandomNumber(1), but faster, hopefully.
- * @return a random number in the interval [0, max].
+ * @return a random bit, either 0 or 1
*/
uint getRandomBit(void);
/**
* Generates a random unsigned integer in the interval [min, max].
* @param min the lower bound
* @param max the upper bound
- * @return a random number in the interval [min, max].
+ * @return a random number in the interval [min, max]
*/
uint getRandomNumberRng(uint min, uint max);
};
diff --git a/common/xmlparser.h b/common/xmlparser.h
index 967b73535b..4b76278d47 100644
--- a/common/xmlparser.h
+++ b/common/xmlparser.h
@@ -217,9 +217,9 @@ public:
return true;
}
- bool loadStream(MemoryReadStream *stream) {
+ bool loadStream(Common::SeekableReadStream *stream) {
_stream = stream;
- _fileName = "Compressed File Stream";
+ _fileName = "File Stream";
return true;
}