aboutsummaryrefslogtreecommitdiff
path: root/engines/kyra/resource.h
diff options
context:
space:
mode:
authorJohannes Schickel2008-09-07 21:46:37 +0000
committerJohannes Schickel2008-09-07 21:46:37 +0000
commit7aaf6139e25b55d4eca335553fe6da654ba1b341 (patch)
treeff4526b996ca66a07547d282f416722c1bc0786f /engines/kyra/resource.h
parentd48a57723a47d127d6e9c02f44743a89423ce6f8 (diff)
downloadscummvm-rg350-7aaf6139e25b55d4eca335553fe6da654ba1b341.tar.gz
scummvm-rg350-7aaf6139e25b55d4eca335553fe6da654ba1b341.tar.bz2
scummvm-rg350-7aaf6139e25b55d4eca335553fe6da654ba1b341.zip
Moved Kyra resource code to a SearchSet/Archive based implementation, this removes dependencies on Common::File.
svn-id: r34428
Diffstat (limited to 'engines/kyra/resource.h')
-rw-r--r--engines/kyra/resource.h101
1 files changed, 14 insertions, 87 deletions
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<Common::String, ResFileEntry, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> ResFileMap;
-typedef Common::HashMap<Common::String, CompFileEntry, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> 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<File> 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<Common::String, Common::ArchivePtr, Common::CaseSensitiveString_Hash, Common::CaseSensitiveString_EqualTo> ArchiveMap;
+ ArchiveMap _archiveCache;
- void detectFileTypes();
- void detectFileType(const Common::String &filename, ResFileEntry *fileEntry);
+ Common::SearchSet _files;
+ Common::SharedPtr<Common::SearchSet> _archiveFiles;
+ Common::SharedPtr<Common::SearchSet> _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<Common::SharedPtr<ResArchiveLoader> > 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<Common::SharedPtr<CompArchiveLoader> > CompLoaderList;
- typedef CompLoaderList::iterator CompLoaderIterator;
- typedef CompLoaderList::const_iterator CCompLoaderIterator;
- CompLoaderList _compLoaders;
- CompFileMap _compFiles;
-
- void tryLoadCompFiles();
- void clearCompFileList();
KyraEngine_v1 *_vm;
};