mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-07 03:18:17 +00:00
Merge pull request #525 from klusark/patchr
GRIM: Improve the way that patchr searches for patches and clean up some code.
This commit is contained in:
commit
1fbdc68154
@ -80,7 +80,7 @@ uint32 Patchr::calcIncSize(Common::Array<Op>::const_iterator start) {
|
||||
return incSize;
|
||||
}
|
||||
|
||||
bool Patchr::patchFile(Common::SeekableReadStream *&file, Common::String &name) {
|
||||
bool Patchr::patchFile(Common::SeekableReadStream *&file, const Common::String &name) {
|
||||
Common::Array<Op>::const_iterator line;
|
||||
Common::String md5;
|
||||
uint32 maxSize, fileSize;
|
||||
|
@ -36,7 +36,7 @@ public:
|
||||
Patchr(): _data(NULL), _err(false), _kMd5size(5000), _kMaxFileSize(0x100000) {}
|
||||
~Patchr() { if (_data) delete[] _data; }
|
||||
void loadPatch(Common::SeekableReadStream *patchStream);
|
||||
bool patchFile(Common::SeekableReadStream *&file, Common::String &name);
|
||||
bool patchFile(Common::SeekableReadStream *&file, const Common::String &name);
|
||||
private:
|
||||
uint32 _kMaxFileSize;
|
||||
uint32 _kMd5size;
|
||||
|
@ -165,20 +165,6 @@ ResourceLoader::ResourceLoader() {
|
||||
}
|
||||
|
||||
files.clear();
|
||||
|
||||
loadPatches();
|
||||
}
|
||||
|
||||
void ResourceLoader::loadPatches() {
|
||||
Common::ArchiveMemberList patches;
|
||||
_patches.clear();
|
||||
_files.listMatchingMembers(patches, "*.patchr");
|
||||
SearchMan.listMatchingMembers(patches, "*.patchr");
|
||||
for (Common::ArchiveMemberList::const_iterator x = patches.begin(); x != patches.end(); ++x) {
|
||||
Common::String filename = (*x)->getName();
|
||||
filename = Common::String(filename.c_str(), filename.size() - 7); //remove the .patchr extension
|
||||
_patches.push_back(filename);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@ -234,7 +220,7 @@ bool ResourceLoader::getFileExists(const Common::String &filename) {
|
||||
return _files.hasFile(filename);
|
||||
}
|
||||
|
||||
Common::SeekableReadStream *ResourceLoader::loadFile(Common::String &filename) {
|
||||
Common::SeekableReadStream *ResourceLoader::loadFile(const Common::String &filename) {
|
||||
Common::SeekableReadStream *rs = NULL;
|
||||
if (_files.hasFile(filename))
|
||||
rs = _files.createReadStreamForMember(filename);
|
||||
@ -243,11 +229,11 @@ Common::SeekableReadStream *ResourceLoader::loadFile(Common::String &filename) {
|
||||
else
|
||||
return NULL;
|
||||
|
||||
//Patch a file, if needed
|
||||
if ((Common::find(_patches.begin(), _patches.end(), filename)) != _patches.end()) {
|
||||
Common::String patchfile = filename + ".patchr";
|
||||
if (getFileExists(patchfile)) {
|
||||
Debug::debug(Debug::Patchr, "Patch requested for %s", filename.c_str());
|
||||
Patchr p;
|
||||
p.loadPatch(openNewStreamFile(filename + ".patchr"));
|
||||
p.loadPatch(openNewStreamFile(patchfile));
|
||||
bool success = p.patchFile(rs, filename);
|
||||
if (success)
|
||||
Debug::debug(Debug::Patchr, "%s successfully patched", filename.c_str());
|
||||
@ -255,6 +241,7 @@ Common::SeekableReadStream *ResourceLoader::loadFile(Common::String &filename) {
|
||||
warning("Patching of %s failed", filename.c_str());
|
||||
rs->seek(0, SEEK_SET);
|
||||
}
|
||||
|
||||
return rs;
|
||||
}
|
||||
|
||||
|
@ -87,14 +87,12 @@ public:
|
||||
};
|
||||
|
||||
private:
|
||||
Common::SeekableReadStream *loadFile(Common::String &filename); //TODO: make it const again at next scummvm sync
|
||||
Common::SeekableReadStream *loadFile(const Common::String &filename); //TODO: make it const again at next scummvm sync
|
||||
Common::SeekableReadStream *getFileFromCache(const Common::String &filename);
|
||||
ResourceLoader::ResourceCache *getEntryFromCache(const Common::String &filename);
|
||||
void putIntoCache(const Common::String &fname, byte *res, uint32 len);
|
||||
void loadPatches();
|
||||
|
||||
Common::SearchSet _files;
|
||||
Common::List<Common::String> _patches;
|
||||
|
||||
Common::Array<ResourceCache> _cache;
|
||||
bool _cacheDirty;
|
||||
|
Loading…
x
Reference in New Issue
Block a user