[Scummvm-cvs-logs] SF.net SVN: scummvm:[34734] scummvm/trunk

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Fri Oct 3 18:57:41 CEST 2008


Revision: 34734
          http://scummvm.svn.sourceforge.net/scummvm/?rev=34734&view=rev
Author:   lordhoto
Date:     2008-10-03 16:57:40 +0000 (Fri, 03 Oct 2008)

Log Message:
-----------
Committed slightly modified patch #2034983 "Case-insensitivy and directory handling for engines".

Modified Paths:
--------------
    scummvm/trunk/common/archive.cpp
    scummvm/trunk/common/archive.h
    scummvm/trunk/common/unzip.cpp
    scummvm/trunk/common/unzip.h
    scummvm/trunk/engines/kyra/resource_intern.cpp
    scummvm/trunk/engines/kyra/resource_intern.h

Modified: scummvm/trunk/common/archive.cpp
===================================================================
--- scummvm/trunk/common/archive.cpp	2008-10-03 16:14:18 UTC (rev 34733)
+++ scummvm/trunk/common/archive.cpp	2008-10-03 16:57:40 UTC (rev 34734)
@@ -30,11 +30,23 @@
 
 namespace Common {
 
+GenericArchiveMember::GenericArchiveMember(String name, Archive *parent)
+	: _parent(parent), _name(name) {
+}
 
-int Archive::matchPattern(StringList &list, const String &pattern) {
+String GenericArchiveMember::getName() const {
+	return _name;
+}
+
+SeekableReadStream *GenericArchiveMember::open() {
+	return _parent->openFile(_name);
+}
+
+
+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 @@
 	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,7 +65,35 @@
 	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 @@
 
 }
 
-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 @@
 		_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 @@
 	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;

Modified: scummvm/trunk/common/archive.h
===================================================================
--- scummvm/trunk/common/archive.h	2008-10-03 16:14:18 UTC (rev 34733)
+++ scummvm/trunk/common/archive.h	2008-10-03 16:57:40 UTC (rev 34734)
@@ -36,7 +36,36 @@
 
 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 @@
 	 *
 	 * @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 @@
 	 *
 	 * @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 @@
 	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 @@
 	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

Modified: scummvm/trunk/common/unzip.cpp
===================================================================
--- scummvm/trunk/common/unzip.cpp	2008-10-03 16:14:18 UTC (rev 34733)
+++ scummvm/trunk/common/unzip.cpp	2008-10-03 16:57:40 UTC (rev 34734)
@@ -1392,26 +1392,6 @@
 	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 @@
 		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)

Modified: scummvm/trunk/common/unzip.h
===================================================================
--- scummvm/trunk/common/unzip.h	2008-10-03 16:14:18 UTC (rev 34733)
+++ scummvm/trunk/common/unzip.h	2008-10-03 16:57:40 UTC (rev 34734)
@@ -44,7 +44,7 @@
 	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);
 };
 

Modified: scummvm/trunk/engines/kyra/resource_intern.cpp
===================================================================
--- scummvm/trunk/engines/kyra/resource_intern.cpp	2008-10-03 16:14:18 UTC (rev 34733)
+++ scummvm/trunk/engines/kyra/resource_intern.cpp	2008-10-03 16:57:40 UTC (rev 34734)
@@ -51,11 +51,11 @@
 	return (_files.find(name) != _files.end());
 }
 
-int PlainArchive::getAllNames(Common::StringList &list) {
+int PlainArchive::listMembers(Common::ArchiveMemberList &list) {
 	int count = 0;
 
 	for (FileMap::const_iterator i = _files.begin(); i != _files.end(); ++i) {
-		list.push_back(i->_key);
+		list.push_back(Common::ArchiveMemberList::value_type(new Common::GenericArchiveMember(i->_key, this)));
 		++count;
 	}
 
@@ -98,11 +98,11 @@
 	return (_files.find(name) != _files.end());
 }
 
-int CachedArchive::getAllNames(Common::StringList &list) {
+int CachedArchive::listMembers(Common::ArchiveMemberList &list) {
 	int count = 0;
 
 	for (FileMap::const_iterator i = _files.begin(); i != _files.end(); ++i) {
-		list.push_back(i->_key);
+		list.push_back(Common::ArchiveMemberList::value_type(new Common::GenericArchiveMember(i->_key, this)));
 		++count;
 	}
 

Modified: scummvm/trunk/engines/kyra/resource_intern.h
===================================================================
--- scummvm/trunk/engines/kyra/resource_intern.h	2008-10-03 16:14:18 UTC (rev 34733)
+++ scummvm/trunk/engines/kyra/resource_intern.h	2008-10-03 16:57:40 UTC (rev 34734)
@@ -50,7 +50,7 @@
 	PlainArchive(Resource *owner, const Common::String &filename, const FileInputList &files);
 
 	bool hasFile(const Common::String &name);
-	int getAllNames(Common::StringList &list);
+	int listMembers(Common::ArchiveMemberList &list);
 	Common::SeekableReadStream *openFile(const Common::String &name);
 private:
 	struct Entry {
@@ -80,7 +80,7 @@
 	~CachedArchive();
 
 	bool hasFile(const Common::String &name);
-	int getAllNames(Common::StringList &list);
+	int listMembers(Common::ArchiveMemberList &list);
 	Common::SeekableReadStream *openFile(const Common::String &name);
 private:
 	struct Entry {


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list