NOISSUE move version file reading and writing to dedicated namespaces
This commit is contained in:
parent
17ad1e64f8
commit
a0b47aee5b
@ -163,6 +163,8 @@ set(LOGIC_SOURCES
|
|||||||
minecraft/onesix/OneSixInstance.cpp
|
minecraft/onesix/OneSixInstance.cpp
|
||||||
minecraft/onesix/OneSixProfileStrategy.cpp
|
minecraft/onesix/OneSixProfileStrategy.cpp
|
||||||
minecraft/onesix/OneSixProfileStrategy.h
|
minecraft/onesix/OneSixProfileStrategy.h
|
||||||
|
minecraft/onesix/OneSixVersionFormat.cpp
|
||||||
|
minecraft/onesix/OneSixVersionFormat.h
|
||||||
minecraft/legacy/LegacyUpdate.h
|
minecraft/legacy/LegacyUpdate.h
|
||||||
minecraft/legacy/LegacyUpdate.cpp
|
minecraft/legacy/LegacyUpdate.cpp
|
||||||
minecraft/legacy/LegacyInstance.h
|
minecraft/legacy/LegacyInstance.h
|
||||||
@ -174,6 +176,8 @@ set(LOGIC_SOURCES
|
|||||||
minecraft/GradleSpecifier.h
|
minecraft/GradleSpecifier.h
|
||||||
minecraft/MinecraftProfile.cpp
|
minecraft/MinecraftProfile.cpp
|
||||||
minecraft/MinecraftProfile.h
|
minecraft/MinecraftProfile.h
|
||||||
|
minecraft/MojangVersionFormat.cpp
|
||||||
|
minecraft/MojangVersionFormat.h
|
||||||
minecraft/JarMod.cpp
|
minecraft/JarMod.cpp
|
||||||
minecraft/JarMod.h
|
minecraft/JarMod.h
|
||||||
minecraft/MinecraftInstance.cpp
|
minecraft/MinecraftInstance.cpp
|
||||||
|
@ -68,7 +68,6 @@ void MinecraftProfile::clear()
|
|||||||
assets.clear();
|
assets.clear();
|
||||||
processArguments.clear();
|
processArguments.clear();
|
||||||
minecraftArguments.clear();
|
minecraftArguments.clear();
|
||||||
minimumLauncherVersion = 0xDEADBEAF;
|
|
||||||
mainClass.clear();
|
mainClass.clear();
|
||||||
appletClass.clear();
|
appletClass.clear();
|
||||||
libraries.clear();
|
libraries.clear();
|
||||||
@ -267,23 +266,6 @@ QList<std::shared_ptr<RawLibrary> > MinecraftProfile::getActiveNativeLibs()
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<MinecraftProfile> MinecraftProfile::fromJson(const QJsonObject &obj)
|
|
||||||
{
|
|
||||||
std::shared_ptr<MinecraftProfile> version(new MinecraftProfile(new NullProfileStrategy()));
|
|
||||||
try
|
|
||||||
{
|
|
||||||
version->clear();
|
|
||||||
auto file = VersionFile::fromJson(QJsonDocument(obj), QString(), false);
|
|
||||||
file->applyTo(version.get());
|
|
||||||
version->appendPatch(file);
|
|
||||||
}
|
|
||||||
catch(Exception &err)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant MinecraftProfile::data(const QModelIndex &index, int role) const
|
QVariant MinecraftProfile::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
|
@ -39,9 +39,6 @@ class MULTIMC_LOGIC_EXPORT MinecraftProfile : public QAbstractListModel
|
|||||||
public:
|
public:
|
||||||
explicit MinecraftProfile(ProfileStrategy *strategy);
|
explicit MinecraftProfile(ProfileStrategy *strategy);
|
||||||
|
|
||||||
/// construct a MinecraftProfile from a single file
|
|
||||||
static std::shared_ptr<MinecraftProfile> fromJson(const QJsonObject &obj);
|
|
||||||
|
|
||||||
void setStrategy(ProfileStrategy * strategy);
|
void setStrategy(ProfileStrategy * strategy);
|
||||||
ProfileStrategy *strategy();
|
ProfileStrategy *strategy();
|
||||||
|
|
||||||
@ -152,11 +149,6 @@ public: /* data */
|
|||||||
QString minecraftArguments;
|
QString minecraftArguments;
|
||||||
/// Same as above, but only for vanilla
|
/// Same as above, but only for vanilla
|
||||||
QString vanillaMinecraftArguments;
|
QString vanillaMinecraftArguments;
|
||||||
/**
|
|
||||||
* the minimum launcher version required by this version ... current is 4 (at point of
|
|
||||||
* writing)
|
|
||||||
*/
|
|
||||||
int minimumLauncherVersion = 0xDEADBEEF;
|
|
||||||
/**
|
/**
|
||||||
* A list of all tweaker classes
|
* A list of all tweaker classes
|
||||||
*/
|
*/
|
||||||
|
@ -64,7 +64,7 @@ void MinecraftVersion::applyFileTo(MinecraftProfile *version)
|
|||||||
throw VersionIncomplete(QObject::tr("Can't apply incomplete/builtin Minecraft version %1").arg(m_name));
|
throw VersionIncomplete(QObject::tr("Can't apply incomplete/builtin Minecraft version %1").arg(m_name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
QJsonDocument MinecraftVersion::toJson(bool saveOrder)
|
QJsonDocument MinecraftVersion::toJson(bool saveOrder)
|
||||||
{
|
{
|
||||||
if(m_versionSource == Local && getVersionFile())
|
if(m_versionSource == Local && getVersionFile())
|
||||||
@ -76,6 +76,7 @@ QJsonDocument MinecraftVersion::toJson(bool saveOrder)
|
|||||||
throw VersionIncomplete(QObject::tr("Can't write incomplete/builtin Minecraft version %1").arg(m_name));
|
throw VersionIncomplete(QObject::tr("Can't write incomplete/builtin Minecraft version %1").arg(m_name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
QString MinecraftVersion::getUrl() const
|
QString MinecraftVersion::getUrl() const
|
||||||
{
|
{
|
||||||
|
@ -74,7 +74,7 @@ public: /* methods */
|
|||||||
|
|
||||||
VersionFilePtr getVersionFile();
|
VersionFilePtr getVersionFile();
|
||||||
|
|
||||||
virtual QJsonDocument toJson(bool saveOrder) override;
|
// virtual QJsonDocument toJson(bool saveOrder) override;
|
||||||
|
|
||||||
QString getUrl() const;
|
QString getUrl() const;
|
||||||
|
|
||||||
|
@ -27,6 +27,8 @@
|
|||||||
#include "ParseUtils.h"
|
#include "ParseUtils.h"
|
||||||
#include "ProfileUtils.h"
|
#include "ProfileUtils.h"
|
||||||
#include "VersionFilterData.h"
|
#include "VersionFilterData.h"
|
||||||
|
#include "onesix/OneSixVersionFormat.h"
|
||||||
|
#include "MojangVersionFormat.h"
|
||||||
#include <FileSystem.h>
|
#include <FileSystem.h>
|
||||||
|
|
||||||
static const char * localVersionCache = "versions/versions.dat";
|
static const char * localVersionCache = "versions/versions.dat";
|
||||||
@ -510,7 +512,7 @@ void MCVListVersionUpdateTask::json_downloaded()
|
|||||||
VersionFilePtr file;
|
VersionFilePtr file;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
file = VersionFile::fromMojangJson(jsonDoc, "net.minecraft.json");
|
file = MojangVersionFormat::fromJson(jsonDoc, "net.minecraft.json");
|
||||||
}
|
}
|
||||||
catch (Exception &e)
|
catch (Exception &e)
|
||||||
{
|
{
|
||||||
@ -526,7 +528,7 @@ void MCVListVersionUpdateTask::json_downloaded()
|
|||||||
file->fileId = "net.minecraft";
|
file->fileId = "net.minecraft";
|
||||||
|
|
||||||
// now dump the file to disk
|
// now dump the file to disk
|
||||||
auto doc = file->toJson(false);
|
auto doc = OneSixVersionFormat::toJson(file, false);
|
||||||
auto newdata = doc.toBinaryData();
|
auto newdata = doc.toBinaryData();
|
||||||
auto id = updatedVersion->descriptor();
|
auto id = updatedVersion->descriptor();
|
||||||
QString targetPath = "versions/" + id + "/" + id + ".dat";
|
QString targetPath = "versions/" + id + "/" + id + ".dat";
|
||||||
|
71
logic/minecraft/MojangVersionFormat.cpp
Normal file
71
logic/minecraft/MojangVersionFormat.cpp
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
#include "MojangVersionFormat.h"
|
||||||
|
|
||||||
|
#include "Json.h"
|
||||||
|
using namespace Json;
|
||||||
|
|
||||||
|
static const int CURRENT_MINIMUM_LAUNCHER_VERSION = 14;
|
||||||
|
|
||||||
|
// FIXME: duplicated in OneSixVersionFormat!
|
||||||
|
static void readString(const QJsonObject &root, const QString &key, QString &variable)
|
||||||
|
{
|
||||||
|
if (root.contains(key))
|
||||||
|
{
|
||||||
|
variable = requireString(root.value(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
VersionFilePtr MojangVersionFormat::fromJson(const QJsonDocument &doc, const QString &filename)
|
||||||
|
{
|
||||||
|
VersionFilePtr out(new VersionFile());
|
||||||
|
if (doc.isEmpty() || doc.isNull())
|
||||||
|
{
|
||||||
|
throw JSONValidationError(filename + " is empty or null");
|
||||||
|
}
|
||||||
|
if (!doc.isObject())
|
||||||
|
{
|
||||||
|
throw JSONValidationError(filename + " is not an object");
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject root = doc.object();
|
||||||
|
|
||||||
|
out->name = root.value("name").toString();
|
||||||
|
out->fileId = root.value("fileId").toString();
|
||||||
|
out->version = root.value("version").toString();
|
||||||
|
out->mcVersion = root.value("mcVersion").toString();
|
||||||
|
out->filename = filename;
|
||||||
|
|
||||||
|
readString(root, "id", out->id);
|
||||||
|
|
||||||
|
readString(root, "mainClass", out->mainClass);
|
||||||
|
readString(root, "appletClass", out->appletClass);
|
||||||
|
readString(root, "minecraftArguments", out->overwriteMinecraftArguments);
|
||||||
|
readString(root, "type", out->type);
|
||||||
|
|
||||||
|
readString(root, "assets", out->assets);
|
||||||
|
|
||||||
|
if (root.contains("minimumLauncherVersion"))
|
||||||
|
{
|
||||||
|
auto minimumLauncherVersion = requireInteger(root.value("minimumLauncherVersion"));
|
||||||
|
if (minimumLauncherVersion > CURRENT_MINIMUM_LAUNCHER_VERSION)
|
||||||
|
{
|
||||||
|
out->addProblem(
|
||||||
|
PROBLEM_WARNING,
|
||||||
|
QObject::tr("The 'minimumLauncherVersion' value of this version (%1) is higher than supported by MultiMC (%2). It might not work properly!")
|
||||||
|
.arg(minimumLauncherVersion)
|
||||||
|
.arg(CURRENT_MINIMUM_LAUNCHER_VERSION));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (root.contains("libraries"))
|
||||||
|
{
|
||||||
|
out->shouldOverwriteLibs = true;
|
||||||
|
for (auto libVal : requireArray(root.value("libraries")))
|
||||||
|
{
|
||||||
|
auto libObj = requireObject(libVal);
|
||||||
|
|
||||||
|
auto lib = RawLibrary::fromJson(libObj, filename);
|
||||||
|
out->overwriteLibs.append(lib);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
8
logic/minecraft/MojangVersionFormat.h
Normal file
8
logic/minecraft/MojangVersionFormat.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <minecraft/VersionFile.h>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
|
||||||
|
namespace MojangVersionFormat {
|
||||||
|
VersionFilePtr fromJson(const QJsonDocument &doc, const QString &filename);
|
||||||
|
}
|
@ -40,7 +40,6 @@ class ProfilePatch
|
|||||||
public:
|
public:
|
||||||
virtual ~ProfilePatch(){};
|
virtual ~ProfilePatch(){};
|
||||||
virtual void applyTo(MinecraftProfile *version) = 0;
|
virtual void applyTo(MinecraftProfile *version) = 0;
|
||||||
virtual QJsonDocument toJson(bool saveOrder) = 0;
|
|
||||||
|
|
||||||
virtual bool isMinecraftVersion() = 0;
|
virtual bool isMinecraftVersion() = 0;
|
||||||
virtual bool hasJarMods() = 0;
|
virtual bool hasJarMods() = 0;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "ProfileUtils.h"
|
#include "ProfileUtils.h"
|
||||||
#include "minecraft/VersionFilterData.h"
|
#include "minecraft/VersionFilterData.h"
|
||||||
|
#include "minecraft/onesix/OneSixVersionFormat.h"
|
||||||
#include "Json.h"
|
#include "Json.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
@ -128,7 +129,7 @@ VersionFilePtr parseJsonFile(const QFileInfo &fileInfo, const bool requireOrder)
|
|||||||
.arg(fileInfo.fileName(), error.errorString())
|
.arg(fileInfo.fileName(), error.errorString())
|
||||||
.arg(line).arg(column));
|
.arg(line).arg(column));
|
||||||
}
|
}
|
||||||
return VersionFile::fromJson(doc, file.fileName(), requireOrder);
|
return OneSixVersionFormat::fromJson(doc, file.fileName(), requireOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
VersionFilePtr parseBinaryJsonFile(const QFileInfo &fileInfo)
|
VersionFilePtr parseBinaryJsonFile(const QFileInfo &fileInfo)
|
||||||
@ -147,7 +148,7 @@ VersionFilePtr parseBinaryJsonFile(const QFileInfo &fileInfo)
|
|||||||
throw JSONValidationError(
|
throw JSONValidationError(
|
||||||
QObject::tr("Unable to process the version file %1.").arg(fileInfo.fileName()));
|
QObject::tr("Unable to process the version file %1.").arg(fileInfo.fileName()));
|
||||||
}
|
}
|
||||||
return VersionFile::fromJson(doc, file.fileName(), false);
|
return OneSixVersionFormat::fromJson(doc, file.fileName(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeLwjglFromPatch(VersionFilePtr patch)
|
void removeLwjglFromPatch(VersionFilePtr patch)
|
||||||
|
@ -9,29 +9,9 @@
|
|||||||
#include "minecraft/JarMod.h"
|
#include "minecraft/JarMod.h"
|
||||||
#include "ParseUtils.h"
|
#include "ParseUtils.h"
|
||||||
|
|
||||||
#include "Json.h"
|
|
||||||
using namespace Json;
|
|
||||||
|
|
||||||
#include "VersionBuildError.h"
|
#include "VersionBuildError.h"
|
||||||
#include <Version.h>
|
#include <Version.h>
|
||||||
|
|
||||||
static void readString(const QJsonObject &root, const QString &key, QString &variable)
|
|
||||||
{
|
|
||||||
if (root.contains(key))
|
|
||||||
{
|
|
||||||
variable = requireString(root.value(key));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static QString readStringRet(const QJsonObject &root, const QString &key)
|
|
||||||
{
|
|
||||||
if (root.contains(key))
|
|
||||||
{
|
|
||||||
return requireString(root.value(key));
|
|
||||||
}
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
int findLibraryByName(QList<RawLibraryPtr> haystack, const GradleSpecifier &needle)
|
int findLibraryByName(QList<RawLibraryPtr> haystack, const GradleSpecifier &needle)
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
@ -48,246 +28,6 @@ int findLibraryByName(QList<RawLibraryPtr> haystack, const GradleSpecifier &need
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkMinimumLauncherVersion(VersionFilePtr out)
|
|
||||||
{
|
|
||||||
const int CURRENT_MINIMUM_LAUNCHER_VERSION = 14;
|
|
||||||
if (out->minimumLauncherVersion > CURRENT_MINIMUM_LAUNCHER_VERSION)
|
|
||||||
{
|
|
||||||
out->addProblem(
|
|
||||||
PROBLEM_WARNING,
|
|
||||||
QObject::tr("The 'minimumLauncherVersion' value of this version (%1) is higher than supported by MultiMC (%2). It might not work properly!")
|
|
||||||
.arg(out->minimumLauncherVersion)
|
|
||||||
.arg(CURRENT_MINIMUM_LAUNCHER_VERSION));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
VersionFilePtr VersionFile::fromMojangJson(const QJsonDocument &doc, const QString &filename)
|
|
||||||
{
|
|
||||||
VersionFilePtr out(new VersionFile());
|
|
||||||
if (doc.isEmpty() || doc.isNull())
|
|
||||||
{
|
|
||||||
throw JSONValidationError(filename + " is empty or null");
|
|
||||||
}
|
|
||||||
if (!doc.isObject())
|
|
||||||
{
|
|
||||||
throw JSONValidationError(filename + " is not an object");
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonObject root = doc.object();
|
|
||||||
|
|
||||||
out->name = root.value("name").toString();
|
|
||||||
out->fileId = root.value("fileId").toString();
|
|
||||||
out->version = root.value("version").toString();
|
|
||||||
out->mcVersion = root.value("mcVersion").toString();
|
|
||||||
out->filename = filename;
|
|
||||||
|
|
||||||
readString(root, "id", out->id);
|
|
||||||
|
|
||||||
readString(root, "mainClass", out->mainClass);
|
|
||||||
readString(root, "appletClass", out->appletClass);
|
|
||||||
readString(root, "minecraftArguments", out->overwriteMinecraftArguments);
|
|
||||||
readString(root, "type", out->type);
|
|
||||||
|
|
||||||
readString(root, "assets", out->assets);
|
|
||||||
|
|
||||||
if (root.contains("minimumLauncherVersion"))
|
|
||||||
{
|
|
||||||
out->minimumLauncherVersion = requireInteger(root.value("minimumLauncherVersion"));
|
|
||||||
checkMinimumLauncherVersion(out);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (root.contains("libraries"))
|
|
||||||
{
|
|
||||||
out->shouldOverwriteLibs = true;
|
|
||||||
for (auto libVal : requireArray(root.value("libraries")))
|
|
||||||
{
|
|
||||||
auto libObj = requireObject(libVal);
|
|
||||||
|
|
||||||
auto lib = RawLibrary::fromJson(libObj, filename);
|
|
||||||
out->overwriteLibs.append(lib);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
VersionFilePtr VersionFile::fromJson(const QJsonDocument &doc, const QString &filename, const bool requireOrder)
|
|
||||||
{
|
|
||||||
VersionFilePtr out(new VersionFile());
|
|
||||||
if (doc.isEmpty() || doc.isNull())
|
|
||||||
{
|
|
||||||
throw JSONValidationError(filename + " is empty or null");
|
|
||||||
}
|
|
||||||
if (!doc.isObject())
|
|
||||||
{
|
|
||||||
throw JSONValidationError(filename + " is not an object");
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonObject root = doc.object();
|
|
||||||
|
|
||||||
if (requireOrder)
|
|
||||||
{
|
|
||||||
if (root.contains("order"))
|
|
||||||
{
|
|
||||||
out->order = requireInteger(root.value("order"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// FIXME: evaluate if we don't want to throw exceptions here instead
|
|
||||||
qCritical() << filename << "doesn't contain an order field";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
out->name = root.value("name").toString();
|
|
||||||
out->fileId = root.value("fileId").toString();
|
|
||||||
out->version = root.value("version").toString();
|
|
||||||
out->mcVersion = root.value("mcVersion").toString();
|
|
||||||
out->filename = filename;
|
|
||||||
|
|
||||||
readString(root, "id", out->id);
|
|
||||||
|
|
||||||
readString(root, "mainClass", out->mainClass);
|
|
||||||
readString(root, "appletClass", out->appletClass);
|
|
||||||
readString(root, "processArguments", out->processArguments);
|
|
||||||
readString(root, "minecraftArguments", out->overwriteMinecraftArguments);
|
|
||||||
readString(root, "+minecraftArguments", out->addMinecraftArguments);
|
|
||||||
readString(root, "type", out->type);
|
|
||||||
|
|
||||||
parse_timestamp(readStringRet(root, "releaseTime"), out->m_releaseTimeString, out->m_releaseTime);
|
|
||||||
parse_timestamp(readStringRet(root, "time"), out->m_updateTimeString, out->m_updateTime);
|
|
||||||
|
|
||||||
readString(root, "assets", out->assets);
|
|
||||||
|
|
||||||
if (root.contains("minimumLauncherVersion"))
|
|
||||||
{
|
|
||||||
out->minimumLauncherVersion = requireInteger(root.value("minimumLauncherVersion"));
|
|
||||||
checkMinimumLauncherVersion(out);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (root.contains("tweakers"))
|
|
||||||
{
|
|
||||||
out->shouldOverwriteTweakers = true;
|
|
||||||
for (auto tweakerVal : requireArray(root.value("tweakers")))
|
|
||||||
{
|
|
||||||
out->overwriteTweakers.append(requireString(tweakerVal));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (root.contains("+tweakers"))
|
|
||||||
{
|
|
||||||
for (auto tweakerVal : requireArray(root.value("+tweakers")))
|
|
||||||
{
|
|
||||||
out->addTweakers.append(requireString(tweakerVal));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (root.contains("+traits"))
|
|
||||||
{
|
|
||||||
for (auto tweakerVal : requireArray(root.value("+traits")))
|
|
||||||
{
|
|
||||||
out->traits.insert(requireString(tweakerVal));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (root.contains("libraries"))
|
|
||||||
{
|
|
||||||
out->shouldOverwriteLibs = true;
|
|
||||||
for (auto libVal : requireArray(root.value("libraries")))
|
|
||||||
{
|
|
||||||
auto libObj = requireObject(libVal);
|
|
||||||
|
|
||||||
auto lib = RawLibrary::fromJson(libObj, filename);
|
|
||||||
out->overwriteLibs.append(lib);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (root.contains("+jarMods"))
|
|
||||||
{
|
|
||||||
for (auto libVal : requireArray(root.value("+jarMods")))
|
|
||||||
{
|
|
||||||
QJsonObject libObj = requireObject(libVal);
|
|
||||||
// parse the jarmod
|
|
||||||
auto lib = Jarmod::fromJson(libObj, filename, out->name);
|
|
||||||
if(lib->originalName.isEmpty())
|
|
||||||
{
|
|
||||||
auto fixed = out->name;
|
|
||||||
fixed.remove(" (jar mod)");
|
|
||||||
lib->originalName = out->name;
|
|
||||||
}
|
|
||||||
// and add to jar mods
|
|
||||||
out->jarMods.append(lib);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (root.contains("+libraries"))
|
|
||||||
{
|
|
||||||
for (auto libVal : requireArray(root.value("+libraries")))
|
|
||||||
{
|
|
||||||
QJsonObject libObj = requireObject(libVal);
|
|
||||||
// parse the library
|
|
||||||
auto lib = RawLibrary::fromJson(libObj, filename);
|
|
||||||
out->addLibs.append(lib);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* removed features that shouldn't be used */
|
|
||||||
if (root.contains("-libraries"))
|
|
||||||
{
|
|
||||||
out->addProblem(PROBLEM_ERROR, QObject::tr("Version file contains unsupported element '-libraries'"));
|
|
||||||
}
|
|
||||||
if (root.contains("-tweakers"))
|
|
||||||
{
|
|
||||||
out->addProblem(PROBLEM_ERROR, QObject::tr("Version file contains unsupported element '-tweakers'"));
|
|
||||||
}
|
|
||||||
if (root.contains("-minecraftArguments"))
|
|
||||||
{
|
|
||||||
out->addProblem(PROBLEM_ERROR, QObject::tr("Version file contains unsupported element '-minecraftArguments'"));
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonDocument VersionFile::toJson(bool saveOrder)
|
|
||||||
{
|
|
||||||
QJsonObject root;
|
|
||||||
if (saveOrder)
|
|
||||||
{
|
|
||||||
root.insert("order", order);
|
|
||||||
}
|
|
||||||
writeString(root, "name", name);
|
|
||||||
writeString(root, "fileId", fileId);
|
|
||||||
writeString(root, "version", version);
|
|
||||||
writeString(root, "mcVersion", mcVersion);
|
|
||||||
writeString(root, "id", id);
|
|
||||||
writeString(root, "mainClass", mainClass);
|
|
||||||
writeString(root, "appletClass", appletClass);
|
|
||||||
writeString(root, "processArguments", processArguments);
|
|
||||||
writeString(root, "minecraftArguments", overwriteMinecraftArguments);
|
|
||||||
writeString(root, "+minecraftArguments", addMinecraftArguments);
|
|
||||||
writeString(root, "type", type);
|
|
||||||
writeString(root, "assets", assets);
|
|
||||||
if (isMinecraftVersion())
|
|
||||||
{
|
|
||||||
writeString(root, "releaseTime", m_releaseTimeString);
|
|
||||||
writeString(root, "time", m_updateTimeString);
|
|
||||||
}
|
|
||||||
if (minimumLauncherVersion != -1)
|
|
||||||
{
|
|
||||||
root.insert("minimumLauncherVersion", minimumLauncherVersion);
|
|
||||||
}
|
|
||||||
writeStringList(root, "tweakers", overwriteTweakers);
|
|
||||||
writeStringList(root, "+tweakers", addTweakers);
|
|
||||||
writeStringList(root, "+traits", traits.toList());
|
|
||||||
writeObjectList(root, "libraries", overwriteLibs);
|
|
||||||
writeObjectList(root, "+libraries", addLibs);
|
|
||||||
writeObjectList(root, "+jarMods", jarMods);
|
|
||||||
// write the contents to a json document.
|
|
||||||
{
|
|
||||||
QJsonDocument out;
|
|
||||||
out.setObject(root);
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool VersionFile::isMinecraftVersion()
|
bool VersionFile::isMinecraftVersion()
|
||||||
{
|
{
|
||||||
return fileId == "net.minecraft";
|
return fileId == "net.minecraft";
|
||||||
@ -350,11 +90,6 @@ void VersionFile::applyTo(MinecraftProfile *version)
|
|||||||
{
|
{
|
||||||
version->assets = assets;
|
version->assets = assets;
|
||||||
}
|
}
|
||||||
if (minimumLauncherVersion >= 0)
|
|
||||||
{
|
|
||||||
if (version->minimumLauncherVersion < minimumLauncherVersion)
|
|
||||||
version->minimumLauncherVersion = minimumLauncherVersion;
|
|
||||||
}
|
|
||||||
if (!overwriteMinecraftArguments.isNull())
|
if (!overwriteMinecraftArguments.isNull())
|
||||||
{
|
{
|
||||||
if (isMinecraftVersion())
|
if (isMinecraftVersion())
|
||||||
|
@ -19,11 +19,6 @@ typedef std::shared_ptr<VersionFile> VersionFilePtr;
|
|||||||
class VersionFile : public ProfilePatch
|
class VersionFile : public ProfilePatch
|
||||||
{
|
{
|
||||||
public: /* methods */
|
public: /* methods */
|
||||||
static VersionFilePtr fromMojangJson(const QJsonDocument &doc, const QString &filename);
|
|
||||||
static VersionFilePtr fromJson(const QJsonDocument &doc, const QString &filename,
|
|
||||||
const bool requireOrder);
|
|
||||||
virtual QJsonDocument toJson(bool saveOrder) override;
|
|
||||||
|
|
||||||
virtual void applyTo(MinecraftProfile *version) override;
|
virtual void applyTo(MinecraftProfile *version) override;
|
||||||
virtual bool isMinecraftVersion() override;
|
virtual bool isMinecraftVersion() override;
|
||||||
virtual bool hasJarMods() override;
|
virtual bool hasJarMods() override;
|
||||||
@ -139,7 +134,6 @@ public: /* data */
|
|||||||
|
|
||||||
/// asset group used by this ... thing.
|
/// asset group used by this ... thing.
|
||||||
QString assets;
|
QString assets;
|
||||||
int minimumLauncherVersion = -1;
|
|
||||||
|
|
||||||
bool shouldOverwriteTweakers = false;
|
bool shouldOverwriteTweakers = false;
|
||||||
QStringList overwriteTweakers;
|
QStringList overwriteTweakers;
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "net/HttpMetaCache.h"
|
#include "net/HttpMetaCache.h"
|
||||||
#include "tasks/Task.h"
|
#include "tasks/Task.h"
|
||||||
#include "minecraft/onesix/OneSixInstance.h"
|
#include "minecraft/onesix/OneSixInstance.h"
|
||||||
|
#include <minecraft/onesix/OneSixVersionFormat.h>
|
||||||
#include "minecraft/VersionFilterData.h"
|
#include "minecraft/VersionFilterData.h"
|
||||||
#include "Env.h"
|
#include "Env.h"
|
||||||
#include "Exception.h"
|
#include "Exception.h"
|
||||||
@ -76,7 +77,7 @@ void ForgeInstaller::prepare(const QString &filename, const QString &universalUr
|
|||||||
|
|
||||||
// read the forge version info
|
// read the forge version info
|
||||||
{
|
{
|
||||||
newVersion = MinecraftProfile::fromJson(versionInfoVal.toObject());
|
newVersion = OneSixVersionFormat::readProfileFromSingleFile(versionInfoVal.toObject());
|
||||||
if (!newVersion)
|
if (!newVersion)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "OneSixProfileStrategy.h"
|
#include "OneSixProfileStrategy.h"
|
||||||
#include "OneSixInstance.h"
|
#include "OneSixInstance.h"
|
||||||
|
#include "OneSixVersionFormat.h"
|
||||||
|
|
||||||
#include "minecraft/VersionBuildError.h"
|
#include "minecraft/VersionBuildError.h"
|
||||||
#include "minecraft/MinecraftVersionList.h"
|
#include "minecraft/MinecraftVersionList.h"
|
||||||
@ -55,7 +56,7 @@ void OneSixProfileStrategy::upgradeDeprecatedFiles()
|
|||||||
file->fileId = "net.minecraft";
|
file->fileId = "net.minecraft";
|
||||||
file->version = file->id;
|
file->version = file->id;
|
||||||
file->name = "Minecraft";
|
file->name = "Minecraft";
|
||||||
auto data = file->toJson(false).toJson();
|
auto data = OneSixVersionFormat::toJson(file, false).toJson();
|
||||||
QSaveFile newPatchFile(mcJson);
|
QSaveFile newPatchFile(mcJson);
|
||||||
if(!newPatchFile.open(QIODevice::WriteOnly))
|
if(!newPatchFile.open(QIODevice::WriteOnly))
|
||||||
{
|
{
|
||||||
@ -300,7 +301,7 @@ bool OneSixProfileStrategy::customizePatch(ProfilePatchPtr patch)
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
auto document = patch->toJson(true);
|
auto document = OneSixVersionFormat::toJson(patch, true);
|
||||||
jsonFile.write(document.toJson());
|
jsonFile.write(document.toJson());
|
||||||
if(!jsonFile.commit())
|
if(!jsonFile.commit())
|
||||||
{
|
{
|
||||||
@ -403,7 +404,7 @@ bool OneSixProfileStrategy::installJarMods(QStringList filepaths)
|
|||||||
<< "for reading:" << file.errorString();
|
<< "for reading:" << file.errorString();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
file.write(f->toJson(true).toJson());
|
file.write(OneSixVersionFormat::toJson(f, true).toJson());
|
||||||
file.close();
|
file.close();
|
||||||
profile->appendPatch(f);
|
profile->appendPatch(f);
|
||||||
}
|
}
|
||||||
|
218
logic/minecraft/onesix/OneSixVersionFormat.cpp
Normal file
218
logic/minecraft/onesix/OneSixVersionFormat.cpp
Normal file
@ -0,0 +1,218 @@
|
|||||||
|
#include "OneSixVersionFormat.h"
|
||||||
|
#include <minecraft/NullProfileStrategy.h>
|
||||||
|
#include <Json.h>
|
||||||
|
#include "minecraft/ParseUtils.h"
|
||||||
|
|
||||||
|
using namespace Json;
|
||||||
|
|
||||||
|
static void readString(const QJsonObject &root, const QString &key, QString &variable)
|
||||||
|
{
|
||||||
|
if (root.contains(key))
|
||||||
|
{
|
||||||
|
variable = requireString(root.value(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static QString readStringRet(const QJsonObject &root, const QString &key)
|
||||||
|
{
|
||||||
|
if (root.contains(key))
|
||||||
|
{
|
||||||
|
return requireString(root.value(key));
|
||||||
|
}
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
VersionFilePtr OneSixVersionFormat::fromJson(const QJsonDocument &doc, const QString &filename, const bool requireOrder)
|
||||||
|
{
|
||||||
|
VersionFilePtr out(new VersionFile());
|
||||||
|
if (doc.isEmpty() || doc.isNull())
|
||||||
|
{
|
||||||
|
throw JSONValidationError(filename + " is empty or null");
|
||||||
|
}
|
||||||
|
if (!doc.isObject())
|
||||||
|
{
|
||||||
|
throw JSONValidationError(filename + " is not an object");
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject root = doc.object();
|
||||||
|
|
||||||
|
if (requireOrder)
|
||||||
|
{
|
||||||
|
if (root.contains("order"))
|
||||||
|
{
|
||||||
|
out->order = requireInteger(root.value("order"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// FIXME: evaluate if we don't want to throw exceptions here instead
|
||||||
|
qCritical() << filename << "doesn't contain an order field";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
out->name = root.value("name").toString();
|
||||||
|
out->fileId = root.value("fileId").toString();
|
||||||
|
out->version = root.value("version").toString();
|
||||||
|
out->mcVersion = root.value("mcVersion").toString();
|
||||||
|
out->filename = filename;
|
||||||
|
|
||||||
|
readString(root, "id", out->id);
|
||||||
|
|
||||||
|
readString(root, "mainClass", out->mainClass);
|
||||||
|
readString(root, "appletClass", out->appletClass);
|
||||||
|
readString(root, "processArguments", out->processArguments);
|
||||||
|
readString(root, "minecraftArguments", out->overwriteMinecraftArguments);
|
||||||
|
readString(root, "+minecraftArguments", out->addMinecraftArguments);
|
||||||
|
readString(root, "type", out->type);
|
||||||
|
|
||||||
|
parse_timestamp(readStringRet(root, "releaseTime"), out->m_releaseTimeString, out->m_releaseTime);
|
||||||
|
parse_timestamp(readStringRet(root, "time"), out->m_updateTimeString, out->m_updateTime);
|
||||||
|
|
||||||
|
readString(root, "assets", out->assets);
|
||||||
|
|
||||||
|
if (root.contains("tweakers"))
|
||||||
|
{
|
||||||
|
out->shouldOverwriteTweakers = true;
|
||||||
|
for (auto tweakerVal : requireArray(root.value("tweakers")))
|
||||||
|
{
|
||||||
|
out->overwriteTweakers.append(requireString(tweakerVal));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (root.contains("+tweakers"))
|
||||||
|
{
|
||||||
|
for (auto tweakerVal : requireArray(root.value("+tweakers")))
|
||||||
|
{
|
||||||
|
out->addTweakers.append(requireString(tweakerVal));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (root.contains("+traits"))
|
||||||
|
{
|
||||||
|
for (auto tweakerVal : requireArray(root.value("+traits")))
|
||||||
|
{
|
||||||
|
out->traits.insert(requireString(tweakerVal));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (root.contains("libraries"))
|
||||||
|
{
|
||||||
|
out->shouldOverwriteLibs = true;
|
||||||
|
for (auto libVal : requireArray(root.value("libraries")))
|
||||||
|
{
|
||||||
|
auto libObj = requireObject(libVal);
|
||||||
|
|
||||||
|
auto lib = RawLibrary::fromJson(libObj, filename);
|
||||||
|
out->overwriteLibs.append(lib);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (root.contains("+jarMods"))
|
||||||
|
{
|
||||||
|
for (auto libVal : requireArray(root.value("+jarMods")))
|
||||||
|
{
|
||||||
|
QJsonObject libObj = requireObject(libVal);
|
||||||
|
// parse the jarmod
|
||||||
|
auto lib = Jarmod::fromJson(libObj, filename, out->name);
|
||||||
|
if(lib->originalName.isEmpty())
|
||||||
|
{
|
||||||
|
auto fixed = out->name;
|
||||||
|
fixed.remove(" (jar mod)");
|
||||||
|
lib->originalName = out->name;
|
||||||
|
}
|
||||||
|
// and add to jar mods
|
||||||
|
out->jarMods.append(lib);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (root.contains("+libraries"))
|
||||||
|
{
|
||||||
|
for (auto libVal : requireArray(root.value("+libraries")))
|
||||||
|
{
|
||||||
|
QJsonObject libObj = requireObject(libVal);
|
||||||
|
// parse the library
|
||||||
|
auto lib = RawLibrary::fromJson(libObj, filename);
|
||||||
|
out->addLibs.append(lib);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* removed features that shouldn't be used */
|
||||||
|
if (root.contains("-libraries"))
|
||||||
|
{
|
||||||
|
out->addProblem(PROBLEM_ERROR, QObject::tr("Version file contains unsupported element '-libraries'"));
|
||||||
|
}
|
||||||
|
if (root.contains("-tweakers"))
|
||||||
|
{
|
||||||
|
out->addProblem(PROBLEM_ERROR, QObject::tr("Version file contains unsupported element '-tweakers'"));
|
||||||
|
}
|
||||||
|
if (root.contains("-minecraftArguments"))
|
||||||
|
{
|
||||||
|
out->addProblem(PROBLEM_ERROR, QObject::tr("Version file contains unsupported element '-minecraftArguments'"));
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
static QJsonDocument versionFileToJson(VersionFilePtr patch, bool saveOrder)
|
||||||
|
{
|
||||||
|
QJsonObject root;
|
||||||
|
if (saveOrder)
|
||||||
|
{
|
||||||
|
root.insert("order", patch->order);
|
||||||
|
}
|
||||||
|
writeString(root, "name", patch->name);
|
||||||
|
writeString(root, "fileId", patch->fileId);
|
||||||
|
writeString(root, "version", patch->version);
|
||||||
|
writeString(root, "mcVersion", patch->mcVersion);
|
||||||
|
writeString(root, "id", patch->id);
|
||||||
|
writeString(root, "mainClass", patch->mainClass);
|
||||||
|
writeString(root, "appletClass", patch->appletClass);
|
||||||
|
writeString(root, "processArguments", patch->processArguments);
|
||||||
|
writeString(root, "minecraftArguments", patch->overwriteMinecraftArguments);
|
||||||
|
writeString(root, "+minecraftArguments", patch->addMinecraftArguments);
|
||||||
|
writeString(root, "type", patch->type);
|
||||||
|
writeString(root, "assets", patch->assets);
|
||||||
|
if (patch->isMinecraftVersion())
|
||||||
|
{
|
||||||
|
writeString(root, "releaseTime", patch->m_releaseTimeString);
|
||||||
|
writeString(root, "time", patch->m_updateTimeString);
|
||||||
|
}
|
||||||
|
writeStringList(root, "tweakers", patch->overwriteTweakers);
|
||||||
|
writeStringList(root, "+tweakers", patch->addTweakers);
|
||||||
|
writeStringList(root, "+traits", patch->traits.toList());
|
||||||
|
writeObjectList(root, "libraries", patch->overwriteLibs);
|
||||||
|
writeObjectList(root, "+libraries", patch->addLibs);
|
||||||
|
writeObjectList(root, "+jarMods", patch->jarMods);
|
||||||
|
// write the contents to a json document.
|
||||||
|
{
|
||||||
|
QJsonDocument out;
|
||||||
|
out.setObject(root);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonDocument OneSixVersionFormat::toJson(const ProfilePatchPtr &patch, bool saveOrder)
|
||||||
|
{
|
||||||
|
auto vfile = std::dynamic_pointer_cast<VersionFile>(patch);
|
||||||
|
if(vfile)
|
||||||
|
{
|
||||||
|
return versionFileToJson(vfile, saveOrder);
|
||||||
|
}
|
||||||
|
return QJsonDocument();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<MinecraftProfile> OneSixVersionFormat::readProfileFromSingleFile(const QJsonObject &obj)
|
||||||
|
{
|
||||||
|
std::shared_ptr<MinecraftProfile> version(new MinecraftProfile(new NullProfileStrategy()));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
version->clear();
|
||||||
|
auto file = fromJson(QJsonDocument(obj), QString(), false);
|
||||||
|
file->applyTo(version.get());
|
||||||
|
version->appendPatch(file);
|
||||||
|
}
|
||||||
|
catch(Exception &err)
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return version;
|
||||||
|
}
|
11
logic/minecraft/onesix/OneSixVersionFormat.h
Normal file
11
logic/minecraft/onesix/OneSixVersionFormat.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <minecraft/VersionFile.h>
|
||||||
|
#include <minecraft/MinecraftProfile.h>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
|
||||||
|
namespace OneSixVersionFormat {
|
||||||
|
std::shared_ptr<MinecraftProfile> readProfileFromSingleFile(const QJsonObject &obj);
|
||||||
|
VersionFilePtr fromJson(const QJsonDocument &doc, const QString &filename, const bool requireOrder);
|
||||||
|
QJsonDocument toJson(const ProfilePatchPtr &patch, bool saveOrder);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user