aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schickel2008-11-01 12:49:29 +0000
committerJohannes Schickel2008-11-01 12:49:29 +0000
commit282ebbb0e54211a1a3cef5510287a7c494fce1d2 (patch)
tree5e64df5b67a4bd44161deffde232fcb537511c34
parentcd3011e4088fc25846278d2e8cf6527245d5d333 (diff)
downloadscummvm-rg350-282ebbb0e54211a1a3cef5510287a7c494fce1d2.tar.gz
scummvm-rg350-282ebbb0e54211a1a3cef5510287a7c494fce1d2.tar.bz2
scummvm-rg350-282ebbb0e54211a1a3cef5510287a7c494fce1d2.zip
Commit of patch #2207782 "ARCHIVE: New method 'getMember'".
svn-id: r34871
-rw-r--r--common/archive.cpp33
-rw-r--r--common/archive.h16
-rw-r--r--common/unzip.cpp7
-rw-r--r--common/unzip.h7
-rw-r--r--engines/kyra/resource.cpp19
-rw-r--r--engines/kyra/resource_intern.cpp14
-rw-r--r--engines/kyra/resource_intern.h2
7 files changed, 84 insertions, 14 deletions
diff --git a/common/archive.cpp b/common/archive.cpp
index 8881d44116..b2113a351c 100644
--- a/common/archive.cpp
+++ b/common/archive.cpp
@@ -153,6 +153,24 @@ bool FSDirectory::hasFile(const String &name) {
return node.exists();
}
+ArchiveMemberPtr FSDirectory::getMember(const String &name) {
+ if (name.empty() || !_node.isDirectory()) {
+ return ArchiveMemberPtr();
+ }
+
+ FSNode node = lookupCache(_fileCache, name);
+
+ if (!node.exists()) {
+ warning("FSDirectory::getMember: FSNode does not exist");
+ return ArchiveMemberPtr();
+ } else if (node.isDirectory()) {
+ warning("FSDirectory::getMember: FSNode is a directory");
+ return ArchiveMemberPtr();
+ }
+
+ return ArchiveMemberPtr(new FSDirectoryMember(node));
+}
+
SeekableReadStream *FSDirectory::openFile(const String &name) {
if (name.empty() || !_node.isDirectory()) {
return 0;
@@ -367,6 +385,21 @@ int SearchSet::listMembers(ArchiveMemberList &list) {
return matches;
}
+ArchiveMemberPtr SearchSet::getMember(const String &name) {
+ if (name.empty()) {
+ return ArchiveMemberPtr();
+ }
+
+ ArchiveList::iterator it = _list.begin();
+ for ( ; it != _list.end(); it++) {
+ if ((*it)._arc->hasFile(name)) {
+ return (*it)._arc->getMember(name);
+ }
+ }
+
+ return ArchiveMemberPtr();
+}
+
SeekableReadStream *SearchSet::openFile(const String &name) {
if (name.empty()) {
return 0;
diff --git a/common/archive.h b/common/archive.h
index b005090a87..5aca4bd450 100644
--- a/common/archive.h
+++ b/common/archive.h
@@ -51,7 +51,8 @@ public:
virtual SeekableReadStream *open() = 0;
};
-typedef List<SharedPtr<ArchiveMember> > ArchiveMemberList;
+typedef SharedPtr<ArchiveMember> ArchiveMemberPtr;
+typedef List<ArchiveMemberPtr> ArchiveMemberList;
class Archive;
@@ -107,6 +108,11 @@ public:
virtual int listMembers(ArchiveMemberList &list) = 0;
/**
+ * Returns a ArchiveMember representation of the given file.
+ */
+ virtual ArchiveMemberPtr getMember(const String &name) = 0;
+
+ /**
* Create a stream bound to a file in the archive.
* @return the newly created input stream
*/
@@ -209,6 +215,12 @@ public:
virtual int listMembers(ArchiveMemberList &list);
/**
+ * Get a ArchiveMember representation of the specified file. A full match of relative
+ * path and filename is needed for success.
+ */
+ virtual ArchiveMemberPtr getMember(const String &name);
+
+ /**
* Open the specified file. A full match of relative path and filename is needed
* for success.
*/
@@ -273,6 +285,8 @@ public:
virtual int listMatchingMembers(ArchiveMemberList &list, const String &pattern);
virtual int listMembers(ArchiveMemberList &list);
+ virtual ArchiveMemberPtr getMember(const String &name);
+
/**
* Implements openFile from Archive base class. The current policy is
* opening the first file encountered that matches the name.
diff --git a/common/unzip.cpp b/common/unzip.cpp
index ac0d64df8f..3272681628 100644
--- a/common/unzip.cpp
+++ b/common/unzip.cpp
@@ -1416,6 +1416,13 @@ int ZipArchive::listMembers(Common::ArchiveMemberList &list) {
return matches;
}
+ArchiveMemberPtr ZipArchive::getMember(const String &name) {
+ if (!_zipFile || !hasFile(name))
+ return ArchiveMemberPtr();
+
+ return ArchiveMemberPtr(new GenericArchiveMember(name, this));
+}
+
Common::SeekableReadStream *ZipArchive::openFile(const Common::String &name) {
if (!_zipFile)
return 0;
diff --git a/common/unzip.h b/common/unzip.h
index 8c9f465b97..d4185155c0 100644
--- a/common/unzip.h
+++ b/common/unzip.h
@@ -39,14 +39,15 @@ class ZipArchive : public Archive {
public:
ZipArchive(const String &name);
- ZipArchive(const Common::FSNode &node);
+ ZipArchive(const FSNode &node);
~ZipArchive();
bool isOpen() const;
virtual bool hasFile(const String &name);
- virtual int listMembers(Common::ArchiveMemberList &list);
- virtual Common::SeekableReadStream *openFile(const Common::String &name);
+ virtual int listMembers(ArchiveMemberList &list);
+ virtual ArchiveMemberPtr getMember(const String &name);
+ virtual SeekableReadStream *openFile(const String &name);
};
} // End of namespace Common
diff --git a/engines/kyra/resource.cpp b/engines/kyra/resource.cpp
index 2b09036b4e..d4b468fed5 100644
--- a/engines/kyra/resource.cpp
+++ b/engines/kyra/resource.cpp
@@ -107,15 +107,15 @@ bool Resource::reset() {
};
for (uint i = 0; i < ARRAYSIZE(list); ++i) {
- Common::ArchiveMemberList fileList;
- listFiles(list[i], fileList);
+ Common::ArchiveMemberPtr file = _files.getMember(list[i]);
+ if (!file)
+ error("Couldn't find PAK file '%s'", list[i]);
- if (fileList.empty())
- error("Couldn't load PAK file '%s'", list[i]);
-
- Common::Archive *archive = loadArchive(list[i], *fileList.begin());
+ Common::Archive *archive = loadArchive(list[i], file);
if (archive)
_protectedFiles.add(list[i], archive, 0, false);
+ else
+ error("Couldn't load PAK file '%s'", list[i]);
}
} else {
for (Common::FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
@@ -142,13 +142,12 @@ bool Resource::reset() {
bool Resource::loadPakFile(Common::String filename) {
filename.toUppercase();
- Common::ArchiveMemberList list;
- _files.listMatchingMembers(list, filename);
- if (list.empty())
+ Common::ArchiveMemberPtr file = _files.getMember(filename);
+ if (!file)
return false;
- return loadPakFile(filename, *list.begin());
+ return loadPakFile(filename, file);
}
bool Resource::loadPakFile(Common::String name, Common::SharedPtr<Common::ArchiveMember> file) {
diff --git a/engines/kyra/resource_intern.cpp b/engines/kyra/resource_intern.cpp
index fbbfe69186..cbb6dc4f0c 100644
--- a/engines/kyra/resource_intern.cpp
+++ b/engines/kyra/resource_intern.cpp
@@ -62,6 +62,13 @@ int PlainArchive::listMembers(Common::ArchiveMemberList &list) {
return count;
}
+Common::ArchiveMemberPtr PlainArchive::getMember(const Common::String &name) {
+ if (!hasFile(name))
+ return Common::ArchiveMemberPtr();
+
+ return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(name, this));
+}
+
Common::SeekableReadStream *PlainArchive::openFile(const Common::String &name) {
FileMap::const_iterator fDesc = _files.find(name);
if (fDesc == _files.end())
@@ -110,6 +117,13 @@ int CachedArchive::listMembers(Common::ArchiveMemberList &list) {
return count;
}
+Common::ArchiveMemberPtr CachedArchive::getMember(const Common::String &name) {
+ if (!hasFile(name))
+ return Common::ArchiveMemberPtr();
+
+ return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(name, this));
+}
+
Common::SeekableReadStream *CachedArchive::openFile(const Common::String &name) {
FileMap::const_iterator fDesc = _files.find(name);
if (fDesc == _files.end())
diff --git a/engines/kyra/resource_intern.h b/engines/kyra/resource_intern.h
index 6347c538fc..f768100afe 100644
--- a/engines/kyra/resource_intern.h
+++ b/engines/kyra/resource_intern.h
@@ -51,6 +51,7 @@ public:
bool hasFile(const Common::String &name);
int listMembers(Common::ArchiveMemberList &list);
+ Common::ArchiveMemberPtr getMember(const Common::String &name);
Common::SeekableReadStream *openFile(const Common::String &name);
private:
struct Entry {
@@ -80,6 +81,7 @@ public:
bool hasFile(const Common::String &name);
int listMembers(Common::ArchiveMemberList &list);
+ Common::ArchiveMemberPtr getMember(const Common::String &name);
Common::SeekableReadStream *openFile(const Common::String &name);
private:
struct Entry {