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-01-16 10:20:21 +00:00
|
|
|
|
2022-06-04 00:45:44 +01:00
|
|
|
static FlameAPI api;
|
2022-07-19 15:50:38 +01:00
|
|
|
static ModPlatform::ProviderCapabilities ProviderCaps;
|
2022-04-21 19:45:20 +01: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-11-25 12:23:46 +00:00
|
|
|
pack.provider = ModPlatform::ResourceProvider::FLAME;
|
2022-01-16 10:20:21 +00:00
|
|
|
pack.name = Json::requireString(obj, "name");
|
2022-06-19 18:31:44 +01:00
|
|
|
pack.slug = Json::requireString(obj, "slug");
|
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-06-19 18:31:44 +01:00
|
|
|
QJsonObject logo = Json::ensureObject(obj, "logo");
|
|
|
|
pack.logoName = Json::ensureString(logo, "title");
|
|
|
|
pack.logoUrl = Json::ensureString(logo, "thumbnailUrl");
|
2022-01-16 10:20:21 +00:00
|
|
|
|
2022-06-19 18:31:44 +01:00
|
|
|
auto authors = Json::ensureArray(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-05-24 16:14:08 +01:00
|
|
|
|
2022-07-19 16:29:31 +01:00
|
|
|
pack.extraDataLoaded = false;
|
|
|
|
loadURLs(pack, obj);
|
2022-05-24 16:14:08 +01:00
|
|
|
}
|
|
|
|
|
2022-07-19 16:29:31 +01:00
|
|
|
void FlameMod::loadURLs(ModPlatform::IndexedPack& pack, QJsonObject& obj)
|
2022-05-24 16:14:08 +01:00
|
|
|
{
|
|
|
|
auto links_obj = Json::ensureObject(obj, "links");
|
|
|
|
|
|
|
|
pack.extraData.issuesUrl = Json::ensureString(links_obj, "issuesUrl");
|
2023-04-14 21:02:33 +01:00
|
|
|
if (pack.extraData.issuesUrl.endsWith('/'))
|
2022-05-24 16:14:08 +01:00
|
|
|
pack.extraData.issuesUrl.chop(1);
|
|
|
|
|
|
|
|
pack.extraData.sourceUrl = Json::ensureString(links_obj, "sourceUrl");
|
2023-04-14 21:02:33 +01:00
|
|
|
if (pack.extraData.sourceUrl.endsWith('/'))
|
2022-05-24 16:14:08 +01:00
|
|
|
pack.extraData.sourceUrl.chop(1);
|
|
|
|
|
|
|
|
pack.extraData.wikiUrl = Json::ensureString(links_obj, "wikiUrl");
|
2023-04-14 21:02:33 +01:00
|
|
|
if (pack.extraData.wikiUrl.endsWith('/'))
|
2022-05-24 16:14:08 +01:00
|
|
|
pack.extraData.wikiUrl.chop(1);
|
|
|
|
|
2022-07-19 16:29:31 +01:00
|
|
|
if (!pack.extraData.body.isEmpty())
|
|
|
|
pack.extraDataLoaded = true;
|
|
|
|
}
|
|
|
|
|
2023-07-01 07:51:15 +01:00
|
|
|
void FlameMod::loadBody(ModPlatform::IndexedPack& pack, [[maybe_unused]] QJsonObject& obj)
|
2022-07-19 16:29:31 +01:00
|
|
|
{
|
2023-04-14 21:02:33 +01:00
|
|
|
pack.extraData.body = api.getModDescription(pack.addonId.toInt());
|
2022-07-19 15:50:38 +01:00
|
|
|
|
2022-07-19 16:29:31 +01:00
|
|
|
if (!pack.extraData.issuesUrl.isEmpty() || !pack.extraData.sourceUrl.isEmpty() || !pack.extraData.wikiUrl.isEmpty())
|
|
|
|
pack.extraDataLoaded = true;
|
2022-01-16 10:20:21 +00:00
|
|
|
}
|
|
|
|
|
2022-05-07 23:39:00 +01:00
|
|
|
static QString enumToString(int hash_algorithm)
|
|
|
|
{
|
2023-04-14 21:02:33 +01:00
|
|
|
switch (hash_algorithm) {
|
|
|
|
default:
|
|
|
|
case 1:
|
|
|
|
return "sha1";
|
|
|
|
case 2:
|
|
|
|
return "md5";
|
2022-05-07 23:39:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-02 21:35:59 +00:00
|
|
|
void FlameMod::loadIndexedPackVersions(ModPlatform::IndexedPack& pack,
|
|
|
|
QJsonArray& arr,
|
2023-07-01 07:51:15 +01:00
|
|
|
[[maybe_unused]] const shared_qobject_ptr<QNetworkAccessManager>& network,
|
2022-12-18 18:41:46 +00:00
|
|
|
const BaseInstance* inst)
|
2022-01-16 10:20:21 +00:00
|
|
|
{
|
2022-03-02 21:35:59 +00:00
|
|
|
QVector<ModPlatform::IndexedVersion> unsortedVersions;
|
2022-12-18 18:41:46 +00:00
|
|
|
auto profile = (dynamic_cast<const MinecraftInstance*>(inst))->getPackProfile();
|
2022-04-15 11:38:27 +01:00
|
|
|
QString mcVersion = profile->getComponentVersion("net.minecraft");
|
2023-08-23 10:52:51 +01:00
|
|
|
auto loaders = profile->getSupportedModLoaders();
|
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();
|
2023-04-14 21:02:33 +01:00
|
|
|
|
2022-05-13 15:42:08 +01:00
|
|
|
auto file = loadIndexedPackVersion(obj);
|
2023-04-14 21:02:33 +01:00
|
|
|
if (!file.addonId.isValid())
|
2022-05-13 15:42:08 +01:00
|
|
|
file.addonId = pack.addonId;
|
2022-02-27 18:05:38 +00:00
|
|
|
|
2023-08-23 10:52:51 +01:00
|
|
|
if (file.fileId.isValid() &&
|
2023-08-25 07:05:04 +01:00
|
|
|
(!loaders.has_value() || !file.loaders || loaders.value() & file.loaders)) // Heuristic to check if the returned value is valid
|
2022-05-13 15:42:08 +01:00
|
|
|
unsortedVersions.append(file);
|
2022-01-16 10:20:21 +00:00
|
|
|
}
|
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 {
|
2023-06-28 11:35:42 +01:00
|
|
|
bool a_better_release = a.version_type <= b.version_type;
|
2022-03-02 21:35:59 +00:00
|
|
|
// dates are in RFC 3339 format
|
2023-05-26 21:50:22 +01:00
|
|
|
return a.date > b.date && a_better_release;
|
2022-01-16 10:20:21 +00:00
|
|
|
};
|
|
|
|
std::sort(unsortedVersions.begin(), unsortedVersions.end(), orderSortPredicate);
|
|
|
|
pack.versions = unsortedVersions;
|
|
|
|
pack.versionsLoaded = true;
|
2022-02-01 21:23:34 +00:00
|
|
|
}
|
2022-05-13 15:42:08 +01:00
|
|
|
|
2022-06-04 00:45:44 +01:00
|
|
|
auto FlameMod::loadIndexedPackVersion(QJsonObject& obj, bool load_changelog) -> ModPlatform::IndexedVersion
|
2022-05-13 15:42:08 +01:00
|
|
|
{
|
|
|
|
auto versionArray = Json::requireArray(obj, "gameVersions");
|
|
|
|
if (versionArray.isEmpty()) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
ModPlatform::IndexedVersion file;
|
|
|
|
for (auto mcVer : versionArray) {
|
|
|
|
auto str = mcVer.toString();
|
|
|
|
|
|
|
|
if (str.contains('.'))
|
|
|
|
file.mcVersion.append(str);
|
2023-08-23 09:33:45 +01:00
|
|
|
auto loader = str.toLower();
|
|
|
|
if (loader == "neoforge")
|
|
|
|
file.loaders |= ModPlatform::NeoForge;
|
|
|
|
if (loader == "forge")
|
|
|
|
file.loaders |= ModPlatform::Forge;
|
|
|
|
if (loader == "cauldron")
|
|
|
|
file.loaders |= ModPlatform::Cauldron;
|
|
|
|
if (loader == "liteloader")
|
|
|
|
file.loaders |= ModPlatform::LiteLoader;
|
|
|
|
if (loader == "fabric")
|
|
|
|
file.loaders |= ModPlatform::Fabric;
|
|
|
|
if (loader == "quilt")
|
|
|
|
file.loaders |= ModPlatform::Quilt;
|
2022-05-13 15:42:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
file.addonId = Json::requireInteger(obj, "modId");
|
|
|
|
file.fileId = Json::requireInteger(obj, "id");
|
|
|
|
file.date = Json::requireString(obj, "fileDate");
|
|
|
|
file.version = Json::requireString(obj, "displayName");
|
2022-06-03 23:06:51 +01:00
|
|
|
file.downloadUrl = Json::ensureString(obj, "downloadUrl");
|
2022-05-13 15:42:08 +01:00
|
|
|
file.fileName = Json::requireString(obj, "fileName");
|
2023-06-28 11:35:42 +01:00
|
|
|
file.version_type = ModPlatform::IndexedVersionType(Json::requireInteger(obj, "releaseType"));
|
2022-05-13 15:42:08 +01:00
|
|
|
|
|
|
|
auto hash_list = Json::ensureArray(obj, "hashes");
|
|
|
|
for (auto h : hash_list) {
|
|
|
|
auto hash_entry = Json::ensureObject(h);
|
2022-11-25 12:23:46 +00:00
|
|
|
auto hash_types = ProviderCaps.hashType(ModPlatform::ResourceProvider::FLAME);
|
2022-05-13 15:42:08 +01:00
|
|
|
auto hash_algo = enumToString(Json::ensureInteger(hash_entry, "algo", 1, "algorithm"));
|
|
|
|
if (hash_types.contains(hash_algo)) {
|
|
|
|
file.hash = Json::requireString(hash_entry, "value");
|
|
|
|
file.hash_type = hash_algo;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-06-04 00:45:44 +01:00
|
|
|
|
2023-04-09 22:04:35 +01:00
|
|
|
auto dependencies = Json::ensureArray(obj, "dependencies");
|
|
|
|
for (auto d : dependencies) {
|
|
|
|
auto dep = Json::ensureObject(d);
|
|
|
|
ModPlatform::Dependency dependency;
|
|
|
|
dependency.addonId = Json::requireInteger(dep, "modId");
|
|
|
|
switch (Json::requireInteger(dep, "relationType")) {
|
|
|
|
case 1: // EmbeddedLibrary
|
|
|
|
dependency.type = ModPlatform::DependencyType::EMBEDDED;
|
|
|
|
break;
|
|
|
|
case 2: // OptionalDependency
|
|
|
|
dependency.type = ModPlatform::DependencyType::OPTIONAL;
|
|
|
|
break;
|
|
|
|
case 3: // RequiredDependency
|
|
|
|
dependency.type = ModPlatform::DependencyType::REQUIRED;
|
|
|
|
break;
|
|
|
|
case 4: // Tool
|
|
|
|
dependency.type = ModPlatform::DependencyType::TOOL;
|
|
|
|
break;
|
|
|
|
case 5: // Incompatible
|
|
|
|
dependency.type = ModPlatform::DependencyType::INCOMPATIBLE;
|
|
|
|
break;
|
|
|
|
case 6: // Include
|
|
|
|
dependency.type = ModPlatform::DependencyType::INCLUDE;
|
|
|
|
break;
|
2023-06-24 13:59:55 +01:00
|
|
|
default:
|
2023-06-18 22:36:37 +01:00
|
|
|
dependency.type = ModPlatform::DependencyType::UNKNOWN;
|
|
|
|
break;
|
2023-04-09 22:04:35 +01:00
|
|
|
}
|
|
|
|
file.dependencies.append(dependency);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (load_changelog)
|
2022-06-04 00:45:44 +01:00
|
|
|
file.changelog = api.getModFileChangelog(file.addonId.toInt(), file.fileId.toInt());
|
|
|
|
|
2022-05-13 15:42:08 +01:00
|
|
|
return file;
|
|
|
|
}
|
2023-04-14 21:02:33 +01:00
|
|
|
|
2023-08-23 10:52:51 +01:00
|
|
|
ModPlatform::IndexedVersion FlameMod::loadDependencyVersions(const ModPlatform::Dependency& m, QJsonArray& arr, const BaseInstance* inst)
|
2023-04-14 21:02:33 +01:00
|
|
|
{
|
2023-08-23 10:52:51 +01:00
|
|
|
auto profile = (dynamic_cast<const MinecraftInstance*>(inst))->getPackProfile();
|
|
|
|
QString mcVersion = profile->getComponentVersion("net.minecraft");
|
|
|
|
auto loaders = profile->getSupportedModLoaders();
|
2023-06-18 22:36:37 +01:00
|
|
|
QVector<ModPlatform::IndexedVersion> versions;
|
2023-04-14 21:02:33 +01:00
|
|
|
for (auto versionIter : arr) {
|
|
|
|
auto obj = versionIter.toObject();
|
|
|
|
|
|
|
|
auto file = loadIndexedPackVersion(obj);
|
|
|
|
if (!file.addonId.isValid())
|
|
|
|
file.addonId = m.addonId;
|
|
|
|
|
2023-08-23 10:52:51 +01:00
|
|
|
if (file.fileId.isValid() &&
|
2023-08-25 07:05:04 +01:00
|
|
|
(!loaders.has_value() || !file.loaders || loaders.value() & file.loaders)) // Heuristic to check if the returned value is valid
|
2023-06-18 22:36:37 +01:00
|
|
|
versions.append(file);
|
2023-04-14 21:02:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
auto orderSortPredicate = [](const ModPlatform::IndexedVersion& a, const ModPlatform::IndexedVersion& b) -> bool {
|
|
|
|
// dates are in RFC 3339 format
|
|
|
|
return a.date > b.date;
|
|
|
|
};
|
2023-06-18 22:36:37 +01:00
|
|
|
std::sort(versions.begin(), versions.end(), orderSortPredicate);
|
2023-08-25 16:35:25 +01:00
|
|
|
if (versions.size() != 0)
|
|
|
|
return versions.front();
|
|
|
|
return {};
|
2023-07-01 07:51:15 +01:00
|
|
|
}
|