GH-1453 handle certain version loading corner cases better, clean up FTB

This commit is contained in:
Petr Mrázek 2016-02-21 05:51:36 +01:00
parent 1a0bbdd9ac
commit 401d5b698f
4 changed files with 38 additions and 88 deletions

View File

@ -15,6 +15,8 @@ FTBProfileStrategy::FTBProfileStrategy(OneSixFTBInstance* instance) : OneSixProf
void FTBProfileStrategy::loadDefaultBuiltinPatches() void FTBProfileStrategy::loadDefaultBuiltinPatches()
{ {
// FIXME: this should be here, but it needs us to be able to deal with multiple libraries paths
// OneSixProfileStrategy::loadDefaultBuiltinPatches();
auto mcVersion = m_instance->intendedVersionId(); auto mcVersion = m_instance->intendedVersionId();
ProfilePatchPtr minecraftPatch; ProfilePatchPtr minecraftPatch;
@ -78,86 +80,18 @@ void FTBProfileStrategy::loadDefaultBuiltinPatches()
} }
} }
} }
minecraftPatch = std::dynamic_pointer_cast<ProfilePatch>(file); packPatch = std::dynamic_pointer_cast<ProfilePatch>(file);
} }
else else
{ {
throw VersionIncomplete("org.multimc.ftb.pack"); throw VersionIncomplete("org.multimc.ftb.pack");
} }
minecraftPatch->setOrder(1); packPatch->setOrder(1);
} }
profile->appendPatch(minecraftPatch); profile->appendPatch(packPatch);
} }
void FTBProfileStrategy::loadUserPatches()
{
// load all patches, put into map for ordering, apply in the right order
ProfileUtils::PatchOrder userOrder;
ProfileUtils::readOverrideOrders(FS::PathCombine(m_instance->instanceRoot(), "order.json"), userOrder);
QDir patches(FS::PathCombine(m_instance->instanceRoot(),"patches"));
// first, load things by sort order.
for (auto id : userOrder)
{
// ignore builtins
if (id == "net.minecraft")
continue;
if (id == "org.lwjgl")
continue;
// parse the file
QString filename = patches.absoluteFilePath(id + ".json");
QFileInfo finfo(filename);
if(!finfo.exists())
{
qDebug() << "Patch file " << filename << " was deleted by external means...";
continue;
}
qDebug() << "Reading" << filename << "by user order";
auto file = ProfileUtils::parseJsonFile(finfo, false);
// sanity check. prevent tampering with files.
if (file->fileId != id)
{
throw VersionBuildError(
QObject::tr("load id %1 does not match internal id %2").arg(id, file->fileId));
}
file->setRemovable(true);
file->setMovable(true);
profile->appendPatch(file);
}
// now load the rest by internal preference.
QMap<int, QPair<QString, VersionFilePtr>> files;
for (auto info : patches.entryInfoList(QStringList() << "*.json", QDir::Files))
{
// parse the file
qDebug() << "Reading" << info.fileName();
auto file = ProfileUtils::parseJsonFile(info, true);
// ignore builtins
if (file->fileId == "net.minecraft")
continue;
if (file->fileId == "org.lwjgl")
continue;
// do not load what we already loaded in the first pass
if (userOrder.contains(file->fileId))
continue;
if (files.contains(file->order))
{
// FIXME: do not throw?
throw VersionBuildError(QObject::tr("%1 has the same order as %2")
.arg(file->fileId, files[file->order].second->fileId));
}
file->setRemovable(true);
file->setMovable(true);
files.insert(file->order, qMakePair(info.fileName(), file));
}
for (auto order : files.keys())
{
auto &filePair = files[order];
profile->appendPatch(filePair.second);
}
}
void FTBProfileStrategy::load() void FTBProfileStrategy::load()
{ {
profile->clearPatches(); profile->clearPatches();

View File

@ -17,6 +17,5 @@ public:
virtual bool revertPatch (ProfilePatchPtr patch) override; virtual bool revertPatch (ProfilePatchPtr patch) override;
protected: protected:
void loadDefaultBuiltinPatches(); virtual void loadDefaultBuiltinPatches() override;
void loadUserPatches();
}; };

View File

@ -140,6 +140,7 @@ void OneSixProfileStrategy::loadUserPatches()
ProfileUtils::PatchOrder userOrder; ProfileUtils::PatchOrder userOrder;
ProfileUtils::readOverrideOrders(FS::PathCombine(m_instance->instanceRoot(), "order.json"), userOrder); ProfileUtils::readOverrideOrders(FS::PathCombine(m_instance->instanceRoot(), "order.json"), userOrder);
QDir patches(FS::PathCombine(m_instance->instanceRoot(),"patches")); QDir patches(FS::PathCombine(m_instance->instanceRoot(),"patches"));
QSet<QString> seen_extra;
// first, load things by sort order. // first, load things by sort order.
for (auto id : userOrder) for (auto id : userOrder)
@ -158,19 +159,19 @@ void OneSixProfileStrategy::loadUserPatches()
continue; continue;
} }
qDebug() << "Reading" << filename << "by user order"; qDebug() << "Reading" << filename << "by user order";
auto file = ProfileUtils::parseJsonFile(finfo, false); VersionFilePtr file = ProfileUtils::parseJsonFile(finfo, false);
// sanity check. prevent tampering with files. // sanity check. prevent tampering with files.
if (file->fileId != id) if (file->fileId != id)
{ {
throw VersionBuildError( file->addProblem(PROBLEM_WARNING, QObject::tr("load id %1 does not match internal id %2").arg(id, file->fileId));
QObject::tr("load id %1 does not match internal id %2").arg(id, file->fileId)); seen_extra.insert(file->fileId);
} }
file->setRemovable(true); file->setRemovable(true);
file->setMovable(true); file->setMovable(true);
profile->appendPatch(file); profile->appendPatch(file);
} }
// now load the rest by internal preference. // now load the rest by internal preference.
QMap<int, QPair<QString, VersionFilePtr>> files; QMultiMap<int, VersionFilePtr> files;
for (auto info : patches.entryInfoList(QStringList() << "*.json", QDir::Files)) for (auto info : patches.entryInfoList(QStringList() << "*.json", QDir::Files))
{ {
// parse the file // parse the file
@ -181,23 +182,39 @@ void OneSixProfileStrategy::loadUserPatches()
continue; continue;
if (file->fileId == "org.lwjgl") if (file->fileId == "org.lwjgl")
continue; continue;
// do not load versions with broken IDs twice
if(seen_extra.contains(file->fileId))
continue;
// do not load what we already loaded in the first pass // do not load what we already loaded in the first pass
if (userOrder.contains(file->fileId)) if (userOrder.contains(file->fileId))
continue; continue;
if (files.contains(file->order))
{
// FIXME: do not throw?
throw VersionBuildError(QObject::tr("%1 has the same order as %2")
.arg(file->fileId, files[file->order].second->fileId));
}
file->setRemovable(true); file->setRemovable(true);
file->setMovable(true); file->setMovable(true);
files.insert(file->order, qMakePair(info.fileName(), file)); files.insert(file->order, file);
} }
QSet<int> seen;
for (auto order : files.keys()) for (auto order : files.keys())
{ {
auto &filePair = files[order]; if(seen.contains(order))
profile->appendPatch(filePair.second); continue;
seen.insert(order);
const auto &values = files.values(order);
if(values.size() == 1)
{
profile->appendPatch(values[0]);
continue;
}
for(auto &file: values)
{
QStringList list;
for(auto &file2: values)
{
if(file != file2)
list.append(file2->name);
}
file->addProblem(PROBLEM_WARNING, QObject::tr("%1 has the same order as the following components:\n%2").arg(file->name, list.join(", ")));
profile->appendPatch(file);
}
} }
} }

View File

@ -17,8 +17,8 @@ public:
virtual bool revertPatch(ProfilePatchPtr patch) override; virtual bool revertPatch(ProfilePatchPtr patch) override;
protected: protected:
void loadDefaultBuiltinPatches(); virtual void loadDefaultBuiltinPatches();
void loadUserPatches(); virtual void loadUserPatches();
void upgradeDeprecatedFiles(); void upgradeDeprecatedFiles();
protected: protected: