2017-04-20 08:52:04 +05:30
|
|
|
#include "PackManifest.h"
|
|
|
|
#include "Json.h"
|
|
|
|
|
2017-04-22 22:21:04 +05:30
|
|
|
static void loadFileV1(Flame::File & f, QJsonObject & file)
|
2017-04-20 08:52:04 +05:30
|
|
|
{
|
|
|
|
f.projectId = Json::requireInteger(file, "projectID");
|
|
|
|
f.fileId = Json::requireInteger(file, "fileID");
|
2017-04-22 03:59:24 +05:30
|
|
|
f.required = Json::ensureBoolean(file, QString("required"), true);
|
2017-04-20 08:52:04 +05:30
|
|
|
}
|
|
|
|
|
2017-04-22 22:21:04 +05:30
|
|
|
static void loadModloaderV1(Flame::Modloader & m, QJsonObject & modLoader)
|
2017-04-20 08:52:04 +05:30
|
|
|
{
|
|
|
|
m.id = Json::requireString(modLoader, "id");
|
2017-04-22 01:53:31 +05:30
|
|
|
m.primary = Json::ensureBoolean(modLoader, QString("primary"), false);
|
2017-04-20 08:52:04 +05:30
|
|
|
}
|
|
|
|
|
2017-04-22 22:21:04 +05:30
|
|
|
static void loadMinecraftV1(Flame::Minecraft & m, QJsonObject & minecraft)
|
2017-04-20 08:52:04 +05:30
|
|
|
{
|
|
|
|
m.version = Json::requireString(minecraft, "version");
|
2017-04-22 08:50:06 +05:30
|
|
|
// extra libraries... apparently only used for a custom Minecraft launcher in the 1.2.5 FTB retro pack
|
2017-04-22 22:21:04 +05:30
|
|
|
// intended use is likely hardcoded in the 'Flame' client, the manifest says nothing
|
2017-04-22 03:59:24 +05:30
|
|
|
m.libraries = Json::ensureString(minecraft, QString("libraries"), QString());
|
2017-04-20 08:52:04 +05:30
|
|
|
auto arr = Json::ensureArray(minecraft, "modLoaders", QJsonArray());
|
|
|
|
for (const auto & item : arr)
|
|
|
|
{
|
|
|
|
auto obj = Json::requireObject(item);
|
2017-04-22 22:21:04 +05:30
|
|
|
Flame::Modloader loader;
|
2017-04-20 08:52:04 +05:30
|
|
|
loadModloaderV1(loader, obj);
|
|
|
|
m.modLoaders.append(loader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-22 22:21:04 +05:30
|
|
|
static void loadManifestV1(Flame::Manifest & m, QJsonObject & manifest)
|
2017-04-20 08:52:04 +05:30
|
|
|
{
|
|
|
|
auto mc = Json::requireObject(manifest, "minecraft");
|
|
|
|
loadMinecraftV1(m.minecraft, mc);
|
2017-04-22 08:50:06 +05:30
|
|
|
m.name = Json::ensureString(manifest, QString("name"), "Unnamed");
|
|
|
|
m.version = Json::ensureString(manifest, QString("version"), QString());
|
|
|
|
m.author = Json::ensureString(manifest, QString("author"), "Anonymous Coward");
|
2017-04-20 08:52:04 +05:30
|
|
|
auto arr = Json::ensureArray(manifest, "files", QJsonArray());
|
|
|
|
for (const auto & item : arr)
|
|
|
|
{
|
|
|
|
auto obj = Json::requireObject(item);
|
2017-04-22 22:21:04 +05:30
|
|
|
Flame::File file;
|
2017-04-20 08:52:04 +05:30
|
|
|
loadFileV1(file, obj);
|
|
|
|
m.files.append(file);
|
|
|
|
}
|
|
|
|
m.overrides = Json::ensureString(manifest, "overrides", "overrides");
|
|
|
|
}
|
|
|
|
|
2017-04-22 22:21:04 +05:30
|
|
|
void Flame::loadManifest(Flame::Manifest & m, const QString &filepath)
|
2017-04-20 08:52:04 +05:30
|
|
|
{
|
|
|
|
auto doc = Json::requireDocument(filepath);
|
|
|
|
auto obj = Json::requireObject(doc);
|
|
|
|
m.manifestType = Json::requireString(obj, "manifestType");
|
|
|
|
if(m.manifestType != "minecraftModpack")
|
|
|
|
{
|
2017-04-22 22:21:04 +05:30
|
|
|
throw JSONValidationError("Not a modpack manifest!");
|
2017-04-20 08:52:04 +05:30
|
|
|
}
|
|
|
|
m.manifestVersion = Json::requireInteger(obj, "manifestVersion");
|
|
|
|
if(m.manifestVersion != 1)
|
|
|
|
{
|
|
|
|
throw JSONValidationError(QString("Unknown manifest version (%1)").arg(m.manifestVersion));
|
|
|
|
}
|
|
|
|
loadManifestV1(m, obj);
|
|
|
|
}
|