Fix #354, make jar mods and patch files in general more resilient.

This commit is contained in:
Petr Mrázek 2014-07-10 01:26:45 +02:00
parent ff06489fed
commit 40c238442f
2 changed files with 12 additions and 3 deletions

View File

@ -85,7 +85,8 @@ bool InstanceVersion::remove(const int index)
{ {
return false; return false;
} }
if(!QFile::remove(VersionPatches.at(index)->getPatchFilename())) auto toDelete = VersionPatches.at(index)->getPatchFilename();
if(!QFile::remove(toDelete))
return false; return false;
beginRemoveRows(QModelIndex(), index, index); beginRemoveRows(QModelIndex(), index, index);
VersionPatches.removeAt(index); VersionPatches.removeAt(index);
@ -504,8 +505,10 @@ void InstanceVersion::installJarModByFilename(QString filepath)
f->name = target_name; f->name = target_name;
f->fileId = target_id; f->fileId = target_id;
f->order = getFreeOrderNumber(); f->order = getFreeOrderNumber();
QString patchFileName = PathCombine(patchDir, target_id + ".json");
f->filename = patchFileName;
QFile file(PathCombine(patchDir, target_id + ".json")); QFile file(patchFileName);
if (!file.open(QFile::WriteOnly)) if (!file.open(QFile::WriteOnly))
{ {
QLOG_ERROR() << "Error opening" << file.fileName() QLOG_ERROR() << "Error opening" << file.fileName()

View File

@ -111,8 +111,14 @@ void VersionBuilder::readInstancePatches()
continue; continue;
// parse the file // parse the file
QString filename = patches.absoluteFilePath(id + ".json"); QString filename = patches.absoluteFilePath(id + ".json");
QFileInfo finfo(filename);
if(!finfo.exists())
{
QLOG_INFO() << "Patch file " << filename << " was deleted by external means...";
continue;
}
QLOG_INFO() << "Reading" << filename << "by user order"; QLOG_INFO() << "Reading" << filename << "by user order";
auto file = parseJsonFile(QFileInfo(filename), false); auto file = parseJsonFile(finfo, false);
// sanity check. prevent tampering with files. // sanity check. prevent tampering with files.
if (file->fileId != id) if (file->fileId != id)
{ {