2022-01-16 15:50:21 +05:30
|
|
|
#include "FlameModIndex.h"
|
2022-03-03 03:05:59 +05:30
|
|
|
|
2022-01-16 15:50:21 +05:30
|
|
|
#include "Json.h"
|
|
|
|
#include "minecraft/MinecraftInstance.h"
|
|
|
|
#include "minecraft/PackProfile.h"
|
2022-04-15 16:08:27 +05:30
|
|
|
#include "modplatform/flame/FlameAPI.h"
|
2022-03-03 03:05:59 +05:30
|
|
|
#include "net/NetJob.h"
|
2022-01-16 15:50:21 +05:30
|
|
|
|
2022-04-22 00:15:20 +05:30
|
|
|
static ModPlatform::ProviderCapabilities ProviderCaps;
|
|
|
|
|
2022-03-03 03:05:59 +05:30
|
|
|
void FlameMod::loadIndexedPack(ModPlatform::IndexedPack& pack, QJsonObject& obj)
|
2022-01-16 15:50:21 +05:30
|
|
|
{
|
|
|
|
pack.addonId = Json::requireInteger(obj, "id");
|
2022-04-14 03:46:36 +05:30
|
|
|
pack.provider = ModPlatform::Provider::FLAME;
|
2022-01-16 15:50:21 +05:30
|
|
|
pack.name = Json::requireString(obj, "name");
|
2022-05-08 12:52:50 +05:30
|
|
|
pack.websiteUrl = Json::ensureString(Json::ensureObject(obj, "links"), "websiteUrl", "");
|
2022-01-16 15:50:21 +05:30
|
|
|
pack.description = Json::ensureString(obj, "summary", "");
|
|
|
|
|
2022-05-08 12:52:50 +05:30
|
|
|
QJsonObject logo = Json::requireObject(obj, "logo");
|
|
|
|
pack.logoName = Json::requireString(logo, "title");
|
|
|
|
pack.logoUrl = Json::requireString(logo, "thumbnailUrl");
|
2022-01-16 15:50:21 +05:30
|
|
|
|
|
|
|
auto authors = Json::requireArray(obj, "authors");
|
2022-03-03 03:05:59 +05:30
|
|
|
for (auto authorIter : authors) {
|
2022-01-16 15:50:21 +05:30
|
|
|
auto author = Json::requireObject(authorIter);
|
2022-03-03 03:05:59 +05:30
|
|
|
ModPlatform::ModpackAuthor packAuthor;
|
2022-01-16 15:50:21 +05:30
|
|
|
packAuthor.name = Json::requireString(author, "name");
|
|
|
|
packAuthor.url = Json::requireString(author, "url");
|
|
|
|
pack.authors.append(packAuthor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-08 04:09:00 +05:30
|
|
|
static QString enumToString(int hash_algorithm)
|
|
|
|
{
|
|
|
|
switch(hash_algorithm){
|
|
|
|
default:
|
|
|
|
case 1:
|
|
|
|
return "sha1";
|
|
|
|
case 2:
|
|
|
|
return "md5";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-03 03:05:59 +05:30
|
|
|
void FlameMod::loadIndexedPackVersions(ModPlatform::IndexedPack& pack,
|
|
|
|
QJsonArray& arr,
|
|
|
|
const shared_qobject_ptr<QNetworkAccessManager>& network,
|
|
|
|
BaseInstance* inst)
|
2022-01-16 15:50:21 +05:30
|
|
|
{
|
2022-03-03 03:05:59 +05:30
|
|
|
QVector<ModPlatform::IndexedVersion> unsortedVersions;
|
2022-04-15 16:08:27 +05:30
|
|
|
auto profile = (dynamic_cast<MinecraftInstance*>(inst))->getPackProfile();
|
|
|
|
QString mcVersion = profile->getComponentVersion("net.minecraft");
|
2022-01-16 15:50:21 +05:30
|
|
|
|
2022-03-03 03:05:59 +05:30
|
|
|
for (auto versionIter : arr) {
|
2022-01-16 15:50:21 +05:30
|
|
|
auto obj = versionIter.toObject();
|
2022-02-27 23:35:38 +05:30
|
|
|
|
2022-05-08 12:52:50 +05:30
|
|
|
auto versionArray = Json::requireArray(obj, "gameVersions");
|
|
|
|
if (versionArray.isEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
2022-02-27 23:35:38 +05:30
|
|
|
|
2022-03-03 03:05:59 +05:30
|
|
|
ModPlatform::IndexedVersion file;
|
|
|
|
for (auto mcVer : versionArray) {
|
2022-05-08 12:52:50 +05:30
|
|
|
auto str = mcVer.toString();
|
|
|
|
|
2022-05-08 19:55:45 +05:30
|
|
|
if (str.contains('.'))
|
2022-05-08 19:55:51 +05:30
|
|
|
file.mcVersion.append(str);
|
2022-01-16 15:50:21 +05:30
|
|
|
}
|
|
|
|
|
2022-02-27 23:35:38 +05:30
|
|
|
file.addonId = pack.addonId;
|
|
|
|
file.fileId = Json::requireInteger(obj, "id");
|
|
|
|
file.date = Json::requireString(obj, "fileDate");
|
2022-01-16 15:50:21 +05:30
|
|
|
file.version = Json::requireString(obj, "displayName");
|
2022-05-23 01:34:24 +05:30
|
|
|
file.downloadUrl = Json::requireString(obj, "downloadUrl");
|
2022-01-16 15:50:21 +05:30
|
|
|
file.fileName = Json::requireString(obj, "fileName");
|
|
|
|
|
2022-04-22 00:15:20 +05:30
|
|
|
auto hash_list = Json::ensureArray(obj, "hashes");
|
2022-05-08 04:09:00 +05:30
|
|
|
for(auto h : hash_list){
|
|
|
|
auto hash_entry = Json::ensureObject(h);
|
2022-05-06 21:12:01 +05:30
|
|
|
auto hash_types = ProviderCaps.hashType(ModPlatform::Provider::FLAME);
|
2022-05-08 04:09:00 +05:30
|
|
|
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-05-06 21:12:01 +05:30
|
|
|
}
|
2022-04-22 00:15:20 +05:30
|
|
|
}
|
|
|
|
|
2022-01-16 15:50:21 +05:30
|
|
|
unsortedVersions.append(file);
|
|
|
|
}
|
2022-05-08 12:52:50 +05:30
|
|
|
|
2022-03-03 03:05:59 +05:30
|
|
|
auto orderSortPredicate = [](const ModPlatform::IndexedVersion& a, const ModPlatform::IndexedVersion& b) -> bool {
|
|
|
|
// dates are in RFC 3339 format
|
2022-01-16 15:50:21 +05:30
|
|
|
return a.date > b.date;
|
|
|
|
};
|
|
|
|
std::sort(unsortedVersions.begin(), unsortedVersions.end(), orderSortPredicate);
|
|
|
|
pack.versions = unsortedVersions;
|
|
|
|
pack.versionsLoaded = true;
|
2022-02-02 02:53:34 +05:30
|
|
|
}
|