PrismLauncher/launcher/modplatform/flame/FlameModIndex.cpp

94 lines
3.4 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);
}
loadExtraPackData(pack, obj);
}
void FlameMod::loadExtraPackData(ModPlatform::IndexedPack& pack, QJsonObject& obj)
{
auto links_obj = Json::ensureObject(obj, "links");
pack.extraData.issuesUrl = Json::ensureString(links_obj, "issuesUrl");
if(pack.extraData.issuesUrl.endsWith('/'))
pack.extraData.issuesUrl.chop(1);
pack.extraData.sourceUrl = Json::ensureString(links_obj, "sourceUrl");
if(pack.extraData.sourceUrl.endsWith('/'))
pack.extraData.sourceUrl.chop(1);
pack.extraData.wikiUrl = Json::ensureString(links_obj, "wikiUrl");
if(pack.extraData.wikiUrl.endsWith('/'))
pack.extraData.wikiUrl.chop(1);
pack.extraDataLoaded = true;
2022-01-16 10:20:21 +00:00
}
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
}