aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
Diffstat (limited to 'engines')
-rw-r--r--engines/kyra/resource.cpp53
-rw-r--r--engines/kyra/resource.h12
-rw-r--r--engines/kyra/staticres.cpp13
3 files changed, 49 insertions, 29 deletions
diff --git a/engines/kyra/resource.cpp b/engines/kyra/resource.cpp
index 9d43d6976a..c3ab6e5e70 100644
--- a/engines/kyra/resource.cpp
+++ b/engines/kyra/resource.cpp
@@ -108,7 +108,13 @@ bool Resource::reset() {
};
for (uint i = 0; i < ARRAYSIZE(list); ++i) {
- Common::ArchivePtr archive = loadArchive(list[i]);
+ Common::ArchiveMemberList fileList;
+ listFiles(list[i], fileList);
+
+ if (fileList.empty())
+ error("Couldn't load PAK file '%s'", list[i]);
+
+ Common::ArchivePtr archive = loadArchive(list[i], *fileList.begin());
if (archive)
_protectedFiles->add(list[i], archive, 0);
}
@@ -137,14 +143,26 @@ bool Resource::reset() {
bool Resource::loadPakFile(Common::String filename) {
filename.toUppercase();
- if (_archiveFiles->hasArchive(filename) || _protectedFiles->hasArchive(filename))
+ Common::ArchiveMemberList list;
+ _files.listMatchingMembers(list, filename);
+
+ if (list.empty())
+ return false;
+
+ return loadPakFile(filename, *list.begin());
+}
+
+bool Resource::loadPakFile(Common::String name, Common::SharedPtr<Common::ArchiveMember> file) {
+ name.toUppercase();
+
+ if (_archiveFiles->hasArchive(name) || _protectedFiles->hasArchive(name))
return true;
- Common::ArchivePtr archive = loadArchive(filename);
+ Common::ArchivePtr archive = loadArchive(name, file);
if (!archive)
return false;
- _archiveFiles->add(filename, archive, 0);
+ _archiveFiles->add(name, archive, 0);
return true;
}
@@ -200,9 +218,11 @@ bool Resource::loadFileList(const char * const *filelist, uint32 numFiles) {
return true;
}
-void Resource::unloadPakFile(Common::String filename) {
+void Resource::unloadPakFile(Common::String filename, bool remFromCache) {
filename.toUppercase();
_archiveFiles->remove(filename);
+ if (remFromCache)
+ _archiveCache.erase(filename);
// We do not remove files from '_protectedFiles' here, since
// those are protected against unloading.
}
@@ -212,11 +232,20 @@ bool Resource::isInPakList(Common::String filename) {
return (_archiveFiles->hasArchive(filename) || _protectedFiles->hasArchive(filename));
}
+bool Resource::isInCacheList(Common::String name) {
+ name.toUppercase();
+ return (_archiveCache.find(name) != _archiveCache.end());
+}
+
void Resource::unloadAllPakFiles() {
_archiveFiles->clear();
_protectedFiles->clear();
}
+void Resource::listFiles(const Common::String &pattern, Common::ArchiveMemberList &list) {
+ _files.listMatchingMembers(list, pattern);
+}
+
uint8 *Resource::fileData(const char *file, uint32 *size) {
Common::SeekableReadStream *stream = getFileStream(file);
if (!stream)
@@ -265,21 +294,11 @@ Common::SeekableReadStream *Resource::getFileStream(const Common::String &file)
return _files.openFile(file);
}
-Common::ArchivePtr Resource::loadArchive(const Common::String &file) {
- ArchiveMap::iterator cachedArchive = _archiveCache.find(file);
+Common::ArchivePtr Resource::loadArchive(const Common::String &name, Common::SharedPtr<Common::ArchiveMember> member) {
+ ArchiveMap::iterator cachedArchive = _archiveCache.find(name);
if (cachedArchive != _archiveCache.end())
return cachedArchive->_value;
- Common::ArchiveMemberList list;
- _files.listMatchingMembers(list, file);
-
- if (list.empty())
- return Common::ArchivePtr();
-
- return loadArchive(file, *list.begin());
-}
-
-Common::ArchivePtr Resource::loadArchive(const Common::String &name, Common::SharedPtr<Common::ArchiveMember> member) {
Common::SeekableReadStream *stream = member->open();
if (!stream)
diff --git a/engines/kyra/resource.h b/engines/kyra/resource.h
index 576f683014..0831acaed6 100644
--- a/engines/kyra/resource.h
+++ b/engines/kyra/resource.h
@@ -47,7 +47,6 @@ class Resource;
class ResArchiveLoader;
class Resource {
- friend class StaticResource;
public:
Resource(KyraEngine_v1 *vm);
~Resource();
@@ -55,14 +54,20 @@ public:
bool reset();
bool loadPakFile(Common::String filename);
- void unloadPakFile(Common::String filename);
+ bool loadPakFile(Common::String name, Common::SharedPtr<Common::ArchiveMember> file);
+ void unloadPakFile(Common::String filename, bool remFromCache = false);
bool isInPakList(Common::String filename);
+ bool isInCacheList(Common::String name);
bool loadFileList(const Common::String &filedata);
bool loadFileList(const char * const *filelist, uint32 numFiles);
- // This unloads *all* pakfiles, even kyra.dat and protected ones
+
+ // This unloads *all* pakfiles, even kyra.dat and protected ones.
+ // It does not remove files from cache though!
void unloadAllPakFiles();
+ void listFiles(const Common::String &pattern, Common::ArchiveMemberList &list);
+
bool exists(const char *file, bool errorOutOnFail=false);
uint32 getFileSize(const char *file);
uint8* fileData(const char *file, uint32 *size);
@@ -77,7 +82,6 @@ protected:
Common::SharedPtr<Common::SearchSet> _archiveFiles;
Common::SharedPtr<Common::SearchSet> _protectedFiles;
- Common::ArchivePtr loadArchive(const Common::String &file);
Common::ArchivePtr loadArchive(const Common::String &name, Common::SharedPtr<Common::ArchiveMember> member);
Common::ArchivePtr loadInstallerArchive(const Common::String &file, const Common::String &ext, const uint8 offset);
diff --git a/engines/kyra/staticres.cpp b/engines/kyra/staticres.cpp
index 543a5c8162..897726868b 100644
--- a/engines/kyra/staticres.cpp
+++ b/engines/kyra/staticres.cpp
@@ -136,11 +136,11 @@ static const LanguageTypes languages[] = {
bool StaticResource::loadStaticResourceFile() {
Resource *res = _vm->resource();
- if (res->_archiveCache.find(staticDataFilename()) != res->_archiveCache.end())
+ if (res->isInCacheList(staticDataFilename()))
return true;
Common::ArchiveMemberList kyraDatFiles;
- res->_files.listMatchingMembers(kyraDatFiles, staticDataFilename());
+ res->listFiles(staticDataFilename(), kyraDatFiles);
bool foundWorkingKyraDat = false;
for (Common::ArchiveMemberList::iterator i = kyraDatFiles.begin(); i != kyraDatFiles.end(); ++i) {
@@ -152,18 +152,15 @@ bool StaticResource::loadStaticResourceFile() {
delete file; file = 0;
- Common::ArchivePtr archive = res->loadArchive(staticDataFilename(), *i);
- if (!archive)
+ if (!res->loadPakFile(staticDataFilename(), *i))
continue;
-
- res->_archiveFiles->add(staticDataFilename(), archive, 0);
+
if (tryKyraDatLoad()) {
foundWorkingKyraDat = true;
break;
}
- res->_archiveCache.erase(staticDataFilename());
- res->_archiveFiles->remove(staticDataFilename());
+ res->unloadPakFile(staticDataFilename(), true);
unloadId(-1);
}