PrismLauncher/launcher/modplatform/flame/FlameModIndex.cpp

73 lines
2.7 KiB
C++
Raw Normal View History

2022-01-16 10:20:21 +00:00
#include "FlameModIndex.h"
2022-01-16 10:20:21 +00:00
#include "Json.h"
#include "minecraft/MinecraftInstance.h"
#include "minecraft/PackProfile.h"
#include "modplatform/flame/FlameAPI.h"
#include "net/NetJob.h"
2022-01-16 10:20:21 +00:00
void FlameMod::loadIndexedPack(ModPlatform::IndexedPack& pack, QJsonObject& obj)
2022-01-16 10:20:21 +00:00
{
pack.addonId = Json::requireInteger(obj, "id");
pack.name = Json::requireString(obj, "name");
2022-05-08 08:22:50 +01:00
pack.websiteUrl = Json::ensureString(Json::ensureObject(obj, "links"), "websiteUrl", "");
2022-01-16 10:20:21 +00:00
pack.description = Json::ensureString(obj, "summary", "");
2022-05-08 08:22:50 +01:00
QJsonObject logo = Json::requireObject(obj, "logo");
pack.logoName = Json::requireString(logo, "title");
pack.logoUrl = Json::requireString(logo, "thumbnailUrl");
2022-01-16 10:20:21 +00:00
auto authors = Json::requireArray(obj, "authors");
for (auto authorIter : authors) {
2022-01-16 10:20:21 +00:00
auto author = Json::requireObject(authorIter);
ModPlatform::ModpackAuthor packAuthor;
2022-01-16 10:20:21 +00:00
packAuthor.name = Json::requireString(author, "name");
packAuthor.url = Json::requireString(author, "url");
pack.authors.append(packAuthor);
}
}
void FlameMod::loadIndexedPackVersions(ModPlatform::IndexedPack& pack,
QJsonArray& arr,
const shared_qobject_ptr<QNetworkAccessManager>& network,
BaseInstance* inst)
2022-01-16 10:20:21 +00:00
{
QVector<ModPlatform::IndexedVersion> unsortedVersions;
auto profile = (dynamic_cast<MinecraftInstance*>(inst))->getPackProfile();
QString mcVersion = profile->getComponentVersion("net.minecraft");
2022-01-16 10:20:21 +00:00
for (auto versionIter : arr) {
2022-01-16 10:20:21 +00:00
auto obj = versionIter.toObject();
2022-05-08 08:22:50 +01:00
auto versionArray = Json::requireArray(obj, "gameVersions");
if (versionArray.isEmpty()) {
continue;
}
ModPlatform::IndexedVersion file;
for (auto mcVer : versionArray) {
2022-05-08 08:22:50 +01:00
auto str = mcVer.toString();
if (str.contains('.'))
file.mcVersion.append(str);
2022-01-16 10:20:21 +00:00
}
file.addonId = pack.addonId;
file.fileId = Json::requireInteger(obj, "id");
file.date = Json::requireString(obj, "fileDate");
2022-01-16 10:20:21 +00:00
file.version = Json::requireString(obj, "displayName");
file.downloadUrl = Json::requireString(obj, "downloadUrl");
2022-01-16 10:20:21 +00:00
file.fileName = Json::requireString(obj, "fileName");
unsortedVersions.append(file);
}
2022-05-08 08:22:50 +01:00
auto orderSortPredicate = [](const ModPlatform::IndexedVersion& a, const ModPlatform::IndexedVersion& b) -> bool {
// dates are in RFC 3339 format
2022-01-16 10:20:21 +00:00
return a.date > b.date;
};
std::sort(unsortedVersions.begin(), unsortedVersions.end(), orderSortPredicate);
pack.versions = unsortedVersions;
pack.versionsLoaded = true;
2022-02-01 21:23:34 +00:00
}