Introducing VersionPatch base class for version files and minecraft versions
This commit is contained in:
parent
8a3a0f5a52
commit
9860d5ee12
@ -467,19 +467,27 @@ SET(MULTIMC_SOURCES
|
||||
logic/OneSixInstance_p.h
|
||||
|
||||
# OneSix version json infrastructure
|
||||
logic/minecraft/JarMod.cpp
|
||||
logic/minecraft/JarMod.h
|
||||
logic/minecraft/MinecraftVersion.cpp
|
||||
logic/minecraft/MinecraftVersion.h
|
||||
logic/minecraft/OneSixVersionBuilder.h
|
||||
logic/minecraft/OneSixVersionBuilder.cpp
|
||||
logic/minecraft/VersionFile.h
|
||||
logic/minecraft/VersionFile.cpp
|
||||
logic/minecraft/VersionFinal.h
|
||||
logic/minecraft/VersionFinal.cpp
|
||||
logic/minecraft/OneSixLibrary.h
|
||||
logic/minecraft/OneSixLibrary.cpp
|
||||
logic/minecraft/OneSixRule.h
|
||||
logic/minecraft/OneSixRule.cpp
|
||||
logic/minecraft/MinecraftVersionList.h
|
||||
logic/minecraft/MinecraftVersionList.cpp
|
||||
logic/minecraft/MinecraftVersionList.h
|
||||
logic/minecraft/OneSixLibrary.cpp
|
||||
logic/minecraft/OneSixLibrary.h
|
||||
logic/minecraft/OneSixRule.cpp
|
||||
logic/minecraft/OneSixRule.h
|
||||
logic/minecraft/OpSys.cpp
|
||||
logic/minecraft/OpSys.h
|
||||
logic/minecraft/RawLibrary.cpp
|
||||
logic/minecraft/RawLibrary.h
|
||||
logic/minecraft/VersionBuilder.cpp
|
||||
logic/minecraft/VersionBuilder.h
|
||||
logic/minecraft/VersionFile.cpp
|
||||
logic/minecraft/VersionFile.h
|
||||
logic/minecraft/VersionFinal.cpp
|
||||
logic/minecraft/VersionFinal.h
|
||||
logic/minecraft/VersionPatch.h
|
||||
|
||||
# Trivial operating system utilities
|
||||
logic/minecraft/OpSys.h
|
||||
|
@ -40,7 +40,7 @@
|
||||
#include "logic/forge/ForgeInstaller.h"
|
||||
#include "logic/liteloader/LiteLoaderVersionList.h"
|
||||
#include "logic/liteloader/LiteLoaderInstaller.h"
|
||||
#include "logic/minecraft/OneSixVersionBuilder.h"
|
||||
#include "logic/minecraft/VersionBuilder.h"
|
||||
#include "logic/auth/MojangAccountList.h"
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include "logic/minecraft/VersionFinal.h"
|
||||
#include "logic/minecraft/OneSixLibrary.h"
|
||||
#include "logic/minecraft/OneSixVersionBuilder.h"
|
||||
#include "logic/minecraft/VersionBuilder.h"
|
||||
#include "tasks/SequentialTask.h"
|
||||
#include "forge/ForgeInstaller.h"
|
||||
#include "forge/ForgeVersionList.h"
|
||||
|
@ -480,7 +480,7 @@ void OneSixUpdate::fmllibsStart()
|
||||
|
||||
// determine if we need some libs for FML or forge
|
||||
setStatus(tr("Checking for FML libraries..."));
|
||||
forge_present = (fullversion->versionFile("net.minecraftforge") != nullptr);
|
||||
forge_present = (fullversion->versionPatch("net.minecraftforge") != nullptr);
|
||||
// we don't...
|
||||
if (!forge_present)
|
||||
{
|
||||
|
44
logic/minecraft/JarMod.cpp
Normal file
44
logic/minecraft/JarMod.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
#include "JarMod.h"
|
||||
#include "logic/MMCJson.h"
|
||||
|
||||
JarmodPtr Jarmod::fromJson(const QJsonObject &libObj, const QString &filename)
|
||||
{
|
||||
JarmodPtr out(new Jarmod());
|
||||
if (!libObj.contains("name"))
|
||||
{
|
||||
throw JSONValidationError(filename +
|
||||
"contains a jarmod that doesn't have a 'name' field");
|
||||
}
|
||||
out->name = libObj.value("name").toString();
|
||||
|
||||
auto readString = [libObj, filename](const QString & key, QString & variable)
|
||||
{
|
||||
if (libObj.contains(key))
|
||||
{
|
||||
QJsonValue val = libObj.value(key);
|
||||
if (!val.isString())
|
||||
{
|
||||
QLOG_WARN() << key << "is not a string in" << filename << "(skipping)";
|
||||
}
|
||||
else
|
||||
{
|
||||
variable = val.toString();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
readString("url", out->baseurl);
|
||||
readString("MMC-absoluteUrl", out->absoluteUrl);
|
||||
if(!out->baseurl.isEmpty() && out->absoluteUrl.isEmpty())
|
||||
{
|
||||
out->absoluteUrl = out->baseurl + out->name;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
QString Jarmod::url()
|
||||
{
|
||||
if(!absoluteUrl.isEmpty())
|
||||
return absoluteUrl;
|
||||
else return baseurl + name;
|
||||
}
|
17
logic/minecraft/JarMod.h
Normal file
17
logic/minecraft/JarMod.h
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include <QString>
|
||||
#include <QJsonObject>
|
||||
#include <memory>
|
||||
class Jarmod;
|
||||
typedef std::shared_ptr<Jarmod> JarmodPtr;
|
||||
class Jarmod
|
||||
{
|
||||
public: /* methods */
|
||||
static JarmodPtr fromJson(const QJsonObject &libObj, const QString &filename);
|
||||
QString url();
|
||||
public: /* data */
|
||||
QString name;
|
||||
QString baseurl;
|
||||
QString hint;
|
||||
QString absoluteUrl;
|
||||
};
|
2
logic/minecraft/MinecraftVersion.cpp
Normal file
2
logic/minecraft/MinecraftVersion.cpp
Normal file
@ -0,0 +1,2 @@
|
||||
#include "MinecraftVersion.h"
|
||||
|
@ -16,10 +16,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "logic/BaseVersion.h"
|
||||
#include "VersionPatch.h"
|
||||
#include <QStringList>
|
||||
#include <QSet>
|
||||
|
||||
struct MinecraftVersion : public BaseVersion
|
||||
struct MinecraftVersion : public BaseVersion, public VersionPatch
|
||||
{
|
||||
/// The version's timestamp - this is primarily used for sorting versions in a list.
|
||||
qint64 timestamp;
|
||||
@ -89,4 +90,19 @@ struct MinecraftVersion : public BaseVersion
|
||||
return QObject::tr("Regular release");
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool hasJarMods() override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool isVanilla() override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void applyTo(VersionFinal *version)
|
||||
{
|
||||
// umm... what now?
|
||||
}
|
||||
};
|
||||
|
@ -18,6 +18,15 @@
|
||||
|
||||
#include "OneSixRule.h"
|
||||
|
||||
RuleAction RuleAction_fromString(QString name)
|
||||
{
|
||||
if (name == "allow")
|
||||
return Allow;
|
||||
if (name == "disallow")
|
||||
return Disallow;
|
||||
return Defer;
|
||||
}
|
||||
|
||||
QList<std::shared_ptr<Rule>> rulesFromJsonV4(const QJsonObject &objectWithRules)
|
||||
{
|
||||
QList<std::shared_ptr<Rule>> rules;
|
||||
@ -79,11 +88,3 @@ QJsonObject OsRule::toJson()
|
||||
return ruleObj;
|
||||
}
|
||||
|
||||
RuleAction RuleAction_fromString(QString name)
|
||||
{
|
||||
if (name == "allow")
|
||||
return Allow;
|
||||
if (name == "disallow")
|
||||
return Disallow;
|
||||
return Defer;
|
||||
}
|
||||
|
@ -26,7 +26,6 @@ enum RuleAction
|
||||
Defer
|
||||
};
|
||||
|
||||
RuleAction RuleAction_fromString(QString);
|
||||
QList<std::shared_ptr<Rule>> rulesFromJsonV4(const QJsonObject &objectWithRules);
|
||||
|
||||
class Rule
|
||||
|
68
logic/minecraft/RawLibrary.cpp
Normal file
68
logic/minecraft/RawLibrary.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
#include "logic/MMCJson.h"
|
||||
using namespace MMCJson;
|
||||
|
||||
#include "RawLibrary.h"
|
||||
|
||||
RawLibraryPtr RawLibrary::fromJson(const QJsonObject &libObj, const QString &filename)
|
||||
{
|
||||
RawLibraryPtr out(new RawLibrary());
|
||||
if (!libObj.contains("name"))
|
||||
{
|
||||
throw JSONValidationError(filename +
|
||||
"contains a library that doesn't have a 'name' field");
|
||||
}
|
||||
out->name = libObj.value("name").toString();
|
||||
|
||||
auto readString = [libObj, filename](const QString & key, QString & variable)
|
||||
{
|
||||
if (libObj.contains(key))
|
||||
{
|
||||
QJsonValue val = libObj.value(key);
|
||||
if (!val.isString())
|
||||
{
|
||||
QLOG_WARN() << key << "is not a string in" << filename << "(skipping)";
|
||||
}
|
||||
else
|
||||
{
|
||||
variable = val.toString();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
readString("url", out->url);
|
||||
readString("MMC-hint", out->hint);
|
||||
readString("MMC-absulute_url", out->absoluteUrl);
|
||||
readString("MMC-absoluteUrl", out->absoluteUrl);
|
||||
if (libObj.contains("extract"))
|
||||
{
|
||||
out->applyExcludes = true;
|
||||
auto extractObj = ensureObject(libObj.value("extract"));
|
||||
for (auto excludeVal : ensureArray(extractObj.value("exclude")))
|
||||
{
|
||||
out->excludes.append(ensureString(excludeVal));
|
||||
}
|
||||
}
|
||||
if (libObj.contains("natives"))
|
||||
{
|
||||
out->applyNatives = true;
|
||||
QJsonObject nativesObj = ensureObject(libObj.value("natives"));
|
||||
for (auto it = nativesObj.begin(); it != nativesObj.end(); ++it)
|
||||
{
|
||||
if (!it.value().isString())
|
||||
{
|
||||
QLOG_WARN() << filename << "contains an invalid native (skipping)";
|
||||
}
|
||||
OpSys opSys = OpSys_fromString(it.key());
|
||||
if (opSys != Os_Other)
|
||||
{
|
||||
out->natives.append(qMakePair(opSys, it.value().toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (libObj.contains("rules"))
|
||||
{
|
||||
out->applyRules = true;
|
||||
out->rules = rulesFromJsonV4(libObj);
|
||||
}
|
||||
return out;
|
||||
}
|
47
logic/minecraft/RawLibrary.h
Normal file
47
logic/minecraft/RawLibrary.h
Normal file
@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
#include <QString>
|
||||
#include <QPair>
|
||||
#include <memory>
|
||||
|
||||
#include "OneSixRule.h"
|
||||
|
||||
class RawLibrary;
|
||||
typedef std::shared_ptr<RawLibrary> RawLibraryPtr;
|
||||
|
||||
class RawLibrary
|
||||
{
|
||||
public: /* methods */
|
||||
static RawLibraryPtr fromJson(const QJsonObject &libObj, const QString &filename);
|
||||
|
||||
public: /* data */
|
||||
QString name;
|
||||
QString url;
|
||||
QString hint;
|
||||
QString absoluteUrl;
|
||||
|
||||
bool applyExcludes = false;
|
||||
QStringList excludes;
|
||||
|
||||
bool applyNatives = false;
|
||||
QList<QPair<OpSys, QString>> natives;
|
||||
|
||||
bool applyRules = false;
|
||||
QList<std::shared_ptr<Rule>> rules;
|
||||
|
||||
// user for '+' libraries
|
||||
enum InsertType
|
||||
{
|
||||
Apply,
|
||||
Append,
|
||||
Prepend,
|
||||
Replace
|
||||
} insertType = Append;
|
||||
QString insertData;
|
||||
|
||||
// soft or hard dependency? hard means 'needs equal', soft means 'needs equal or newer'
|
||||
enum DependType
|
||||
{
|
||||
Soft,
|
||||
Hard
|
||||
} dependType = Soft;
|
||||
};
|
@ -25,7 +25,7 @@
|
||||
#include <QDebug>
|
||||
#include <modutils.h>
|
||||
|
||||
#include "logic/minecraft/OneSixVersionBuilder.h"
|
||||
#include "logic/minecraft/VersionBuilder.h"
|
||||
#include "logic/minecraft/VersionFinal.h"
|
||||
#include "logic/minecraft/OneSixRule.h"
|
||||
#include "logic/minecraft/VersionFile.h"
|
||||
@ -35,28 +35,28 @@
|
||||
|
||||
#include "logger/QsLog.h"
|
||||
|
||||
OneSixVersionBuilder::OneSixVersionBuilder()
|
||||
VersionBuilder::VersionBuilder()
|
||||
{
|
||||
}
|
||||
|
||||
void OneSixVersionBuilder::build(VersionFinal *version, OneSixInstance *instance, const QStringList &external)
|
||||
void VersionBuilder::build(VersionFinal *version, OneSixInstance *instance, const QStringList &external)
|
||||
{
|
||||
OneSixVersionBuilder builder;
|
||||
VersionBuilder builder;
|
||||
builder.m_version = version;
|
||||
builder.m_instance = instance;
|
||||
builder.buildInternal(external);
|
||||
}
|
||||
|
||||
void OneSixVersionBuilder::readJsonAndApplyToVersion(VersionFinal *version,
|
||||
void VersionBuilder::readJsonAndApplyToVersion(VersionFinal *version,
|
||||
const QJsonObject &obj)
|
||||
{
|
||||
OneSixVersionBuilder builder;
|
||||
VersionBuilder builder;
|
||||
builder.m_version = version;
|
||||
builder.m_instance = 0;
|
||||
builder.readJsonAndApply(obj);
|
||||
}
|
||||
|
||||
void OneSixVersionBuilder::buildInternal(const QStringList &external)
|
||||
void VersionBuilder::buildInternal(const QStringList &external)
|
||||
{
|
||||
m_version->versionFiles.clear();
|
||||
|
||||
@ -139,7 +139,7 @@ void OneSixVersionBuilder::buildInternal(const QStringList &external)
|
||||
|
||||
|
||||
|
||||
void OneSixVersionBuilder::readJsonAndApply(const QJsonObject &obj)
|
||||
void VersionBuilder::readJsonAndApply(const QJsonObject &obj)
|
||||
{
|
||||
m_version->clear();
|
||||
|
||||
@ -153,7 +153,7 @@ void OneSixVersionBuilder::readJsonAndApply(const QJsonObject &obj)
|
||||
// version of MultiMC"));
|
||||
}
|
||||
|
||||
VersionFilePtr OneSixVersionBuilder::parseJsonFile(const QFileInfo &fileInfo,
|
||||
VersionFilePtr VersionBuilder::parseJsonFile(const QFileInfo &fileInfo,
|
||||
const bool requireOrder, bool isFTB)
|
||||
{
|
||||
QFile file(fileInfo.absoluteFilePath());
|
||||
@ -175,7 +175,7 @@ VersionFilePtr OneSixVersionBuilder::parseJsonFile(const QFileInfo &fileInfo,
|
||||
// info.").arg(file.fileName());
|
||||
}
|
||||
|
||||
QMap<QString, int> OneSixVersionBuilder::readOverrideOrders(OneSixInstance *instance)
|
||||
QMap<QString, int> VersionBuilder::readOverrideOrders(OneSixInstance *instance)
|
||||
{
|
||||
QMap<QString, int> out;
|
||||
|
||||
@ -225,7 +225,7 @@ QMap<QString, int> OneSixVersionBuilder::readOverrideOrders(OneSixInstance *inst
|
||||
return out;
|
||||
}
|
||||
|
||||
bool OneSixVersionBuilder::writeOverrideOrders(const QMap<QString, int> &order,
|
||||
bool VersionBuilder::writeOverrideOrders(const QMap<QString, int> &order,
|
||||
OneSixInstance *instance)
|
||||
{
|
||||
QJsonObject obj;
|
@ -24,9 +24,9 @@ class OneSixInstance;
|
||||
class QJsonObject;
|
||||
class QFileInfo;
|
||||
|
||||
class OneSixVersionBuilder
|
||||
class VersionBuilder
|
||||
{
|
||||
OneSixVersionBuilder();
|
||||
VersionBuilder();
|
||||
public:
|
||||
static void build(VersionFinal *version, OneSixInstance *instance, const QStringList &external);
|
||||
static void readJsonAndApplyToVersion(VersionFinal *version, const QJsonObject &obj);
|
@ -7,111 +7,28 @@
|
||||
#include "logic/minecraft/VersionFile.h"
|
||||
#include "logic/minecraft/OneSixLibrary.h"
|
||||
#include "logic/minecraft/VersionFinal.h"
|
||||
#include "logic/MMCJson.h"
|
||||
#include "logic/minecraft/JarMod.h"
|
||||
|
||||
#include "logic/MMCJson.h"
|
||||
using namespace MMCJson;
|
||||
|
||||
#define CURRENT_MINIMUM_LAUNCHER_VERSION 14
|
||||
|
||||
JarmodPtr Jarmod::fromJson(const QJsonObject &libObj, const QString &filename)
|
||||
int findLibrary(QList<OneSixLibraryPtr> haystack, const QString &needle)
|
||||
{
|
||||
JarmodPtr out(new Jarmod());
|
||||
if (!libObj.contains("name"))
|
||||
int retval = -1;
|
||||
for (int i = 0; i < haystack.size(); ++i)
|
||||
{
|
||||
throw JSONValidationError(filename +
|
||||
"contains a jarmod that doesn't have a 'name' field");
|
||||
}
|
||||
out->name = libObj.value("name").toString();
|
||||
|
||||
auto readString = [libObj, filename](const QString & key, QString & variable)
|
||||
{
|
||||
if (libObj.contains(key))
|
||||
QString chunk = haystack.at(i)->rawName();
|
||||
if (QRegExp(needle, Qt::CaseSensitive, QRegExp::WildcardUnix).indexIn(chunk) != -1)
|
||||
{
|
||||
QJsonValue val = libObj.value(key);
|
||||
if (!val.isString())
|
||||
{
|
||||
QLOG_WARN() << key << "is not a string in" << filename << "(skipping)";
|
||||
}
|
||||
else
|
||||
{
|
||||
variable = val.toString();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
readString("url", out->baseurl);
|
||||
readString("MMC-absoluteUrl", out->absoluteUrl);
|
||||
if(!out->baseurl.isEmpty() && out->absoluteUrl.isEmpty())
|
||||
{
|
||||
out->absoluteUrl = out->baseurl + out->name;
|
||||
}
|
||||
return out;
|
||||
|
||||
}
|
||||
|
||||
|
||||
RawLibraryPtr RawLibrary::fromJson(const QJsonObject &libObj, const QString &filename)
|
||||
{
|
||||
RawLibraryPtr out(new RawLibrary());
|
||||
if (!libObj.contains("name"))
|
||||
{
|
||||
throw JSONValidationError(filename +
|
||||
"contains a library that doesn't have a 'name' field");
|
||||
}
|
||||
out->name = libObj.value("name").toString();
|
||||
|
||||
auto readString = [libObj, filename](const QString & key, QString & variable)
|
||||
{
|
||||
if (libObj.contains(key))
|
||||
{
|
||||
QJsonValue val = libObj.value(key);
|
||||
if (!val.isString())
|
||||
{
|
||||
QLOG_WARN() << key << "is not a string in" << filename << "(skipping)";
|
||||
}
|
||||
else
|
||||
{
|
||||
variable = val.toString();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
readString("url", out->url);
|
||||
readString("MMC-hint", out->hint);
|
||||
readString("MMC-absulute_url", out->absoluteUrl);
|
||||
readString("MMC-absoluteUrl", out->absoluteUrl);
|
||||
if (libObj.contains("extract"))
|
||||
{
|
||||
out->applyExcludes = true;
|
||||
auto extractObj = ensureObject(libObj.value("extract"));
|
||||
for (auto excludeVal : ensureArray(extractObj.value("exclude")))
|
||||
{
|
||||
out->excludes.append(ensureString(excludeVal));
|
||||
// only one is allowed.
|
||||
if(retval != -1)
|
||||
return -1;
|
||||
retval = i;
|
||||
}
|
||||
}
|
||||
if (libObj.contains("natives"))
|
||||
{
|
||||
out->applyNatives = true;
|
||||
QJsonObject nativesObj = ensureObject(libObj.value("natives"));
|
||||
for (auto it = nativesObj.begin(); it != nativesObj.end(); ++it)
|
||||
{
|
||||
if (!it.value().isString())
|
||||
{
|
||||
QLOG_WARN() << filename << "contains an invalid native (skipping)";
|
||||
}
|
||||
OpSys opSys = OpSys_fromString(it.key());
|
||||
if (opSys != Os_Other)
|
||||
{
|
||||
out->natives.append(qMakePair(opSys, it.value().toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (libObj.contains("rules"))
|
||||
{
|
||||
out->applyRules = true;
|
||||
out->rules = rulesFromJsonV4(libObj);
|
||||
}
|
||||
return out;
|
||||
return retval;
|
||||
}
|
||||
|
||||
VersionFilePtr VersionFile::fromJson(const QJsonDocument &doc, const QString &filename,
|
||||
@ -351,23 +268,6 @@ OneSixLibraryPtr VersionFile::createLibrary(RawLibraryPtr lib)
|
||||
return out;
|
||||
}
|
||||
|
||||
int VersionFile::findLibrary(QList<OneSixLibraryPtr> haystack, const QString &needle)
|
||||
{
|
||||
int retval = -1;
|
||||
for (int i = 0; i < haystack.size(); ++i)
|
||||
{
|
||||
QString chunk = haystack.at(i)->rawName();
|
||||
if (QRegExp(needle, Qt::CaseSensitive, QRegExp::WildcardUnix).indexIn(chunk) != -1)
|
||||
{
|
||||
// only one is allowed.
|
||||
if(retval != -1)
|
||||
return -1;
|
||||
retval = i;
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
bool VersionFile::isVanilla()
|
||||
{
|
||||
return fileId == "org.multimc.version.json";
|
||||
|
@ -5,10 +5,14 @@
|
||||
#include <memory>
|
||||
#include "logic/minecraft/OpSys.h"
|
||||
#include "logic/minecraft/OneSixRule.h"
|
||||
#include "VersionPatch.h"
|
||||
#include "MMCError.h"
|
||||
#include "RawLibrary.h"
|
||||
#include "JarMod.h"
|
||||
|
||||
class VersionFinal;
|
||||
|
||||
|
||||
class VersionBuildError : public MMCError
|
||||
{
|
||||
public:
|
||||
@ -46,66 +50,19 @@ public:
|
||||
virtual ~MinecraftVersionMismatch() noexcept {}
|
||||
};
|
||||
|
||||
struct RawLibrary;
|
||||
typedef std::shared_ptr<RawLibrary> RawLibraryPtr;
|
||||
struct RawLibrary
|
||||
{
|
||||
QString name;
|
||||
QString url;
|
||||
QString hint;
|
||||
QString absoluteUrl;
|
||||
bool applyExcludes = false;
|
||||
QStringList excludes;
|
||||
bool applyNatives = false;
|
||||
QList<QPair<OpSys, QString>> natives;
|
||||
bool applyRules = false;
|
||||
QList<std::shared_ptr<Rule>> rules;
|
||||
|
||||
// user for '+' libraries
|
||||
enum InsertType
|
||||
{
|
||||
Apply,
|
||||
Append,
|
||||
Prepend,
|
||||
Replace
|
||||
};
|
||||
InsertType insertType = Append;
|
||||
QString insertData;
|
||||
enum DependType
|
||||
{
|
||||
Soft,
|
||||
Hard
|
||||
};
|
||||
DependType dependType = Soft;
|
||||
|
||||
static RawLibraryPtr fromJson(const QJsonObject &libObj, const QString &filename);
|
||||
};
|
||||
|
||||
struct Jarmod;
|
||||
typedef std::shared_ptr<Jarmod> JarmodPtr;
|
||||
struct Jarmod
|
||||
{
|
||||
QString name;
|
||||
QString baseurl;
|
||||
QString hint;
|
||||
QString absoluteUrl;
|
||||
|
||||
static JarmodPtr fromJson(const QJsonObject &libObj, const QString &filename);
|
||||
};
|
||||
|
||||
struct VersionFile;
|
||||
typedef std::shared_ptr<VersionFile> VersionFilePtr;
|
||||
struct VersionFile
|
||||
class VersionFile : public VersionPatch
|
||||
{
|
||||
public: /* methods */
|
||||
static VersionFilePtr fromJson(const QJsonDocument &doc, const QString &filename,
|
||||
const bool requireOrder, const bool isFTB = false);
|
||||
|
||||
static OneSixLibraryPtr createLibrary(RawLibraryPtr lib);
|
||||
int findLibrary(QList<OneSixLibraryPtr> haystack, const QString &needle);
|
||||
void applyTo(VersionFinal *version);
|
||||
bool isVanilla();
|
||||
bool hasJarMods();
|
||||
virtual void applyTo(VersionFinal *version) override;
|
||||
virtual bool isVanilla() override;
|
||||
virtual bool hasJarMods() override;
|
||||
|
||||
public: /* data */
|
||||
int order = 0;
|
||||
QString name;
|
||||
@ -143,3 +100,5 @@ public: /* data */
|
||||
|
||||
QList<JarmodPtr> jarMods;
|
||||
};
|
||||
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include <pathutils.h>
|
||||
|
||||
#include "logic/minecraft/VersionFinal.h"
|
||||
#include "logic/minecraft/OneSixVersionBuilder.h"
|
||||
#include "logic/minecraft/VersionBuilder.h"
|
||||
#include "logic/OneSixInstance.h"
|
||||
|
||||
VersionFinal::VersionFinal(OneSixInstance *instance, QObject *parent)
|
||||
@ -31,7 +31,7 @@ VersionFinal::VersionFinal(OneSixInstance *instance, QObject *parent)
|
||||
void VersionFinal::reload(const QStringList &external)
|
||||
{
|
||||
beginResetModel();
|
||||
OneSixVersionBuilder::build(this, m_instance, external);
|
||||
VersionBuilder::build(this, m_instance, external);
|
||||
reapply(true);
|
||||
endResetModel();
|
||||
}
|
||||
@ -116,7 +116,7 @@ QString VersionFinal::versionFileId(const int index) const
|
||||
return versionFiles.at(index)->fileId;
|
||||
}
|
||||
|
||||
VersionFilePtr VersionFinal::versionFile(const QString &id)
|
||||
VersionFilePtr VersionFinal::versionPatch(const QString &id)
|
||||
{
|
||||
for (auto file : versionFiles)
|
||||
{
|
||||
@ -135,7 +135,7 @@ bool VersionFinal::hasJarMods()
|
||||
|
||||
bool VersionFinal::hasFtbPack()
|
||||
{
|
||||
return versionFile("org.multimc.ftb.pack.json") != nullptr;
|
||||
return versionPatch("org.multimc.ftb.pack.json") != nullptr;
|
||||
}
|
||||
|
||||
bool VersionFinal::removeFtbPack()
|
||||
@ -216,7 +216,7 @@ std::shared_ptr<VersionFinal> VersionFinal::fromJson(const QJsonObject &obj)
|
||||
std::shared_ptr<VersionFinal> version(new VersionFinal(0));
|
||||
try
|
||||
{
|
||||
OneSixVersionBuilder::readJsonAndApplyToVersion(version.get(), obj);
|
||||
VersionBuilder::readJsonAndApplyToVersion(version.get(), obj);
|
||||
}
|
||||
catch(MMCError & err)
|
||||
{
|
||||
@ -299,7 +299,7 @@ QMap<QString, int> VersionFinal::getExistingOrder() const
|
||||
}
|
||||
// overriden
|
||||
{
|
||||
QMap<QString, int> overridenOrder = OneSixVersionBuilder::readOverrideOrders(m_instance);
|
||||
QMap<QString, int> overridenOrder = VersionBuilder::readOverrideOrders(m_instance);
|
||||
for (auto id : order.keys())
|
||||
{
|
||||
if (overridenOrder.contains(id))
|
||||
@ -348,7 +348,7 @@ void VersionFinal::move(const int index, const MoveDirection direction)
|
||||
order[ourId] = theirIndex;
|
||||
order[theirId] = index;
|
||||
|
||||
if (!OneSixVersionBuilder::writeOverrideOrders(order, m_instance))
|
||||
if (!VersionBuilder::writeOverrideOrders(order, m_instance))
|
||||
{
|
||||
throw MMCError(tr("Couldn't save the new order"));
|
||||
}
|
||||
@ -378,7 +378,7 @@ void VersionFinal::reapply(const bool alreadyReseting)
|
||||
QList<VersionFilePtr> newVersionFiles;
|
||||
for (auto order : orders)
|
||||
{
|
||||
auto file = versionFile(existingOrders.key(order));
|
||||
auto file = versionPatch(existingOrders.key(order));
|
||||
newVersionFiles.append(file);
|
||||
file->applyTo(this);
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
#include "OneSixLibrary.h"
|
||||
#include "VersionFile.h"
|
||||
#include "JarMod.h"
|
||||
|
||||
class OneSixInstance;
|
||||
|
||||
@ -164,7 +165,7 @@ public:
|
||||
// QList<Rule> rules;
|
||||
|
||||
QList<VersionFilePtr> versionFiles;
|
||||
VersionFilePtr versionFile(const QString &id);
|
||||
VersionFilePtr versionPatch(const QString &id);
|
||||
|
||||
private:
|
||||
OneSixInstance *m_instance;
|
||||
|
15
logic/minecraft/VersionPatch.h
Normal file
15
logic/minecraft/VersionPatch.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
class VersionFinal;
|
||||
class VersionPatch
|
||||
{
|
||||
public:
|
||||
virtual ~VersionPatch(){};
|
||||
virtual void applyTo(VersionFinal *version) = 0;
|
||||
virtual bool isVanilla() = 0;
|
||||
virtual bool hasJarMods() = 0;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<VersionPatch> VersionPatchPtr;
|
Loading…
Reference in New Issue
Block a user