2016-02-28 02:32:56 +05:30
|
|
|
#include "OneSixVersionFormat.h"
|
|
|
|
#include <Json.h>
|
|
|
|
#include "minecraft/ParseUtils.h"
|
2016-02-28 23:31:54 +05:30
|
|
|
#include <minecraft/VersionBuildError.h>
|
2016-03-07 06:31:28 +05:30
|
|
|
#include <minecraft/MojangVersionFormat.h>
|
2016-02-28 02:32:56 +05:30
|
|
|
|
|
|
|
using namespace Json;
|
|
|
|
|
|
|
|
static void readString(const QJsonObject &root, const QString &key, QString &variable)
|
|
|
|
{
|
|
|
|
if (root.contains(key))
|
|
|
|
{
|
|
|
|
variable = requireString(root.value(key));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-07 06:31:28 +05:30
|
|
|
LibraryPtr OneSixVersionFormat::libraryFromJson(const QJsonObject &libObj, const QString &filename)
|
2016-02-28 23:31:54 +05:30
|
|
|
{
|
2016-03-07 06:31:28 +05:30
|
|
|
LibraryPtr out = MojangVersionFormat::libraryFromJson(libObj, filename);
|
2016-02-28 23:31:54 +05:30
|
|
|
readString(libObj, "MMC-hint", out->m_hint);
|
2016-03-26 21:26:57 +05:30
|
|
|
readString(libObj, "MMC-absulute_url", out->m_absoluteURL);
|
|
|
|
readString(libObj, "MMC-absoluteUrl", out->m_absoluteURL);
|
2017-04-18 02:21:30 +05:30
|
|
|
readString(libObj, "MMC-filename", out->m_filename);
|
|
|
|
readString(libObj, "MMC-displayname", out->m_displayname);
|
2016-02-28 23:31:54 +05:30
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2016-03-07 06:31:28 +05:30
|
|
|
QJsonObject OneSixVersionFormat::libraryToJson(Library *library)
|
2016-02-28 23:31:54 +05:30
|
|
|
{
|
2016-03-07 06:31:28 +05:30
|
|
|
QJsonObject libRoot = MojangVersionFormat::libraryToJson(library);
|
2016-03-26 21:26:57 +05:30
|
|
|
if (library->m_absoluteURL.size())
|
|
|
|
libRoot.insert("MMC-absoluteUrl", library->m_absoluteURL);
|
2016-02-28 23:31:54 +05:30
|
|
|
if (library->m_hint.size())
|
|
|
|
libRoot.insert("MMC-hint", library->m_hint);
|
2017-04-18 02:21:30 +05:30
|
|
|
if (library->m_filename.size())
|
|
|
|
libRoot.insert("MMC-filename", library->m_filename);
|
|
|
|
if (library->m_displayname.size())
|
|
|
|
libRoot.insert("MMC-displayname", library->m_displayname);
|
2016-02-28 23:31:54 +05:30
|
|
|
return libRoot;
|
|
|
|
}
|
|
|
|
|
|
|
|
VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument &doc, const QString &filename, const bool requireOrder)
|
2016-02-28 02:32:56 +05:30
|
|
|
{
|
|
|
|
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"))
|
|
|
|
{
|
2017-03-27 07:04:39 +05:30
|
|
|
out->order = requireInteger(root.value("order"));
|
2016-02-28 02:32:56 +05:30
|
|
|
}
|
|
|
|
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();
|
2017-03-20 04:28:54 +05:30
|
|
|
|
|
|
|
if(root.contains("uid"))
|
|
|
|
{
|
|
|
|
out->uid = root.value("uid").toString();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
out->uid = root.value("fileId").toString();
|
|
|
|
}
|
|
|
|
|
2016-02-28 02:32:56 +05:30
|
|
|
out->version = root.value("version").toString();
|
2016-03-26 21:26:57 +05:30
|
|
|
out->dependsOnMinecraftVersion = root.value("mcVersion").toString();
|
2017-03-27 07:04:39 +05:30
|
|
|
// out->filename = filename;
|
2016-02-28 02:32:56 +05:30
|
|
|
|
2016-03-19 07:36:32 +05:30
|
|
|
MojangVersionFormat::readVersionProperties(root, out.get());
|
2016-02-28 02:32:56 +05:30
|
|
|
|
2016-03-19 07:36:32 +05:30
|
|
|
// added for legacy Minecraft window embedding, TODO: remove
|
2016-02-28 02:32:56 +05:30
|
|
|
readString(root, "appletClass", out->appletClass);
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-18 02:21:30 +05:30
|
|
|
|
|
|
|
if (root.contains("jarMods"))
|
|
|
|
{
|
|
|
|
for (auto libVal : requireArray(root.value("jarMods")))
|
|
|
|
{
|
|
|
|
QJsonObject libObj = requireObject(libVal);
|
|
|
|
// parse the jarmod
|
|
|
|
auto lib = OneSixVersionFormat::jarModFromJson(libObj, filename);
|
|
|
|
// and add to jar mods
|
|
|
|
out->jarMods.append(lib);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (root.contains("+jarMods")) // DEPRECATED: old style '+jarMods' are only here for backwards compatibility
|
2016-02-28 02:32:56 +05:30
|
|
|
{
|
|
|
|
for (auto libVal : requireArray(root.value("+jarMods")))
|
|
|
|
{
|
|
|
|
QJsonObject libObj = requireObject(libVal);
|
|
|
|
// parse the jarmod
|
2017-04-18 02:21:30 +05:30
|
|
|
auto lib = OneSixVersionFormat::plusJarModFromJson(libObj, filename, out->name);
|
2016-02-28 02:32:56 +05:30
|
|
|
// and add to jar mods
|
|
|
|
out->jarMods.append(lib);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-22 01:53:00 +05:30
|
|
|
if (root.contains("mods"))
|
|
|
|
{
|
|
|
|
for (auto libVal : requireArray(root.value("mods")))
|
|
|
|
{
|
|
|
|
QJsonObject libObj = requireObject(libVal);
|
|
|
|
// parse the jarmod
|
|
|
|
auto lib = OneSixVersionFormat::modFromJson(libObj, filename);
|
|
|
|
// and add to jar mods
|
|
|
|
out->mods.append(lib);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-13 04:53:45 +05:30
|
|
|
auto readLibs = [&](const char * which)
|
2016-02-28 02:32:56 +05:30
|
|
|
{
|
2016-03-13 04:53:45 +05:30
|
|
|
for (auto libVal : requireArray(root.value(which)))
|
2016-02-28 02:32:56 +05:30
|
|
|
{
|
|
|
|
QJsonObject libObj = requireObject(libVal);
|
|
|
|
// parse the library
|
2016-02-28 23:31:54 +05:30
|
|
|
auto lib = libraryFromJson(libObj, filename);
|
2016-03-13 06:58:55 +05:30
|
|
|
out->libraries.append(lib);
|
2016-02-28 02:32:56 +05:30
|
|
|
}
|
2016-03-13 04:53:45 +05:30
|
|
|
};
|
|
|
|
bool hasPlusLibs = root.contains("+libraries");
|
|
|
|
bool hasLibs = root.contains("libraries");
|
|
|
|
if (hasPlusLibs && hasLibs)
|
|
|
|
{
|
2017-03-27 07:04:39 +05:30
|
|
|
out->addProblem(ProblemSeverity::Warning,
|
|
|
|
QObject::tr("Version file has both '+libraries' and 'libraries'. This is no longer supported."));
|
2016-03-13 04:53:45 +05:30
|
|
|
readLibs("libraries");
|
|
|
|
readLibs("+libraries");
|
|
|
|
}
|
|
|
|
else if (hasLibs)
|
|
|
|
{
|
|
|
|
readLibs("libraries");
|
|
|
|
}
|
|
|
|
else if(hasPlusLibs)
|
|
|
|
{
|
|
|
|
readLibs("+libraries");
|
2016-02-28 02:32:56 +05:30
|
|
|
}
|
|
|
|
|
2017-04-13 12:58:25 +05:30
|
|
|
// if we have mainJar, just use it
|
|
|
|
if(root.contains("mainJar"))
|
|
|
|
{
|
|
|
|
QJsonObject libObj = requireObject(root, "mainJar");
|
|
|
|
out->mainJar = libraryFromJson(libObj, filename);
|
|
|
|
}
|
|
|
|
// else reconstruct it from downloads and id ... if that's available
|
|
|
|
else if(!out->minecraftVersion.isEmpty())
|
|
|
|
{
|
|
|
|
auto lib = std::make_shared<Library>();
|
|
|
|
lib->setRawName(GradleSpecifier(QString("com.mojang:minecraft:%1:client").arg(out->minecraftVersion)));
|
|
|
|
// we have a reliable client download, use it.
|
|
|
|
if(out->mojangDownloads.contains("client"))
|
|
|
|
{
|
|
|
|
auto LibDLInfo = std::make_shared<MojangLibraryDownloadInfo>();
|
|
|
|
LibDLInfo->artifact = out->mojangDownloads["client"];
|
|
|
|
lib->setMojangDownloadInfo(LibDLInfo);
|
|
|
|
}
|
|
|
|
// we got nothing... guess based on ancient hardcoded Mojang behaviour
|
|
|
|
// FIXME: this will eventually break...
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lib->setAbsoluteUrl(URLConstants::getLegacyJarUrl(out->minecraftVersion));
|
|
|
|
}
|
2017-04-14 16:03:54 +05:30
|
|
|
out->mainJar = lib;
|
2017-04-13 12:58:25 +05:30
|
|
|
}
|
|
|
|
|
2016-02-28 02:32:56 +05:30
|
|
|
/* removed features that shouldn't be used */
|
2016-03-13 04:53:45 +05:30
|
|
|
if (root.contains("tweakers"))
|
|
|
|
{
|
2017-03-27 07:04:39 +05:30
|
|
|
out->addProblem(ProblemSeverity::Error, QObject::tr("Version file contains unsupported element 'tweakers'"));
|
2016-03-13 04:53:45 +05:30
|
|
|
}
|
2016-02-28 02:32:56 +05:30
|
|
|
if (root.contains("-libraries"))
|
|
|
|
{
|
2017-03-27 07:04:39 +05:30
|
|
|
out->addProblem(ProblemSeverity::Error, QObject::tr("Version file contains unsupported element '-libraries'"));
|
2016-02-28 02:32:56 +05:30
|
|
|
}
|
|
|
|
if (root.contains("-tweakers"))
|
|
|
|
{
|
2017-03-27 07:04:39 +05:30
|
|
|
out->addProblem(ProblemSeverity::Error, QObject::tr("Version file contains unsupported element '-tweakers'"));
|
2016-02-28 02:32:56 +05:30
|
|
|
}
|
|
|
|
if (root.contains("-minecraftArguments"))
|
|
|
|
{
|
2017-03-27 07:04:39 +05:30
|
|
|
out->addProblem(ProblemSeverity::Error, QObject::tr("Version file contains unsupported element '-minecraftArguments'"));
|
2016-02-28 02:32:56 +05:30
|
|
|
}
|
2016-03-13 04:53:45 +05:30
|
|
|
if (root.contains("+minecraftArguments"))
|
|
|
|
{
|
2017-03-27 07:04:39 +05:30
|
|
|
out->addProblem(ProblemSeverity::Error, QObject::tr("Version file contains unsupported element '+minecraftArguments'"));
|
2016-03-13 04:53:45 +05:30
|
|
|
}
|
2016-02-28 02:32:56 +05:30
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2016-03-19 07:36:32 +05:30
|
|
|
QJsonDocument OneSixVersionFormat::versionFileToJson(const VersionFilePtr &patch, bool saveOrder)
|
2016-02-28 02:32:56 +05:30
|
|
|
{
|
|
|
|
QJsonObject root;
|
|
|
|
if (saveOrder)
|
|
|
|
{
|
2017-03-27 07:04:39 +05:30
|
|
|
root.insert("order", patch->order);
|
2016-02-28 02:32:56 +05:30
|
|
|
}
|
|
|
|
writeString(root, "name", patch->name);
|
2017-03-20 04:28:54 +05:30
|
|
|
|
|
|
|
writeString(root, "uid", patch->uid);
|
|
|
|
|
2016-02-28 02:32:56 +05:30
|
|
|
writeString(root, "version", patch->version);
|
2016-03-26 21:26:57 +05:30
|
|
|
writeString(root, "mcVersion", patch->dependsOnMinecraftVersion);
|
2016-03-19 07:36:32 +05:30
|
|
|
|
|
|
|
MojangVersionFormat::writeVersionProperties(patch.get(), root);
|
|
|
|
|
2017-04-18 02:21:30 +05:30
|
|
|
if(patch->mainJar)
|
|
|
|
{
|
|
|
|
root.insert("mainJar", libraryToJson(patch->mainJar.get()));
|
|
|
|
}
|
2016-02-28 02:32:56 +05:30
|
|
|
writeString(root, "appletClass", patch->appletClass);
|
|
|
|
writeStringList(root, "+tweakers", patch->addTweakers);
|
|
|
|
writeStringList(root, "+traits", patch->traits.toList());
|
2016-03-13 06:58:55 +05:30
|
|
|
if (!patch->libraries.isEmpty())
|
2016-02-28 23:31:54 +05:30
|
|
|
{
|
|
|
|
QJsonArray array;
|
2016-03-13 06:58:55 +05:30
|
|
|
for (auto value: patch->libraries)
|
2016-02-28 23:31:54 +05:30
|
|
|
{
|
|
|
|
array.append(OneSixVersionFormat::libraryToJson(value.get()));
|
|
|
|
}
|
2017-04-18 02:21:30 +05:30
|
|
|
root.insert("libraries", array);
|
2016-02-28 23:31:54 +05:30
|
|
|
}
|
|
|
|
if (!patch->jarMods.isEmpty())
|
|
|
|
{
|
|
|
|
QJsonArray array;
|
|
|
|
for (auto value: patch->jarMods)
|
|
|
|
{
|
|
|
|
array.append(OneSixVersionFormat::jarModtoJson(value.get()));
|
|
|
|
}
|
2017-04-18 02:21:30 +05:30
|
|
|
root.insert("jarMods", array);
|
2016-02-28 23:31:54 +05:30
|
|
|
}
|
2017-04-22 01:53:00 +05:30
|
|
|
if (!patch->mods.isEmpty())
|
|
|
|
{
|
|
|
|
QJsonArray array;
|
|
|
|
for (auto value: patch->jarMods)
|
|
|
|
{
|
|
|
|
array.append(OneSixVersionFormat::modtoJson(value.get()));
|
|
|
|
}
|
|
|
|
root.insert("mods", array);
|
|
|
|
}
|
2016-02-28 02:32:56 +05:30
|
|
|
// write the contents to a json document.
|
|
|
|
{
|
|
|
|
QJsonDocument out;
|
|
|
|
out.setObject(root);
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-18 02:21:30 +05:30
|
|
|
LibraryPtr OneSixVersionFormat::plusJarModFromJson(const QJsonObject &libObj, const QString &filename, const QString &originalName)
|
2016-02-28 23:31:54 +05:30
|
|
|
{
|
2017-04-18 02:21:30 +05:30
|
|
|
LibraryPtr out(new Library());
|
2016-02-28 23:31:54 +05:30
|
|
|
if (!libObj.contains("name"))
|
|
|
|
{
|
|
|
|
throw JSONValidationError(filename +
|
|
|
|
"contains a jarmod that doesn't have a 'name' field");
|
|
|
|
}
|
2017-04-18 02:21:30 +05:30
|
|
|
|
|
|
|
// just make up something unique on the spot for the library name.
|
|
|
|
auto uuid = QUuid::createUuid();
|
|
|
|
QString id = uuid.toString().remove('{').remove('}');
|
2017-04-22 23:08:28 +05:30
|
|
|
out->setRawName(GradleSpecifier("org.multimc.jarmods:" + id + ":1"));
|
2017-04-18 02:21:30 +05:30
|
|
|
|
|
|
|
// filename override is the old name
|
|
|
|
out->setFilename(libObj.value("name").toString());
|
|
|
|
|
|
|
|
// it needs to be local, it is stored in the instance jarmods folder
|
|
|
|
out->setHint("local");
|
|
|
|
|
|
|
|
// read the original name if present - some versions did not set it
|
|
|
|
// it is the original jar mod filename before it got renamed at the point of addition
|
|
|
|
auto displayName = libObj.value("originalName").toString();
|
|
|
|
if(displayName.isEmpty())
|
2017-04-14 15:51:10 +05:30
|
|
|
{
|
|
|
|
auto fixed = originalName;
|
|
|
|
fixed.remove(" (jar mod)");
|
2017-04-18 02:21:30 +05:30
|
|
|
out->setDisplayName(fixed);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
out->setDisplayName(displayName);
|
2017-04-14 15:51:10 +05:30
|
|
|
}
|
2016-02-28 23:31:54 +05:30
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2017-04-18 02:21:30 +05:30
|
|
|
LibraryPtr OneSixVersionFormat::jarModFromJson(const QJsonObject& libObj, const QString& filename)
|
|
|
|
{
|
2017-04-22 23:57:00 +05:30
|
|
|
return libraryFromJson(libObj, filename);
|
2017-04-18 02:21:30 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QJsonObject OneSixVersionFormat::jarModtoJson(Library *jarmod)
|
2016-02-28 23:31:54 +05:30
|
|
|
{
|
2017-04-22 23:57:00 +05:30
|
|
|
return libraryToJson(jarmod);
|
2016-02-28 23:31:54 +05:30
|
|
|
}
|
2017-04-22 01:53:00 +05:30
|
|
|
|
|
|
|
LibraryPtr OneSixVersionFormat::modFromJson(const QJsonObject& libObj, const QString& filename)
|
|
|
|
{
|
|
|
|
return libraryFromJson(libObj, filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
QJsonObject OneSixVersionFormat::modtoJson(Library *jarmod)
|
|
|
|
{
|
|
|
|
return libraryToJson(jarmod);
|
|
|
|
}
|