Ticket #8931: archive_ptr_v1.1.patch
File archive_ptr_v1.1.patch, 16.9 KB (added by , 16 years ago) |
---|
-
gui/ThemeEngine.cpp
525 525 if (!node.exists() || !node.isReadable()) 526 526 return false; 527 527 528 Common::Archive Ptrarchive;528 Common::Archive *archive; 529 529 530 530 if (node.getName().hasSuffix(".zip") && !node.isDirectory()) { 531 531 #ifdef USE_ZLIB 532 532 Common::ZipArchive *zipArchive = new Common::ZipArchive(node); 533 archive = Common::ArchivePtr(zipArchive);533 archive = zipArchive; 534 534 535 535 if (!zipArchive || !zipArchive->isOpen()) { 536 delete zipArchive; 536 537 warning("Failed to open Zip archive '%s'.", themeName.c_str()); 537 538 return false; 538 539 } 539 540 540 541 #endif 541 542 } else if (node.isDirectory()) { 542 archive = Common::ArchivePtr(new Common::FSDirectory(node));543 archive = new Common::FSDirectory(node); 543 544 } 544 545 545 546 Common::File themercFile; 546 547 themercFile.open("THEMERC", *archive); 547 548 if (!themercFile.isOpen()) { 549 delete archive; 548 550 warning("Theme '%s' contains no 'THEMERC' file.", themeName.c_str()); 549 551 return false; 550 552 } 551 553 552 554 Common::String stxHeader = themercFile.readLine(); 553 555 if (!themeConfigParseHeader(stxHeader, _themeName) || _themeName.empty()) { 556 delete archive; 554 557 warning("Corrupted 'THEMERC' file in theme '%s'", _themeFileName.c_str()); 555 558 return false; 556 559 } 557 560 558 561 Common::ArchiveMemberList members; 559 562 if (0 == archive->listMatchingMembers(members, "*.stx")) { 563 delete archive; 560 564 warning("Found no STX files for theme '%s'.", themeName.c_str()); 561 565 return false; 562 566 } … … 566 570 assert((*i)->getName().hasSuffix(".stx")); 567 571 568 572 if (_parser->loadStream((*i)->open()) == false) { 573 delete archive; 569 574 warning("Failed to load STX file '%s'", (*i)->getName().c_str()); 570 575 _parser->close(); 571 576 return false; 572 577 } 573 578 574 579 if (_parser->parse() == false) { 580 delete archive; 575 581 warning("Failed to parse STX file '%s'", (*i)->getName().c_str()); 576 582 _parser->close(); 577 583 return false; … … 580 586 _parser->close(); 581 587 } 582 588 589 delete archive; 583 590 assert(!_themeName.empty()); 584 591 return true; 585 592 } -
engines/kyra/resource.h
55 55 56 56 bool loadPakFile(Common::String filename); 57 57 bool loadPakFile(Common::String name, Common::SharedPtr<Common::ArchiveMember> file); 58 58 59 void unloadPakFile(Common::String filename, bool remFromCache = false); 60 59 61 bool isInPakList(Common::String filename); 62 60 63 bool isInCacheList(Common::String name); 61 64 62 65 bool loadFileList(const Common::String &filedata); … … 75 78 76 79 bool loadFileToBuf(const char *file, void *buf, uint32 maxSize); 77 80 protected: 78 typedef Common::HashMap<Common::String, Common::Archive Ptr, Common::CaseSensitiveString_Hash, Common::CaseSensitiveString_EqualTo> ArchiveMap;81 typedef Common::HashMap<Common::String, Common::Archive*, Common::CaseSensitiveString_Hash, Common::CaseSensitiveString_EqualTo> ArchiveMap; 79 82 ArchiveMap _archiveCache; 80 83 81 84 Common::SearchSet _files; 82 Common::S haredPtr<Common::SearchSet>_archiveFiles;83 Common::S haredPtr<Common::SearchSet>_protectedFiles;85 Common::SearchSet _archiveFiles; 86 Common::SearchSet _protectedFiles; 84 87 85 Common::Archive PtrloadArchive(const Common::String &name, Common::SharedPtr<Common::ArchiveMember> member);86 Common::Archive PtrloadInstallerArchive(const Common::String &file, const Common::String &ext, const uint8 offset);88 Common::Archive *loadArchive(const Common::String &name, Common::SharedPtr<Common::ArchiveMember> member); 89 Common::Archive *loadInstallerArchive(const Common::String &file, const Common::String &ext, const uint8 offset); 87 90 88 91 void initializeLoaders(); 89 92 -
engines/kyra/resource.cpp
35 35 36 36 namespace Kyra { 37 37 38 Resource::Resource(KyraEngine_v1 *vm) : _archiveCache(), _files(), _archiveFiles( new Common::SearchSet()), _protectedFiles(new Common::SearchSet()), _loaders(), _vm(vm) {38 Resource::Resource(KyraEngine_v1 *vm) : _archiveCache(), _files(), _archiveFiles(), _protectedFiles(), _loaders(), _vm(vm) { 39 39 initializeLoaders(); 40 40 41 Common::SharedPtr<Common::Archive> path(new Common::FSDirectory(ConfMan.get("path"), 2)); 42 Common::SharedPtr<Common::Archive> extrapath(new Common::FSDirectory(ConfMan.get("extrapath"))); 43 44 _files.add("path", path, 4); 45 _files.add("extrapath", extrapath, 4); 46 _vm->_system->addSysArchivesToSearchSet(_files, 3); 41 _files.add("global_search", &Common::SearchManager::instance(), 3, false); 47 42 // compressed installer archives are added at level '2', 48 43 // but that's done in Resource::reset not here 49 _files.add("protected", _protectedFiles, 1);50 _files.add("archives", _archiveFiles, 0);44 _files.add("protected", &_protectedFiles, 1, false); 45 _files.add("archives", &_archiveFiles, 0, false); 51 46 } 52 47 53 48 Resource::~Resource() { 54 49 _loaders.clear(); 50 51 for (ArchiveMap::iterator i = _archiveCache.begin(); i != _archiveCache.end(); ++i) 52 delete i->_value; 53 _archiveCache.clear(); 55 54 } 56 55 57 56 bool Resource::reset() { … … 68 67 return true; 69 68 } else if (_vm->game() == GI_KYRA2) { 70 69 if (_vm->gameFlags().useInstallerPackage) 71 _files.add("installer", loadInstallerArchive("WESTWOOD", "%03d", 6), 2 );70 _files.add("installer", loadInstallerArchive("WESTWOOD", "%03d", 6), 2, false); 72 71 73 72 // mouse pointer, fonts, etc. required for initializing 74 73 if (_vm->gameFlags().isDemo && !_vm->gameFlags().isTalkie) { … … 91 90 return true; 92 91 } else if (_vm->game() == GI_LOL) { 93 92 if (_vm->gameFlags().useInstallerPackage) 94 _files.add("installer", loadInstallerArchive("WESTWOOD", "%d", 0), 2 );93 _files.add("installer", loadInstallerArchive("WESTWOOD", "%d", 0), 2, false); 95 94 96 95 return true; 97 96 } … … 114 113 if (fileList.empty()) 115 114 error("Couldn't load PAK file '%s'", list[i]); 116 115 117 Common::Archive Ptrarchive = loadArchive(list[i], *fileList.begin());116 Common::Archive *archive = loadArchive(list[i], *fileList.begin()); 118 117 if (archive) 119 _protectedFiles ->add(list[i], archive, 0);118 _protectedFiles.add(list[i], archive, 0, false); 120 119 } 121 120 } else { 122 121 for (Common::FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) { … … 155 154 bool Resource::loadPakFile(Common::String name, Common::SharedPtr<Common::ArchiveMember> file) { 156 155 name.toUppercase(); 157 156 158 if (_archiveFiles ->hasArchive(name) || _protectedFiles->hasArchive(name))157 if (_archiveFiles.hasArchive(name) || _protectedFiles.hasArchive(name)) 159 158 return true; 160 159 161 Common::Archive Ptrarchive = loadArchive(name, file);160 Common::Archive *archive = loadArchive(name, file); 162 161 if (!archive) 163 162 return false; 164 163 165 _archiveFiles ->add(name, archive, 0);164 _archiveFiles.add(name, archive, 0, false); 166 165 167 166 return true; 168 167 } … … 220 219 221 220 void Resource::unloadPakFile(Common::String filename, bool remFromCache) { 222 221 filename.toUppercase(); 223 _archiveFiles->remove(filename); 224 if (remFromCache) 225 _archiveCache.erase(filename); 222 226 223 // We do not remove files from '_protectedFiles' here, since 227 224 // those are protected against unloading. 225 if (_archiveFiles.hasArchive(filename)) { 226 _archiveFiles.remove(filename); 227 if (remFromCache) { 228 ArchiveMap::iterator iter = _archiveCache.find(filename); 229 if (iter != _archiveCache.end()) { 230 delete iter->_value; 231 _archiveCache.erase(filename); 232 } 233 } 234 } 228 235 } 229 236 230 237 bool Resource::isInPakList(Common::String filename) { 231 238 filename.toUppercase(); 232 return (_archiveFiles ->hasArchive(filename) || _protectedFiles->hasArchive(filename));239 return (_archiveFiles.hasArchive(filename) || _protectedFiles.hasArchive(filename)); 233 240 } 234 241 235 242 bool Resource::isInCacheList(Common::String name) { … … 238 245 } 239 246 240 247 void Resource::unloadAllPakFiles() { 241 _archiveFiles ->clear();242 _protectedFiles ->clear();248 _archiveFiles.clear(); 249 _protectedFiles.clear(); 243 250 } 244 251 245 252 void Resource::listFiles(const Common::String &pattern, Common::ArchiveMemberList &list) { … … 294 301 return _files.openFile(file); 295 302 } 296 303 297 Common::Archive PtrResource::loadArchive(const Common::String &name, Common::SharedPtr<Common::ArchiveMember> member) {304 Common::Archive *Resource::loadArchive(const Common::String &name, Common::SharedPtr<Common::ArchiveMember> member) { 298 305 ArchiveMap::iterator cachedArchive = _archiveCache.find(name); 299 306 if (cachedArchive != _archiveCache.end()) 300 307 return cachedArchive->_value; … … 302 309 Common::SeekableReadStream *stream = member->open(); 303 310 304 311 if (!stream) 305 return Common::ArchivePtr();312 return 0; 306 313 307 Common::Archive Ptr archive;314 Common::Archive *archive = 0; 308 315 for (LoaderList::const_iterator i = _loaders.begin(); i != _loaders.end(); ++i) { 309 316 if ((*i)->checkFilename(name)) { 310 317 if ((*i)->isLoadable(name, *stream)) { 311 318 stream->seek(0, SEEK_SET); 312 archive = Common::ArchivePtr((*i)->load(member, *stream));319 archive = (*i)->load(member, *stream); 313 320 break; 314 321 } else { 315 322 stream->seek(0, SEEK_SET); … … 320 327 delete stream; 321 328 322 329 if (!archive) 323 return Common::ArchivePtr();330 return 0; 324 331 325 332 _archiveCache[name] = archive; 326 333 return archive; 327 334 } 328 335 329 Common::Archive PtrResource::loadInstallerArchive(const Common::String &file, const Common::String &ext, const uint8 offset) {336 Common::Archive *Resource::loadInstallerArchive(const Common::String &file, const Common::String &ext, const uint8 offset) { 330 337 ArchiveMap::iterator cachedArchive = _archiveCache.find(file); 331 338 if (cachedArchive != _archiveCache.end()) 332 339 return cachedArchive->_value; 333 340 334 Common::Archive Ptr archive(InstallerLoader::load(this, file, ext, offset));341 Common::Archive *archive = InstallerLoader::load(this, file, ext, offset); 335 342 if (!archive) 336 return Common::ArchivePtr();343 return 0; 337 344 338 345 _archiveCache[file] = archive; 339 346 return archive; -
engines/parallaction/disk_br.cpp
129 129 130 130 debugC(5, kDebugDisk, "DosDisk_br::selectArchive: adding part directory to search set"); 131 131 _sset.remove("part"); 132 Common::SharedPtr<Common::FSDirectory> partDir(_baseDir->getSubDirectory(name, 3)); 133 _sset.add("part", partDir, 10); 132 _sset.add("part", _baseDir->getSubDirectory(name, 3), 10); 134 133 135 134 return oldPath; 136 135 } … … 149 148 // TODO: clarify whether the engine or OSystem should add the base game directory to the search manager. 150 149 // Right now, I am keeping an internal search set to do the job. 151 150 _baseDir = Common::SharedPtr<Common::FSDirectory>(new Common::FSDirectory(ConfMan.get("path"))); 152 _sset.add("base", _baseDir, 5); 151 // FIXME: We use this gross hack here since we switched SearchSet to accept plain pointers 152 _sset.add("base", _baseDir.get(), 5, false); 153 153 } 154 154 155 155 … … 392 392 // TODO: clarify whether the engine or OSystem should add the base game directory to the search manager. 393 393 // Right now, I am keeping an internal search set to do the job. 394 394 _baseDir = Common::SharedPtr<Common::FSDirectory>(new Common::FSDirectory(ConfMan.get("path"), 2)); 395 _sset.add("base", _baseDir, 5); 395 // FIXME: We use this gross hack here since we switched SearchSet to accept plain pointers 396 _sset.add("base", _baseDir.get(), 5, false); 396 397 } 397 398 398 399 … … 413 414 414 415 void AmigaDisk_br::init() { 415 416 _baseDir = Common::SharedPtr<Common::FSDirectory>(new Common::FSDirectory(ConfMan.get("path"))); 416 _sset.add("base", _baseDir, 5); 417 // FIXME: We use this gross hack here since we switched SearchSet to accept plain pointers 418 _sset.add("base", _baseDir.get(), 5, false); 417 419 418 420 const Common::String subDirNames[3] = { "fonts", "backs", "common" }; 419 421 const Common::String subDirPrefixes[3] = { "fonts", "backs", Common::String::emptyString }; 420 for (int i = 0; i < 3; i++) { 421 Common::SharedPtr<Common::Archive> subDir(_baseDir->getSubDirectory(subDirPrefixes[i], subDirNames[i], 2)); 422 _sset.add(subDirNames[i], subDir, 6); 423 } 422 for (int i = 0; i < 3; i++) 423 _sset.add(subDirNames[i], _baseDir->getSubDirectory(subDirPrefixes[i], subDirNames[i], 2), 6); 424 424 } 425 425 426 426 AmigaDisk_br::~AmigaDisk_br() { … … 623 623 624 624 debugC(5, kDebugDisk, "AmigaDisk_br::selectArchive: adding part directory to search set"); 625 625 _sset.remove("part"); 626 Common::SharedPtr<Common::FSDirectory> partDir(_baseDir->getSubDirectory(name, 3)); 627 _sset.add("part", partDir, 10); 626 _sset.add("part", _baseDir->getSubDirectory(name, 3), 10); 628 627 629 628 return oldPath; 630 629 } -
common/file.cpp
49 49 if (level <= 0 || !dir.exists() || !dir.isDirectory()) 50 50 return; 51 51 52 Common::ArchivePtr dataArchive(new Common::FSDirectory(dir, level)); 53 SearchMan.add(dir.getPath(), dataArchive); 52 SearchMan.add(dir.getPath(), new Common::FSDirectory(dir, level)); 54 53 } 55 54 56 55 void File::resetDefaultDirectories() { -
common/archive.cpp
281 281 _list.insert(it, node); 282 282 } 283 283 284 void SearchSet::add(const String& name, Archive Ptr archive, int priority) {284 void SearchSet::add(const String& name, Archive *archive, int priority, bool autoFree) { 285 285 if (find(name) == _list.end()) { 286 Node node(priority, name, archive );286 Node node(priority, name, archive, autoFree); 287 287 insert(node); 288 288 } else { 289 289 warning("SearchSet::add: archive '%s' already present", name.c_str()); … … 294 294 void SearchSet::remove(const String& name) { 295 295 ArchiveList::iterator it = find(name); 296 296 if (it != _list.end()) { 297 if (it->_autoFree) 298 delete it->_arc; 297 299 _list.erase(it); 298 300 } 299 301 } … … 303 305 } 304 306 305 307 void SearchSet::clear() { 308 for (ArchiveList::iterator i = _list.begin(); i != _list.end(); ++i) { 309 if (i->_autoFree) 310 delete i->_arc; 311 } 312 306 313 _list.clear(); 307 314 } 308 315 … … 387 394 } 388 395 389 396 void SearchManager::addDirectoryRecursive(const String &name, const String &directory, int depth, int priority) { 390 add(name, ArchivePtr(new FSDirectory(directory, depth)), priority);397 add(name, new FSDirectory(directory, depth), priority, true); 391 398 } 392 399 393 400 void SearchManager::clear() { … … 400 407 401 408 // Add the current dir as a very last resort. 402 409 // See also bug #2137680. 403 add(".", ArchivePtr(new FSDirectory(".")), -2);410 add(".", new FSDirectory("."), -2, true); 404 411 } 405 412 406 413 } // namespace Common -
common/archive.h
114 114 }; 115 115 116 116 117 typedef SharedPtr<Archive> ArchivePtr;118 119 120 117 /** 121 118 * FSDirectory models a directory tree from the filesystem and allows users 122 119 * to access it through the Archive interface. Searching is case-insensitive, … … 228 225 */ 229 226 class SearchSet : public Archive { 230 227 struct Node { 231 int _priority; 232 String _name; 233 ArchivePtr _arc; 234 Node(int priority, const String &name, ArchivePtr arc) 235 : _priority(priority), _name(name), _arc(arc) { 228 int _priority; 229 String _name; 230 Archive *_arc; 231 bool _autoFree; 232 Node(int priority, const String &name, Archive *arc, bool autoFree) 233 : _priority(priority), _name(name), _arc(arc), _autoFree(autoFree) { 236 234 } 237 235 }; 238 236 typedef List<Node> ArchiveList; … … 244 242 void insert(const Node& node); 245 243 246 244 public: 245 virtual ~SearchSet() { clear(); } 246 247 247 /** 248 248 * Add a new archive to the searchable set. 249 249 */ 250 void add(const String& name, Archive Ptr archive, int priority = 0);250 void add(const String& name, Archive *arch, int priority = 0, bool autoFree = true); 251 251 252 252 /** 253 253 * Remove an archive from the searchable set. -
graphics/imageman.cpp
66 66 arch = dir; 67 67 } 68 68 69 _archives.add(name, Common::ArchivePtr(arch));69 _archives.add(name, arch); 70 70 return true; 71 71 } 72 72 -
backends/platform/sdl/sdl.cpp
282 282 // FIXME: We use depth = 4 for now, to match the old code. May want to change that 283 283 Common::FSNode dataNode(DATA_PATH); 284 284 if (dataNode.exists() && dataNode.isDirectory()) { 285 Common::ArchivePtr dataArchive(new Common::FSDirectory(dataNode, 4)); 286 s.add(DATA_PATH, dataArchive, priority); 285 s.add(DATA_PATH, new Common::FSDirectory(dataNode, 4), priority); 287 286 } 288 287 #endif 289 288 … … 296 295 if (CFURLGetFileSystemRepresentation(fileUrl, true, buf, sizeof(buf))) { 297 296 // Success: Add it to the search path 298 297 Common::String bundlePath((const char *)buf); 299 Common::ArchivePtr bundleArchive(new Common::FSDirectory(bundlePath)); 300 s.add("__OSX_BUNDLE__", bundleArchive, priority); 298 s.add("__OSX_BUNDLE__", new Common::FSDirectory(bundlePath), priority); 301 299 } 302 300 CFRelease(fileUrl); 303 301 }