Ticket #8904: archivemember-3.patch
File archivemember-3.patch, 10.3 KB (added by , 16 years ago) |
---|
-
common/unzip.cpp
1392 1392 return (_zipFile && unzLocateFile(_zipFile, name.c_str(), 2) == UNZ_OK); 1393 1393 } 1394 1394 1395 int ZipArchive::getAllNames(Common::StringList &list) {1396 if (!_zipFile)1397 return 0;1398 1399 if (unzGoToFirstFile(_zipFile) != UNZ_OK)1400 return 0;1401 1402 char fileNameBuffer[UNZ_MAXFILENAMEINZIP + 1];1403 int fileCount = 0;1404 1405 do {1406 unzGetCurrentFileInfo(_zipFile, 0, fileNameBuffer, UNZ_MAXFILENAMEINZIP + 1, 0, 0, 0, 0);1407 list.push_back(Common::String(fileNameBuffer));1408 fileCount++;1409 } while (unzGoToNextFile(_zipFile) == UNZ_OK);1410 1411 return fileCount;1412 }1413 1414 /*1415 1395 int ZipArchive::listMembers(Common::ArchiveMemberList &list) { 1416 1396 if (!_zipFile) 1417 1397 return 0; … … 1424 1404 unzGetCurrentFileInfo(_zipFile, NULL, 1425 1405 szCurrentFileName, sizeof(szCurrentFileName)-1, 1426 1406 NULL, 0, NULL, 0); 1427 1428 szCurrentFileName 1407 list.push_back(ArchiveMemberList::value_type(new GenericArchiveMember(szCurrentFileName, this))); 1429 1408 matches++; 1430 err = unzGoToNextFile( file);1409 err = unzGoToNextFile(_zipFile); 1431 1410 } 1432 return 0; 1411 1412 return matches; 1433 1413 } 1434 */1435 1414 1436 1415 Common::SeekableReadStream *ZipArchive::openFile(const Common::String &name) { 1437 1416 if (!_zipFile) -
common/archive.cpp
30 30 31 31 namespace Common { 32 32 33 GenericArchiveMember::GenericArchiveMember(String name, Archive *parent) 34 : _parent(parent), _name(name) { 35 } 33 36 34 int Archive::matchPattern(StringList &list, const String &pattern) { 37 String GenericArchiveMember::getName() const { 38 return _name; 39 } 40 41 SeekableReadStream *GenericArchiveMember::open() { 42 return _parent->openFile(_name); 43 } 44 45 46 int Archive::listMatchingMembers(ArchiveMemberList &list, const String &pattern) { 35 47 // Get all "names" (TODO: "files" ?) 36 StringList allNames;37 getAllNames(allNames);48 ArchiveMemberList allNames; 49 listMembers(allNames); 38 50 39 51 int matches = 0; 40 52 … … 42 54 String lowercasePattern = pattern; 43 55 lowercasePattern.toLowercase(); 44 56 45 StringList::iterator it = allNames.begin();57 ArchiveMemberList::iterator it = allNames.begin(); 46 58 for ( ; it != allNames.end(); it++) { 47 if ( it->matchString(lowercasePattern)) {59 if ((*it)->getName().matchString(lowercasePattern)) { 48 60 list.push_back(*it); 49 61 matches++; 50 62 } … … 53 65 return matches; 54 66 } 55 67 68 /** 69 * FSDirectoryMemeber is the implementation of ArchiveMember used by 70 * by FSDirectory. It is right now a light wrapper or FSNode. 71 */ 72 class FSDirectoryMember : public ArchiveMember { 73 FSNode _node; 74 75 public: 76 FSDirectoryMember(FSNode &node) : _node(node) { 77 } 56 78 79 /* 80 NOTE/FIXME: since I assume that the only use case for getName() 81 is for error messages, I am returning the full path of the node 82 here. This seems better than we did before, when matchPattern 83 and getAllNames used to work with StringList, and we used to 84 put the relative path of the file to the list instead. 85 */ 86 String getName() const { 87 return _node.getPath(); 88 } 89 90 SeekableReadStream *open() { 91 return _node.openForReading(); 92 } 93 }; 94 95 typedef SharedPtr<FSDirectoryMember> FSDirectoryMemberPtr; 96 57 97 FSDirectory::FSDirectory(const FSNode &node, int depth) 58 98 : _node(node), _cached(false), _depth(depth) { 59 99 } … … 160 200 161 201 } 162 202 163 int FSDirectory:: matchPattern(StringList &list, const String &pattern) {203 int FSDirectory::listMatchingMembers(ArchiveMemberList &list, const String &pattern) { 164 204 if (!_node.isDirectory()) 165 205 return 0; 166 206 … … 170 210 _cached = true; 171 211 } 172 212 173 // Small optimization: Ensure the StringList has to grow at most once174 l ist.reserve(list.size() + _fileCache.size());175 176 // Add all filenames from our cache213 String lowercasePattern(pattern); 214 lowercasePattern.toLowercase(); 215 216 int matches = 0; 177 217 NodeCache::iterator it = _fileCache.begin(); 178 218 for ( ; it != _fileCache.end(); it++) { 179 if (it->_key.matchString(pattern)) 180 list.push_back(it->_key); 219 if ((*it)._key.matchString(lowercasePattern)) { 220 list.push_back(FSDirectoryMemberPtr(new FSDirectoryMember((*it)._value))); 221 matches++; 222 } 181 223 } 182 183 return _fileCache.size(); 224 return matches; 184 225 } 185 226 186 int FSDirectory:: getAllNames(StringList &list) {187 if (!_node.isDirectory())188 return 0; 227 int FSDirectory::listMembers(ArchiveMemberList &list) { 228 return listMatchingMembers(list, "*"); 229 } 189 230 190 // Cache dir data191 if (!_cached) {192 cacheDirectoryRecursive(_node, _depth, "");193 _cached = true;194 }195 231 196 // Small optimization: Ensure the StringList has to grow at most once197 list.reserve(list.size() + _fileCache.size());198 199 // Add all filenames from our cache200 NodeCache::iterator it = _fileCache.begin();201 for ( ; it != _fileCache.end(); it++) {202 list.push_back((*it)._key);203 }204 205 return _fileCache.size();206 }207 232 208 233 209 234 … … 289 314 return false; 290 315 } 291 316 292 int SearchSet:: matchPattern(StringList &list, const String &pattern) {317 int SearchSet::listMatchingMembers(ArchiveMemberList &list, const String &pattern) { 293 318 int matches = 0; 294 319 295 320 ArchiveList::iterator it = _list.begin(); 296 321 for ( ; it != _list.end(); it++) { 297 matches += (*it)._arc-> matchPattern(list, pattern);322 matches += (*it)._arc->listMatchingMembers(list, pattern); 298 323 } 299 324 300 325 return matches; 301 326 } 302 327 303 int SearchSet:: getAllNames(StringList &list) {328 int SearchSet::listMembers(ArchiveMemberList &list) { 304 329 int matches = 0; 305 330 306 331 ArchiveList::iterator it = _list.begin(); 307 332 for ( ; it != _list.end(); it++) { 308 matches += (*it)._arc-> getAllNames(list);333 matches += (*it)._arc->listMembers(list); 309 334 } 310 335 311 336 return matches; -
common/unzip.h
44 44 bool isOpen() const; 45 45 46 46 virtual bool hasFile(const String &name); 47 virtual int getAllNames(StringList &list);47 virtual int listMembers(Common::ArchiveMemberList &list); 48 48 virtual Common::SeekableReadStream *openFile(const Common::String &name); 49 49 }; 50 50 -
common/archive.h
36 36 37 37 namespace Common { 38 38 39 class ArchiveMember { 40 public: 41 virtual ~ArchiveMember() { } 42 virtual String getName() const = 0; 43 virtual SeekableReadStream *open() = 0; 44 }; 45 46 typedef List<SharedPtr<ArchiveMember> > ArchiveMemberList; 47 48 class Archive; 49 39 50 /** 51 * Simple ArchiveMemeber implementation which allows 52 * creation of ArchiveMember compatible objects via 53 * a simple Archive and name pair. 54 */ 55 class GenericArchiveMember : public ArchiveMember { 56 Archive *_parent; 57 String _name; 58 public: 59 GenericArchiveMember(String name, Archive *parent); 60 String getName() const; 61 SeekableReadStream *open(); 62 }; 63 64 /** 40 65 * FilePtr is a convenient way to keep track of a SeekableReadStream without 41 66 * having to worry about releasing its memory. 42 67 */ … … 63 88 * 64 89 * @return the number of names added to list 65 90 */ 66 virtual int matchPattern(StringList &list, const String &pattern);91 virtual int listMatchingMembers(ArchiveMemberList &list, const String &pattern); 67 92 68 93 /** 69 94 * Add all the names present in the Archive to list. Returned … … 72 97 * 73 98 * @return the number of names added to list 74 99 */ 75 virtual int getAllNames(StringList &list) = 0;100 virtual int listMembers(ArchiveMemberList &list) = 0; 76 101 77 102 /** 78 103 * Create a stream bound to a file in the archive. … … 138 163 FSDirectory *getSubDirectory(const String &name); 139 164 140 165 virtual bool hasFile(const String &name); 141 virtual int matchPattern(StringList &list, const String &pattern);142 virtual int getAllNames(StringList &list);166 virtual int listMatchingMembers(ArchiveMemberList &list, const String &pattern); 167 virtual int listMembers(ArchiveMemberList &list); 143 168 virtual SeekableReadStream *openFile(const String &name); 144 169 }; 145 170 … … 195 220 void setPriority(const String& name, int priority); 196 221 197 222 virtual bool hasFile(const String &name); 198 virtual int matchPattern(StringList &list, const String &pattern);199 virtual int getAllNames(StringList &list);223 virtual int listMatchingMembers(ArchiveMemberList &list, const String &pattern); 224 virtual int listMembers(ArchiveMemberList &list); 200 225 201 226 /** 202 227 * Implements openFile from Archive base class. The current policy is -
engines/kyra/resource_intern.cpp
51 51 return (_files.find(name) != _files.end()); 52 52 } 53 53 54 int PlainArchive:: getAllNames(Common::StringList &list) {54 int PlainArchive::listMembers(Common::ArchiveMemberList &list) { 55 55 int count = 0; 56 56 57 57 for (FileMap::const_iterator i = _files.begin(); i != _files.end(); ++i) { 58 list.push_back( i->_key);58 list.push_back(Common::ArchiveMemberList::value_type(new Common::GenericArchiveMember(i->_key, this))); 59 59 ++count; 60 60 } 61 61 … … 98 98 return (_files.find(name) != _files.end()); 99 99 } 100 100 101 int CachedArchive:: getAllNames(Common::StringList &list) {101 int CachedArchive::listMembers(Common::ArchiveMemberList &list) { 102 102 int count = 0; 103 103 104 104 for (FileMap::const_iterator i = _files.begin(); i != _files.end(); ++i) { 105 list.push_back( i->_key);105 list.push_back(Common::ArchiveMemberList::value_type(new Common::GenericArchiveMember(i->_key, this))); 106 106 ++count; 107 107 } 108 108 -
engines/kyra/resource_intern.h
50 50 PlainArchive(Resource *owner, const Common::String &filename, const FileInputList &files); 51 51 52 52 bool hasFile(const Common::String &name); 53 int getAllNames(Common::StringList &list);53 int listMembers(Common::ArchiveMemberList &list); 54 54 Common::SeekableReadStream *openFile(const Common::String &name); 55 55 private: 56 56 struct Entry { … … 80 80 ~CachedArchive(); 81 81 82 82 bool hasFile(const Common::String &name); 83 int getAllNames(Common::StringList &list);83 int listMembers(Common::ArchiveMemberList &list); 84 84 Common::SeekableReadStream *openFile(const Common::String &name); 85 85 private: 86 86 struct Entry {