2016-02-28 02:32:56 +05:30
|
|
|
#include "MojangVersionFormat.h"
|
2016-02-28 23:31:54 +05:30
|
|
|
#include "onesix/OneSixVersionFormat.h"
|
|
|
|
#include "MinecraftVersion.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
|
|
|
|
|
|
|
static const int CURRENT_MINIMUM_LAUNCHER_VERSION = 14;
|
|
|
|
|
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-19 07:36:32 +05:30
|
|
|
Bits::readString(in, "id", out->id);
|
|
|
|
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())
|
|
|
|
{
|
|
|
|
out->addProblem(PROBLEM_ERROR, QObject::tr("processArguments is set to unknown value '%1'").arg(processArguments));
|
|
|
|
}
|
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-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-19 07:36:32 +05:30
|
|
|
Bits::readString(in, "assets", out->assets);
|
2016-02-28 02:32:56 +05:30
|
|
|
|
2016-03-19 07:36:32 +05:30
|
|
|
out->m_releaseTime = timeFromS3Time(in.value("releaseTime").toString(""));
|
|
|
|
out->m_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(
|
|
|
|
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 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";
|
|
|
|
out->fileId = "net.minecraft";
|
|
|
|
out->version = out->id;
|
|
|
|
out->filename = filename;
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
writeString(out, "id", in->id);
|
|
|
|
writeString(out, "mainClass", in->mainClass);
|
|
|
|
writeString(out, "minecraftArguments", in->minecraftArguments);
|
|
|
|
writeString(out, "type", in->type);
|
|
|
|
writeString(out, "assets", in->assets);
|
2016-03-19 07:58:17 +05:30
|
|
|
if(!in->m_releaseTime.isNull())
|
|
|
|
{
|
|
|
|
writeString(out, "releaseTime", timeToS3Time(in->m_releaseTime));
|
|
|
|
}
|
|
|
|
if(!in->m_updateTime.isNull())
|
|
|
|
{
|
|
|
|
writeString(out, "time", timeToS3Time(in->m_updateTime));
|
|
|
|
}
|
2016-03-19 07:36:32 +05:30
|
|
|
if(in->minimumLauncherVersion != -1)
|
|
|
|
{
|
|
|
|
out.insert("minimumLauncherVersion", in->minimumLauncherVersion);
|
|
|
|
}
|
|
|
|
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-08 02:56:44 +05:30
|
|
|
Bits::readString(libObj, "url", out->m_base_url);
|
2016-03-07 06:31:28 +05:30
|
|
|
if (libObj.contains("extract"))
|
|
|
|
{
|
|
|
|
out->applyExcludes = true;
|
|
|
|
auto extractObj = requireObject(libObj.value("extract"));
|
|
|
|
for (auto excludeVal : requireArray(extractObj.value("exclude")))
|
|
|
|
{
|
|
|
|
out->extract_excludes.append(requireString(excludeVal));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
out->m_native_classifiers[opSys] = it.value().toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (libObj.contains("rules"))
|
|
|
|
{
|
|
|
|
out->applyRules = true;
|
|
|
|
out->m_rules = rulesFromJsonV4(libObj);
|
|
|
|
}
|
|
|
|
if (libObj.contains("downloads"))
|
|
|
|
{
|
|
|
|
out->m_mojang_downloads = libDownloadInfoFromJson(libObj);
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
QJsonObject MojangVersionFormat::libraryToJson(Library *library)
|
|
|
|
{
|
|
|
|
QJsonObject libRoot;
|
|
|
|
libRoot.insert("name", (QString)library->m_name);
|
|
|
|
if (library->m_base_url != "http://" + URLConstants::AWS_DOWNLOAD_LIBRARIES &&
|
|
|
|
library->m_base_url != "https://" + URLConstants::AWS_DOWNLOAD_LIBRARIES &&
|
|
|
|
library->m_base_url != "https://" + URLConstants::LIBRARY_BASE && !library->m_base_url.isEmpty())
|
|
|
|
{
|
|
|
|
libRoot.insert("url", library->m_base_url);
|
|
|
|
}
|
|
|
|
if (library->isNative())
|
|
|
|
{
|
|
|
|
QJsonObject nativeList;
|
|
|
|
auto iter = library->m_native_classifiers.begin();
|
|
|
|
while (iter != library->m_native_classifiers.end())
|
|
|
|
{
|
|
|
|
nativeList.insert(OpSys_toString(iter.key()), iter.value());
|
|
|
|
iter++;
|
|
|
|
}
|
|
|
|
libRoot.insert("natives", nativeList);
|
|
|
|
if (library->extract_excludes.size())
|
|
|
|
{
|
|
|
|
QJsonArray excludes;
|
|
|
|
QJsonObject extract;
|
|
|
|
for (auto exclude : library->extract_excludes)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
if(library->m_mojang_downloads)
|
|
|
|
{
|
|
|
|
auto downloadsObj = libDownloadInfoToJson(library->m_mojang_downloads);
|
|
|
|
libRoot.insert("downloads", downloadsObj);
|
|
|
|
}
|
|
|
|
return libRoot;
|
|
|
|
}
|