Improved version of my resource loading patch from -devel (check also r33876).

svn-id: r33878
This commit is contained in:
Johannes Schickel 2008-08-14 22:09:36 +00:00
parent e56359eac0
commit 027e6c51a8

View file

@ -184,7 +184,13 @@ bool Resource::loadPakFile(const Common::String &filename) {
for (ResArchiveLoader::FileList::iterator i = files.begin(); i != files.end(); ++i) { for (ResArchiveLoader::FileList::iterator i = files.begin(); i != files.end(); ++i) {
iter = _map.find(i->filename); iter = _map.find(i->filename);
if (iter == _map.end()) { 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. // A new file entry, so we just insert it into the file map.
if (_map.find(i->filename) == _map.end())
_map[i->filename] = i->entry; _map[i->filename] = i->entry;
} else if (!iter->_value.parent.empty()) { } else if (!iter->_value.parent.empty()) {
if (!iter->_value.parent.equalsIgnoreCase(filename)) { if (!iter->_value.parent.equalsIgnoreCase(filename)) {
@ -353,17 +359,9 @@ bool Resource::loadFileToBuf(const char *file, void *buf, uint32 maxSize) {
Common::SeekableReadStream *Resource::getFileStream(const Common::String &file) { Common::SeekableReadStream *Resource::getFileStream(const Common::String &file) {
CompFileMap::iterator compEntry; CompFileMap::iterator compEntry;
if (Common::File::exists(file)) { if ((compEntry = _compFiles.find(file)) != _compFiles.end())
Common::File *stream = new Common::File();
if (!stream->open(file)) {
delete stream;
stream = 0;
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); return new Common::MemoryReadStream(compEntry->_value.data, compEntry->_value.size, false);
} else {
if (!isAccessable(file)) if (!isAccessable(file))
return 0; return 0;
@ -371,7 +369,15 @@ Common::SeekableReadStream *Resource::getFileStream(const Common::String &file)
if (iter == _map.end()) if (iter == _map.end())
return 0; return 0;
if (!iter->_value.parent.empty()) { if (iter->_value.parent.empty()) {
Common::File *stream = new Common::File();
if (!stream->open(file)) {
delete stream;
stream = 0;
error("Couldn't open file '%s'", file.c_str());
}
return stream;
} else {
Common::SeekableReadStream *parent = getFileStream(iter->_value.parent); Common::SeekableReadStream *parent = getFileStream(iter->_value.parent);
assert(parent); assert(parent);
@ -380,9 +386,6 @@ Common::SeekableReadStream *Resource::getFileStream(const Common::String &file)
assert(loader); assert(loader);
return loader->loadFileFromArchive(file, parent, iter->_value); return loader->loadFileFromArchive(file, parent, iter->_value);
} else {
error("Couldn't open file '%s'", file.c_str());
}
} }
return 0; return 0;
@ -414,7 +417,19 @@ void Resource::checkFile(const Common::String &file) {
if (_map.find(file) == _map.end()) { if (_map.find(file) == _map.end()) {
CompFileMap::const_iterator iter; 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; Common::File temp;
if (temp.open(file)) { if (temp.open(file)) {
ResFileEntry entry; ResFileEntry entry;
@ -430,18 +445,6 @@ void Resource::checkFile(const Common::String &file) {
detectFileTypes(); 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();
} }
} }
} }