aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorJohannes Schickel2008-10-03 16:57:40 +0000
committerJohannes Schickel2008-10-03 16:57:40 +0000
commite4174711773c7dab12faf870c6d4973a2bdcff0b (patch)
tree9cd74919429e2592d28024d7f3c4ea43252c4b90 /common
parent4b236a787f028259f3a8c6a63c86bc8661a35438 (diff)
downloadscummvm-rg350-e4174711773c7dab12faf870c6d4973a2bdcff0b.tar.gz
scummvm-rg350-e4174711773c7dab12faf870c6d4973a2bdcff0b.tar.bz2
scummvm-rg350-e4174711773c7dab12faf870c6d4973a2bdcff0b.zip
Committed slightly modified patch #2034983 "Case-insensitivy and directory handling for engines".
svn-id: r34734
Diffstat (limited to 'common')
-rw-r--r--common/archive.cpp99
-rw-r--r--common/archive.h41
-rw-r--r--common/unzip.cpp29
-rw-r--r--common/unzip.h2
4 files changed, 102 insertions, 69 deletions
diff --git a/common/archive.cpp b/common/archive.cpp
index 7f2b67eed0..40c2f01ee6 100644
--- a/common/archive.cpp
+++ b/common/archive.cpp
@@ -30,11 +30,23 @@
namespace Common {
+GenericArchiveMember::GenericArchiveMember(String name, Archive *parent)
+ : _parent(parent), _name(name) {
+}
+
+String GenericArchiveMember::getName() const {
+ return _name;
+}
+
+SeekableReadStream *GenericArchiveMember::open() {
+ return _parent->openFile(_name);
+}
+
-int Archive::matchPattern(StringList &list, const String &pattern) {
+int Archive::listMatchingMembers(ArchiveMemberList &list, const String &pattern) {
// Get all "names" (TODO: "files" ?)
- StringList allNames;
- getAllNames(allNames);
+ ArchiveMemberList allNames;
+ listMembers(allNames);
int matches = 0;
@@ -42,9 +54,9 @@ int Archive::matchPattern(StringList &list, const String &pattern) {
String lowercasePattern = pattern;
lowercasePattern.toLowercase();
- StringList::iterator it = allNames.begin();
+ ArchiveMemberList::iterator it = allNames.begin();
for ( ; it != allNames.end(); it++) {
- if (it->matchString(lowercasePattern)) {
+ if ((*it)->getName().matchString(lowercasePattern)) {
list.push_back(*it);
matches++;
}
@@ -53,6 +65,34 @@ int Archive::matchPattern(StringList &list, const String &pattern) {
return matches;
}
+/**
+ * FSDirectoryMemeber is the implementation of ArchiveMember used by
+ * by FSDirectory. It is right now a light wrapper or FSNode.
+ */
+class FSDirectoryMember : public ArchiveMember {
+ FSNode _node;
+
+public:
+ FSDirectoryMember(FSNode &node) : _node(node) {
+ }
+
+ /*
+ NOTE/FIXME: since I assume that the only use case for getName()
+ is for error messages, I am returning the full path of the node
+ here. This seems better than we did before, when matchPattern
+ and getAllNames used to work with StringList, and we used to
+ put the relative path of the file to the list instead.
+ */
+ String getName() const {
+ return _node.getPath();
+ }
+
+ SeekableReadStream *open() {
+ return _node.openForReading();
+ }
+};
+
+typedef SharedPtr<FSDirectoryMember> FSDirectoryMemberPtr;
FSDirectory::FSDirectory(const FSNode &node, int depth)
: _node(node), _cached(false), _depth(depth) {
@@ -160,7 +200,7 @@ void FSDirectory::cacheDirectoryRecursive(FSNode node, int depth, const String&
}
-int FSDirectory::matchPattern(StringList &list, const String &pattern) {
+int FSDirectory::listMatchingMembers(ArchiveMemberList &list, const String &pattern) {
if (!_node.isDirectory())
return 0;
@@ -170,40 +210,25 @@ int FSDirectory::matchPattern(StringList &list, const String &pattern) {
_cached = true;
}
- // Small optimization: Ensure the StringList has to grow at most once
- list.reserve(list.size() + _fileCache.size());
-
- // Add all filenames from our cache
+ String lowercasePattern(pattern);
+ lowercasePattern.toLowercase();
+
+ int matches = 0;
NodeCache::iterator it = _fileCache.begin();
for ( ; it != _fileCache.end(); it++) {
- if (it->_key.matchString(pattern))
- list.push_back(it->_key);
+ if ((*it)._key.matchString(lowercasePattern)) {
+ list.push_back(FSDirectoryMemberPtr(new FSDirectoryMember((*it)._value)));
+ matches++;
+ }
}
-
- return _fileCache.size();
+ return matches;
}
-int FSDirectory::getAllNames(StringList &list) {
- if (!_node.isDirectory())
- return 0;
+int FSDirectory::listMembers(ArchiveMemberList &list) {
+ return listMatchingMembers(list, "*");
+}
- // Cache dir data
- if (!_cached) {
- cacheDirectoryRecursive(_node, _depth, "");
- _cached = true;
- }
- // Small optimization: Ensure the StringList has to grow at most once
- list.reserve(list.size() + _fileCache.size());
-
- // Add all filenames from our cache
- NodeCache::iterator it = _fileCache.begin();
- for ( ; it != _fileCache.end(); it++) {
- list.push_back((*it)._key);
- }
-
- return _fileCache.size();
-}
@@ -289,23 +314,23 @@ bool SearchSet::hasFile(const String &name) {
return false;
}
-int SearchSet::matchPattern(StringList &list, const String &pattern) {
+int SearchSet::listMatchingMembers(ArchiveMemberList &list, const String &pattern) {
int matches = 0;
ArchiveList::iterator it = _list.begin();
for ( ; it != _list.end(); it++) {
- matches += (*it)._arc->matchPattern(list, pattern);
+ matches += (*it)._arc->listMatchingMembers(list, pattern);
}
return matches;
}
-int SearchSet::getAllNames(StringList &list) {
+int SearchSet::listMembers(ArchiveMemberList &list) {
int matches = 0;
ArchiveList::iterator it = _list.begin();
for ( ; it != _list.end(); it++) {
- matches += (*it)._arc->getAllNames(list);
+ matches += (*it)._arc->listMembers(list);
}
return matches;
diff --git a/common/archive.h b/common/archive.h
index 9103586d7d..2fc86b1b57 100644
--- a/common/archive.h
+++ b/common/archive.h
@@ -36,6 +36,35 @@
namespace Common {
+class ArchiveMember {
+public:
+ virtual ~ArchiveMember() { }
+ virtual String getName() const = 0;
+ virtual SeekableReadStream *open() = 0;
+};
+
+typedef List<SharedPtr<ArchiveMember> > ArchiveMemberList;
+
+class Archive;
+
+/**
+ * Simple ArchiveMemeber implementation which allows
+ * creation of ArchiveMember compatible objects via
+ * a simple Archive and name pair.
+ *
+ * Note that GenericArchiveMember objects will not
+ * be working anymore after the 'parent' object
+ * is destroyed.
+ */
+class GenericArchiveMember : public ArchiveMember {
+ Archive *_parent;
+ String _name;
+public:
+ GenericArchiveMember(String name, Archive *parent);
+ String getName() const;
+ SeekableReadStream *open();
+};
+
/**
* FilePtr is a convenient way to keep track of a SeekableReadStream without
* having to worry about releasing its memory.
@@ -63,7 +92,7 @@ public:
*
* @return the number of names added to list
*/
- virtual int matchPattern(StringList &list, const String &pattern);
+ virtual int listMatchingMembers(ArchiveMemberList &list, const String &pattern);
/**
* Add all the names present in the Archive to list. Returned
@@ -72,7 +101,7 @@ public:
*
* @return the number of names added to list
*/
- virtual int getAllNames(StringList &list) = 0;
+ virtual int listMembers(ArchiveMemberList &list) = 0;
/**
* Create a stream bound to a file in the archive.
@@ -138,8 +167,8 @@ public:
FSDirectory *getSubDirectory(const String &name);
virtual bool hasFile(const String &name);
- virtual int matchPattern(StringList &list, const String &pattern);
- virtual int getAllNames(StringList &list);
+ virtual int listMatchingMembers(ArchiveMemberList &list, const String &pattern);
+ virtual int listMembers(ArchiveMemberList &list);
virtual SeekableReadStream *openFile(const String &name);
};
@@ -195,8 +224,8 @@ public:
void setPriority(const String& name, int priority);
virtual bool hasFile(const String &name);
- virtual int matchPattern(StringList &list, const String &pattern);
- virtual int getAllNames(StringList &list);
+ virtual int listMatchingMembers(ArchiveMemberList &list, const String &pattern);
+ virtual int listMembers(ArchiveMemberList &list);
/**
* Implements openFile from Archive base class. The current policy is
diff --git a/common/unzip.cpp b/common/unzip.cpp
index 894631b262..9049b000d7 100644
--- a/common/unzip.cpp
+++ b/common/unzip.cpp
@@ -1392,26 +1392,6 @@ 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];
- int fileCount = 0;
-
- do {
- unzGetCurrentFileInfo(_zipFile, 0, fileNameBuffer, UNZ_MAXFILENAMEINZIP + 1, 0, 0, 0, 0);
- list.push_back(Common::String(fileNameBuffer));
- fileCount++;
- } while (unzGoToNextFile(_zipFile) == UNZ_OK);
-
- return fileCount;
-}
-
-/*
int ZipArchive::listMembers(Common::ArchiveMemberList &list) {
if (!_zipFile)
return 0;
@@ -1424,14 +1404,13 @@ int ZipArchive::listMembers(Common::ArchiveMemberList &list) {
unzGetCurrentFileInfo(_zipFile, NULL,
szCurrentFileName, sizeof(szCurrentFileName)-1,
NULL, 0, NULL, 0);
-
- szCurrentFileName
+ list.push_back(ArchiveMemberList::value_type(new GenericArchiveMember(szCurrentFileName, this)));
matches++;
- err = unzGoToNextFile(file);
+ err = unzGoToNextFile(_zipFile);
}
- return 0;
+
+ return matches;
}
-*/
Common::SeekableReadStream *ZipArchive::openFile(const Common::String &name) {
if (!_zipFile)
diff --git a/common/unzip.h b/common/unzip.h
index e4eb754eee..e6c1863e51 100644
--- a/common/unzip.h
+++ b/common/unzip.h
@@ -44,7 +44,7 @@ public:
bool isOpen() const;
virtual bool hasFile(const String &name);
- virtual int getAllNames(StringList &list);
+ virtual int listMembers(Common::ArchiveMemberList &list);
virtual Common::SeekableReadStream *openFile(const Common::String &name);
};