Improved version of my resource loading patch from -devel (check also r33876).
svn-id: r33878
This commit is contained in:
parent
e56359eac0
commit
027e6c51a8
1 changed files with 37 additions and 34 deletions
|
@ -184,8 +184,14 @@ 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.
|
||||||
_map[i->filename] = i->entry;
|
if (_map.find(i->filename) == _map.end())
|
||||||
|
_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)) {
|
||||||
ResFileMap::iterator oldParent = _map.find(iter->_value.parent);
|
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) {
|
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())
|
||||||
|
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();
|
Common::File *stream = new Common::File();
|
||||||
if (!stream->open(file)) {
|
if (!stream->open(file)) {
|
||||||
delete stream;
|
delete stream;
|
||||||
|
@ -361,28 +377,15 @@ Common::SeekableReadStream *Resource::getFileStream(const Common::String &file)
|
||||||
error("Couldn't open file '%s'", file.c_str());
|
error("Couldn't open file '%s'", file.c_str());
|
||||||
}
|
}
|
||||||
return stream;
|
return stream;
|
||||||
} else if ((compEntry = _compFiles.find(file)) != _compFiles.end()) {
|
|
||||||
return new Common::MemoryReadStream(compEntry->_value.data, compEntry->_value.size, false);
|
|
||||||
} else {
|
} else {
|
||||||
if (!isAccessable(file))
|
Common::SeekableReadStream *parent = getFileStream(iter->_value.parent);
|
||||||
return 0;
|
assert(parent);
|
||||||
|
|
||||||
ResFileMap::const_iterator iter = _map.find(file);
|
ResFileMap::const_iterator parentIter = _map.find(iter->_value.parent);
|
||||||
if (iter == _map.end())
|
const ResArchiveLoader *loader = getLoader(parentIter->_value.type);
|
||||||
return 0;
|
assert(loader);
|
||||||
|
|
||||||
if (!iter->_value.parent.empty()) {
|
return loader->loadFileFromArchive(file, parent, iter->_value);
|
||||||
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 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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue