2022-01-16 10:20:21 +00:00
|
|
|
#include "FlameModIndex.h"
|
2022-03-02 21:35:59 +00:00
|
|
|
|
2022-01-16 10:20:21 +00:00
|
|
|
#include "Json.h"
|
|
|
|
#include "minecraft/MinecraftInstance.h"
|
|
|
|
#include "minecraft/PackProfile.h"
|
2022-04-15 11:38:27 +01:00
|
|
|
#include "modplatform/flame/FlameAPI.h"
|
2022-03-02 21:35:59 +00:00
|
|
|
#include "net/NetJob.h"
|
2022-01-16 10:20:21 +00:00
|
|
|
|
2022-03-02 21:35:59 +00:00
|
|
|
void FlameMod::loadIndexedPack(ModPlatform::IndexedPack& pack, QJsonObject& obj)
|
2022-01-16 10:20:21 +00:00
|
|
|
{
|
|
|
|
pack.addonId = Json::requireInteger(obj, "id");
|
2022-04-13 23:16:36 +01:00
|
|
|
pack.provider = ModPlatform::Provider::FLAME;
|
2022-01-16 10:20:21 +00:00
|
|
|
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");
|
2022-03-02 21:35:59 +00:00
|
|
|
for (auto authorIter : authors) {
|
2022-01-16 10:20:21 +00:00
|
|
|
auto author = Json::requireObject(authorIter);
|
2022-03-02 21:35:59 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-02 21:35:59 +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
|
|
|
{
|
2022-03-02 21:35:59 +00:00
|
|
|
QVector<ModPlatform::IndexedVersion> unsortedVersions;
|
2022-04-15 11:38:27 +01:00
|
|
|
auto profile = (dynamic_cast<MinecraftInstance*>(inst))->getPackProfile();
|
|
|
|
QString mcVersion = profile->getComponentVersion("net.minecraft");
|
2022-01-16 10:20:21 +00:00
|
|
|
|
2022-03-02 21:35:59 +00:00
|
|
|
for (auto versionIter : arr) {
|
2022-01-16 10:20:21 +00:00
|
|
|
auto obj = versionIter.toObject();
|
2022-02-27 18:05:38 +00:00
|
|
|
|
2022-05-08 08:22:50 +01:00
|
|
|
auto versionArray = Json::requireArray(obj, "gameVersions");
|
|
|
|
if (versionArray.isEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
2022-02-27 18:05:38 +00:00
|
|
|
|
2022-03-02 21:35:59 +00:00
|
|
|
ModPlatform::IndexedVersion file;
|
|
|
|
for (auto mcVer : versionArray) {
|
2022-05-08 08:22:50 +01:00
|
|
|
auto str = mcVer.toString();
|
|
|
|
|
2022-05-08 15:25:45 +01:00
|
|
|
if (str.contains('.'))
|
2022-05-08 15:25:51 +01:00
|
|
|
file.mcVersion.append(str);
|
2022-01-16 10:20:21 +00:00
|
|
|
}
|
|
|
|
|
2022-02-27 18:05:38 +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");
|
2022-05-22 21:04:24 +01:00
|
|
|
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
|
|
|
|
2022-03-02 21:35:59 +00: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
|
|
|
}
|