From 881b2f2b385f19d9b64a149fca3c3741a803a172 Mon Sep 17 00:00:00 2001 From: flow Date: Wed, 2 Mar 2022 18:35:59 -0300 Subject: refactor: Use a single indexed pack for mods Since there's little difference between them, let's remove duplication and merge them. --- .../modplatform/modrinth/ModrinthPackIndex.cpp | 69 +++++++++++----------- 1 file changed, 33 insertions(+), 36 deletions(-) (limited to 'launcher/modplatform/modrinth/ModrinthPackIndex.cpp') diff --git a/launcher/modplatform/modrinth/ModrinthPackIndex.cpp b/launcher/modplatform/modrinth/ModrinthPackIndex.cpp index 9017eb67..a59186f7 100644 --- a/launcher/modplatform/modrinth/ModrinthPackIndex.cpp +++ b/launcher/modplatform/modrinth/ModrinthPackIndex.cpp @@ -1,14 +1,11 @@ -#include #include "ModrinthPackIndex.h" #include "Json.h" -#include "net/NetJob.h" -#include "BaseInstance.h" #include "minecraft/MinecraftInstance.h" #include "minecraft/PackProfile.h" +#include "net/NetJob.h" - -void Modrinth::loadIndexedPack(Modrinth::IndexedPack & pack, QJsonObject & obj) +void Modrinth::loadIndexedPack(ModPlatform::IndexedPack& pack, QJsonObject& obj) { pack.addonId = Json::requireString(obj, "project_id"); pack.name = Json::requireString(obj, "title"); @@ -16,59 +13,60 @@ void Modrinth::loadIndexedPack(Modrinth::IndexedPack & pack, QJsonObject & obj) pack.description = Json::ensureString(obj, "description", ""); pack.logoUrl = Json::requireString(obj, "icon_url"); - pack.logoName = pack.addonId; + pack.logoName = pack.addonId.toString(); - Modrinth::ModpackAuthor modAuthor; + ModPlatform::ModpackAuthor modAuthor; modAuthor.name = Json::requireString(obj, "author"); - modAuthor.url = "https://modrinth.com/user/"+modAuthor.name; - pack.author = modAuthor; + modAuthor.url = "https://modrinth.com/user/" + modAuthor.name; + pack.authors.append(modAuthor); } -void Modrinth::loadIndexedPackVersions(Modrinth::IndexedPack & pack, QJsonArray & arr, const shared_qobject_ptr& network, BaseInstance * inst) +void Modrinth::loadIndexedPackVersions(ModPlatform::IndexedPack& pack, + QJsonArray& arr, + const shared_qobject_ptr& network, + BaseInstance* inst) { - QVector unsortedVersions; - bool hasFabric = !((MinecraftInstance *)inst)->getPackProfile()->getComponentVersion("net.fabricmc.fabric-loader").isEmpty(); - QString mcVersion = ((MinecraftInstance *)inst)->getPackProfile()->getComponentVersion("net.minecraft"); + QVector unsortedVersions; + bool hasFabric = !((MinecraftInstance*)inst)->getPackProfile()->getComponentVersion("net.fabricmc.fabric-loader").isEmpty(); + QString mcVersion = ((MinecraftInstance*)inst)->getPackProfile()->getComponentVersion("net.minecraft"); - for(auto versionIter: arr) { + for (auto versionIter : arr) { auto obj = versionIter.toObject(); - Modrinth::IndexedVersion file; - file.addonId = Json::requireString(obj,"project_id") ; + ModPlatform::IndexedVersion file; + file.addonId = Json::requireString(obj, "project_id"); file.fileId = Json::requireString(obj, "id"); file.date = Json::requireString(obj, "date_published"); auto versionArray = Json::requireArray(obj, "game_versions"); - if (versionArray.empty()) { - continue; - } - for(auto mcVer : versionArray){ + if (versionArray.empty()) { continue; } + for (auto mcVer : versionArray) { file.mcVersion.append(mcVer.toString()); } - auto loaders = Json::requireArray(obj,"loaders"); - for(auto loader : loaders){ + auto loaders = Json::requireArray(obj, "loaders"); + for (auto loader : loaders) { file.loaders.append(loader.toString()); } file.version = Json::requireString(obj, "name"); auto files = Json::requireArray(obj, "files"); int i = 0; - while (files.count() > 1 && i < files.count()){ - //try to resolve the correct file + while (files.count() > 1 && i < files.count()) { + // try to resolve the correct file auto parent = files[i].toObject(); auto fileName = Json::requireString(parent, "filename"); - //avoid grabbing "dev" files - if(fileName.contains("javadocs",Qt::CaseInsensitive) || fileName.contains("sources",Qt::CaseInsensitive)){ + // avoid grabbing "dev" files + if (fileName.contains("javadocs", Qt::CaseInsensitive) || fileName.contains("sources", Qt::CaseInsensitive)) { i++; continue; } - //grab the correct mod loader - if(fileName.contains("forge",Qt::CaseInsensitive) || fileName.contains("fabric",Qt::CaseInsensitive) ){ - if(hasFabric){ - if(fileName.contains("forge",Qt::CaseInsensitive)){ + // grab the correct mod loader + if (fileName.contains("forge", Qt::CaseInsensitive) || fileName.contains("fabric", Qt::CaseInsensitive)) { + if (hasFabric) { + if (fileName.contains("forge", Qt::CaseInsensitive)) { i++; continue; } - }else{ - if(fileName.contains("fabric",Qt::CaseInsensitive)){ + } else { + if (fileName.contains("fabric", Qt::CaseInsensitive)) { i++; continue; } @@ -77,16 +75,15 @@ void Modrinth::loadIndexedPackVersions(Modrinth::IndexedPack & pack, QJsonArray break; } auto parent = files[i].toObject(); - if(parent.contains("url")) { + if (parent.contains("url")) { file.downloadUrl = Json::requireString(parent, "url"); file.fileName = Json::requireString(parent, "filename"); unsortedVersions.append(file); } } - auto orderSortPredicate = [](const IndexedVersion & a, const IndexedVersion & b) -> bool - { - //dates are in RFC 3339 format + auto orderSortPredicate = [](const ModPlatform::IndexedVersion& a, const ModPlatform::IndexedVersion& b) -> bool { + // dates are in RFC 3339 format return a.date > b.date; }; std::sort(unsortedVersions.begin(), unsortedVersions.end(), orderSortPredicate); -- cgit From 2d68308d4920be4c28a73d7646814765eee7b7a2 Mon Sep 17 00:00:00 2001 From: flow Date: Wed, 2 Mar 2022 23:01:23 -0300 Subject: refactor: move url creation for mods to modplatform/ Moves all things related to creating the URLs of the mod platforms that go to network tasks to a single place, so that: 1. Maintaining and fixing eventual issues is more straightforward. 2. Makes it possible to factor out more common code between the different modplatform pages --- launcher/modplatform/ModAPI.h | 12 ++++++ launcher/modplatform/flame/FlameAPI.h | 27 ++++++++++++++ launcher/modplatform/modrinth/ModrinthAPI.h | 25 +++++++++++++ .../modplatform/modrinth/ModrinthPackIndex.cpp | 5 ++- launcher/ui/pages/modplatform/ModModel.cpp | 20 ++++++++++ launcher/ui/pages/modplatform/ModModel.h | 7 +++- launcher/ui/pages/modplatform/ModPage.cpp | 9 +---- launcher/ui/pages/modplatform/ModPage.h | 2 + .../ui/pages/modplatform/flame/FlameModModel.cpp | 43 ++++------------------ .../ui/pages/modplatform/flame/FlameModModel.h | 4 +- launcher/ui/pages/modplatform/flame/FlameModPage.h | 6 +++ .../pages/modplatform/modrinth/ModrinthModel.cpp | 39 ++++---------------- .../ui/pages/modplatform/modrinth/ModrinthModel.h | 4 +- .../ui/pages/modplatform/modrinth/ModrinthPage.h | 6 +++ 14 files changed, 130 insertions(+), 79 deletions(-) create mode 100644 launcher/modplatform/ModAPI.h create mode 100644 launcher/modplatform/flame/FlameAPI.h create mode 100644 launcher/modplatform/modrinth/ModrinthAPI.h (limited to 'launcher/modplatform/modrinth/ModrinthPackIndex.cpp') diff --git a/launcher/modplatform/ModAPI.h b/launcher/modplatform/ModAPI.h new file mode 100644 index 00000000..e60fa8e0 --- /dev/null +++ b/launcher/modplatform/ModAPI.h @@ -0,0 +1,12 @@ +#pragma once + +#include + +class ModAPI { + public: + virtual ~ModAPI() = default; + + inline virtual QString getModSearchURL(int, QString, QString, bool, QString) const { return ""; }; + inline virtual QString getVersionsURL(const QString& addonId) const { return ""; }; + inline virtual QString getAuthorURL(const QString& name) const { return ""; }; +}; diff --git a/launcher/modplatform/flame/FlameAPI.h b/launcher/modplatform/flame/FlameAPI.h new file mode 100644 index 00000000..6e2b9e25 --- /dev/null +++ b/launcher/modplatform/flame/FlameAPI.h @@ -0,0 +1,27 @@ +#pragma once + +#include "modplatform/ModAPI.h" + +class FlameAPI : public ModAPI { + public: + inline QString getModSearchURL(int index, QString searchFilter, QString sort, bool fabricCompatible, QString version) const override + { + return QString("https://addons-ecs.forgesvc.net/api/v2/addon/search?" + "gameId=432&" "categoryId=0&" "sectionId=6&" + + "index=%1&" "pageSize=25&" "searchFilter=%2&" + "sort=%3&" "modLoaderType=%4&" "gameVersion=%5") + .arg(index) + .arg(searchFilter) + .arg(sort) + .arg(fabricCompatible ? 4 : 1) // Enum: https://docs.curseforge.com/?http#tocS_ModLoaderType + .arg(version); + }; + + inline QString getVersionsURL(const QString& addonId) const override + { + return QString("https://addons-ecs.forgesvc.net/api/v2/addon/%1/files").arg(addonId); + }; + + inline QString getAuthorURL(const QString& name) const override { return ""; }; +}; diff --git a/launcher/modplatform/modrinth/ModrinthAPI.h b/launcher/modplatform/modrinth/ModrinthAPI.h new file mode 100644 index 00000000..4ae8b8f9 --- /dev/null +++ b/launcher/modplatform/modrinth/ModrinthAPI.h @@ -0,0 +1,25 @@ +#pragma once + +#include "modplatform/ModAPI.h" + +class ModrinthAPI : public ModAPI { + public: + inline QString getModSearchURL(int offset, QString query, QString sort, bool fabricCompatible, QString version) const override + { + return QString("https://api.modrinth.com/v2/search?" + "offset=%1&" "limit=25&" "query=%2&" "index=%3&" + "facets=[[\"categories:%4\"],[\"versions:%5\"],[\"project_type:mod\"]]") + .arg(offset) + .arg(query) + .arg(sort) + .arg(fabricCompatible ? "fabric" : "forge") + .arg(version); + }; + + inline QString getVersionsURL(const QString& addonId) const override + { + return QString("https://api.modrinth.com/v2/project/%1/version").arg(addonId); + }; + + inline QString getAuthorURL(const QString& name) const override { return "https://modrinth.com/user/" + name; }; +}; diff --git a/launcher/modplatform/modrinth/ModrinthPackIndex.cpp b/launcher/modplatform/modrinth/ModrinthPackIndex.cpp index a59186f7..02aac34d 100644 --- a/launcher/modplatform/modrinth/ModrinthPackIndex.cpp +++ b/launcher/modplatform/modrinth/ModrinthPackIndex.cpp @@ -1,10 +1,13 @@ #include "ModrinthPackIndex.h" +#include "ModrinthAPI.h" #include "Json.h" #include "minecraft/MinecraftInstance.h" #include "minecraft/PackProfile.h" #include "net/NetJob.h" +static ModrinthAPI api; + void Modrinth::loadIndexedPack(ModPlatform::IndexedPack& pack, QJsonObject& obj) { pack.addonId = Json::requireString(obj, "project_id"); @@ -17,7 +20,7 @@ void Modrinth::loadIndexedPack(ModPlatform::IndexedPack& pack, QJsonObject& obj) ModPlatform::ModpackAuthor modAuthor; modAuthor.name = Json::requireString(obj, "author"); - modAuthor.url = "https://modrinth.com/user/" + modAuthor.name; + modAuthor.url = api.getAuthorURL(modAuthor.name); pack.authors.append(modAuthor); } diff --git a/launcher/ui/pages/modplatform/ModModel.cpp b/launcher/ui/pages/modplatform/ModModel.cpp index 5bd7e33e..481f1c56 100644 --- a/launcher/ui/pages/modplatform/ModModel.cpp +++ b/launcher/ui/pages/modplatform/ModModel.cpp @@ -1,6 +1,8 @@ #include "ModModel.h" #include "ModPage.h" +#include "minecraft/MinecraftInstance.h" +#include "minecraft/PackProfile.h" #include "ui/dialogs/ModDownloadDialog.h" #include @@ -95,6 +97,24 @@ void ListModel::getLogo(const QString& logo, const QString& logoUrl, LogoCallbac } } +void ListModel::performPaginatedSearch() +{ + QString mcVersion = ((MinecraftInstance*)((ModPage*)parent())->m_instance)->getPackProfile()->getComponentVersion("net.minecraft"); + bool hasFabric = !((MinecraftInstance*)((ModPage*)parent())->m_instance) + ->getPackProfile() + ->getComponentVersion("net.fabricmc.fabric-loader") + .isEmpty(); + auto netJob = new NetJob(QString("%1::Search").arg(m_parent->debugName()), APPLICATION->network()); + auto searchUrl = m_parent->apiProvider()->getModSearchURL(nextSearchOffset, currentSearchTerm, getSorts()[currentSort], hasFabric, mcVersion); + + netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), &response)); + jobPtr = netJob; + jobPtr->start(); + + QObject::connect(netJob, &NetJob::succeeded, this, &ListModel::searchRequestFinished); + QObject::connect(netJob, &NetJob::failed, this, &ListModel::searchRequestFailed); +} + void ListModel::searchWithTerm(const QString& term, const int sort) { if (currentSearchTerm == term && currentSearchTerm.isNull() == term.isNull() && currentSort == sort) { return; } diff --git a/launcher/ui/pages/modplatform/ModModel.h b/launcher/ui/pages/modplatform/ModModel.h index ae8ceb7c..23e544f1 100644 --- a/launcher/ui/pages/modplatform/ModModel.h +++ b/launcher/ui/pages/modplatform/ModModel.h @@ -3,6 +3,7 @@ #include #include "modplatform/ModIndex.h" +#include "modplatform/ModAPI.h" #include "net/NetJob.h" class ModPage; @@ -30,15 +31,18 @@ class ListModel : public QAbstractListModel { void searchWithTerm(const QString& term, const int sort); protected slots: - virtual void performPaginatedSearch() = 0; virtual void searchRequestFinished() = 0; + void performPaginatedSearch(); + void logoFailed(QString logo); void logoLoaded(QString logo, QIcon out); void searchRequestFailed(QString reason); protected: + virtual const char** getSorts() const = 0; + void requestLogo(QString file, QString url); protected: @@ -56,5 +60,6 @@ class ListModel : public QAbstractListModel { enum SearchState { None, CanPossiblyFetchMore, ResetRequested, Finished } searchState = None; NetJob::Ptr jobPtr; QByteArray response; + }; } // namespace ModPlatform diff --git a/launcher/ui/pages/modplatform/ModPage.cpp b/launcher/ui/pages/modplatform/ModPage.cpp index 8af534a6..2d47e31c 100644 --- a/launcher/ui/pages/modplatform/ModPage.cpp +++ b/launcher/ui/pages/modplatform/ModPage.cpp @@ -101,13 +101,8 @@ void ModPage::onSelectionChanged(QModelIndex first, QModelIndex second) auto netJob = new NetJob(QString("%1::ModVersions(%2)").arg(debugName()).arg(current.name), APPLICATION->network()); auto response = new QByteArray(); QString addonId = current.addonId.toString(); - //FIXME - if(debugName() == "Modrinth") - netJob->addNetAction( - Net::Download::makeByteArray(QString("https://api.modrinth.com/v2/project/%1/version").arg(addonId), response)); - else - netJob->addNetAction( - Net::Download::makeByteArray(QString("https://addons-ecs.forgesvc.net/api/v2/addon/%1/files").arg(addonId), response)); + + netJob->addNetAction(Net::Download::makeByteArray(apiProvider()->getVersionsURL(addonId), response)); QObject::connect(netJob, &NetJob::succeeded, this, [this, response, addonId]{ onModVersionSucceed(this, response, addonId); diff --git a/launcher/ui/pages/modplatform/ModPage.h b/launcher/ui/pages/modplatform/ModPage.h index c0102549..4657bc5e 100644 --- a/launcher/ui/pages/modplatform/ModPage.h +++ b/launcher/ui/pages/modplatform/ModPage.h @@ -3,6 +3,7 @@ #include #include +#include "modplatform/ModAPI.h" #include "modplatform/ModIndex.h" #include "tasks/Task.h" #include "ui/pages/BasePage.h" @@ -30,6 +31,7 @@ class ModPage : public QWidget, public BasePage { inline virtual QString metaEntryBase() const = 0; virtual bool shouldDisplay() const override = 0; + virtual const ModAPI* apiProvider() const = 0; void openedImpl() override; bool eventFilter(QObject* watched, QEvent* event) override; diff --git a/launcher/ui/pages/modplatform/flame/FlameModModel.cpp b/launcher/ui/pages/modplatform/flame/FlameModModel.cpp index 5ab6672f..283f9ce7 100644 --- a/launcher/ui/pages/modplatform/flame/FlameModModel.cpp +++ b/launcher/ui/pages/modplatform/flame/FlameModModel.cpp @@ -1,6 +1,5 @@ #include "FlameModModel.h" #include "FlameModPage.h" -#include "minecraft/MinecraftInstance.h" #include "minecraft/PackProfile.h" #include @@ -11,41 +10,6 @@ ListModel::ListModel(FlameModPage* parent) : ModPlatform::ListModel(parent) {} ListModel::~ListModel() {} -const char* sorts[6]{ "Featured", "Popularity", "LastUpdated", "Name", "Author", "TotalDownloads" }; - -void ListModel::performPaginatedSearch() -{ - QString mcVersion = ((MinecraftInstance*)((FlameModPage*)parent())->m_instance)->getPackProfile()->getComponentVersion("net.minecraft"); - bool hasFabric = !((MinecraftInstance*)((FlameModPage*)parent())->m_instance) - ->getPackProfile() - ->getComponentVersion("net.fabricmc.fabric-loader") - .isEmpty(); - auto netJob = new NetJob("Flame::Search", APPLICATION->network()); - auto searchUrl = QString( - "https://addons-ecs.forgesvc.net/api/v2/addon/search?" - "gameId=432&" - "categoryId=0&" - "sectionId=6&" - - "index=%1&" - "pageSize=25&" - "searchFilter=%2&" - "sort=%3&" - "modLoaderType=%4&" - "gameVersion=%5") - .arg(nextSearchOffset) - .arg(currentSearchTerm) - .arg(sorts[currentSort]) - .arg(hasFabric ? 4 : 1) // Enum: https://docs.curseforge.com/?http#tocS_ModLoaderType - .arg(mcVersion); - - netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), &response)); - jobPtr = netJob; - jobPtr->start(); - - QObject::connect(netJob, &NetJob::succeeded, this, &FlameMod::ListModel::searchRequestFinished); - QObject::connect(netJob, &NetJob::failed, this, &ListModel::searchRequestFailed); -} void FlameMod::ListModel::searchRequestFinished() { @@ -87,4 +51,11 @@ void FlameMod::ListModel::searchRequestFinished() endInsertRows(); } +const char* sorts[6]{ "Featured", "Popularity", "LastUpdated", "Name", "Author", "TotalDownloads" }; + +const char** FlameMod::ListModel::getSorts() const +{ + return sorts; +} + } // namespace FlameMod diff --git a/launcher/ui/pages/modplatform/flame/FlameModModel.h b/launcher/ui/pages/modplatform/flame/FlameModModel.h index a585331d..ae919e63 100644 --- a/launcher/ui/pages/modplatform/flame/FlameModModel.h +++ b/launcher/ui/pages/modplatform/flame/FlameModModel.h @@ -30,8 +30,10 @@ class ListModel : public ModPlatform::ListModel { virtual ~ListModel(); private slots: - void performPaginatedSearch() override; void searchRequestFinished() override; + + private: + const char** getSorts() const override; }; } // namespace Modrinth diff --git a/launcher/ui/pages/modplatform/flame/FlameModPage.h b/launcher/ui/pages/modplatform/flame/FlameModPage.h index 2daa155f..e7d98cb0 100644 --- a/launcher/ui/pages/modplatform/flame/FlameModPage.h +++ b/launcher/ui/pages/modplatform/flame/FlameModPage.h @@ -2,6 +2,8 @@ #include "ui/pages/modplatform/ModPage.h" +#include "modplatform/flame/FlameAPI.h" + class FlameModPage : public ModPage { Q_OBJECT @@ -18,7 +20,11 @@ class FlameModPage : public ModPage { inline QString metaEntryBase() const override { return "FlameMods"; }; bool shouldDisplay() const override; + const ModAPI* apiProvider() const override { return &api; }; private: void onModVersionSucceed(ModPage*, QByteArray*, QString) override; + + private: + FlameAPI api; }; diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp index d2e86ef8..dc3d1469 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp @@ -1,7 +1,6 @@ #include "ModrinthModel.h" #include "ModrinthPage.h" #include "minecraft/MinecraftInstance.h" -#include "minecraft/PackProfile.h" #include @@ -11,37 +10,6 @@ ListModel::ListModel(ModrinthPage* parent) : ModPlatform::ListModel(parent) {} ListModel::~ListModel() {} -const char* sorts[5]{ "relevance", "downloads", "follows", "updated", "newest" }; - -void ListModel::performPaginatedSearch() -{ - QString mcVersion = ((MinecraftInstance*)((ModrinthPage*)parent())->m_instance)->getPackProfile()->getComponentVersion("net.minecraft"); - bool hasFabric = !((MinecraftInstance*)((ModrinthPage*)parent())->m_instance) - ->getPackProfile() - ->getComponentVersion("net.fabricmc.fabric-loader") - .isEmpty(); - auto netJob = new NetJob("Modrinth::Search", APPLICATION->network()); - auto searchUrl = QString( - "https://api.modrinth.com/v2/search?" - "offset=%1&" - "limit=25&" - "query=%2&" - "index=%3&" - "facets=[[\"categories:%4\"],[\"versions:%5\"],[\"project_type:mod\"]]") - .arg(nextSearchOffset) - .arg(currentSearchTerm) - .arg(sorts[currentSort]) - .arg(hasFabric ? "fabric" : "forge") - .arg(mcVersion); - - netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), &response)); - jobPtr = netJob; - jobPtr->start(); - - QObject::connect(netJob, &NetJob::succeeded, this, &Modrinth::ListModel::searchRequestFinished); - QObject::connect(netJob, &NetJob::failed, this, &ListModel::searchRequestFailed); -} - void Modrinth::ListModel::searchRequestFinished() { jobPtr.reset(); @@ -80,4 +48,11 @@ void Modrinth::ListModel::searchRequestFinished() endInsertRows(); } +const char* sorts[5]{ "relevance", "downloads", "follows", "updated", "newest" }; + +const char** Modrinth::ListModel::getSorts() const +{ + return sorts; +} + } // namespace Modrinth diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h index 73492356..b8937b50 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h @@ -30,8 +30,10 @@ class ListModel : public ModPlatform::ListModel { virtual ~ListModel(); private slots: - void performPaginatedSearch() override; void searchRequestFinished() override; + + private: + const char** getSorts() const override; }; } // namespace Modrinth diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h index 41c6c31d..504f42ad 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h @@ -2,6 +2,8 @@ #include "ui/pages/modplatform/ModPage.h" +#include "modplatform/modrinth/ModrinthAPI.h" + class ModrinthPage : public ModPage { Q_OBJECT @@ -18,7 +20,11 @@ class ModrinthPage : public ModPage { inline QString metaEntryBase() const override { return "ModrinthPacks"; }; bool shouldDisplay() const override; + const ModAPI* apiProvider() const override { return &api; }; private: void onModVersionSucceed(ModPage*, QByteArray*, QString) override; + + private: + ModrinthAPI api; }; -- cgit From 8409aa2571d57f015a634a220107d199e88ba2fd Mon Sep 17 00:00:00 2001 From: flow Date: Tue, 8 Mar 2022 11:12:35 -0300 Subject: tidy: Fix clang-tidy issues on files changed in this PR The checks used are roughly the same as the ones proposed in the clang-tidy PR (except perhaps that I used modernize-* instead of listing them individually,though I don't think this caused any readability detriments). In ModrinthModel.cpp and FlameModModel.cpp I ignored the modernize-avoid-c-arrays one, mostly because making the sorts array an std::array would most likely increase the code complexity because of the virtual function. Aside from that, the static_cast warning from Application.h was not dealt with, since it's not in this PR's scope. --- launcher/modplatform/flame/FlameAPI.h | 4 ++-- launcher/modplatform/flame/FlameModIndex.cpp | 4 ++-- launcher/modplatform/flame/FlameModIndex.h | 2 +- launcher/modplatform/helpers/NetworkModAPI.cpp | 6 ++--- launcher/modplatform/helpers/NetworkModAPI.h | 4 ++-- launcher/modplatform/modrinth/ModrinthAPI.h | 10 ++++---- .../modplatform/modrinth/ModrinthPackIndex.cpp | 4 ++-- launcher/modplatform/modrinth/ModrinthPackIndex.h | 2 +- launcher/ui/pages/modplatform/ModModel.cpp | 12 +++++----- launcher/ui/pages/modplatform/ModModel.h | 22 +++++++++--------- launcher/ui/pages/modplatform/ModPage.cpp | 8 +++---- launcher/ui/pages/modplatform/ModPage.h | 27 +++++++++++----------- .../ui/pages/modplatform/flame/FlameModModel.cpp | 3 ++- .../ui/pages/modplatform/flame/FlameModModel.h | 8 +++---- .../ui/pages/modplatform/flame/FlameModPage.cpp | 4 ++-- launcher/ui/pages/modplatform/flame/FlameModPage.h | 18 +++++++-------- .../pages/modplatform/modrinth/ModrinthModel.cpp | 3 ++- .../ui/pages/modplatform/modrinth/ModrinthModel.h | 7 +++--- .../ui/pages/modplatform/modrinth/ModrinthPage.cpp | 4 ++-- .../ui/pages/modplatform/modrinth/ModrinthPage.h | 18 +++++++-------- 20 files changed, 86 insertions(+), 84 deletions(-) (limited to 'launcher/modplatform/modrinth/ModrinthPackIndex.cpp') diff --git a/launcher/modplatform/flame/FlameAPI.h b/launcher/modplatform/flame/FlameAPI.h index f7f993d7..62accfa4 100644 --- a/launcher/modplatform/flame/FlameAPI.h +++ b/launcher/modplatform/flame/FlameAPI.h @@ -4,7 +4,7 @@ class FlameAPI : public NetworkModAPI { private: - inline QString getModSearchURL(SearchArgs& args) const + inline auto getModSearchURL(SearchArgs& args) const -> QString override { return QString( "https://addons-ecs.forgesvc.net/api/v2/addon/search?" @@ -25,7 +25,7 @@ class FlameAPI : public NetworkModAPI { .arg(args.version); }; - inline QString getVersionsURL(const QString& addonId) const + inline auto getVersionsURL(const QString& addonId) const -> QString override { return QString("https://addons-ecs.forgesvc.net/api/v2/addon/%1/files").arg(addonId); }; diff --git a/launcher/modplatform/flame/FlameModIndex.cpp b/launcher/modplatform/flame/FlameModIndex.cpp index 61cb534c..2c3adee4 100644 --- a/launcher/modplatform/flame/FlameModIndex.cpp +++ b/launcher/modplatform/flame/FlameModIndex.cpp @@ -43,8 +43,8 @@ void FlameMod::loadIndexedPackVersions(ModPlatform::IndexedPack& pack, BaseInstance* inst) { QVector unsortedVersions; - bool hasFabric = !((MinecraftInstance*)inst)->getPackProfile()->getComponentVersion("net.fabricmc.fabric-loader").isEmpty(); - QString mcVersion = ((MinecraftInstance*)inst)->getPackProfile()->getComponentVersion("net.minecraft"); + bool hasFabric = !(dynamic_cast(inst))->getPackProfile()->getComponentVersion("net.fabricmc.fabric-loader").isEmpty(); + QString mcVersion = (dynamic_cast(inst))->getPackProfile()->getComponentVersion("net.minecraft"); for (auto versionIter : arr) { auto obj = versionIter.toObject(); diff --git a/launcher/modplatform/flame/FlameModIndex.h b/launcher/modplatform/flame/FlameModIndex.h index 34f71498..d3171d94 100644 --- a/launcher/modplatform/flame/FlameModIndex.h +++ b/launcher/modplatform/flame/FlameModIndex.h @@ -6,8 +6,8 @@ #include "modplatform/ModIndex.h" -#include #include "BaseInstance.h" +#include namespace FlameMod { diff --git a/launcher/modplatform/helpers/NetworkModAPI.cpp b/launcher/modplatform/helpers/NetworkModAPI.cpp index ef084535..25c7b9fd 100644 --- a/launcher/modplatform/helpers/NetworkModAPI.cpp +++ b/launcher/modplatform/helpers/NetworkModAPI.cpp @@ -7,7 +7,7 @@ void NetworkModAPI::searchMods(CallerType* caller, SearchArgs&& args) const { - auto netJob = new NetJob(QString("Modrinth::Search"), APPLICATION->network()); + auto netJob = new NetJob(QString("%1::Search").arg(caller->debugName()), APPLICATION->network()); auto searchUrl = getModSearchURL(args); auto response = new QByteArray(); @@ -16,7 +16,7 @@ void NetworkModAPI::searchMods(CallerType* caller, SearchArgs&& args) const QObject::connect(netJob, &NetJob::started, caller, [caller, netJob] { caller->setActiveJob(netJob); }); QObject::connect(netJob, &NetJob::failed, caller, &CallerType::searchRequestFailed); QObject::connect(netJob, &NetJob::succeeded, caller, [caller, response] { - QJsonParseError parse_error; + QJsonParseError parse_error{}; QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error); if (parse_error.error != QJsonParseError::NoError) { qWarning() << "Error while parsing JSON response from " << caller->debugName() << " at " << parse_error.offset @@ -39,7 +39,7 @@ void NetworkModAPI::getVersions(CallerType* caller, const QString& addonId) cons netJob->addNetAction(Net::Download::makeByteArray(getVersionsURL(addonId), response)); QObject::connect(netJob, &NetJob::succeeded, caller, [response, caller, addonId] { - QJsonParseError parse_error; + QJsonParseError parse_error{}; QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error); if (parse_error.error != QJsonParseError::NoError) { qWarning() << "Error while parsing JSON response from " << caller->debugName() << " at " << parse_error.offset diff --git a/launcher/modplatform/helpers/NetworkModAPI.h b/launcher/modplatform/helpers/NetworkModAPI.h index 65192046..4d3f7005 100644 --- a/launcher/modplatform/helpers/NetworkModAPI.h +++ b/launcher/modplatform/helpers/NetworkModAPI.h @@ -8,6 +8,6 @@ class NetworkModAPI : public ModAPI { void getVersions(CallerType* caller, const QString& addonId) const override; protected: - virtual QString getModSearchURL(SearchArgs& args) const = 0; - virtual QString getVersionsURL(const QString& addonId) const = 0; + virtual auto getModSearchURL(SearchArgs& args) const -> QString = 0; + virtual auto getVersionsURL(const QString& addonId) const -> QString = 0; }; diff --git a/launcher/modplatform/modrinth/ModrinthAPI.h b/launcher/modplatform/modrinth/ModrinthAPI.h index 1cc51ff2..cf4dec1a 100644 --- a/launcher/modplatform/modrinth/ModrinthAPI.h +++ b/launcher/modplatform/modrinth/ModrinthAPI.h @@ -6,10 +6,10 @@ class ModrinthAPI : public NetworkModAPI { public: - inline QString getAuthorURL(const QString& name) const { return "https://modrinth.com/user/" + name; }; + inline auto getAuthorURL(const QString& name) const -> QString { return "https://modrinth.com/user/" + name; }; private: - inline QString getModSearchURL(SearchArgs& args) const override + inline auto getModSearchURL(SearchArgs& args) const -> QString override { if (!validateModLoader(args.mod_loader)) { qWarning() << "Modrinth only have Forge and Fabric-compatible mods!"; @@ -30,12 +30,12 @@ class ModrinthAPI : public NetworkModAPI { .arg(args.version); }; - inline QString getVersionsURL(const QString& addonId) const override + inline auto getVersionsURL(const QString& addonId) const -> QString override { return QString("https://api.modrinth.com/v2/project/%1/version").arg(addonId); }; - inline QString getModLoaderString(ModLoaderType modLoader) const + inline auto getModLoaderString(ModLoaderType modLoader) const -> QString { switch (modLoader) { case Any: @@ -49,7 +49,7 @@ class ModrinthAPI : public NetworkModAPI { } } - inline bool validateModLoader(ModLoaderType modLoader) const + inline auto validateModLoader(ModLoaderType modLoader) const -> bool { return modLoader == Any || modLoader == Forge || modLoader == Fabric; } diff --git a/launcher/modplatform/modrinth/ModrinthPackIndex.cpp b/launcher/modplatform/modrinth/ModrinthPackIndex.cpp index 02aac34d..ab6b451b 100644 --- a/launcher/modplatform/modrinth/ModrinthPackIndex.cpp +++ b/launcher/modplatform/modrinth/ModrinthPackIndex.cpp @@ -30,8 +30,8 @@ void Modrinth::loadIndexedPackVersions(ModPlatform::IndexedPack& pack, BaseInstance* inst) { QVector unsortedVersions; - bool hasFabric = !((MinecraftInstance*)inst)->getPackProfile()->getComponentVersion("net.fabricmc.fabric-loader").isEmpty(); - QString mcVersion = ((MinecraftInstance*)inst)->getPackProfile()->getComponentVersion("net.minecraft"); + bool hasFabric = !(static_cast(inst))->getPackProfile()->getComponentVersion("net.fabricmc.fabric-loader").isEmpty(); + QString mcVersion = (static_cast(inst))->getPackProfile()->getComponentVersion("net.minecraft"); for (auto versionIter : arr) { auto obj = versionIter.toObject(); diff --git a/launcher/modplatform/modrinth/ModrinthPackIndex.h b/launcher/modplatform/modrinth/ModrinthPackIndex.h index abfdabb6..fd17847a 100644 --- a/launcher/modplatform/modrinth/ModrinthPackIndex.h +++ b/launcher/modplatform/modrinth/ModrinthPackIndex.h @@ -2,8 +2,8 @@ #include "modplatform/ModIndex.h" -#include #include "BaseInstance.h" +#include namespace Modrinth { diff --git a/launcher/ui/pages/modplatform/ModModel.cpp b/launcher/ui/pages/modplatform/ModModel.cpp index 6f3c6ce0..cc3c5326 100644 --- a/launcher/ui/pages/modplatform/ModModel.cpp +++ b/launcher/ui/pages/modplatform/ModModel.cpp @@ -11,7 +11,7 @@ namespace ModPlatform { ListModel::ListModel(ModPage* parent) : QAbstractListModel(parent), m_parent(parent) {} -QString ListModel::debugName() const +auto ListModel::debugName() const -> QString { return m_parent->debugName(); } @@ -29,7 +29,7 @@ void ListModel::fetchMore(const QModelIndex& parent) performPaginatedSearch(); } -QVariant ListModel::data(const QModelIndex& index, int role) const +auto ListModel::data(const QModelIndex& index, int role) const -> QVariant { int pos = index.row(); if (pos >= modpacks.size() || pos < 0 || !index.isValid()) { return QString("INVALID INDEX %1").arg(pos); } @@ -56,7 +56,7 @@ QVariant ListModel::data(const QModelIndex& index, int role) const return v; } - return QVariant(); + return {}; } void ListModel::requestModVersions(ModPlatform::IndexedPack const& current) @@ -66,8 +66,8 @@ void ListModel::requestModVersions(ModPlatform::IndexedPack const& current) void ListModel::performPaginatedSearch() { - QString mcVersion = ((MinecraftInstance*)((ModPage*)parent())->m_instance)->getPackProfile()->getComponentVersion("net.minecraft"); - bool hasFabric = !((MinecraftInstance*)((ModPage*)parent())->m_instance) + QString mcVersion = (dynamic_cast((dynamic_cast(parent()))->m_instance))->getPackProfile()->getComponentVersion("net.minecraft"); + bool hasFabric = !(dynamic_cast((dynamic_cast(parent()))->m_instance)) ->getPackProfile() ->getComponentVersion("net.fabricmc.fabric-loader") .isEmpty(); @@ -188,7 +188,7 @@ void ListModel::searchRequestFailed(QString reason) QMessageBox::critical(nullptr, tr("Error"), QString("%1 %2").arg(m_parent->displayName()).arg(tr("API version too old!\nPlease update PolyMC!"))); // self-destruct - ((ModDownloadDialog*)((ModPage*)parent())->parentWidget())->reject(); + (dynamic_cast((dynamic_cast(parent()))->parentWidget()))->reject(); } jobPtr.reset(); diff --git a/launcher/ui/pages/modplatform/ModModel.h b/launcher/ui/pages/modplatform/ModModel.h index 6c3ecc3d..02be6049 100644 --- a/launcher/ui/pages/modplatform/ModModel.h +++ b/launcher/ui/pages/modplatform/ModModel.h @@ -10,24 +10,24 @@ class ModPage; namespace ModPlatform { -typedef QMap LogoMap; -typedef std::function LogoCallback; +using LogoMap = QMap; +using LogoCallback = std::function; class ListModel : public QAbstractListModel { Q_OBJECT public: ListModel(ModPage* parent); - virtual ~ListModel() = default; + ~ListModel() override = default; - inline int rowCount(const QModelIndex& parent) const override { return modpacks.size(); }; - inline int columnCount(const QModelIndex& parent) const override { return 1; }; - inline Qt::ItemFlags flags(const QModelIndex& index) const override { return QAbstractListModel::flags(index); }; + inline auto rowCount(const QModelIndex& parent) const -> int override { return modpacks.size(); }; + inline auto columnCount(const QModelIndex& parent) const -> int override { return 1; }; + inline auto flags(const QModelIndex& index) const -> Qt::ItemFlags override { return QAbstractListModel::flags(index); }; - QString debugName() const; + auto debugName() const -> QString; /* Retrieve information from the model at a given index with the given role */ - QVariant data(const QModelIndex& index, int role) const override; + auto data(const QModelIndex& index, int role) const -> QVariant override; inline void setActiveJob(NetJob::Ptr ptr) { jobPtr = ptr; } @@ -41,7 +41,7 @@ class ListModel : public QAbstractListModel { void getLogo(const QString& logo, const QString& logoUrl, LogoCallback callback); - inline bool canFetchMore(const QModelIndex& parent) const override { return searchState == CanPossiblyFetchMore; }; + inline auto canFetchMore(const QModelIndex& parent) const -> bool override { return searchState == CanPossiblyFetchMore; }; public slots: void searchRequestFinished(QJsonDocument& doc); @@ -57,8 +57,8 @@ class ListModel : public QAbstractListModel { void performPaginatedSearch(); protected: - virtual QJsonArray documentToArray(QJsonDocument& obj) const = 0; - virtual const char** getSorts() const = 0; + virtual auto documentToArray(QJsonDocument& obj) const -> QJsonArray = 0; + virtual auto getSorts() const -> const char** = 0; void requestLogo(QString file, QString url); diff --git a/launcher/ui/pages/modplatform/ModPage.cpp b/launcher/ui/pages/modplatform/ModPage.cpp index 94cf4bcf..1386ba24 100644 --- a/launcher/ui/pages/modplatform/ModPage.cpp +++ b/launcher/ui/pages/modplatform/ModPage.cpp @@ -33,10 +33,10 @@ void ModPage::openedImpl() triggerSearch(); } -bool ModPage::eventFilter(QObject* watched, QEvent* event) +auto ModPage::eventFilter(QObject* watched, QEvent* event) -> bool { if (watched == ui->searchEdit && event->type() == QEvent::KeyPress) { - QKeyEvent* keyEvent = static_cast(event); + auto* keyEvent = dynamic_cast(event); if (keyEvent->key() == Qt::Key_Return) { triggerSearch(); keyEvent->accept(); @@ -70,7 +70,7 @@ void ModPage::onSelectionChanged(QModelIndex first, QModelIndex second) text = "" + name + ""; if (!current.authors.empty()) { - auto authorToStr = [](ModPlatform::ModpackAuthor& author) { + auto authorToStr = [](ModPlatform::ModpackAuthor& author) -> QString { if (author.url.isEmpty()) { return author.name; } return QString("%2").arg(author.url, author.name); }; @@ -128,7 +128,7 @@ void ModPage::onModSelected() void ModPage::updateModVersions() { - auto packProfile = (static_cast(m_instance))->getPackProfile(); + auto packProfile = (dynamic_cast(m_instance))->getPackProfile(); QString mcVersion = packProfile->getComponentVersion("net.minecraft"); QString loaderString = (packProfile->getComponentVersion("net.minecraftforge").isEmpty()) ? "fabric" : "forge"; diff --git a/launcher/ui/pages/modplatform/ModPage.h b/launcher/ui/pages/modplatform/ModPage.h index de66b3b0..58024260 100644 --- a/launcher/ui/pages/modplatform/ModPage.h +++ b/launcher/ui/pages/modplatform/ModPage.h @@ -14,36 +14,35 @@ namespace Ui { class ModPage; } -/* This page handles most logic related to browsing and selecting mods to download. - * By default, the methods provided work with net requests, to fetch data from remote APIs. */ +/* This page handles most logic related to browsing and selecting mods to download. */ class ModPage : public QWidget, public BasePage { Q_OBJECT public: explicit ModPage(ModDownloadDialog* dialog, BaseInstance* instance, ModAPI* api); - virtual ~ModPage(); + ~ModPage() override; /* Affects what the user sees */ - virtual QString displayName() const override = 0; - virtual QIcon icon() const override = 0; - virtual QString id() const override = 0; - virtual QString helpPage() const override = 0; + auto displayName() const -> QString override = 0; + auto icon() const -> QIcon override = 0; + auto id() const -> QString override = 0; + auto helpPage() const -> QString override = 0; /* Used internally */ - virtual QString metaEntryBase() const = 0; - virtual QString debugName() const = 0; + virtual auto metaEntryBase() const -> QString = 0; + virtual auto debugName() const -> QString = 0; - virtual bool shouldDisplay() const override = 0; - virtual bool validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, QString loaderVer = "") const = 0; + auto shouldDisplay() const -> bool override = 0; + virtual auto validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, QString loaderVer = "") const -> bool = 0; - const ModAPI* apiProvider() const { return api.get(); }; + auto apiProvider() const -> const ModAPI* { return api.get(); }; - ModPlatform::IndexedPack& getCurrent() { return current; } + auto getCurrent() -> ModPlatform::IndexedPack& { return current; } void updateModVersions(); void openedImpl() override; - bool eventFilter(QObject* watched, QEvent* event) override; + auto eventFilter(QObject* watched, QEvent* event) -> bool override; BaseInstance* m_instance; diff --git a/launcher/ui/pages/modplatform/flame/FlameModModel.cpp b/launcher/ui/pages/modplatform/flame/FlameModModel.cpp index 8437f623..905fb2dd 100644 --- a/launcher/ui/pages/modplatform/flame/FlameModModel.cpp +++ b/launcher/ui/pages/modplatform/flame/FlameModModel.cpp @@ -4,6 +4,7 @@ namespace FlameMod { +// NOLINTNEXTLINE(modernize-avoid-c-arrays) const char* ListModel::sorts[6]{ "Featured", "Popularity", "LastUpdated", "Name", "Author", "TotalDownloads" }; void ListModel::loadIndexedPack(ModPlatform::IndexedPack& m, QJsonObject& obj) @@ -16,7 +17,7 @@ void ListModel::loadIndexedPackVersions(ModPlatform::IndexedPack& m, QJsonArray& FlameMod::loadIndexedPackVersions(m, arr, APPLICATION->network(), m_parent->m_instance); } -QJsonArray ListModel::documentToArray(QJsonDocument& obj) const +auto ListModel::documentToArray(QJsonDocument& obj) const -> QJsonArray { return obj.array(); } diff --git a/launcher/ui/pages/modplatform/flame/FlameModModel.h b/launcher/ui/pages/modplatform/flame/FlameModModel.h index cf3042ed..707c1bb1 100644 --- a/launcher/ui/pages/modplatform/flame/FlameModModel.h +++ b/launcher/ui/pages/modplatform/flame/FlameModModel.h @@ -9,17 +9,17 @@ class ListModel : public ModPlatform::ListModel { public: ListModel(FlameModPage* parent) : ModPlatform::ListModel(parent) {} -; - virtual ~ListModel() = default; + ~ListModel() override = default; private: void loadIndexedPack(ModPlatform::IndexedPack& m, QJsonObject& obj) override; void loadIndexedPackVersions(ModPlatform::IndexedPack& m, QJsonArray& arr) override; - QJsonArray documentToArray(QJsonDocument& obj) const override; + auto documentToArray(QJsonDocument& obj) const -> QJsonArray override; + // NOLINTNEXTLINE(modernize-avoid-c-arrays) static const char* sorts[6]; - inline const char** getSorts() const override { return sorts; }; + inline auto getSorts() const -> const char** override { return sorts; }; }; } // namespace FlameMod diff --git a/launcher/ui/pages/modplatform/flame/FlameModPage.cpp b/launcher/ui/pages/modplatform/flame/FlameModPage.cpp index 091e49c7..c409a5cb 100644 --- a/launcher/ui/pages/modplatform/flame/FlameModPage.cpp +++ b/launcher/ui/pages/modplatform/flame/FlameModPage.cpp @@ -26,7 +26,7 @@ FlameModPage::FlameModPage(ModDownloadDialog* dialog, BaseInstance* instance) connect(ui->modSelectionButton, &QPushButton::clicked, this, &FlameModPage::onModSelected); } -bool FlameModPage::validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, QString loaderVer) const +auto FlameModPage::validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, QString loaderVer) const -> bool { (void) loaderVer; return ver.mcVersion.contains(mineVer); @@ -35,4 +35,4 @@ bool FlameModPage::validateVersion(ModPlatform::IndexedVersion& ver, QString min // I don't know why, but doing this on the parent class makes it so that // other mod providers start loading before being selected, at least with // my Qt, so we need to implement this in every derived class... -bool FlameModPage::shouldDisplay() const { return true; } +auto FlameModPage::shouldDisplay() const -> bool { return true; } diff --git a/launcher/ui/pages/modplatform/flame/FlameModPage.h b/launcher/ui/pages/modplatform/flame/FlameModPage.h index 90513ca5..b48216bb 100644 --- a/launcher/ui/pages/modplatform/flame/FlameModPage.h +++ b/launcher/ui/pages/modplatform/flame/FlameModPage.h @@ -9,17 +9,17 @@ class FlameModPage : public ModPage { public: explicit FlameModPage(ModDownloadDialog* dialog, BaseInstance* instance); - virtual ~FlameModPage() = default; + ~FlameModPage() override = default; - inline QString displayName() const override { return tr("CurseForge"); } - inline QIcon icon() const override { return APPLICATION->getThemedIcon("flame"); } - inline QString id() const override { return "curseforge"; } - inline QString helpPage() const override { return "Flame-platform"; } + inline auto displayName() const -> QString override { return tr("CurseForge"); } + inline auto icon() const -> QIcon override { return APPLICATION->getThemedIcon("flame"); } + inline auto id() const -> QString override { return "curseforge"; } + inline auto helpPage() const -> QString override { return "Flame-platform"; } - inline QString debugName() const override { return tr("Flame"); } - inline QString metaEntryBase() const override { return "FlameMods"; }; + inline auto debugName() const -> QString override { return tr("Flame"); } + inline auto metaEntryBase() const -> QString override { return "FlameMods"; }; - bool validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, QString loaderVer = "") const override; + auto validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, QString loaderVer = "") const -> bool override; - bool shouldDisplay() const override; + auto shouldDisplay() const -> bool override; }; diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp index ac3c14f2..daa43e26 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp @@ -4,6 +4,7 @@ namespace Modrinth { +// NOLINTNEXTLINE(modernize-avoid-c-arrays) const char* ListModel::sorts[5]{ "relevance", "downloads", "follows", "updated", "newest" }; void ListModel::loadIndexedPack(ModPlatform::IndexedPack& m, QJsonObject& obj) @@ -16,7 +17,7 @@ void ListModel::loadIndexedPackVersions(ModPlatform::IndexedPack& m, QJsonArray& Modrinth::loadIndexedPackVersions(m, arr, APPLICATION->network(), m_parent->m_instance); } -QJsonArray ListModel::documentToArray(QJsonDocument& obj) const +auto ListModel::documentToArray(QJsonDocument& obj) const -> QJsonArray { return obj.object().value("hits").toArray(); } diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h index de73704c..45a6090a 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h @@ -9,16 +9,17 @@ class ListModel : public ModPlatform::ListModel { public: ListModel(ModrinthPage* parent) : ModPlatform::ListModel(parent){}; - virtual ~ListModel() = default; + ~ListModel() override = default; private: void loadIndexedPack(ModPlatform::IndexedPack& m, QJsonObject& obj) override; void loadIndexedPackVersions(ModPlatform::IndexedPack& m, QJsonArray& arr) override; - QJsonArray documentToArray(QJsonDocument& obj) const override; + auto documentToArray(QJsonDocument& obj) const -> QJsonArray override; + // NOLINTNEXTLINE(modernize-avoid-c-arrays) static const char* sorts[5]; - inline const char** getSorts() const override { return sorts; }; + inline auto getSorts() const -> const char** override { return sorts; }; }; } // namespace Modrinth diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp index cf01506e..aebfee74 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp @@ -25,7 +25,7 @@ ModrinthPage::ModrinthPage(ModDownloadDialog* dialog, BaseInstance* instance) connect(ui->modSelectionButton, &QPushButton::clicked, this, &ModrinthPage::onModSelected); } -bool ModrinthPage::validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, QString loaderVer) const +auto ModrinthPage::validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, QString loaderVer) const -> bool { return ver.mcVersion.contains(mineVer) && ver.loaders.contains(loaderVer); } @@ -33,4 +33,4 @@ bool ModrinthPage::validateVersion(ModPlatform::IndexedVersion& ver, QString min // I don't know why, but doing this on the parent class makes it so that // other mod providers start loading before being selected, at least with // my Qt, so we need to implement this in every derived class... -bool ModrinthPage::shouldDisplay() const { return true; } +auto ModrinthPage::shouldDisplay() const -> bool { return true; } diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h index 6f387708..6e911b83 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h @@ -9,17 +9,17 @@ class ModrinthPage : public ModPage { public: explicit ModrinthPage(ModDownloadDialog* dialog, BaseInstance* instance); - virtual ~ModrinthPage() = default; + ~ModrinthPage() override = default; - inline QString displayName() const override { return tr("Modrinth"); } - inline QIcon icon() const override { return APPLICATION->getThemedIcon("modrinth"); } - inline QString id() const override { return "modrinth"; } - inline QString helpPage() const override { return "Modrinth-platform"; } + inline auto displayName() const -> QString override { return tr("Modrinth"); } + inline auto icon() const -> QIcon override { return APPLICATION->getThemedIcon("modrinth"); } + inline auto id() const -> QString override { return "modrinth"; } + inline auto helpPage() const -> QString override { return "Modrinth-platform"; } - inline QString debugName() const override { return tr("Modrinth"); } - inline QString metaEntryBase() const override { return "ModrinthPacks"; }; + inline auto debugName() const -> QString override { return tr("Modrinth"); } + inline auto metaEntryBase() const -> QString override { return "ModrinthPacks"; }; - bool validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, QString loaderVer = "") const override; + auto validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, QString loaderVer = "") const -> bool override; - bool shouldDisplay() const override; + auto shouldDisplay() const -> bool override; }; -- cgit