2021-03-26 22:15:20 +00:00
|
|
|
#include "FlamePackIndex.h"
|
|
|
|
|
|
|
|
#include "Json.h"
|
|
|
|
|
2022-05-08 08:22:50 +01:00
|
|
|
void Flame::loadIndexedPack(Flame::IndexedPack& pack, QJsonObject& obj)
|
2021-03-26 22:15:20 +00:00
|
|
|
{
|
|
|
|
pack.addonId = Json::requireInteger(obj, "id");
|
|
|
|
pack.name = Json::requireString(obj, "name");
|
|
|
|
pack.description = Json::ensureString(obj, "summary", "");
|
|
|
|
|
2022-05-08 08:22:50 +01:00
|
|
|
auto logo = Json::requireObject(obj, "logo");
|
|
|
|
pack.logoName = Json::requireString(logo, "title");
|
|
|
|
pack.logoUrl = Json::requireString(logo, "thumbnailUrl");
|
2021-03-26 22:15:20 +00:00
|
|
|
|
|
|
|
auto authors = Json::requireArray(obj, "authors");
|
2022-05-08 08:22:50 +01:00
|
|
|
for (auto authorIter : authors) {
|
2021-03-26 22:15:20 +00:00
|
|
|
auto author = Json::requireObject(authorIter);
|
|
|
|
Flame::ModpackAuthor packAuthor;
|
|
|
|
packAuthor.name = Json::requireString(author, "name");
|
|
|
|
packAuthor.url = Json::requireString(author, "url");
|
|
|
|
pack.authors.append(packAuthor);
|
|
|
|
}
|
2022-05-08 08:22:50 +01:00
|
|
|
int defaultFileId = Json::requireInteger(obj, "mainFileId");
|
2021-03-26 22:15:20 +00:00
|
|
|
|
|
|
|
bool found = false;
|
|
|
|
// check if there are some files before adding the pack
|
|
|
|
auto files = Json::requireArray(obj, "latestFiles");
|
2022-05-08 08:22:50 +01:00
|
|
|
for (auto fileIter : files) {
|
2021-03-26 22:15:20 +00:00
|
|
|
auto file = Json::requireObject(fileIter);
|
|
|
|
int id = Json::requireInteger(file, "id");
|
|
|
|
|
|
|
|
// NOTE: for now, ignore everything that's not the default...
|
2022-05-08 08:22:50 +01:00
|
|
|
if (id != defaultFileId) {
|
2021-03-26 22:15:20 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-05-08 08:22:50 +01:00
|
|
|
auto versionArray = Json::requireArray(file, "gameVersions");
|
|
|
|
if (versionArray.size() < 1) {
|
2021-03-26 22:15:20 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
2022-05-08 08:22:50 +01:00
|
|
|
if (!found) {
|
2021-03-26 22:15:20 +00:00
|
|
|
throw JSONValidationError(QString("Pack with no good file, skipping: %1").arg(pack.name));
|
|
|
|
}
|
2022-05-24 16:27:32 +01:00
|
|
|
|
|
|
|
loadIndexedInfo(pack, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Flame::loadIndexedInfo(IndexedPack& pack, QJsonObject& obj)
|
|
|
|
{
|
|
|
|
auto links_obj = Json::ensureObject(obj, "links");
|
|
|
|
|
2022-06-15 08:11:23 +01:00
|
|
|
pack.extra.websiteUrl = Json::ensureString(links_obj, "websiteUrl");
|
2023-08-14 17:16:53 +01:00
|
|
|
if (pack.extra.websiteUrl.endsWith('/'))
|
2022-05-24 16:27:32 +01:00
|
|
|
pack.extra.websiteUrl.chop(1);
|
|
|
|
|
|
|
|
pack.extra.issuesUrl = Json::ensureString(links_obj, "issuesUrl");
|
2023-08-14 17:16:53 +01:00
|
|
|
if (pack.extra.issuesUrl.endsWith('/'))
|
2022-05-24 16:27:32 +01:00
|
|
|
pack.extra.issuesUrl.chop(1);
|
|
|
|
|
|
|
|
pack.extra.sourceUrl = Json::ensureString(links_obj, "sourceUrl");
|
2023-08-14 17:16:53 +01:00
|
|
|
if (pack.extra.sourceUrl.endsWith('/'))
|
2022-05-24 16:27:32 +01:00
|
|
|
pack.extra.sourceUrl.chop(1);
|
|
|
|
|
|
|
|
pack.extra.wikiUrl = Json::ensureString(links_obj, "wikiUrl");
|
2023-08-14 17:16:53 +01:00
|
|
|
if (pack.extra.wikiUrl.endsWith('/'))
|
2022-05-24 16:27:32 +01:00
|
|
|
pack.extra.wikiUrl.chop(1);
|
|
|
|
|
|
|
|
pack.extraInfoLoaded = true;
|
2021-03-26 22:15:20 +00:00
|
|
|
}
|
|
|
|
|
2022-05-08 08:22:50 +01:00
|
|
|
void Flame::loadIndexedPackVersions(Flame::IndexedPack& pack, QJsonArray& arr)
|
2021-03-26 22:15:20 +00:00
|
|
|
{
|
|
|
|
QVector<Flame::IndexedVersion> unsortedVersions;
|
2022-05-08 08:22:50 +01:00
|
|
|
for (auto versionIter : arr) {
|
2021-03-26 22:15:20 +00:00
|
|
|
auto version = Json::requireObject(versionIter);
|
2022-05-08 08:22:50 +01:00
|
|
|
Flame::IndexedVersion file;
|
2021-03-26 22:15:20 +00:00
|
|
|
|
|
|
|
file.addonId = pack.addonId;
|
|
|
|
file.fileId = Json::requireInteger(version, "id");
|
2022-05-08 08:22:50 +01:00
|
|
|
auto versionArray = Json::requireArray(version, "gameVersions");
|
|
|
|
if (versionArray.size() < 1) {
|
2021-03-26 22:15:20 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// pick the latest version supported
|
|
|
|
file.mcVersion = versionArray[0].toString();
|
|
|
|
file.version = Json::requireString(version, "displayName");
|
2022-05-21 07:31:07 +01:00
|
|
|
file.downloadUrl = Json::ensureString(version, "downloadUrl");
|
2022-05-25 22:04:49 +01:00
|
|
|
|
|
|
|
// only add if we have a download URL (third party distribution is enabled)
|
|
|
|
if (!file.downloadUrl.isEmpty()) {
|
|
|
|
unsortedVersions.append(file);
|
2022-05-21 07:31:07 +01:00
|
|
|
}
|
2021-03-26 22:15:20 +00:00
|
|
|
}
|
|
|
|
|
2022-05-08 08:22:50 +01:00
|
|
|
auto orderSortPredicate = [](const IndexedVersion& a, const IndexedVersion& b) -> bool { return a.fileId > b.fileId; };
|
2021-03-26 22:15:20 +00:00
|
|
|
std::sort(unsortedVersions.begin(), unsortedVersions.end(), orderSortPredicate);
|
|
|
|
pack.versions = unsortedVersions;
|
|
|
|
pack.versionsLoaded = true;
|
|
|
|
}
|