2022-01-16 15:50:21 +05:30
|
|
|
#include "FlameModIndex.h"
|
2022-03-03 03:05:59 +05:30
|
|
|
|
2022-01-16 15:50:21 +05:30
|
|
|
#include "Json.h"
|
|
|
|
#include "minecraft/MinecraftInstance.h"
|
|
|
|
#include "minecraft/PackProfile.h"
|
2022-03-03 03:05:59 +05:30
|
|
|
#include "net/NetJob.h"
|
2022-01-16 15:50:21 +05:30
|
|
|
|
2022-03-03 03:05:59 +05:30
|
|
|
void FlameMod::loadIndexedPack(ModPlatform::IndexedPack& pack, QJsonObject& obj)
|
2022-01-16 15:50:21 +05:30
|
|
|
{
|
|
|
|
pack.addonId = Json::requireInteger(obj, "id");
|
|
|
|
pack.name = Json::requireString(obj, "name");
|
|
|
|
pack.websiteUrl = Json::ensureString(obj, "websiteUrl", "");
|
|
|
|
pack.description = Json::ensureString(obj, "summary", "");
|
|
|
|
|
|
|
|
bool thumbnailFound = false;
|
|
|
|
auto attachments = Json::requireArray(obj, "attachments");
|
2022-03-03 03:05:59 +05:30
|
|
|
for (auto attachmentRaw : attachments) {
|
2022-01-16 15:50:21 +05:30
|
|
|
auto attachmentObj = Json::requireObject(attachmentRaw);
|
|
|
|
bool isDefault = attachmentObj.value("isDefault").toBool(false);
|
2022-03-03 03:05:59 +05:30
|
|
|
if (isDefault) {
|
2022-01-16 15:50:21 +05:30
|
|
|
thumbnailFound = true;
|
|
|
|
pack.logoName = Json::requireString(attachmentObj, "title");
|
|
|
|
pack.logoUrl = Json::requireString(attachmentObj, "thumbnailUrl");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-03 03:05:59 +05:30
|
|
|
if (!thumbnailFound) { throw JSONValidationError(QString("Pack without an icon, skipping: %1").arg(pack.name)); }
|
2022-01-16 15:50:21 +05:30
|
|
|
|
|
|
|
auto authors = Json::requireArray(obj, "authors");
|
2022-03-03 03:05:59 +05:30
|
|
|
for (auto authorIter : authors) {
|
2022-01-16 15:50:21 +05:30
|
|
|
auto author = Json::requireObject(authorIter);
|
2022-03-03 03:05:59 +05:30
|
|
|
ModPlatform::ModpackAuthor packAuthor;
|
2022-01-16 15:50:21 +05:30
|
|
|
packAuthor.name = Json::requireString(author, "name");
|
|
|
|
packAuthor.url = Json::requireString(author, "url");
|
|
|
|
pack.authors.append(packAuthor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-03 03:05:59 +05:30
|
|
|
void FlameMod::loadIndexedPackVersions(ModPlatform::IndexedPack& pack,
|
|
|
|
QJsonArray& arr,
|
|
|
|
const shared_qobject_ptr<QNetworkAccessManager>& network,
|
|
|
|
BaseInstance* inst)
|
2022-01-16 15:50:21 +05:30
|
|
|
{
|
2022-03-03 03:05:59 +05:30
|
|
|
QVector<ModPlatform::IndexedVersion> unsortedVersions;
|
2022-03-08 19:42:35 +05:30
|
|
|
bool hasFabric = !(dynamic_cast<MinecraftInstance*>(inst))->getPackProfile()->getComponentVersion("net.fabricmc.fabric-loader").isEmpty();
|
|
|
|
QString mcVersion = (dynamic_cast<MinecraftInstance*>(inst))->getPackProfile()->getComponentVersion("net.minecraft");
|
2022-01-16 15:50:21 +05:30
|
|
|
|
2022-03-03 03:05:59 +05:30
|
|
|
for (auto versionIter : arr) {
|
2022-01-16 15:50:21 +05:30
|
|
|
auto obj = versionIter.toObject();
|
2022-02-27 23:35:38 +05:30
|
|
|
|
2022-01-16 15:50:21 +05:30
|
|
|
auto versionArray = Json::requireArray(obj, "gameVersion");
|
2022-03-03 03:05:59 +05:30
|
|
|
if (versionArray.isEmpty()) { continue; }
|
2022-02-27 23:35:38 +05:30
|
|
|
|
2022-03-03 03:05:59 +05:30
|
|
|
ModPlatform::IndexedVersion file;
|
|
|
|
for (auto mcVer : versionArray) {
|
2022-01-16 15:50:21 +05:30
|
|
|
file.mcVersion.append(mcVer.toString());
|
|
|
|
}
|
|
|
|
|
2022-02-27 23:35:38 +05:30
|
|
|
file.addonId = pack.addonId;
|
|
|
|
file.fileId = Json::requireInteger(obj, "id");
|
|
|
|
file.date = Json::requireString(obj, "fileDate");
|
2022-01-16 15:50:21 +05:30
|
|
|
file.version = Json::requireString(obj, "displayName");
|
|
|
|
file.downloadUrl = Json::requireString(obj, "downloadUrl");
|
|
|
|
file.fileName = Json::requireString(obj, "fileName");
|
|
|
|
|
|
|
|
auto modules = Json::requireArray(obj, "modules");
|
2022-02-27 23:35:38 +05:30
|
|
|
bool is_valid_fabric_version = false;
|
2022-03-03 03:05:59 +05:30
|
|
|
for (auto m : modules) {
|
|
|
|
auto fname = Json::requireString(m.toObject(), "foldername");
|
2022-02-27 23:35:38 +05:30
|
|
|
// FIXME: This does not work properly when a mod supports more than one mod loader, since
|
|
|
|
// they bundle the meta files for all of them in the same arquive, even when that version
|
|
|
|
// doesn't support the given mod loader.
|
2022-03-03 03:05:59 +05:30
|
|
|
if (hasFabric) {
|
|
|
|
if (fname == "fabric.mod.json") {
|
2022-02-27 23:35:38 +05:30
|
|
|
is_valid_fabric_version = true;
|
2022-01-16 15:50:21 +05:30
|
|
|
break;
|
|
|
|
}
|
2022-03-03 03:05:59 +05:30
|
|
|
} else
|
|
|
|
break;
|
2022-02-28 06:32:43 +05:30
|
|
|
// NOTE: Since we're not validating forge versions, we can just skip this loop.
|
2022-01-16 15:50:21 +05:30
|
|
|
}
|
2022-02-27 23:35:38 +05:30
|
|
|
|
2022-03-03 03:05:59 +05:30
|
|
|
if (hasFabric && !is_valid_fabric_version) continue;
|
2022-01-16 15:50:21 +05:30
|
|
|
|
|
|
|
unsortedVersions.append(file);
|
|
|
|
}
|
2022-03-03 03:05:59 +05:30
|
|
|
auto orderSortPredicate = [](const ModPlatform::IndexedVersion& a, const ModPlatform::IndexedVersion& b) -> bool {
|
|
|
|
// dates are in RFC 3339 format
|
2022-01-16 15:50:21 +05:30
|
|
|
return a.date > b.date;
|
|
|
|
};
|
|
|
|
std::sort(unsortedVersions.begin(), unsortedVersions.end(), orderSortPredicate);
|
|
|
|
pack.versions = unsortedVersions;
|
|
|
|
pack.versionsLoaded = true;
|
2022-02-02 02:53:34 +05:30
|
|
|
}
|