2017-04-20 08:52:04 +05:30
|
|
|
#include "PackManifest.h"
|
|
|
|
#include "Json.h"
|
|
|
|
|
2022-05-08 12:52:50 +05:30
|
|
|
static void loadFileV1(Flame::File& f, QJsonObject& file)
|
2017-04-20 08:52:04 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
f.projectId = Json::requireInteger(file, "projectID");
|
|
|
|
f.fileId = Json::requireInteger(file, "fileID");
|
|
|
|
f.required = Json::ensureBoolean(file, QString("required"), true);
|
2017-04-20 08:52:04 +05:30
|
|
|
}
|
|
|
|
|
2022-05-08 12:52:50 +05:30
|
|
|
static void loadModloaderV1(Flame::Modloader& m, QJsonObject& modLoader)
|
2017-04-20 08:52:04 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
m.id = Json::requireString(modLoader, "id");
|
|
|
|
m.primary = Json::ensureBoolean(modLoader, QString("primary"), false);
|
2017-04-20 08:52:04 +05:30
|
|
|
}
|
|
|
|
|
2022-05-08 12:52:50 +05:30
|
|
|
static void loadMinecraftV1(Flame::Minecraft& m, QJsonObject& minecraft)
|
2017-04-20 08:52:04 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
m.version = Json::requireString(minecraft, "version");
|
|
|
|
// extra libraries... apparently only used for a custom Minecraft launcher in the 1.2.5 FTB retro pack
|
|
|
|
// intended use is likely hardcoded in the 'Flame' client, the manifest says nothing
|
|
|
|
m.libraries = Json::ensureString(minecraft, QString("libraries"), QString());
|
|
|
|
auto arr = Json::ensureArray(minecraft, "modLoaders", QJsonArray());
|
2022-05-08 12:52:50 +05:30
|
|
|
for (QJsonValueRef item : arr) {
|
2018-07-15 18:21:05 +05:30
|
|
|
auto obj = Json::requireObject(item);
|
|
|
|
Flame::Modloader loader;
|
|
|
|
loadModloaderV1(loader, obj);
|
|
|
|
m.modLoaders.append(loader);
|
|
|
|
}
|
2017-04-20 08:52:04 +05:30
|
|
|
}
|
|
|
|
|
2022-07-15 01:11:49 +05:30
|
|
|
static void loadManifestV1(Flame::Manifest& pack, QJsonObject& manifest)
|
2017-04-20 08:52:04 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
auto mc = Json::requireObject(manifest, "minecraft");
|
2022-07-15 01:11:49 +05:30
|
|
|
|
|
|
|
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");
|
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
auto arr = Json::ensureArray(manifest, "files", QJsonArray());
|
2022-07-15 01:11:49 +05:30
|
|
|
for (auto item : arr) {
|
2018-07-15 18:21:05 +05:30
|
|
|
auto obj = Json::requireObject(item);
|
2022-07-15 01:11:49 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
Flame::File file;
|
|
|
|
loadFileV1(file, obj);
|
2022-07-15 01:11:49 +05:30
|
|
|
|
|
|
|
pack.files.insert(file.fileId,file);
|
2018-07-15 18:21:05 +05:30
|
|
|
}
|
2022-07-15 01:11:49 +05:30
|
|
|
|
|
|
|
pack.overrides = Json::ensureString(manifest, "overrides", "overrides");
|
|
|
|
|
|
|
|
pack.is_loaded = true;
|
2017-04-20 08:52:04 +05:30
|
|
|
}
|
|
|
|
|
2022-05-08 12:52:50 +05:30
|
|
|
void Flame::loadManifest(Flame::Manifest& m, const QString& filepath)
|
2017-04-20 08:52:04 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
auto doc = Json::requireDocument(filepath);
|
|
|
|
auto obj = Json::requireObject(doc);
|
|
|
|
m.manifestType = Json::requireString(obj, "manifestType");
|
2022-05-08 12:52:50 +05:30
|
|
|
if (m.manifestType != "minecraftModpack") {
|
2018-07-15 18:21:05 +05:30
|
|
|
throw JSONValidationError("Not a modpack manifest!");
|
|
|
|
}
|
|
|
|
m.manifestVersion = Json::requireInteger(obj, "manifestVersion");
|
2022-05-08 12:52:50 +05:30
|
|
|
if (m.manifestVersion != 1) {
|
2018-07-15 18:21:05 +05:30
|
|
|
throw JSONValidationError(QString("Unknown manifest version (%1)").arg(m.manifestVersion));
|
|
|
|
}
|
|
|
|
loadManifestV1(m, obj);
|
2017-04-20 08:52:04 +05:30
|
|
|
}
|
2019-06-30 14:33:59 +05:30
|
|
|
|
2022-07-22 01:11:44 +05:30
|
|
|
bool Flame::File::parseFromObject(const QJsonObject& obj, bool throw_on_blocked)
|
2019-06-30 14:33:59 +05:30
|
|
|
{
|
2022-05-08 12:52:50 +05:30
|
|
|
fileName = Json::requireString(obj, "fileName");
|
2019-06-30 14:33:59 +05:30
|
|
|
// 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 12:52:50 +05:30
|
|
|
type = File::Type::SingleFile;
|
|
|
|
|
|
|
|
if (fileName.endsWith(".zip")) {
|
|
|
|
// this is probably a resource pack
|
|
|
|
targetFolder = "resourcepacks";
|
|
|
|
} else {
|
|
|
|
// this is probably a mod, dunno what else could modpacks download
|
|
|
|
targetFolder = "mods";
|
2019-06-30 14:33:59 +05:30
|
|
|
}
|
2022-05-29 01:23:12 +05:30
|
|
|
// get the hash
|
|
|
|
hash = QString();
|
|
|
|
auto hashes = Json::ensureArray(obj, "hashes");
|
|
|
|
for(QJsonValueRef item : hashes) {
|
|
|
|
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-22 01:11:44 +05:30
|
|
|
if (!url.isValid() && throw_on_blocked) {
|
2022-05-29 01:23:12 +05:30
|
|
|
throw JSONValidationError(QString("Invalid URL: %1").arg(rawUrl));
|
|
|
|
}
|
2022-05-21 01:36:36 +05:30
|
|
|
|
2019-06-30 14:33:59 +05:30
|
|
|
resolved = true;
|
|
|
|
return true;
|
|
|
|
}
|