2017-04-20 04:22:04 +01:00
|
|
|
#include "PackManifest.h"
|
|
|
|
#include "Json.h"
|
|
|
|
|
2022-05-08 08:22:50 +01:00
|
|
|
static void loadFileV1(Flame::File& f, QJsonObject& file)
|
2017-04-20 04:22:04 +01:00
|
|
|
{
|
|
|
|
f.projectId = Json::requireInteger(file, "projectID");
|
|
|
|
f.fileId = Json::requireInteger(file, "fileID");
|
2017-04-21 23:29:24 +01:00
|
|
|
f.required = Json::ensureBoolean(file, QString("required"), true);
|
2017-04-20 04:22:04 +01:00
|
|
|
}
|
|
|
|
|
2022-05-08 08:22:50 +01:00
|
|
|
static void loadModloaderV1(Flame::Modloader& m, QJsonObject& modLoader)
|
2017-04-20 04:22:04 +01:00
|
|
|
{
|
|
|
|
m.id = Json::requireString(modLoader, "id");
|
2017-04-21 21:23:31 +01:00
|
|
|
m.primary = Json::ensureBoolean(modLoader, QString("primary"), false);
|
2017-04-20 04:22:04 +01:00
|
|
|
}
|
|
|
|
|
2022-05-08 08:22:50 +01:00
|
|
|
static void loadMinecraftV1(Flame::Minecraft& m, QJsonObject& minecraft)
|
2017-04-20 04:22:04 +01:00
|
|
|
{
|
|
|
|
m.version = Json::requireString(minecraft, "version");
|
2017-04-22 04:20:06 +01:00
|
|
|
// extra libraries... apparently only used for a custom Minecraft launcher in the 1.2.5 FTB retro pack
|
2017-04-22 17:51:04 +01:00
|
|
|
// intended use is likely hardcoded in the 'Flame' client, the manifest says nothing
|
2017-04-21 23:29:24 +01:00
|
|
|
m.libraries = Json::ensureString(minecraft, QString("libraries"), QString());
|
2017-04-20 04:22:04 +01:00
|
|
|
auto arr = Json::ensureArray(minecraft, "modLoaders", QJsonArray());
|
2022-05-08 08:22:50 +01:00
|
|
|
for (QJsonValueRef item : arr) {
|
2017-04-20 04:22:04 +01:00
|
|
|
auto obj = Json::requireObject(item);
|
2017-04-22 17:51:04 +01:00
|
|
|
Flame::Modloader loader;
|
2017-04-20 04:22:04 +01:00
|
|
|
loadModloaderV1(loader, obj);
|
|
|
|
m.modLoaders.append(loader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-14 20:41:49 +01:00
|
|
|
static void loadManifestV1(Flame::Manifest& pack, QJsonObject& manifest)
|
2017-04-20 04:22:04 +01:00
|
|
|
{
|
|
|
|
auto mc = Json::requireObject(manifest, "minecraft");
|
2022-07-14 20:41:49 +01:00
|
|
|
|
|
|
|
loadMinecraftV1(pack.minecraft, mc);
|
|
|
|
|
|
|
|
pack.name = Json::ensureString(manifest, QString("name"), "Unnamed");
|
|
|
|
pack.version = Json::ensureString(manifest, QString("version"), QString());
|
|
|
|
pack.author = Json::ensureString(manifest, QString("author"), "Anonymous");
|
|
|
|
|
2017-04-20 04:22:04 +01:00
|
|
|
auto arr = Json::ensureArray(manifest, "files", QJsonArray());
|
2022-07-14 20:41:49 +01:00
|
|
|
for (auto item : arr) {
|
2017-04-20 04:22:04 +01:00
|
|
|
auto obj = Json::requireObject(item);
|
2022-07-14 20:41:49 +01:00
|
|
|
|
2017-04-22 17:51:04 +01:00
|
|
|
Flame::File file;
|
2017-04-20 04:22:04 +01:00
|
|
|
loadFileV1(file, obj);
|
2022-07-14 20:41:49 +01:00
|
|
|
|
2023-08-14 17:16:53 +01:00
|
|
|
pack.files.insert(file.fileId, file);
|
2017-04-20 04:22:04 +01:00
|
|
|
}
|
2022-07-14 20:41:49 +01:00
|
|
|
|
|
|
|
pack.overrides = Json::ensureString(manifest, "overrides", "overrides");
|
|
|
|
|
|
|
|
pack.is_loaded = true;
|
2017-04-20 04:22:04 +01:00
|
|
|
}
|
|
|
|
|
2022-05-08 08:22:50 +01:00
|
|
|
void Flame::loadManifest(Flame::Manifest& m, const QString& filepath)
|
2017-04-20 04:22:04 +01:00
|
|
|
{
|
|
|
|
auto doc = Json::requireDocument(filepath);
|
|
|
|
auto obj = Json::requireObject(doc);
|
|
|
|
m.manifestType = Json::requireString(obj, "manifestType");
|
2022-05-08 08:22:50 +01:00
|
|
|
if (m.manifestType != "minecraftModpack") {
|
2017-04-22 17:51:04 +01:00
|
|
|
throw JSONValidationError("Not a modpack manifest!");
|
2017-04-20 04:22:04 +01:00
|
|
|
}
|
|
|
|
m.manifestVersion = Json::requireInteger(obj, "manifestVersion");
|
2022-05-08 08:22:50 +01:00
|
|
|
if (m.manifestVersion != 1) {
|
2017-04-20 04:22:04 +01:00
|
|
|
throw JSONValidationError(QString("Unknown manifest version (%1)").arg(m.manifestVersion));
|
|
|
|
}
|
|
|
|
loadManifestV1(m, obj);
|
|
|
|
}
|
2019-06-30 10:03:59 +01:00
|
|
|
|
2023-08-14 17:16:53 +01:00
|
|
|
bool Flame::File::parseFromObject(const QJsonObject& obj, bool throw_on_blocked)
|
2019-06-30 10:03:59 +01:00
|
|
|
{
|
2022-05-08 08:22:50 +01:00
|
|
|
fileName = Json::requireString(obj, "fileName");
|
2019-06-30 10:03:59 +01:00
|
|
|
// This is a piece of a Flame project JSON pulled out into the file metadata (here) for convenience
|
|
|
|
// It is also optional
|
2022-05-08 08:22:50 +01:00
|
|
|
type = File::Type::SingleFile;
|
|
|
|
|
2023-07-08 21:38:00 +01:00
|
|
|
targetFolder = "mods";
|
|
|
|
|
2022-05-28 20:53:12 +01:00
|
|
|
// get the hash
|
|
|
|
hash = QString();
|
|
|
|
auto hashes = Json::ensureArray(obj, "hashes");
|
2023-08-14 17:16:53 +01:00
|
|
|
for (QJsonValueRef item : hashes) {
|
2022-05-28 20:53:12 +01:00
|
|
|
auto hobj = Json::requireObject(item);
|
|
|
|
auto algo = Json::requireInteger(hobj, "algo");
|
|
|
|
auto value = Json::requireString(hobj, "value");
|
|
|
|
if (algo == 1) {
|
|
|
|
hash = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// may throw, if the project is blocked
|
|
|
|
QString rawUrl = Json::ensureString(obj, "downloadUrl");
|
|
|
|
url = QUrl(rawUrl, QUrl::TolerantMode);
|
2022-07-21 20:41:44 +01:00
|
|
|
if (!url.isValid() && throw_on_blocked) {
|
2022-05-28 20:53:12 +01:00
|
|
|
throw JSONValidationError(QString("Invalid URL: %1").arg(rawUrl));
|
|
|
|
}
|
2022-05-20 21:06:36 +01:00
|
|
|
|
2019-06-30 10:03:59 +01:00
|
|
|
resolved = true;
|
|
|
|
return true;
|
|
|
|
}
|