From 7aaf6139e25b55d4eca335553fe6da654ba1b341 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 7 Sep 2008 21:46:37 +0000 Subject: Moved Kyra resource code to a SearchSet/Archive based implementation, this removes dependencies on Common::File. svn-id: r34428 --- engines/kyra/resource.h | 101 +++++++----------------------------------------- 1 file changed, 14 insertions(+), 87 deletions(-) (limited to 'engines/kyra/resource.h') diff --git a/engines/kyra/resource.h b/engines/kyra/resource.h index 5ecbd145fe..cfefa6e3b0 100644 --- a/engines/kyra/resource.h +++ b/engines/kyra/resource.h @@ -35,77 +35,16 @@ #include "common/hashmap.h" #include "common/stream.h" #include "common/ptr.h" +#include "common/archive.h" #include "kyra/kyra_v1.h" #include "kyra/kyra_hof.h" namespace Kyra { -struct ResFileEntry { - Common::String parent; - mutable ResFileEntry *parentEntry; // Cache to avoid lookup by string in the map - // No smart invalidation is needed because the map is cleared globally - // or expanded but no element is ever removed - uint32 size; - - bool preload; - bool mounted; - bool prot; - - enum kType { - kRaw = 0, - kPak = 1, - kInsMal = 2, - kTlk = 3, - kAutoDetect - }; - kType type; - uint32 offset; -}; - -struct CompFileEntry { - uint32 size; - uint8 *data; -}; - -typedef Common::HashMap ResFileMap; -typedef Common::HashMap CompFileMap; class Resource; -class ResArchiveLoader { -public: - struct File { - File() : filename(), entry() {} - File(const Common::String &f, const ResFileEntry &e) : filename(f), entry(e) {} - - bool operator ==(const Common::String &r) const { - return filename.equalsIgnoreCase(r); - } - - Common::String filename; - ResFileEntry entry; - }; - typedef Common::List FileList; - - virtual ~ResArchiveLoader() {} - - virtual bool checkFilename(Common::String filename) const = 0; - virtual bool isLoadable(const Common::String &filename, Common::SeekableReadStream &stream) const = 0; - virtual bool loadFile(const Common::String &filename, Common::SeekableReadStream &stream, FileList &files) const = 0; - // parameter 'archive' can be deleted by this method and it may not be deleted from the caller - virtual Common::SeekableReadStream *loadFileFromArchive(const Common::String &file, Common::SeekableReadStream *archive, const ResFileEntry entry) const = 0; - - virtual ResFileEntry::kType getType() const = 0; -protected: -}; - -class CompArchiveLoader { -public: - virtual ~CompArchiveLoader() {} - - virtual bool checkForFiles() const = 0; - virtual bool loadFile(CompFileMap &loadTo) const = 0; -}; +class ResArchiveLoader; class Resource { public: @@ -114,9 +53,9 @@ public: bool reset(); - bool loadPakFile(const Common::String &filename); - void unloadPakFile(const Common::String &filename); - bool isInPakList(const Common::String &filename); + bool loadPakFile(Common::String filename); + void unloadPakFile(Common::String filename); + bool isInPakList(Common::String filename); bool loadFileList(const Common::String &filedata); bool loadFileList(const char * const *filelist, uint32 numFiles); @@ -130,32 +69,20 @@ public: bool loadFileToBuf(const char *file, void *buf, uint32 maxSize); protected: - void checkFile(const Common::String &file); - bool isAccessible(const Common::String &file); - bool isAccessible(const ResFileEntry *fileEntry); + typedef Common::HashMap ArchiveMap; + ArchiveMap _archiveCache; - void detectFileTypes(); - void detectFileType(const Common::String &filename, ResFileEntry *fileEntry); + Common::SearchSet _files; + Common::SharedPtr _archiveFiles; + Common::SharedPtr _protectedFiles; + + Common::ArchivePtr loadArchive(const Common::String &file); + Common::ArchivePtr loadInstallerArchive(const Common::String &file, const Common::String &ext, const uint8 offset); void initializeLoaders(); - const ResArchiveLoader *getLoader(ResFileEntry::kType type) const; + typedef Common::List > LoaderList; - typedef LoaderList::iterator LoaderIterator; - typedef LoaderList::const_iterator CLoaderIterator; LoaderList _loaders; - ResFileMap _map; - - ResFileEntry *getParentEntry(const ResFileEntry *entry) const; - ResFileEntry *getParentEntry(const Common::String &filename) const; - - typedef Common::List > CompLoaderList; - typedef CompLoaderList::iterator CompLoaderIterator; - typedef CompLoaderList::const_iterator CCompLoaderIterator; - CompLoaderList _compLoaders; - CompFileMap _compFiles; - - void tryLoadCompFiles(); - void clearCompFileList(); KyraEngine_v1 *_vm; }; -- cgit v1.2.3