aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorJohannes Schickel2008-08-14 22:09:36 +0000
committerJohannes Schickel2008-08-14 22:09:36 +0000
commit027e6c51a8279a7e4e2a66ddb40cf6bfc31af3c6 (patch)
treef98b2fe077f713bbdd2b630c1a5e6078e64b56eb /engines
parente56359eac0d994c18e79a8a3a19acfcbedc0e0fb (diff)
downloadscummvm-rg350-027e6c51a8279a7e4e2a66ddb40cf6bfc31af3c6.tar.gz
scummvm-rg350-027e6c51a8279a7e4e2a66ddb40cf6bfc31af3c6.tar.bz2
scummvm-rg350-027e6c51a8279a7e4e2a66ddb40cf6bfc31af3c6.zip
Improved version of my resource loading patch from -devel (check also r33876).
svn-id: r33878
Diffstat (limited to 'engines')
-rw-r--r--engines/kyra/resource.cpp71
1 files changed, 37 insertions, 34 deletions
diff --git a/engines/kyra/resource.cpp b/engines/kyra/resource.cpp
index d3b66ba6c6..0ce364500d 100644
--- a/engines/kyra/resource.cpp
+++ b/engines/kyra/resource.cpp
@@ -184,8 +184,14 @@ bool Resource::loadPakFile(const Common::String &filename) {
for (ResArchiveLoader::FileList::iterator i = files.begin(); i != files.end(); ++i) {
iter = _map.find(i->filename);
if (iter == _map.end()) {
+ // We do an internal check for a file in gamepath with same filename to
+ // allow overwriting files inside archives with plain files inside the
+ // game directory
+ checkFile(i->filename);
+
// A new file entry, so we just insert it into the file map.
- _map[i->filename] = i->entry;
+ if (_map.find(i->filename) == _map.end())
+ _map[i->filename] = i->entry;
} else if (!iter->_value.parent.empty()) {
if (!iter->_value.parent.equalsIgnoreCase(filename)) {
ResFileMap::iterator oldParent = _map.find(iter->_value.parent);
@@ -353,7 +359,17 @@ bool Resource::loadFileToBuf(const char *file, void *buf, uint32 maxSize) {
Common::SeekableReadStream *Resource::getFileStream(const Common::String &file) {
CompFileMap::iterator compEntry;
- if (Common::File::exists(file)) {
+ if ((compEntry = _compFiles.find(file)) != _compFiles.end())
+ return new Common::MemoryReadStream(compEntry->_value.data, compEntry->_value.size, false);
+
+ if (!isAccessable(file))
+ return 0;
+
+ ResFileMap::const_iterator iter = _map.find(file);
+ if (iter == _map.end())
+ return 0;
+
+ if (iter->_value.parent.empty()) {
Common::File *stream = new Common::File();
if (!stream->open(file)) {
delete stream;
@@ -361,28 +377,15 @@ Common::SeekableReadStream *Resource::getFileStream(const Common::String &file)
error("Couldn't open file '%s'", file.c_str());
}
return stream;
- } else if ((compEntry = _compFiles.find(file)) != _compFiles.end()) {
- return new Common::MemoryReadStream(compEntry->_value.data, compEntry->_value.size, false);
} else {
- if (!isAccessable(file))
- return 0;
+ Common::SeekableReadStream *parent = getFileStream(iter->_value.parent);
+ assert(parent);
- ResFileMap::const_iterator iter = _map.find(file);
- if (iter == _map.end())
- return 0;
+ ResFileMap::const_iterator parentIter = _map.find(iter->_value.parent);
+ const ResArchiveLoader *loader = getLoader(parentIter->_value.type);
+ assert(loader);
- if (!iter->_value.parent.empty()) {
- Common::SeekableReadStream *parent = getFileStream(iter->_value.parent);
- assert(parent);
-
- ResFileMap::const_iterator parentIter = _map.find(iter->_value.parent);
- const ResArchiveLoader *loader = getLoader(parentIter->_value.type);
- assert(loader);
-
- return loader->loadFileFromArchive(file, parent, iter->_value);
- } else {
- error("Couldn't open file '%s'", file.c_str());
- }
+ return loader->loadFileFromArchive(file, parent, iter->_value);
}
return 0;
@@ -414,7 +417,19 @@ void Resource::checkFile(const Common::String &file) {
if (_map.find(file) == _map.end()) {
CompFileMap::const_iterator iter;
- if (Common::File::exists(file)) {
+ if ((iter = _compFiles.find(file)) != _compFiles.end()) {
+ ResFileEntry entry;
+ entry.parent = "";
+ entry.size = iter->_value.size;
+ entry.mounted = false;
+ entry.preload = false;
+ entry.prot = false;
+ entry.type = ResFileEntry::kAutoDetect;
+ entry.offset = 0;
+ _map[file] = entry;
+
+ detectFileTypes();
+ } else if (Common::File::exists(file)) {
Common::File temp;
if (temp.open(file)) {
ResFileEntry entry;
@@ -430,18 +445,6 @@ void Resource::checkFile(const Common::String &file) {
detectFileTypes();
}
- } else if ((iter = _compFiles.find(file)) != _compFiles.end()) {
- ResFileEntry entry;
- entry.parent = "";
- entry.size = iter->_value.size;
- entry.mounted = false;
- entry.preload = false;
- entry.prot = false;
- entry.type = ResFileEntry::kAutoDetect;
- entry.offset = 0;
- _map[file] = entry;
-
- detectFileTypes();
}
}
}