2022-01-16 10:20:21 +00:00
|
|
|
#include <QObject>
|
|
|
|
#include "FlameModIndex.h"
|
|
|
|
#include "Json.h"
|
|
|
|
#include "net/NetJob.h"
|
|
|
|
#include "BaseInstance.h"
|
|
|
|
#include "minecraft/MinecraftInstance.h"
|
|
|
|
#include "minecraft/PackProfile.h"
|
|
|
|
|
|
|
|
|
|
|
|
void FlameMod::loadIndexedPack(FlameMod::IndexedPack & pack, QJsonObject & obj)
|
|
|
|
{
|
|
|
|
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");
|
|
|
|
for(auto attachmentRaw: attachments) {
|
|
|
|
auto attachmentObj = Json::requireObject(attachmentRaw);
|
|
|
|
bool isDefault = attachmentObj.value("isDefault").toBool(false);
|
|
|
|
if(isDefault) {
|
|
|
|
thumbnailFound = true;
|
|
|
|
pack.logoName = Json::requireString(attachmentObj, "title");
|
|
|
|
pack.logoUrl = Json::requireString(attachmentObj, "thumbnailUrl");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!thumbnailFound) {
|
|
|
|
throw JSONValidationError(QString("Pack without an icon, skipping: %1").arg(pack.name));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
auto authors = Json::requireArray(obj, "authors");
|
|
|
|
for(auto authorIter: authors) {
|
|
|
|
auto author = Json::requireObject(authorIter);
|
|
|
|
FlameMod::ModpackAuthor packAuthor;
|
|
|
|
packAuthor.name = Json::requireString(author, "name");
|
|
|
|
packAuthor.url = Json::requireString(author, "url");
|
|
|
|
pack.authors.append(packAuthor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FlameMod::loadIndexedPackVersions(FlameMod::IndexedPack & pack, QJsonArray & arr, const shared_qobject_ptr<QNetworkAccessManager>& network, BaseInstance * inst)
|
|
|
|
{
|
|
|
|
QVector<FlameMod::IndexedVersion> unsortedVersions;
|
|
|
|
bool hasFabric = !((MinecraftInstance *)inst)->getPackProfile()->getComponentVersion("net.fabricmc.fabric-loader").isEmpty();
|
|
|
|
QString mcVersion = ((MinecraftInstance *)inst)->getPackProfile()->getComponentVersion("net.minecraft");
|
|
|
|
|
|
|
|
for(auto versionIter: arr) {
|
|
|
|
auto obj = versionIter.toObject();
|
2022-02-27 18:05:38 +00:00
|
|
|
|
2022-01-16 10:20:21 +00:00
|
|
|
auto versionArray = Json::requireArray(obj, "gameVersion");
|
2022-02-27 18:05:38 +00:00
|
|
|
if (versionArray.isEmpty()) {
|
2022-01-16 10:20:21 +00:00
|
|
|
continue;
|
|
|
|
}
|
2022-02-27 18:05:38 +00:00
|
|
|
|
|
|
|
FlameMod::IndexedVersion file;
|
2022-01-16 10:20:21 +00:00
|
|
|
for(auto mcVer : versionArray){
|
|
|
|
file.mcVersion.append(mcVer.toString());
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
file.downloadUrl = Json::requireString(obj, "downloadUrl");
|
|
|
|
file.fileName = Json::requireString(obj, "fileName");
|
|
|
|
|
|
|
|
auto modules = Json::requireArray(obj, "modules");
|
2022-02-27 18:05:38 +00:00
|
|
|
bool is_valid_fabric_version = false;
|
2022-01-16 10:20:21 +00:00
|
|
|
for(auto m : modules){
|
|
|
|
auto fname = Json::requireString(m.toObject(),"foldername");
|
2022-02-27 18:05:38 +00:00
|
|
|
// 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-01-16 10:20:21 +00:00
|
|
|
if(hasFabric){
|
|
|
|
if(fname == "fabric.mod.json"){
|
2022-02-27 18:05:38 +00:00
|
|
|
is_valid_fabric_version = true;
|
2022-01-16 10:20:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-02-28 01:02:43 +00:00
|
|
|
else break;
|
|
|
|
// NOTE: Since we're not validating forge versions, we can just skip this loop.
|
2022-01-16 10:20:21 +00:00
|
|
|
}
|
2022-02-27 18:05:38 +00:00
|
|
|
|
|
|
|
if(hasFabric && !is_valid_fabric_version)
|
2022-01-16 10:20:21 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
unsortedVersions.append(file);
|
|
|
|
}
|
|
|
|
auto orderSortPredicate = [](const IndexedVersion & a, const IndexedVersion & b) -> bool
|
|
|
|
{
|
|
|
|
//dates are in RFC 3339 format
|
|
|
|
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
|
|
|
}
|