2016-02-28 02:32:56 +05:30
|
|
|
#include "MojangVersionFormat.h"
|
2016-02-28 23:31:54 +05:30
|
|
|
#include "onesix/OneSixVersionFormat.h"
|
|
|
|
#include "VersionBuildError.h"
|
2016-03-08 02:56:44 +05:30
|
|
|
#include "MojangDownloadInfo.h"
|
2016-02-28 02:32:56 +05:30
|
|
|
|
|
|
|
#include "Json.h"
|
|
|
|
using namespace Json;
|
2016-03-01 14:17:12 +05:30
|
|
|
#include "ParseUtils.h"
|
2016-02-28 02:32:56 +05:30
|
|
|
|
2016-03-26 21:26:57 +05:30
|
|
|
static const int CURRENT_MINIMUM_LAUNCHER_VERSION = 18;
|
2016-02-28 02:32:56 +05:30
|
|
|
|
2016-03-08 02:56:44 +05:30
|
|
|
static MojangAssetIndexInfo::Ptr assetIndexFromJson (const QJsonObject &obj);
|
|
|
|
static MojangDownloadInfo::Ptr downloadInfoFromJson (const QJsonObject &obj);
|
|
|
|
static MojangLibraryDownloadInfo::Ptr libDownloadInfoFromJson (const QJsonObject &libObj);
|
|
|
|
static QJsonObject assetIndexToJson (MojangAssetIndexInfo::Ptr assetidxinfo);
|
|
|
|
static QJsonObject libDownloadInfoToJson (MojangLibraryDownloadInfo::Ptr libinfo);
|
|
|
|
static QJsonObject downloadInfoToJson (MojangDownloadInfo::Ptr info);
|
|
|
|
|
|
|
|
namespace Bits
|
|
|
|
{
|
2016-02-28 02:32:56 +05:30
|
|
|
static void readString(const QJsonObject &root, const QString &key, QString &variable)
|
|
|
|
{
|
|
|
|
if (root.contains(key))
|
|
|
|
{
|
|
|
|
variable = requireString(root.value(key));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-08 02:56:44 +05:30
|
|
|
static void readDownloadInfo(MojangDownloadInfo::Ptr out, const QJsonObject &obj)
|
2016-03-07 06:31:28 +05:30
|
|
|
{
|
|
|
|
// optional, not used
|
2016-03-08 02:56:44 +05:30
|
|
|
readString(obj, "path", out->path);
|
2016-03-07 06:31:28 +05:30
|
|
|
// required!
|
2016-03-08 02:56:44 +05:30
|
|
|
out->sha1 = requireString(obj, "sha1");
|
|
|
|
out->url = requireString(obj, "url");
|
|
|
|
out->size = requireInteger(obj, "size");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void readAssetIndex(MojangAssetIndexInfo::Ptr out, const QJsonObject &obj)
|
|
|
|
{
|
|
|
|
out->totalSize = requireInteger(obj, "totalSize");
|
|
|
|
out->id = requireString(obj, "id");
|
|
|
|
// out->known = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MojangDownloadInfo::Ptr downloadInfoFromJson(const QJsonObject &obj)
|
|
|
|
{
|
|
|
|
auto out = std::make_shared<MojangDownloadInfo>();
|
|
|
|
Bits::readDownloadInfo(out, obj);
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
MojangAssetIndexInfo::Ptr assetIndexFromJson(const QJsonObject &obj)
|
|
|
|
{
|
|
|
|
auto out = std::make_shared<MojangAssetIndexInfo>();
|
|
|
|
Bits::readDownloadInfo(out, obj);
|
|
|
|
Bits::readAssetIndex(out, obj);
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
QJsonObject downloadInfoToJson(MojangDownloadInfo::Ptr info)
|
|
|
|
{
|
|
|
|
QJsonObject out;
|
|
|
|
if(!info->path.isNull())
|
|
|
|
{
|
|
|
|
out.insert("path", info->path);
|
|
|
|
}
|
|
|
|
out.insert("sha1", info->sha1);
|
|
|
|
out.insert("size", info->size);
|
|
|
|
out.insert("url", info->url);
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
MojangLibraryDownloadInfo::Ptr libDownloadInfoFromJson(const QJsonObject &libObj)
|
|
|
|
{
|
|
|
|
auto out = std::make_shared<MojangLibraryDownloadInfo>();
|
|
|
|
auto dlObj = requireObject(libObj.value("downloads"));
|
|
|
|
if(dlObj.contains("artifact"))
|
|
|
|
{
|
|
|
|
out->artifact = downloadInfoFromJson(requireObject(dlObj, "artifact"));
|
|
|
|
}
|
|
|
|
if(dlObj.contains("classifiers"))
|
|
|
|
{
|
|
|
|
auto classifiersObj = requireObject(dlObj, "classifiers");
|
|
|
|
for(auto iter = classifiersObj.begin(); iter != classifiersObj.end(); iter++)
|
|
|
|
{
|
|
|
|
auto classifier = iter.key();
|
|
|
|
auto classifierObj = requireObject(iter.value());
|
|
|
|
out->classifiers[classifier] = downloadInfoFromJson(classifierObj);
|
|
|
|
}
|
|
|
|
}
|
2016-03-07 06:31:28 +05:30
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2016-03-08 02:56:44 +05:30
|
|
|
QJsonObject libDownloadInfoToJson(MojangLibraryDownloadInfo::Ptr libinfo)
|
2016-03-07 06:31:28 +05:30
|
|
|
{
|
|
|
|
QJsonObject out;
|
2016-03-08 02:56:44 +05:30
|
|
|
if(libinfo->artifact)
|
2016-03-07 06:31:28 +05:30
|
|
|
{
|
2016-03-08 02:56:44 +05:30
|
|
|
out.insert("artifact", downloadInfoToJson(libinfo->artifact));
|
|
|
|
}
|
|
|
|
if(libinfo->classifiers.size())
|
|
|
|
{
|
|
|
|
QJsonObject classifiersOut;
|
|
|
|
for(auto iter = libinfo->classifiers.begin(); iter != libinfo->classifiers.end(); iter++)
|
|
|
|
{
|
|
|
|
classifiersOut.insert(iter.key(), downloadInfoToJson(iter.value()));
|
|
|
|
}
|
|
|
|
out.insert("classifiers", classifiersOut);
|
2016-03-07 06:31:28 +05:30
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2016-03-08 02:56:44 +05:30
|
|
|
QJsonObject assetIndexToJson(MojangAssetIndexInfo::Ptr info)
|
|
|
|
{
|
|
|
|
QJsonObject out;
|
|
|
|
if(!info->path.isNull())
|
|
|
|
{
|
|
|
|
out.insert("path", info->path);
|
|
|
|
}
|
|
|
|
out.insert("sha1", info->sha1);
|
|
|
|
out.insert("size", info->size);
|
|
|
|
out.insert("url", info->url);
|
|
|
|
out.insert("totalSize", info->totalSize);
|
|
|
|
out.insert("id", info->id);
|
|
|
|
return out;
|
|
|
|
}
|
2016-03-07 06:31:28 +05:30
|
|
|
|
2016-03-19 07:36:32 +05:30
|
|
|
void MojangVersionFormat::readVersionProperties(const QJsonObject &in, VersionFile *out)
|
2016-02-28 02:32:56 +05:30
|
|
|
{
|
2016-03-26 21:26:57 +05:30
|
|
|
Bits::readString(in, "id", out->minecraftVersion);
|
2016-03-19 07:36:32 +05:30
|
|
|
Bits::readString(in, "mainClass", out->mainClass);
|
|
|
|
Bits::readString(in, "minecraftArguments", out->minecraftArguments);
|
|
|
|
if(out->minecraftArguments.isEmpty())
|
2016-02-28 02:32:56 +05:30
|
|
|
{
|
2016-03-19 07:36:32 +05:30
|
|
|
QString processArguments;
|
|
|
|
Bits::readString(in, "processArguments", processArguments);
|
|
|
|
QString toCompare = processArguments.toLower();
|
|
|
|
if (toCompare == "legacy")
|
|
|
|
{
|
|
|
|
out->minecraftArguments = " ${auth_player_name} ${auth_session}";
|
|
|
|
}
|
|
|
|
else if (toCompare == "username_session")
|
|
|
|
{
|
|
|
|
out->minecraftArguments = "--username ${auth_player_name} --session ${auth_session}";
|
|
|
|
}
|
|
|
|
else if (toCompare == "username_session_version")
|
|
|
|
{
|
|
|
|
out->minecraftArguments = "--username ${auth_player_name} --session ${auth_session} --version ${profile_name}";
|
|
|
|
}
|
|
|
|
else if (!toCompare.isEmpty())
|
|
|
|
{
|
2017-03-27 07:04:39 +05:30
|
|
|
out->addProblem(ProblemSeverity::Error, QObject::tr("processArguments is set to unknown value '%1'").arg(processArguments));
|
2016-03-19 07:36:32 +05:30
|
|
|
}
|
2016-02-28 02:32:56 +05:30
|
|
|
}
|
2016-03-19 07:36:32 +05:30
|
|
|
Bits::readString(in, "type", out->type);
|
2016-02-28 02:32:56 +05:30
|
|
|
|
2016-03-21 06:49:23 +05:30
|
|
|
Bits::readString(in, "assets", out->assets);
|
2016-03-19 07:36:32 +05:30
|
|
|
if(in.contains("assetIndex"))
|
2016-03-07 06:31:28 +05:30
|
|
|
{
|
2016-03-19 07:36:32 +05:30
|
|
|
out->mojangAssetIndex = assetIndexFromJson(requireObject(in, "assetIndex"));
|
2016-03-07 06:31:28 +05:30
|
|
|
}
|
2016-03-21 06:49:23 +05:30
|
|
|
else if (!out->assets.isNull())
|
|
|
|
{
|
|
|
|
out->mojangAssetIndex = std::make_shared<MojangAssetIndexInfo>(out->assets);
|
|
|
|
}
|
2016-02-28 02:32:56 +05:30
|
|
|
|
2017-03-27 07:04:39 +05:30
|
|
|
out->releaseTime = timeFromS3Time(in.value("releaseTime").toString(""));
|
|
|
|
out->updateTime = timeFromS3Time(in.value("time").toString(""));
|
2016-03-01 14:17:12 +05:30
|
|
|
|
2016-03-19 07:36:32 +05:30
|
|
|
if (in.contains("minimumLauncherVersion"))
|
2016-02-28 02:32:56 +05:30
|
|
|
{
|
2016-03-19 07:36:32 +05:30
|
|
|
out->minimumLauncherVersion = requireInteger(in.value("minimumLauncherVersion"));
|
2016-03-01 14:17:12 +05:30
|
|
|
if (out->minimumLauncherVersion > CURRENT_MINIMUM_LAUNCHER_VERSION)
|
2016-02-28 02:32:56 +05:30
|
|
|
{
|
|
|
|
out->addProblem(
|
2017-03-27 07:04:39 +05:30
|
|
|
ProblemSeverity::Warning,
|
2016-02-28 02:32:56 +05:30
|
|
|
QObject::tr("The 'minimumLauncherVersion' value of this version (%1) is higher than supported by MultiMC (%2). It might not work properly!")
|
2016-03-01 14:17:12 +05:30
|
|
|
.arg(out->minimumLauncherVersion)
|
2016-02-28 02:32:56 +05:30
|
|
|
.arg(CURRENT_MINIMUM_LAUNCHER_VERSION));
|
|
|
|
}
|
|
|
|
}
|
2016-03-19 07:36:32 +05:30
|
|
|
if(in.contains("downloads"))
|
2016-03-07 06:31:28 +05:30
|
|
|
{
|
2016-03-19 07:36:32 +05:30
|
|
|
auto downloadsObj = requireObject(in, "downloads");
|
2016-03-07 06:31:28 +05:30
|
|
|
for(auto iter = downloadsObj.begin(); iter != downloadsObj.end(); iter++)
|
|
|
|
{
|
|
|
|
auto classifier = iter.key();
|
|
|
|
auto classifierObj = requireObject(iter.value());
|
|
|
|
out->mojangDownloads[classifier] = downloadInfoFromJson(classifierObj);
|
|
|
|
}
|
|
|
|
}
|
2016-02-28 02:32:56 +05:30
|
|
|
}
|
2016-03-01 14:17:12 +05:30
|
|
|
|
2016-03-19 07:36:32 +05:30
|
|
|
VersionFilePtr MojangVersionFormat::versionFileFromJson(const QJsonDocument &doc, const QString &filename)
|
2016-02-28 23:31:54 +05:30
|
|
|
{
|
2016-03-19 07:36:32 +05:30
|
|
|
VersionFilePtr out(new VersionFile());
|
|
|
|
if (doc.isEmpty() || doc.isNull())
|
2016-03-03 06:10:12 +05:30
|
|
|
{
|
2016-03-19 07:36:32 +05:30
|
|
|
throw JSONValidationError(filename + " is empty or null");
|
|
|
|
}
|
|
|
|
if (!doc.isObject())
|
|
|
|
{
|
|
|
|
throw JSONValidationError(filename + " is not an object");
|
2016-03-03 06:10:12 +05:30
|
|
|
}
|
2016-02-28 23:31:54 +05:30
|
|
|
|
2016-03-19 07:36:32 +05:30
|
|
|
QJsonObject root = doc.object();
|
|
|
|
|
|
|
|
readVersionProperties(root, out.get());
|
|
|
|
|
|
|
|
out->name = "Minecraft";
|
2017-03-20 04:28:54 +05:30
|
|
|
out->uid = "net.minecraft";
|
2016-03-26 21:26:57 +05:30
|
|
|
out->version = out->minecraftVersion;
|
2017-03-27 07:04:39 +05:30
|
|
|
// out->filename = filename;
|
2016-03-19 07:36:32 +05:30
|
|
|
|
|
|
|
|
|
|
|
if (root.contains("libraries"))
|
2016-02-28 23:31:54 +05:30
|
|
|
{
|
2016-03-19 07:36:32 +05:30
|
|
|
for (auto libVal : requireArray(root.value("libraries")))
|
2016-02-28 23:31:54 +05:30
|
|
|
{
|
2016-03-19 07:36:32 +05:30
|
|
|
auto libObj = requireObject(libVal);
|
|
|
|
|
|
|
|
auto lib = MojangVersionFormat::libraryFromJson(libObj, filename);
|
|
|
|
out->libraries.append(lib);
|
2016-02-28 23:31:54 +05:30
|
|
|
}
|
|
|
|
}
|
2016-03-19 07:36:32 +05:30
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MojangVersionFormat::writeVersionProperties(const VersionFile* in, QJsonObject& out)
|
|
|
|
{
|
2016-03-26 21:26:57 +05:30
|
|
|
writeString(out, "id", in->minecraftVersion);
|
2016-03-19 07:36:32 +05:30
|
|
|
writeString(out, "mainClass", in->mainClass);
|
|
|
|
writeString(out, "minecraftArguments", in->minecraftArguments);
|
|
|
|
writeString(out, "type", in->type);
|
2017-03-27 07:04:39 +05:30
|
|
|
if(!in->releaseTime.isNull())
|
2016-03-19 07:58:17 +05:30
|
|
|
{
|
2017-03-27 07:04:39 +05:30
|
|
|
writeString(out, "releaseTime", timeToS3Time(in->releaseTime));
|
2016-03-19 07:58:17 +05:30
|
|
|
}
|
2017-03-27 07:04:39 +05:30
|
|
|
if(!in->updateTime.isNull())
|
2016-03-19 07:58:17 +05:30
|
|
|
{
|
2017-03-27 07:04:39 +05:30
|
|
|
writeString(out, "time", timeToS3Time(in->updateTime));
|
2016-03-19 07:58:17 +05:30
|
|
|
}
|
2016-03-19 07:36:32 +05:30
|
|
|
if(in->minimumLauncherVersion != -1)
|
|
|
|
{
|
|
|
|
out.insert("minimumLauncherVersion", in->minimumLauncherVersion);
|
|
|
|
}
|
2016-03-21 06:49:23 +05:30
|
|
|
writeString(out, "assets", in->assets);
|
2016-03-19 07:36:32 +05:30
|
|
|
if(in->mojangAssetIndex && in->mojangAssetIndex->known)
|
2016-03-07 06:31:28 +05:30
|
|
|
{
|
2016-03-19 07:36:32 +05:30
|
|
|
out.insert("assetIndex", assetIndexToJson(in->mojangAssetIndex));
|
2016-03-07 06:31:28 +05:30
|
|
|
}
|
2016-03-19 07:36:32 +05:30
|
|
|
if(in->mojangDownloads.size())
|
2016-03-07 06:31:28 +05:30
|
|
|
{
|
|
|
|
QJsonObject downloadsOut;
|
2016-03-19 07:36:32 +05:30
|
|
|
for(auto iter = in->mojangDownloads.begin(); iter != in->mojangDownloads.end(); iter++)
|
2016-03-07 06:31:28 +05:30
|
|
|
{
|
|
|
|
downloadsOut.insert(iter.key(), downloadInfoToJson(iter.value()));
|
|
|
|
}
|
2016-03-19 07:36:32 +05:30
|
|
|
out.insert("downloads", downloadsOut);
|
2016-02-28 23:31:54 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-19 07:36:32 +05:30
|
|
|
QJsonDocument MojangVersionFormat::versionFileToJson(const VersionFilePtr &patch)
|
2016-02-28 23:31:54 +05:30
|
|
|
{
|
2016-03-19 07:36:32 +05:30
|
|
|
QJsonObject root;
|
|
|
|
writeVersionProperties(patch.get(), root);
|
|
|
|
if (!patch->libraries.isEmpty())
|
2016-02-28 23:31:54 +05:30
|
|
|
{
|
2016-03-19 07:36:32 +05:30
|
|
|
QJsonArray array;
|
|
|
|
for (auto value: patch->libraries)
|
|
|
|
{
|
|
|
|
array.append(MojangVersionFormat::libraryToJson(value.get()));
|
|
|
|
}
|
|
|
|
root.insert("libraries", array);
|
2016-02-28 23:31:54 +05:30
|
|
|
}
|
|
|
|
|
2016-03-19 07:36:32 +05:30
|
|
|
// write the contents to a json document.
|
2016-02-28 23:31:54 +05:30
|
|
|
{
|
2016-03-19 07:36:32 +05:30
|
|
|
QJsonDocument out;
|
|
|
|
out.setObject(root);
|
|
|
|
return out;
|
2016-02-28 23:31:54 +05:30
|
|
|
}
|
|
|
|
}
|
2016-03-07 06:31:28 +05:30
|
|
|
|
|
|
|
LibraryPtr MojangVersionFormat::libraryFromJson(const QJsonObject &libObj, const QString &filename)
|
|
|
|
{
|
|
|
|
LibraryPtr out(new Library());
|
|
|
|
if (!libObj.contains("name"))
|
|
|
|
{
|
|
|
|
throw JSONValidationError(filename + "contains a library that doesn't have a 'name' field");
|
|
|
|
}
|
|
|
|
out->m_name = libObj.value("name").toString();
|
|
|
|
|
2016-03-26 21:26:57 +05:30
|
|
|
Bits::readString(libObj, "url", out->m_repositoryURL);
|
2016-03-07 06:31:28 +05:30
|
|
|
if (libObj.contains("extract"))
|
|
|
|
{
|
2016-03-26 21:26:57 +05:30
|
|
|
out->m_hasExcludes = true;
|
2016-03-07 06:31:28 +05:30
|
|
|
auto extractObj = requireObject(libObj.value("extract"));
|
|
|
|
for (auto excludeVal : requireArray(extractObj.value("exclude")))
|
|
|
|
{
|
2016-03-26 21:26:57 +05:30
|
|
|
out->m_extractExcludes.append(requireString(excludeVal));
|
2016-03-07 06:31:28 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
if (libObj.contains("natives"))
|
|
|
|
{
|
|
|
|
QJsonObject nativesObj = requireObject(libObj.value("natives"));
|
|
|
|
for (auto it = nativesObj.begin(); it != nativesObj.end(); ++it)
|
|
|
|
{
|
|
|
|
if (!it.value().isString())
|
|
|
|
{
|
|
|
|
qWarning() << filename << "contains an invalid native (skipping)";
|
|
|
|
}
|
|
|
|
OpSys opSys = OpSys_fromString(it.key());
|
|
|
|
if (opSys != Os_Other)
|
|
|
|
{
|
2016-03-26 21:26:57 +05:30
|
|
|
out->m_nativeClassifiers[opSys] = it.value().toString();
|
2016-03-07 06:31:28 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (libObj.contains("rules"))
|
|
|
|
{
|
|
|
|
out->applyRules = true;
|
|
|
|
out->m_rules = rulesFromJsonV4(libObj);
|
|
|
|
}
|
|
|
|
if (libObj.contains("downloads"))
|
|
|
|
{
|
2016-03-26 21:26:57 +05:30
|
|
|
out->m_mojangDownloads = libDownloadInfoFromJson(libObj);
|
2016-03-07 06:31:28 +05:30
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
QJsonObject MojangVersionFormat::libraryToJson(Library *library)
|
|
|
|
{
|
|
|
|
QJsonObject libRoot;
|
|
|
|
libRoot.insert("name", (QString)library->m_name);
|
2016-03-26 21:26:57 +05:30
|
|
|
if (!library->m_repositoryURL.isEmpty())
|
2016-03-07 06:31:28 +05:30
|
|
|
{
|
2016-03-26 21:26:57 +05:30
|
|
|
libRoot.insert("url", library->m_repositoryURL);
|
2016-03-07 06:31:28 +05:30
|
|
|
}
|
|
|
|
if (library->isNative())
|
|
|
|
{
|
|
|
|
QJsonObject nativeList;
|
2016-03-26 21:26:57 +05:30
|
|
|
auto iter = library->m_nativeClassifiers.begin();
|
|
|
|
while (iter != library->m_nativeClassifiers.end())
|
2016-03-07 06:31:28 +05:30
|
|
|
{
|
|
|
|
nativeList.insert(OpSys_toString(iter.key()), iter.value());
|
|
|
|
iter++;
|
|
|
|
}
|
|
|
|
libRoot.insert("natives", nativeList);
|
2016-03-26 21:26:57 +05:30
|
|
|
if (library->m_extractExcludes.size())
|
2016-03-07 06:31:28 +05:30
|
|
|
{
|
|
|
|
QJsonArray excludes;
|
|
|
|
QJsonObject extract;
|
2016-03-26 21:26:57 +05:30
|
|
|
for (auto exclude : library->m_extractExcludes)
|
2016-03-07 06:31:28 +05:30
|
|
|
{
|
|
|
|
excludes.append(exclude);
|
|
|
|
}
|
|
|
|
extract.insert("exclude", excludes);
|
|
|
|
libRoot.insert("extract", extract);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (library->m_rules.size())
|
|
|
|
{
|
|
|
|
QJsonArray allRules;
|
|
|
|
for (auto &rule : library->m_rules)
|
|
|
|
{
|
|
|
|
QJsonObject ruleObj = rule->toJson();
|
|
|
|
allRules.append(ruleObj);
|
|
|
|
}
|
|
|
|
libRoot.insert("rules", allRules);
|
|
|
|
}
|
2016-03-26 21:26:57 +05:30
|
|
|
if(library->m_mojangDownloads)
|
2016-03-07 06:31:28 +05:30
|
|
|
{
|
2016-03-26 21:26:57 +05:30
|
|
|
auto downloadsObj = libDownloadInfoToJson(library->m_mojangDownloads);
|
2016-03-07 06:31:28 +05:30
|
|
|
libRoot.insert("downloads", downloadsObj);
|
|
|
|
}
|
|
|
|
return libRoot;
|
|
|
|
}
|