Allow overriding the order in which patches are applied
This commit is contained in:
@ -81,6 +81,15 @@ bool OneSixVersion::canRemove(const int index) const
|
||||
return false;
|
||||
}
|
||||
|
||||
QString OneSixVersion::versionFileId(const int index) const
|
||||
{
|
||||
if (index < 0 || index >= versionFiles.size())
|
||||
{
|
||||
return QString();
|
||||
}
|
||||
return versionFiles.at(index).id;
|
||||
}
|
||||
|
||||
bool OneSixVersion::remove(const int index)
|
||||
{
|
||||
if (canRemove(index))
|
||||
|
@ -44,6 +44,8 @@ public:
|
||||
|
||||
bool canRemove(const int index) const;
|
||||
|
||||
QString versionFileId(const int index) const;
|
||||
|
||||
public
|
||||
slots:
|
||||
bool remove(const int index);
|
||||
@ -123,6 +125,7 @@ public:
|
||||
QString version;
|
||||
QString mcVersion;
|
||||
QString filename;
|
||||
int order;
|
||||
};
|
||||
QList<VersionFile> versionFiles;
|
||||
|
||||
|
@ -763,6 +763,7 @@ struct VersionFile
|
||||
versionFile.version = this->version;
|
||||
versionFile.mcVersion = mcVersion;
|
||||
versionFile.filename = filename;
|
||||
versionFile.order = order;
|
||||
version->versionFiles.append(versionFile);
|
||||
|
||||
isError = false;
|
||||
@ -858,6 +859,7 @@ bool OneSixVersionBuilder::build(const bool onlyVanilla)
|
||||
// patches/
|
||||
{
|
||||
// load all, put into map for ordering, apply in the right order
|
||||
QMap<QString, int> overrideOrder = readOverrideOrders(m_instance);
|
||||
|
||||
QMap<int, QPair<QString, VersionFile>> files;
|
||||
for (auto info : patches.entryInfoList(QStringList() << "*.json", QDir::Files))
|
||||
@ -868,6 +870,15 @@ bool OneSixVersionBuilder::build(const bool onlyVanilla)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (overrideOrder.contains(file.fileId))
|
||||
{
|
||||
file.order = overrideOrder.value(file.fileId);
|
||||
}
|
||||
if (files.contains(file.order))
|
||||
{
|
||||
QLOG_ERROR() << file.fileId << "has the same order as" << files[file.order].second.fileId;
|
||||
return false;
|
||||
}
|
||||
files.insert(file.order, qMakePair(info.fileName(), file));
|
||||
}
|
||||
for (auto order : files.keys())
|
||||
@ -1007,3 +1018,60 @@ bool OneSixVersionBuilder::read(const QFileInfo &fileInfo, const bool requireOrd
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
QMap<QString, int> OneSixVersionBuilder::readOverrideOrders(OneSixInstance *instance)
|
||||
{
|
||||
QMap<QString, int> out;
|
||||
if (QDir(instance->instanceRoot()).exists("order.json"))
|
||||
{
|
||||
QFile orderFile(instance->instanceRoot() + "/order.json");
|
||||
if (!orderFile.open(QFile::ReadOnly))
|
||||
{
|
||||
QLOG_ERROR() << "Couldn't open" << orderFile.fileName() << " for reading:" << orderFile.errorString();
|
||||
QLOG_WARN() << "Ignoring overriden order";
|
||||
}
|
||||
else
|
||||
{
|
||||
QJsonParseError error;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(orderFile.readAll(), &error);
|
||||
if (error.error != QJsonParseError::NoError || !doc.isObject())
|
||||
{
|
||||
QLOG_ERROR() << "Couldn't parse" << orderFile.fileName() << ":" << error.errorString();
|
||||
QLOG_WARN() << "Ignoring overriden order";
|
||||
}
|
||||
else
|
||||
{
|
||||
QJsonObject obj = doc.object();
|
||||
for (auto it = obj.begin(); it != obj.end(); ++it)
|
||||
{
|
||||
if (it.key().startsWith("org.multimc."))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
out.insert(it.key(), it.value().toDouble());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
bool OneSixVersionBuilder::writeOverrideOrders(const QMap<QString, int> &order, OneSixInstance *instance)
|
||||
{
|
||||
QJsonObject obj;
|
||||
for (auto it = order.cbegin(); it != order.cend(); ++it)
|
||||
{
|
||||
if (it.key().startsWith("org.multimc."))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
obj.insert(it.key(), it.value());
|
||||
}
|
||||
QFile orderFile(instance->instanceRoot() + "/order.json");
|
||||
if (!orderFile.open(QFile::WriteOnly))
|
||||
{
|
||||
QLOG_ERROR() << "Couldn't open" << orderFile.fileName() << "for writing:" << orderFile.errorString();
|
||||
return false;
|
||||
}
|
||||
orderFile.write(QJsonDocument(obj).toJson(QJsonDocument::Indented));
|
||||
return true;
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <QMap>
|
||||
|
||||
class OneSixVersion;
|
||||
class OneSixInstance;
|
||||
@ -30,6 +31,8 @@ class OneSixVersionBuilder
|
||||
public:
|
||||
static bool build(OneSixVersion *version, OneSixInstance *instance, QWidget *widgetParent, const bool onlyVanilla);
|
||||
static bool read(OneSixVersion *version, const QJsonObject &obj);
|
||||
static QMap<QString, int> readOverrideOrders(OneSixInstance *instance);
|
||||
static bool writeOverrideOrders(const QMap<QString, int> &order, OneSixInstance *instance);
|
||||
|
||||
private:
|
||||
OneSixVersion *m_version;
|
||||
@ -40,4 +43,5 @@ private:
|
||||
bool read(const QJsonObject &obj);
|
||||
|
||||
bool read(const QFileInfo &fileInfo, const bool requireOrder, VersionFile *out);
|
||||
|
||||
};
|
||||
|
Reference in New Issue
Block a user