diff options
-rw-r--r-- | common/archive.cpp | 12 | ||||
-rw-r--r-- | common/archive.h | 8 | ||||
-rw-r--r-- | common/fs.h | 25 | ||||
-rw-r--r-- | common/unzip.cpp | 2 | ||||
-rw-r--r-- | common/unzip.h | 2 | ||||
-rw-r--r-- | engines/kyra/resource.cpp | 2 | ||||
-rw-r--r-- | engines/kyra/resource_intern.cpp | 6 | ||||
-rw-r--r-- | engines/kyra/resource_intern.h | 4 | ||||
-rw-r--r-- | engines/kyra/staticres.cpp | 2 | ||||
-rw-r--r-- | engines/parallaction/disk_ns.cpp | 8 | ||||
-rw-r--r-- | gui/ThemeEngine.cpp | 2 |
11 files changed, 35 insertions, 38 deletions
diff --git a/common/archive.cpp b/common/archive.cpp index 1a78f4629a..614215685a 100644 --- a/common/archive.cpp +++ b/common/archive.cpp @@ -38,7 +38,7 @@ String GenericArchiveMember::getName() const { return _name; } -SeekableReadStream *GenericArchiveMember::open() { +SeekableReadStream *GenericArchiveMember::createReadStream() const { return _parent->openFile(_name); } @@ -99,7 +99,7 @@ FSNode FSDirectory::getFSNode() const { return _node; } -FSNode FSDirectory::lookupCache(NodeCache &cache, const String &name) { +FSNode FSDirectory::lookupCache(NodeCache &cache, const String &name) const { // make caching as lazy as possible if (!name.empty()) { ensureCached(); @@ -136,7 +136,7 @@ ArchiveMemberPtr FSDirectory::getMember(const String &name) { return ArchiveMemberPtr(new FSNode(node)); } -SeekableReadStream *FSDirectory::openFile(const String &name) { +SeekableReadStream *FSDirectory::openFile(const String &name) const { if (name.empty() || !_node.isDirectory()) return 0; @@ -169,7 +169,7 @@ FSDirectory *FSDirectory::getSubDirectory(const String &prefix, const String &na return new FSDirectory(prefix, node, depth); } -void FSDirectory::cacheDirectoryRecursive(FSNode node, int depth, const String& prefix) { +void FSDirectory::cacheDirectoryRecursive(FSNode node, int depth, const String& prefix) const { if (depth <= 0) return; @@ -203,7 +203,7 @@ void FSDirectory::cacheDirectoryRecursive(FSNode node, int depth, const String& } -void FSDirectory::ensureCached() { +void FSDirectory::ensureCached() const { if (_cached) return; cacheDirectoryRecursive(_node, _depth, _prefix); @@ -434,7 +434,7 @@ ArchiveMemberPtr SearchSet::getMember(const String &name) { return ArchiveMemberPtr(); } -SeekableReadStream *SearchSet::openFile(const String &name) { +SeekableReadStream *SearchSet::openFile(const String &name) const { if (name.empty()) return 0; diff --git a/common/archive.h b/common/archive.h index db42df8546..ea556d199f 100644 --- a/common/archive.h +++ b/common/archive.h @@ -50,7 +50,7 @@ class SeekableReadStream; class ArchiveMember { public: virtual ~ArchiveMember() { } - virtual SeekableReadStream *open() = 0; + virtual SeekableReadStream *createReadStream() const = 0; virtual String getName() const = 0; virtual String getDisplayName() const { return getName(); } }; @@ -75,7 +75,7 @@ class GenericArchiveMember : public ArchiveMember { public: GenericArchiveMember(String name, Archive *parent); String getName() const; - SeekableReadStream *open(); + SeekableReadStream *createReadStream() const; }; @@ -120,7 +120,7 @@ public: * Create a stream bound to a file in the archive. * @return the newly created input stream */ - virtual SeekableReadStream *openFile(const String &name) = 0; + virtual SeekableReadStream *openFile(const String &name) const = 0; }; @@ -197,7 +197,7 @@ public: * Implements openFile from Archive base class. The current policy is * opening the first file encountered that matches the name. */ - virtual SeekableReadStream *openFile(const String &name); + virtual SeekableReadStream *openFile(const String &name) const; }; diff --git a/common/fs.h b/common/fs.h index 72b492e9c4..61ce21bec5 100644 --- a/common/fs.h +++ b/common/fs.h @@ -223,11 +223,6 @@ public: * @return pointer to the stream object, 0 in case of a failure */ virtual WriteStream *createWriteStream() const; - - // Compatibility with ArchiveMember API. - SeekableReadStream *open() { - return createReadStream(); - } }; /** @@ -262,22 +257,24 @@ public: class FSDirectory : public Archive { FSNode _node; + String _prefix; // string that is prepended to each cache item key + void setPrefix(const String &prefix); + // Caches are case insensitive, clashes are dealt with when creating // Key is stored in lowercase. typedef HashMap<String, FSNode, IgnoreCase_Hash, IgnoreCase_EqualTo> NodeCache; - NodeCache _fileCache, _subDirCache; - String _prefix; // string that is prepended to each cache item key - void setPrefix(const String &prefix); + mutable NodeCache _fileCache, _subDirCache; + mutable bool _cached; + mutable int _depth; // look for a match - FSNode lookupCache(NodeCache &cache, const String &name); + FSNode lookupCache(NodeCache &cache, const String &name) const; // cache management - void cacheDirectoryRecursive(FSNode node, int depth, const String& prefix); + void cacheDirectoryRecursive(FSNode node, int depth, const String& prefix) const; + // fill cache if not already cached - void ensureCached(); - bool _cached; - int _depth; + void ensureCached() const; public: /** @@ -336,7 +333,7 @@ public: * Open the specified file. A full match of relative path and filename is needed * for success. */ - virtual SeekableReadStream *openFile(const String &name); + virtual SeekableReadStream *openFile(const String &name) const; }; diff --git a/common/unzip.cpp b/common/unzip.cpp index 25e26ec24c..9b102872f8 100644 --- a/common/unzip.cpp +++ b/common/unzip.cpp @@ -1428,7 +1428,7 @@ ArchiveMemberPtr ZipArchive::getMember(const String &name) { return ArchiveMemberPtr(new GenericArchiveMember(name, this)); } -Common::SeekableReadStream *ZipArchive::openFile(const Common::String &name) { +Common::SeekableReadStream *ZipArchive::openFile(const Common::String &name) const { if (!_zipFile) return 0; diff --git a/common/unzip.h b/common/unzip.h index 358bf6cbba..970a84ad57 100644 --- a/common/unzip.h +++ b/common/unzip.h @@ -62,7 +62,7 @@ public: virtual bool hasFile(const String &name); virtual int listMembers(ArchiveMemberList &list); virtual ArchiveMemberPtr getMember(const String &name); - virtual SeekableReadStream *openFile(const String &name); + virtual SeekableReadStream *openFile(const String &name) const; }; } // End of namespace Common diff --git a/engines/kyra/resource.cpp b/engines/kyra/resource.cpp index 061cb7e602..e319b89023 100644 --- a/engines/kyra/resource.cpp +++ b/engines/kyra/resource.cpp @@ -319,7 +319,7 @@ Common::Archive *Resource::loadArchive(const Common::String &name, Common::Share if (cachedArchive != _archiveCache.end()) return cachedArchive->_value; - Common::SeekableReadStream *stream = member->open(); + Common::SeekableReadStream *stream = member->createReadStream(); if (!stream) return 0; diff --git a/engines/kyra/resource_intern.cpp b/engines/kyra/resource_intern.cpp index 1368b005c9..68a4a55886 100644 --- a/engines/kyra/resource_intern.cpp +++ b/engines/kyra/resource_intern.cpp @@ -69,12 +69,12 @@ Common::ArchiveMemberPtr PlainArchive::getMember(const Common::String &name) { return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(name, this)); } -Common::SeekableReadStream *PlainArchive::openFile(const Common::String &name) { +Common::SeekableReadStream *PlainArchive::openFile(const Common::String &name) const { FileMap::const_iterator fDesc = _files.find(name); if (fDesc == _files.end()) return 0; - Common::SeekableReadStream *parent = _file->open(); + Common::SeekableReadStream *parent = _file->createReadStream(); if (!parent) return 0; @@ -124,7 +124,7 @@ Common::ArchiveMemberPtr CachedArchive::getMember(const Common::String &name) { return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(name, this)); } -Common::SeekableReadStream *CachedArchive::openFile(const Common::String &name) { +Common::SeekableReadStream *CachedArchive::openFile(const Common::String &name) const { FileMap::const_iterator fDesc = _files.find(name); if (fDesc == _files.end()) return 0; diff --git a/engines/kyra/resource_intern.h b/engines/kyra/resource_intern.h index f768100afe..6f16a2ba8e 100644 --- a/engines/kyra/resource_intern.h +++ b/engines/kyra/resource_intern.h @@ -52,7 +52,7 @@ public: bool hasFile(const Common::String &name); int listMembers(Common::ArchiveMemberList &list); Common::ArchiveMemberPtr getMember(const Common::String &name); - Common::SeekableReadStream *openFile(const Common::String &name); + Common::SeekableReadStream *openFile(const Common::String &name) const; private: struct Entry { uint32 offset; @@ -82,7 +82,7 @@ public: bool hasFile(const Common::String &name); int listMembers(Common::ArchiveMemberList &list); Common::ArchiveMemberPtr getMember(const Common::String &name); - Common::SeekableReadStream *openFile(const Common::String &name); + Common::SeekableReadStream *openFile(const Common::String &name) const; private: struct Entry { byte *data; diff --git a/engines/kyra/staticres.cpp b/engines/kyra/staticres.cpp index 3e510f552f..ce1e54ea48 100644 --- a/engines/kyra/staticres.cpp +++ b/engines/kyra/staticres.cpp @@ -144,7 +144,7 @@ bool StaticResource::loadStaticResourceFile() { bool foundWorkingKyraDat = false; for (Common::ArchiveMemberList::iterator i = kyraDatFiles.begin(); i != kyraDatFiles.end(); ++i) { - Common::SeekableReadStream *file = (*i)->open(); + Common::SeekableReadStream *file = (*i)->createReadStream(); if (!checkKyraDat(file)) { delete file; continue; diff --git a/engines/parallaction/disk_ns.cpp b/engines/parallaction/disk_ns.cpp index 43f20be054..a526facaad 100644 --- a/engines/parallaction/disk_ns.cpp +++ b/engines/parallaction/disk_ns.cpp @@ -72,13 +72,13 @@ class NSArchive : public Common::Archive { uint32 _archiveOffsets[MAX_ARCHIVE_ENTRIES]; uint32 _numFiles; - uint32 lookup(const char *name); + uint32 lookup(const char *name) const; public: NSArchive(Common::SeekableReadStream *stream, Common::Platform platform, uint32 features); ~NSArchive(); - Common::SeekableReadStream *openFile(const Common::String &name); + Common::SeekableReadStream *openFile(const Common::String &name) const; bool hasFile(const Common::String &name); int listMembers(Common::ArchiveMemberList &list); Common::ArchiveMemberPtr getMember(const Common::String &name); @@ -119,7 +119,7 @@ NSArchive::~NSArchive() { delete _stream; } -uint32 NSArchive::lookup(const char *name) { +uint32 NSArchive::lookup(const char *name) const { uint32 i = 0; for ( ; i < _numFiles; i++) { if (!scumm_stricmp(_archiveDir[i], name)) break; @@ -127,7 +127,7 @@ uint32 NSArchive::lookup(const char *name) { return i; } -Common::SeekableReadStream *NSArchive::openFile(const Common::String &name) { +Common::SeekableReadStream *NSArchive::openFile(const Common::String &name) const { debugC(3, kDebugDisk, "NSArchive::openFile(%s)", name.c_str()); if (name.empty()) diff --git a/gui/ThemeEngine.cpp b/gui/ThemeEngine.cpp index 000ce21da9..3e61400f9f 100644 --- a/gui/ThemeEngine.cpp +++ b/gui/ThemeEngine.cpp @@ -718,7 +718,7 @@ bool ThemeEngine::loadThemeXML(const Common::String &themeId) { for (Common::ArchiveMemberList::iterator i = members.begin(); i != members.end(); ++i) { assert((*i)->getName().hasSuffix(".stx")); - if (_parser->loadStream((*i)->open()) == false) { + if (_parser->loadStream((*i)->createReadStream()) == false) { warning("Failed to load STX file '%s'", (*i)->getDisplayName().c_str()); _parser->close(); return false; |