2016-02-27 21:02:56 +00:00
|
|
|
#include "MojangVersionFormat.h"
|
2016-02-28 18:01:54 +00:00
|
|
|
#include "onesix/OneSixVersionFormat.h"
|
|
|
|
#include "MinecraftVersion.h"
|
|
|
|
#include "VersionBuildError.h"
|
2016-02-27 21:02:56 +00:00
|
|
|
|
|
|
|
#include "Json.h"
|
|
|
|
using namespace Json;
|
2016-03-01 08:47:12 +00:00
|
|
|
#include "ParseUtils.h"
|
2016-02-27 21:02:56 +00:00
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-28 18:01:54 +00:00
|
|
|
VersionFilePtr MojangVersionFormat::versionFileFromJson(const QJsonDocument &doc, const QString &filename)
|
2016-02-27 21:02:56 +00:00
|
|
|
{
|
|
|
|
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();
|
|
|
|
|
2016-03-01 08:47:12 +00:00
|
|
|
out->name = "Minecraft";
|
|
|
|
out->fileId = "net.minecraft";
|
2016-02-27 21:02:56 +00:00
|
|
|
out->version = root.value("version").toString();
|
|
|
|
out->filename = filename;
|
|
|
|
|
|
|
|
readString(root, "id", out->id);
|
|
|
|
|
|
|
|
readString(root, "mainClass", out->mainClass);
|
|
|
|
readString(root, "minecraftArguments", out->overwriteMinecraftArguments);
|
|
|
|
readString(root, "type", out->type);
|
|
|
|
|
|
|
|
readString(root, "assets", out->assets);
|
|
|
|
|
2016-03-02 02:03:44 +00:00
|
|
|
out->m_releaseTime = timeFromS3Time(root.value("releaseTime").toString(""));
|
|
|
|
out->m_updateTime = timeFromS3Time(root.value("time").toString(""));
|
2016-03-01 08:47:12 +00:00
|
|
|
|
2016-02-27 21:02:56 +00:00
|
|
|
if (root.contains("minimumLauncherVersion"))
|
|
|
|
{
|
2016-03-01 08:47:12 +00:00
|
|
|
out->minimumLauncherVersion = requireInteger(root.value("minimumLauncherVersion"));
|
|
|
|
if (out->minimumLauncherVersion > CURRENT_MINIMUM_LAUNCHER_VERSION)
|
2016-02-27 21:02:56 +00:00
|
|
|
{
|
|
|
|
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!")
|
2016-03-01 08:47:12 +00:00
|
|
|
.arg(out->minimumLauncherVersion)
|
2016-02-27 21:02:56 +00:00
|
|
|
.arg(CURRENT_MINIMUM_LAUNCHER_VERSION));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (root.contains("libraries"))
|
|
|
|
{
|
|
|
|
for (auto libVal : requireArray(root.value("libraries")))
|
|
|
|
{
|
|
|
|
auto libObj = requireObject(libVal);
|
|
|
|
|
2016-02-28 18:01:54 +00:00
|
|
|
auto lib = OneSixVersionFormat::libraryFromJson(libObj, filename);
|
2016-03-03 00:40:12 +00:00
|
|
|
out->addLibs.append(lib);
|
2016-02-27 21:02:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
2016-03-01 08:47:12 +00:00
|
|
|
|
2016-02-28 18:01:54 +00:00
|
|
|
static QJsonDocument versionFileToJson(VersionFilePtr patch)
|
|
|
|
{
|
|
|
|
QJsonObject root;
|
|
|
|
writeString(root, "id", patch->id);
|
|
|
|
writeString(root, "mainClass", patch->mainClass);
|
|
|
|
writeString(root, "processArguments", patch->processArguments);
|
|
|
|
writeString(root, "minecraftArguments", patch->overwriteMinecraftArguments);
|
|
|
|
writeString(root, "type", patch->type);
|
|
|
|
writeString(root, "assets", patch->assets);
|
2016-03-02 02:03:44 +00:00
|
|
|
writeString(root, "releaseTime", timeToS3Time(patch->m_releaseTime));
|
|
|
|
writeString(root, "time", timeToS3Time(patch->m_updateTime));
|
2016-03-03 00:40:12 +00:00
|
|
|
if(patch->minimumLauncherVersion != -1)
|
|
|
|
{
|
|
|
|
root.insert("minimumLauncherVersion", patch->minimumLauncherVersion);
|
|
|
|
}
|
2016-02-28 18:01:54 +00:00
|
|
|
|
|
|
|
if (!patch->addLibs.isEmpty())
|
|
|
|
{
|
|
|
|
QJsonArray array;
|
|
|
|
for (auto value: patch->addLibs)
|
|
|
|
{
|
|
|
|
array.append(OneSixVersionFormat::libraryToJson(value.get()));
|
|
|
|
}
|
|
|
|
root.insert("libraries", array);
|
|
|
|
}
|
|
|
|
// write the contents to a json document.
|
|
|
|
{
|
|
|
|
QJsonDocument out;
|
|
|
|
out.setObject(root);
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static QJsonDocument minecraftVersionToJson(MinecraftVersionPtr patch)
|
|
|
|
{
|
|
|
|
if(patch->m_versionSource == Local && patch->getVersionFile())
|
|
|
|
{
|
|
|
|
return MojangVersionFormat::profilePatchToJson(patch->getVersionFile());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw VersionIncomplete(QObject::tr("Can't write incomplete/builtin Minecraft version %1").arg(patch->name()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QJsonDocument MojangVersionFormat::profilePatchToJson(const ProfilePatchPtr &patch)
|
|
|
|
{
|
|
|
|
auto vfile = std::dynamic_pointer_cast<VersionFile>(patch);
|
|
|
|
if(vfile)
|
|
|
|
{
|
|
|
|
return versionFileToJson(vfile);
|
|
|
|
}
|
|
|
|
auto mversion = std::dynamic_pointer_cast<MinecraftVersion>(patch);
|
|
|
|
if(mversion)
|
|
|
|
{
|
|
|
|
return minecraftVersionToJson(mversion);
|
|
|
|
}
|
|
|
|
throw VersionIncomplete(QObject::tr("Unhandled object type while processing %1").arg(patch->getPatchName()));
|
|
|
|
}
|