diff options
Diffstat (limited to 'launcher/modplatform')
-rw-r--r-- | launcher/modplatform/CheckUpdateTask.h | 11 | ||||
-rw-r--r-- | launcher/modplatform/ModIndex.cpp | 68 | ||||
-rw-r--r-- | launcher/modplatform/ModIndex.h | 31 | ||||
-rw-r--r-- | launcher/modplatform/flame/FlameAPI.cpp | 3 | ||||
-rw-r--r-- | launcher/modplatform/flame/FlameCheckUpdate.cpp | 2 | ||||
-rw-r--r-- | launcher/modplatform/flame/FlameModIndex.cpp | 4 | ||||
-rw-r--r-- | launcher/modplatform/flame/FlamePackIndex.cpp | 1 | ||||
-rw-r--r-- | launcher/modplatform/flame/FlamePackIndex.h | 3 | ||||
-rw-r--r-- | launcher/modplatform/modrinth/ModrinthCheckUpdate.cpp | 4 | ||||
-rw-r--r-- | launcher/modplatform/modrinth/ModrinthPackIndex.cpp | 5 | ||||
-rw-r--r-- | launcher/modplatform/modrinth/ModrinthPackManifest.cpp | 4 | ||||
-rw-r--r-- | launcher/modplatform/modrinth/ModrinthPackManifest.h | 3 |
12 files changed, 131 insertions, 8 deletions
diff --git a/launcher/modplatform/CheckUpdateTask.h b/launcher/modplatform/CheckUpdateTask.h index 6d968ea4..65c80d26 100644 --- a/launcher/modplatform/CheckUpdateTask.h +++ b/launcher/modplatform/CheckUpdateTask.h @@ -23,6 +23,7 @@ class CheckUpdateTask : public Task { QString old_hash; QString old_version; QString new_version; + std::optional<ModPlatform::IndexedVersionType> new_version_type; QString changelog; ModPlatform::ResourceProvider provider; shared_qobject_ptr<ResourceDownloadTask> download; @@ -32,10 +33,18 @@ class CheckUpdateTask : public Task { QString old_h, QString old_v, QString new_v, + std::optional<ModPlatform::IndexedVersionType> new_v_type, QString changelog, ModPlatform::ResourceProvider p, shared_qobject_ptr<ResourceDownloadTask> t) - : name(name), old_hash(old_h), old_version(old_v), new_version(new_v), changelog(changelog), provider(p), download(t) + : name(name) + , old_hash(old_h) + , old_version(old_v) + , new_version(new_v) + , new_version_type(new_v_type) + , changelog(changelog) + , provider(p) + , download(t) {} }; diff --git a/launcher/modplatform/ModIndex.cpp b/launcher/modplatform/ModIndex.cpp index 350a9f10..2e0d9e37 100644 --- a/launcher/modplatform/ModIndex.cpp +++ b/launcher/modplatform/ModIndex.cpp @@ -24,6 +24,74 @@ namespace ModPlatform { +static const QMap<QString, IndexedVersionType::Enum> s_indexed_version_type_names = { + {"release", IndexedVersionType::Enum::Release}, + {"beta", IndexedVersionType::Enum::Beta}, + {"alpha", IndexedVersionType::Enum::Alpha} +}; + +IndexedVersionType::IndexedVersionType(const QString& type): IndexedVersionType(enumFromString(type)) +{} + +IndexedVersionType::IndexedVersionType(int type) +{ + switch (type) { + case 1: + m_type = IndexedVersionType::Enum::Release; + break; + case 2: + m_type = IndexedVersionType::Enum::Beta; + break; + case 3: + m_type = IndexedVersionType::Enum::Alpha; + break; + default: + m_type = IndexedVersionType::Enum::UNKNOWN; + } +} + +IndexedVersionType::IndexedVersionType(const IndexedVersionType::Enum& type) +{ + m_type = type; +} + +IndexedVersionType::IndexedVersionType(const IndexedVersionType& other) +{ + m_type = other.m_type; +} + +IndexedVersionType& IndexedVersionType::operator=(const IndexedVersionType& other) +{ + m_type = other.m_type; + return *this; +} + +const QString IndexedVersionType::toString (const IndexedVersionType::Enum& type) +{ + switch (type) { + case IndexedVersionType::Enum::Release: + return "release"; + case IndexedVersionType::Enum::Beta: + return "beta"; + case IndexedVersionType::Enum::Alpha: + return "alpha"; + case IndexedVersionType::Enum::UNKNOWN: + default: + return "unknown"; + + } +} + +IndexedVersionType::Enum IndexedVersionType::enumFromString(const QString& type) +{ + auto found = s_indexed_version_type_names.constFind(type); + if (found != s_indexed_version_type_names.constEnd()) { + return *found; + } else { + return IndexedVersionType::Enum::UNKNOWN; + } +} + auto ProviderCapabilities::name(ResourceProvider p) -> const char* { switch (p) { diff --git a/launcher/modplatform/ModIndex.h b/launcher/modplatform/ModIndex.h index 2aa91602..e430f2b0 100644 --- a/launcher/modplatform/ModIndex.h +++ b/launcher/modplatform/ModIndex.h @@ -25,6 +25,7 @@ #include <QVariant> #include <QVector> #include <memory> +#include <optional> class QIODevice; @@ -55,6 +56,35 @@ struct DonationData { QString url; }; +struct IndexedVersionType { + enum class Enum { Release = 1, Beta, Alpha, UNKNOWN }; + IndexedVersionType(const QString& type); + IndexedVersionType(int type); + IndexedVersionType(const IndexedVersionType::Enum& type); + IndexedVersionType(const IndexedVersionType& type); + IndexedVersionType() : IndexedVersionType(IndexedVersionType::Enum::UNKNOWN) {} + static const QString toString(const IndexedVersionType::Enum& type); + static IndexedVersionType::Enum enumFromString(const QString& type); + bool isValid() const { return m_type != IndexedVersionType::Enum::UNKNOWN; } + IndexedVersionType& operator=(const IndexedVersionType& other); + bool operator==(const IndexedVersionType& other) const { return m_type == other.m_type; } + bool operator==(const IndexedVersionType::Enum& type) const { return m_type == type; } + bool operator!=(const IndexedVersionType& other) const { return m_type != other.m_type; } + bool operator!=(const IndexedVersionType::Enum& type) const { return m_type != type; } + bool operator<(const IndexedVersionType& other) const { return m_type < other.m_type; } + bool operator<(const IndexedVersionType::Enum& type) const { return m_type < type; } + bool operator<=(const IndexedVersionType& other) const { return m_type <= other.m_type; } + bool operator<=(const IndexedVersionType::Enum& type) const { return m_type <= type; } + bool operator>(const IndexedVersionType& other) const { return m_type > other.m_type; } + bool operator>(const IndexedVersionType::Enum& type) const { return m_type > type; } + bool operator>=(const IndexedVersionType& other) const { return m_type >= other.m_type; } + bool operator>=(const IndexedVersionType::Enum& type) const { return m_type >= type; } + + QString toString() const { return toString(m_type); } + + IndexedVersionType::Enum m_type; +}; + struct Dependency { QVariant addonId; DependencyType type; @@ -66,6 +96,7 @@ struct IndexedVersion { QVariant fileId; QString version; QString version_number = {}; + IndexedVersionType version_type; QStringList mcVersion; QString downloadUrl; QString date; diff --git a/launcher/modplatform/flame/FlameAPI.cpp b/launcher/modplatform/flame/FlameAPI.cpp index 5b0b1d8b..885c4687 100644 --- a/launcher/modplatform/flame/FlameAPI.cpp +++ b/launcher/modplatform/flame/FlameAPI.cpp @@ -135,7 +135,8 @@ auto FlameAPI::getLatestVersion(VersionSearchArgs&& args) -> ModPlatform::Indexe for (auto file : arr) { auto file_obj = Json::requireObject(file); auto file_tmp = FlameMod::loadIndexedPackVersion(file_obj); - if (file_tmp.date > ver_tmp.date) { + bool better_release = file_tmp.version_type <= ver_tmp.version_type; + if (file_tmp.date > ver_tmp.date && better_release) { ver_tmp = file_tmp; latest_file_obj = file_obj; } diff --git a/launcher/modplatform/flame/FlameCheckUpdate.cpp b/launcher/modplatform/flame/FlameCheckUpdate.cpp index a2628e34..5ff833cf 100644 --- a/launcher/modplatform/flame/FlameCheckUpdate.cpp +++ b/launcher/modplatform/flame/FlameCheckUpdate.cpp @@ -173,7 +173,7 @@ void FlameCheckUpdate::executeTask() } auto download_task = makeShared<ResourceDownloadTask>(pack, latest_ver, m_mods_folder); - m_updatable.emplace_back(pack->name, mod->metadata()->hash, old_version, latest_ver.version, + m_updatable.emplace_back(pack->name, mod->metadata()->hash, old_version, latest_ver.version, latest_ver.version_type, api.getModFileChangelog(latest_ver.addonId.toInt(), latest_ver.fileId.toInt()), ModPlatform::ResourceProvider::FLAME, download_task); } diff --git a/launcher/modplatform/flame/FlameModIndex.cpp b/launcher/modplatform/flame/FlameModIndex.cpp index 227ce489..5a44d4db 100644 --- a/launcher/modplatform/flame/FlameModIndex.cpp +++ b/launcher/modplatform/flame/FlameModIndex.cpp @@ -94,8 +94,9 @@ void FlameMod::loadIndexedPackVersions(ModPlatform::IndexedPack& pack, } auto orderSortPredicate = [](const ModPlatform::IndexedVersion& a, const ModPlatform::IndexedVersion& b) -> bool { + bool a_better_release = a.version_type <= b.version_type; // dates are in RFC 3339 format - return a.date > b.date; + return a.date > b.date && a_better_release; }; std::sort(unsortedVersions.begin(), unsortedVersions.end(), orderSortPredicate); pack.versions = unsortedVersions; @@ -123,6 +124,7 @@ auto FlameMod::loadIndexedPackVersion(QJsonObject& obj, bool load_changelog) -> file.version = Json::requireString(obj, "displayName"); file.downloadUrl = Json::ensureString(obj, "downloadUrl"); file.fileName = Json::requireString(obj, "fileName"); + file.version_type = ModPlatform::IndexedVersionType(Json::requireInteger(obj, "releaseType")); auto hash_list = Json::ensureArray(obj, "hashes"); for (auto h : hash_list) { diff --git a/launcher/modplatform/flame/FlamePackIndex.cpp b/launcher/modplatform/flame/FlamePackIndex.cpp index 21835a54..5a160673 100644 --- a/launcher/modplatform/flame/FlamePackIndex.cpp +++ b/launcher/modplatform/flame/FlamePackIndex.cpp @@ -89,6 +89,7 @@ void Flame::loadIndexedPackVersions(Flame::IndexedPack& pack, QJsonArray& arr) // pick the latest version supported file.mcVersion = versionArray[0].toString(); file.version = Json::requireString(version, "displayName"); + file.version_type = ModPlatform::IndexedVersionType(Json::requireInteger(version, "releaseType")); file.downloadUrl = Json::ensureString(version, "downloadUrl"); // only add if we have a download URL (third party distribution is enabled) diff --git a/launcher/modplatform/flame/FlamePackIndex.h b/launcher/modplatform/flame/FlamePackIndex.h index b089b722..5f642ace 100644 --- a/launcher/modplatform/flame/FlamePackIndex.h +++ b/launcher/modplatform/flame/FlamePackIndex.h @@ -6,6 +6,8 @@ #include <QVector> #include "modplatform/ModIndex.h" +#include "modplatform/ModIndex.h" + namespace Flame { struct ModpackAuthor { @@ -17,6 +19,7 @@ struct IndexedVersion { int addonId; int fileId; QString version; + ModPlatform::IndexedVersionType version_type; QString mcVersion; QString downloadUrl; }; diff --git a/launcher/modplatform/modrinth/ModrinthCheckUpdate.cpp b/launcher/modplatform/modrinth/ModrinthCheckUpdate.cpp index a7c22832..845e0c61 100644 --- a/launcher/modplatform/modrinth/ModrinthCheckUpdate.cpp +++ b/launcher/modplatform/modrinth/ModrinthCheckUpdate.cpp @@ -162,8 +162,8 @@ void ModrinthCheckUpdate::executeTask() auto download_task = makeShared<ResourceDownloadTask>(pack, project_ver, m_mods_folder); - m_updatable.emplace_back(pack->name, hash, mod->version(), project_ver.version_number, project_ver.changelog, - ModPlatform::ResourceProvider::MODRINTH, download_task); + m_updatable.emplace_back(pack->name, hash, mod->version(), project_ver.version_number, project_ver.version_type, + project_ver.changelog, ModPlatform::ResourceProvider::MODRINTH, download_task); } } } catch (Json::JsonException& e) { diff --git a/launcher/modplatform/modrinth/ModrinthPackIndex.cpp b/launcher/modplatform/modrinth/ModrinthPackIndex.cpp index 96dafe70..dbb6aeed 100644 --- a/launcher/modplatform/modrinth/ModrinthPackIndex.cpp +++ b/launcher/modplatform/modrinth/ModrinthPackIndex.cpp @@ -109,8 +109,9 @@ void Modrinth::loadIndexedPackVersions(ModPlatform::IndexedPack& pack, unsortedVersions.append(file); } auto orderSortPredicate = [](const ModPlatform::IndexedVersion& a, const ModPlatform::IndexedVersion& b) -> bool { + bool a_better_release = a.version_type <= b.version_type; // dates are in RFC 3339 format - return a.date > b.date; + return a.date > b.date && a_better_release; }; std::sort(unsortedVersions.begin(), unsortedVersions.end(), orderSortPredicate); pack.versions = unsortedVersions; @@ -138,6 +139,8 @@ auto Modrinth::loadIndexedPackVersion(QJsonObject& obj, QString preferred_hash_t } file.version = Json::requireString(obj, "name"); file.version_number = Json::requireString(obj, "version_number"); + file.version_type = ModPlatform::IndexedVersionType(Json::requireString(obj, "version_type")); + file.changelog = Json::requireString(obj, "changelog"); auto dependencies = Json::ensureArray(obj, "dependencies"); diff --git a/launcher/modplatform/modrinth/ModrinthPackManifest.cpp b/launcher/modplatform/modrinth/ModrinthPackManifest.cpp index 0d07c636..a154317f 100644 --- a/launcher/modplatform/modrinth/ModrinthPackManifest.cpp +++ b/launcher/modplatform/modrinth/ModrinthPackManifest.cpp @@ -111,8 +111,9 @@ void loadIndexedVersions(Modpack& pack, QJsonDocument& doc) unsortedVersions.append(file); } auto orderSortPredicate = [](const ModpackVersion& a, const ModpackVersion& b) -> bool { + bool a_better_release = a.version_type <= b.version_type; // dates are in RFC 3339 format - return a.date > b.date; + return a.date > b.date && a_better_release; }; std::sort(unsortedVersions.begin(), unsortedVersions.end(), orderSortPredicate); @@ -128,6 +129,7 @@ auto loadIndexedVersion(QJsonObject& obj) -> ModpackVersion file.name = Json::requireString(obj, "name"); file.version = Json::requireString(obj, "version_number"); + file.version_type = ModPlatform::IndexedVersionType(Json::requireString(obj, "version_type")); file.changelog = Json::ensureString(obj, "changelog"); file.id = Json::requireString(obj, "id"); diff --git a/launcher/modplatform/modrinth/ModrinthPackManifest.h b/launcher/modplatform/modrinth/ModrinthPackManifest.h index effa1a84..8e530677 100644 --- a/launcher/modplatform/modrinth/ModrinthPackManifest.h +++ b/launcher/modplatform/modrinth/ModrinthPackManifest.h @@ -45,6 +45,8 @@ #include <QUrl> #include <QVector> +#include "modplatform/ModIndex.h" + class MinecraftInstance; namespace Modrinth { @@ -79,6 +81,7 @@ struct ModpackExtra { struct ModpackVersion { QString name; QString version; + ModPlatform::IndexedVersionType version_type; QString changelog; QString id; |