Ticket #8933: archive_getfile_v1.patch
File archive_getfile_v1.patch, 7.1 KB (added by , 16 years ago) |
---|
-
common/unzip.cpp
1416 1416 return matches; 1417 1417 } 1418 1418 1419 ArchiveMemberPtr ZipArchive::getFile(const String &name) { 1420 if (!_zipFile || !hasFile(name)) 1421 return ArchiveMemberPtr(); 1422 1423 return ArchiveMemberPtr(new GenericArchiveMember(name, this)); 1424 } 1425 1419 1426 Common::SeekableReadStream *ZipArchive::openFile(const Common::String &name) { 1420 1427 if (!_zipFile) 1421 1428 return 0; -
common/archive.cpp
153 153 return node.exists(); 154 154 } 155 155 156 ArchiveMemberPtr FSDirectory::getFile(const String &name) { 157 if (name.empty() || !_node.isDirectory()) { 158 return ArchiveMemberPtr(); 159 } 160 161 FSNode node = lookupCache(_fileCache, name); 162 163 if (!node.exists()) { 164 warning("FSDirectory::getFile: FSNode does not exist"); 165 return ArchiveMemberPtr(); 166 } else if (node.isDirectory()) { 167 warning("FSDirectory::getFile: FSNode is a directory"); 168 return ArchiveMemberPtr(); 169 } 170 171 return ArchiveMemberPtr(new FSDirectoryMember(node)); 172 } 173 156 174 SeekableReadStream *FSDirectory::openFile(const String &name) { 157 175 if (name.empty() || !_node.isDirectory()) { 158 176 return 0; … … 367 385 return matches; 368 386 } 369 387 388 ArchiveMemberPtr SearchSet::getFile(const String &name) { 389 if (name.empty()) { 390 return ArchiveMemberPtr(); 391 } 392 393 ArchiveList::iterator it = _list.begin(); 394 for ( ; it != _list.end(); it++) { 395 if ((*it)._arc->hasFile(name)) { 396 return (*it)._arc->getFile(name); 397 } 398 } 399 400 return ArchiveMemberPtr(); 401 } 402 370 403 SeekableReadStream *SearchSet::openFile(const String &name) { 371 404 if (name.empty()) { 372 405 return 0; -
common/unzip.h
39 39 40 40 public: 41 41 ZipArchive(const String &name); 42 ZipArchive(const Common::FSNode &node);42 ZipArchive(const FSNode &node); 43 43 ~ZipArchive(); 44 44 45 45 bool isOpen() const; 46 46 47 47 virtual bool hasFile(const String &name); 48 virtual int listMembers(Common::ArchiveMemberList &list); 49 virtual Common::SeekableReadStream *openFile(const Common::String &name); 48 virtual int listMembers(ArchiveMemberList &list); 49 virtual ArchiveMemberPtr getFile(const String &name); 50 virtual SeekableReadStream *openFile(const String &name); 50 51 }; 51 52 52 53 } // End of namespace Common -
common/archive.h
51 51 virtual SeekableReadStream *open() = 0; 52 52 }; 53 53 54 typedef List<SharedPtr<ArchiveMember> > ArchiveMemberList; 54 typedef SharedPtr<ArchiveMember> ArchiveMemberPtr; 55 typedef List<ArchiveMemberPtr> ArchiveMemberList; 55 56 56 57 class Archive; 57 58 … … 107 108 virtual int listMembers(ArchiveMemberList &list) = 0; 108 109 109 110 /** 111 * Returns a ArchiveMember representation of the given file. 112 */ 113 virtual ArchiveMemberPtr getFile(const String &name) = 0; 114 115 /** 110 116 * Create a stream bound to a file in the archive. 111 117 * @return the newly created input stream 112 118 */ … … 209 215 virtual int listMembers(ArchiveMemberList &list); 210 216 211 217 /** 218 * Get a ArchiveMember representation of the specified file. A full match of relative 219 * path and filename is needed for success. 220 */ 221 virtual ArchiveMemberPtr getFile(const String &name); 222 223 /** 212 224 * Open the specified file. A full match of relative path and filename is needed 213 225 * for success. 214 226 */ … … 273 285 virtual int listMatchingMembers(ArchiveMemberList &list, const String &pattern); 274 286 virtual int listMembers(ArchiveMemberList &list); 275 287 288 virtual ArchiveMemberPtr getFile(const String &name); 289 276 290 /** 277 291 * Implements openFile from Archive base class. The current policy is 278 292 * opening the first file encountered that matches the name. -
engines/kyra/resource_intern.cpp
62 62 return count; 63 63 } 64 64 65 Common::ArchiveMemberPtr PlainArchive::getFile(const Common::String &name) { 66 if (!hasFile(name)) 67 return Common::ArchiveMemberPtr(); 68 69 return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(name, this)); 70 } 71 65 72 Common::SeekableReadStream *PlainArchive::openFile(const Common::String &name) { 66 73 FileMap::const_iterator fDesc = _files.find(name); 67 74 if (fDesc == _files.end()) … … 110 117 return count; 111 118 } 112 119 120 Common::ArchiveMemberPtr CachedArchive::getFile(const Common::String &name) { 121 if (!hasFile(name)) 122 return Common::ArchiveMemberPtr(); 123 124 return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(name, this)); 125 } 126 113 127 Common::SeekableReadStream *CachedArchive::openFile(const Common::String &name) { 114 128 FileMap::const_iterator fDesc = _files.find(name); 115 129 if (fDesc == _files.end()) -
engines/kyra/resource_intern.h
51 51 52 52 bool hasFile(const Common::String &name); 53 53 int listMembers(Common::ArchiveMemberList &list); 54 Common::ArchiveMemberPtr getFile(const Common::String &name); 54 55 Common::SeekableReadStream *openFile(const Common::String &name); 55 56 private: 56 57 struct Entry { … … 80 81 81 82 bool hasFile(const Common::String &name); 82 83 int listMembers(Common::ArchiveMemberList &list); 84 Common::ArchiveMemberPtr getFile(const Common::String &name); 83 85 Common::SeekableReadStream *openFile(const Common::String &name); 84 86 private: 85 87 struct Entry { -
engines/kyra/resource.cpp
107 107 }; 108 108 109 109 for (uint i = 0; i < ARRAYSIZE(list); ++i) { 110 Common::ArchiveMemberList fileList; 111 listFiles(list[i], fileList); 110 Common::ArchiveMemberPtr file = _files.getFile(list[i]); 111 if (!file) 112 error("Couldn't find PAK file '%s'", list[i]); 112 113 113 if (fileList.empty()) 114 error("Couldn't load PAK file '%s'", list[i]); 115 116 Common::Archive *archive = loadArchive(list[i], *fileList.begin()); 114 Common::Archive *archive = loadArchive(list[i], file); 117 115 if (archive) 118 116 _protectedFiles.add(list[i], archive, 0, false); 117 else 118 error("Couldn't load PAK file '%s'", list[i]); 119 119 } 120 120 } else { 121 121 for (Common::FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) { … … 142 142 bool Resource::loadPakFile(Common::String filename) { 143 143 filename.toUppercase(); 144 144 145 Common::ArchiveMemberList list;146 _files.listMatchingMembers(list, filename);147 145 148 if (list.empty()) 146 Common::ArchiveMemberPtr file = _files.getFile(filename); 147 if (!file) 149 148 return false; 150 149 151 return loadPakFile(filename, *list.begin());150 return loadPakFile(filename, file); 152 151 } 153 152 154 153 bool Resource::loadPakFile(Common::String name, Common::SharedPtr<Common::ArchiveMember> file) {