aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/archive.cpp33
-rw-r--r--common/archive.h16
-rw-r--r--common/unzip.cpp7
-rw-r--r--common/unzip.h7
4 files changed, 59 insertions, 4 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