Moved Kyra resource code to a SearchSet/Archive based implementation, this removes dependencies on Common::File.

svn-id: r34428
This commit is contained in:
Johannes Schickel 2008-09-07 21:46:37 +00:00
parent d48a57723a
commit 7aaf6139e2
5 changed files with 1292 additions and 1433 deletions

View File

@ -23,6 +23,7 @@ MODULE_OBJS := \
kyra_mr.o \
lol.o \
resource.o \
resource_intern.o \
saveload.o \
saveload_lok.o \
saveload_hof.o \

File diff suppressed because it is too large Load Diff

View File

@ -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;
};

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,131 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $URL$
* $Id$
*
*/
#ifndef KYRA_RESOURCE_INTERN_H
#define KYRA_RESOURCE_INTERN_H
#include "common/archive.h"
#include "common/hash-str.h"
#include "common/hashmap.h"
#include "common/str.h"
#include "common/list.h"
namespace Kyra {
class Resource;
class PlainArchive : public Common::Archive {
public:
struct InputEntry {
Common::String name;
uint32 offset;
uint32 size;
};
typedef Common::List<InputEntry> FileInputList;
PlainArchive(Resource *owner, const Common::String &filename, const FileInputList &files);
bool hasFile(const Common::String &name);
int getAllNames(Common::StringList &list);
Common::SeekableReadStream *openFile(const Common::String &name);
private:
struct Entry {
uint32 offset;
uint32 size;
};
typedef Common::HashMap<Common::String, Entry, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> FileMap;
Resource *_owner;
Common::String _filename;
FileMap _files;
};
class CachedArchive : public Common::Archive {
public:
struct InputEntry {
Common::String name;
byte *data;
uint32 size;
};
typedef Common::List<InputEntry> FileInputList;
CachedArchive(const FileInputList &files);
~CachedArchive();
bool hasFile(const Common::String &name);
int getAllNames(Common::StringList &list);
Common::SeekableReadStream *openFile(const Common::String &name);
private:
struct Entry {
byte *data;
uint32 size;
};
typedef Common::HashMap<Common::String, Entry, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> FileMap;
FileMap _files;
};
class ResArchiveLoader {
public:
virtual bool checkFilename(Common::String filename) const = 0;
virtual bool isLoadable(const Common::String &filename, Common::SeekableReadStream &stream) const = 0;
virtual Common::Archive *load(Resource *owner, const Common::String &filename, Common::SeekableReadStream &stream) const = 0;
};
class ResLoaderPak : public ResArchiveLoader {
public:
bool checkFilename(Common::String filename) const;
bool isLoadable(const Common::String &filename, Common::SeekableReadStream &stream) const;
Common::Archive *load(Resource *owner, const Common::String &filename, Common::SeekableReadStream &stream) const;
};
class ResLoaderInsMalcolm : public ResArchiveLoader {
public:
bool checkFilename(Common::String filename) const;
bool isLoadable(const Common::String &filename, Common::SeekableReadStream &stream) const;
Common::Archive *load(Resource *owner, const Common::String &filename, Common::SeekableReadStream &stream) const;
};
class ResLoaderTlk : public ResArchiveLoader {
public:
bool checkFilename(Common::String filename) const;
bool isLoadable(const Common::String &filename, Common::SeekableReadStream &stream) const;
Common::Archive *load(Resource *owner, const Common::String &filename, Common::SeekableReadStream &stream) const;
};
class InstallerLoader {
public:
static Common::Archive *load(Resource *owner, const Common::String &filename, const Common::String &extension, const uint8 offset);
};
} // end of namespace Kyra
#endif