From 148b97ef94a364e95e7f3ce475d50e8cd9fb7c77 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Sun, 29 Mar 2026 22:19:45 +0300 Subject: [PATCH] clang-tidy Signed-off-by: Trial97 --- launcher/EnumWrapper.h | 9 ++- launcher/MessageLevel.h | 2 + launcher/modplatform/ModIndex.h | 2 + launcher/modplatform/flame/FlameModIndex.cpp | 58 ++++++++------ launcher/modplatform/flame/FlameModIndex.h | 8 +- .../modrinth/ModrinthPackExportTask.cpp | 57 +++++++------ launcher/ui/pages/modplatform/ModModel.cpp | 79 ++++++++++++------- launcher/ui/pages/modplatform/ModModel.h | 20 +++-- 8 files changed, 146 insertions(+), 89 deletions(-) diff --git a/launcher/EnumWrapper.h b/launcher/EnumWrapper.h index e7a55eebb..b08d75fe9 100644 --- a/launcher/EnumWrapper.h +++ b/launcher/EnumWrapper.h @@ -18,6 +18,8 @@ #pragma once +#include +#include #include #include @@ -26,6 +28,7 @@ struct EnumWrapper { using Enum = EnumV; using EnumBase = std::underlying_type_t; + // NOLINTNEXTLINE(hicpp-explicit-conversions) constexpr EnumWrapper(Enum e = Derived::invalid()) : m_value(e) {} constexpr bool isValid() const { return m_value != Derived::invalid(); } @@ -39,8 +42,9 @@ struct EnumWrapper { QString toString() const { for (auto&& [e, name] : Derived::mapping()) { - if (e == m_value) + if (e == m_value) { return QString(name); + } } Q_ASSERT_X(false, "EnumWrapper::toString()", "No string mapping found for current enum value"); return {}; @@ -49,8 +53,9 @@ struct EnumWrapper { static constexpr Derived fromString(const QString& str) { for (auto&& [e, name] : Derived::mapping()) { - if (str == name) + if (str == name) { return Derived(e); + } } return Derived(Derived::invalid()); } diff --git a/launcher/MessageLevel.h b/launcher/MessageLevel.h index 06043fdc8..04ffd954e 100644 --- a/launcher/MessageLevel.h +++ b/launcher/MessageLevel.h @@ -1,7 +1,9 @@ #pragma once #include +#include #include +#include #include "EnumWrapper.h" enum class MessageLevelValue : std::uint8_t { diff --git a/launcher/modplatform/ModIndex.h b/launcher/modplatform/ModIndex.h index a7f9920a8..3f6c3eeab 100644 --- a/launcher/modplatform/ModIndex.h +++ b/launcher/modplatform/ModIndex.h @@ -23,8 +23,10 @@ #include #include #include +#include #include #include +#include #include "EnumWrapper.h" class QIODevice; diff --git a/launcher/modplatform/flame/FlameModIndex.cpp b/launcher/modplatform/flame/FlameModIndex.cpp index cec5d3025..977ce54bb 100644 --- a/launcher/modplatform/flame/FlameModIndex.cpp +++ b/launcher/modplatform/flame/FlameModIndex.cpp @@ -2,13 +2,9 @@ #include "FileSystem.h" #include "Json.h" -#include "minecraft/MinecraftInstance.h" -#include "minecraft/PackProfile.h" #include "modplatform/ModIndex.h" #include "modplatform/flame/FlameAPI.h" -static FlameAPI api; - void FlameMod::loadIndexedPack(ModPlatform::IndexedPack& pack, QJsonObject& obj) { pack.addonId = Json::requireInteger(obj, "id"); @@ -46,30 +42,36 @@ void FlameMod::loadURLs(ModPlatform::IndexedPack& pack, QJsonObject& obj) auto links_obj = obj["links"].toObject(); pack.extraData.issuesUrl = links_obj["issuesUrl"].toString(); - if (pack.extraData.issuesUrl.endsWith('/')) + if (pack.extraData.issuesUrl.endsWith('/')) { pack.extraData.issuesUrl.chop(1); + } pack.extraData.sourceUrl = links_obj["sourceUrl"].toString(); - if (pack.extraData.sourceUrl.endsWith('/')) + if (pack.extraData.sourceUrl.endsWith('/')) { pack.extraData.sourceUrl.chop(1); + } pack.extraData.wikiUrl = links_obj["wikiUrl"].toString(); - if (pack.extraData.wikiUrl.endsWith('/')) + if (pack.extraData.wikiUrl.endsWith('/')) { pack.extraData.wikiUrl.chop(1); + } - if (!pack.extraData.body.isEmpty()) + if (!pack.extraData.body.isEmpty()) { pack.extraDataLoaded = true; + } } void FlameMod::loadBody(ModPlatform::IndexedPack& pack) { - pack.extraData.body = api.getModDescription(pack.addonId.toInt()); + pack.extraData.body = FlameAPI().getModDescription(pack.addonId.toInt()); - if (!pack.extraData.issuesUrl.isEmpty() || !pack.extraData.sourceUrl.isEmpty() || !pack.extraData.wikiUrl.isEmpty()) + if (!pack.extraData.issuesUrl.isEmpty() || !pack.extraData.sourceUrl.isEmpty() || !pack.extraData.wikiUrl.isEmpty()) { pack.extraDataLoaded = true; + } } -static QString enumToString(int hash_algorithm) +namespace { +QString enumToString(int hash_algorithm) { switch (hash_algorithm) { default: @@ -79,6 +81,7 @@ static QString enumToString(int hash_algorithm) return "md5"; } } +} // namespace void FlameMod::loadIndexedPackVersions(ModPlatform::IndexedPack& pack, QJsonArray& arr) { @@ -87,11 +90,13 @@ void FlameMod::loadIndexedPackVersions(ModPlatform::IndexedPack& pack, QJsonArra auto obj = versionIter.toObject(); auto file = loadIndexedPackVersion(obj); - if (!file.addonId.isValid()) + if (!file.addonId.isValid()) { file.addonId = pack.addonId; + } - if (file.fileId.isValid()) // Heuristic to check if the returned value is valid + if (file.fileId.isValid()) { // Heuristic to check if the returned value is valid unsortedVersions.append(file); + } } auto orderSortPredicate = [](const ModPlatform::IndexedVersion& a, const ModPlatform::IndexedVersion& b) -> bool { @@ -111,27 +116,29 @@ auto FlameMod::loadIndexedPackVersion(QJsonObject& obj, bool load_changelog) -> for (auto mcVer : versionArray) { auto str = mcVer.toString(); - if (str.contains('.')) + if (str.contains('.')) { file.mcVersion.append(str); + } file.side = ModPlatform::SideType::NoSide; - if (auto loader = str.toLower(); loader == "neoforge") + if (auto loader = str.toLower(); loader == "neoforge") { file.loaders |= ModPlatform::NeoForge; - else if (loader == "forge") + } else if (loader == "forge") { file.loaders |= ModPlatform::Forge; - else if (loader == "cauldron") + } else if (loader == "cauldron") { file.loaders |= ModPlatform::Cauldron; - else if (loader == "liteloader") + } else if (loader == "liteloader") { file.loaders |= ModPlatform::LiteLoader; - else if (loader == "fabric") + } else if (loader == "fabric") { file.loaders |= ModPlatform::Fabric; - else if (loader == "quilt") + } else if (loader == "quilt") { file.loaders |= ModPlatform::Quilt; - else if (loader == "server" || loader == "client") { - if (!file.side.isValid()) + } else if (loader == "server" || loader == "client") { + if (!file.side.isValid()) { file.side = ModPlatform::SideType::fromString(loader); - else if (file.side != ModPlatform::SideType::fromString(loader)) + } else if (file.side != ModPlatform::SideType::fromString(loader)) { file.side = ModPlatform::SideType::UniversalSide; + } } } @@ -203,8 +210,9 @@ auto FlameMod::loadIndexedPackVersion(QJsonObject& obj, bool load_changelog) -> file.dependencies.append(dependency); } - if (load_changelog) - file.changelog = api.getModFileChangelog(file.addonId.toInt(), file.fileId.toInt()); + if (load_changelog) { + file.changelog = FlameAPI().getModFileChangelog(file.addonId.toInt(), file.fileId.toInt()); + } return file; } diff --git a/launcher/modplatform/flame/FlameModIndex.h b/launcher/modplatform/flame/FlameModIndex.h index 2631fab74..fd4facb2a 100644 --- a/launcher/modplatform/flame/FlameModIndex.h +++ b/launcher/modplatform/flame/FlameModIndex.h @@ -6,13 +6,11 @@ #include "modplatform/ModIndex.h" -#include "BaseInstance.h" - namespace FlameMod { -void loadIndexedPack(ModPlatform::IndexedPack& m, QJsonObject& obj); -void loadURLs(ModPlatform::IndexedPack& m, QJsonObject& obj); -void loadBody(ModPlatform::IndexedPack& m); +void loadIndexedPack(ModPlatform::IndexedPack& pack, QJsonObject& obj); +void loadURLs(ModPlatform::IndexedPack& pack, QJsonObject& obj); +void loadBody(ModPlatform::IndexedPack& pack); void loadIndexedPackVersions(ModPlatform::IndexedPack& pack, QJsonArray& arr); ModPlatform::IndexedVersion loadIndexedPackVersion(QJsonObject& obj, bool load_changelog = false); } // namespace FlameMod diff --git a/launcher/modplatform/modrinth/ModrinthPackExportTask.cpp b/launcher/modplatform/modrinth/ModrinthPackExportTask.cpp index 346aea93a..1c3ff9e92 100644 --- a/launcher/modplatform/modrinth/ModrinthPackExportTask.cpp +++ b/launcher/modplatform/modrinth/ModrinthPackExportTask.cpp @@ -23,11 +23,12 @@ #include #include #include +#include +#include #include "Json.h" #include "MMCZip.h" #include "archive/ExportToZipTask.h" #include "minecraft/PackProfile.h" -#include "minecraft/mod/MetadataHandler.h" #include "minecraft/mod/ModFolderModel.h" #include "modplatform/ModIndex.h" #include "modplatform/helpers/HashUtils.h" @@ -51,7 +52,7 @@ ModrinthPackExportTask::ModrinthPackExportTask(const QString& name, , mcInstance(dynamic_cast(instance)) , gameRoot(instance->gameRoot()) , output(output) - , filter(filter) + , filter(std::move(filter)) {} void ModrinthPackExportTask::executeTask() @@ -87,8 +88,9 @@ void ModrinthPackExportTask::collectFiles() if (mcInstance) { mcInstance->loaderModList()->update(); connect(mcInstance->loaderModList(), &ModFolderModel::updateFinished, this, &ModrinthPackExportTask::collectHashes); - } else + } else { collectHashes(); + } } void ModrinthPackExportTask::collectHashes() @@ -99,12 +101,14 @@ void ModrinthPackExportTask::collectHashes() const QString relative = gameRoot.relativeFilePath(file.absoluteFilePath()); // require sensible file types - if (!std::any_of(PREFIXES.begin(), PREFIXES.end(), [&relative](const QString& prefix) { return relative.startsWith(prefix); })) + if (!std::ranges::any_of(PREFIXES, [&relative](const QString& prefix) { return relative.startsWith(prefix); })) { continue; - if (!std::any_of(FILE_EXTENSIONS.begin(), FILE_EXTENSIONS.end(), [&relative](const QString& extension) { + } + if (!std::ranges::any_of(FILE_EXTENSIONS, [&relative](const QString& extension) { return relative.endsWith('.' + extension) || relative.endsWith('.' + extension + ".disabled"); - })) + })) { continue; + } QFile openFile(file.absoluteFilePath()); if (!openFile.open(QFile::ReadOnly)) { @@ -151,9 +155,9 @@ void ModrinthPackExportTask::collectHashes() void ModrinthPackExportTask::makeApiRequest() { - if (pendingHashes.isEmpty()) + if (pendingHashes.isEmpty()) { buildZip(); - else { + } else { setStatus(tr("Finding versions for hashes...")); auto [versionsTask, response] = api.currentVersions(pendingHashes.values(), "sha512"); task = versionsTask; @@ -176,17 +180,19 @@ void ModrinthPackExportTask::parseApiResponse(QByteArray* response) iterator.next(); const QJsonObject obj = doc[iterator.value()].toObject(); - if (obj.isEmpty()) + if (obj.isEmpty()) { continue; + } const QJsonArray files_array = obj["files"].toArray(); if (auto fileIter = std::find_if(files_array.begin(), files_array.end(), [&iterator](const QJsonValue& file) { return file["hashes"]["sha512"] == iterator.value(); }); fileIter != files_array.end()) { // map the file to the url - resolvedFiles[iterator.key()] = - ResolvedFile{ fileIter->toObject()["hashes"].toObject()["sha1"].toString(), iterator.value(), - fileIter->toObject()["url"].toString(), fileIter->toObject()["size"].toInt() }; + resolvedFiles[iterator.key()] = ResolvedFile{ .sha1 = fileIter->toObject()["hashes"].toObject()["sha1"].toString(), + .sha512 = iterator.value(), + .url = fileIter->toObject()["url"].toString(), + .size = fileIter->toObject()["size"].toInt() }; } } } catch (const Json::JsonException& e) { @@ -217,7 +223,7 @@ void ModrinthPackExportTask::buildZip() connect(zipTask.get(), &Task::failed, this, [this, progressStep](QString reason) { progressStep->state = TaskStepState::Failed; stepProgress(*progressStep); - emitFailed(reason); + emitFailed(std::move(reason)); }); connect(zipTask.get(), &Task::stepProgress, this, &ModrinthPackExportTask::propagateStepProgress); @@ -226,7 +232,7 @@ void ModrinthPackExportTask::buildZip() stepProgress(*progressStep); }); connect(zipTask.get(), &Task::status, this, [this, progressStep](QString status) { - progressStep->status = status; + progressStep->status = std::move(status); stepProgress(*progressStep); }); task.reset(zipTask); @@ -240,11 +246,12 @@ QByteArray ModrinthPackExportTask::generateIndex() out["game"] = "minecraft"; out["name"] = name; out["versionId"] = version; - if (!summary.isEmpty()) + if (!summary.isEmpty()) { out["summary"] = summary; + } if (mcInstance) { - auto profile = mcInstance->getPackProfile(); + auto* profile = mcInstance->getPackProfile(); // collect all supported components const ComponentPtr minecraft = profile->getComponent("net.minecraft"); const ComponentPtr quilt = profile->getComponent("org.quiltmc.quilt-loader"); @@ -254,16 +261,21 @@ QByteArray ModrinthPackExportTask::generateIndex() // convert all available components to mrpack dependencies QJsonObject dependencies; - if (minecraft != nullptr) + if (minecraft != nullptr) { dependencies["minecraft"] = minecraft->m_version; - if (quilt != nullptr) + } + if (quilt != nullptr) { dependencies["quilt-loader"] = quilt->m_version; - if (fabric != nullptr) + } + if (fabric != nullptr) { dependencies["fabric-loader"] = fabric->m_version; - if (forge != nullptr) + } + if (forge != nullptr) { dependencies["forge"] = forge->m_version; - if (neoForge != nullptr) + } + if (neoForge != nullptr) { dependencies["neoforge"] = neoForge->m_version; + } out["dependencies"] = dependencies; } @@ -291,8 +303,9 @@ QByteArray ModrinthPackExportTask::generateIndex() // a server side mod does not imply that the mod does not work on the client // however, if a mrpack mod is marked as server-only it will not install on the client - if (iterator->side == ModPlatform::SideType::ClientSide) + if (iterator->side == ModPlatform::SideType::ClientSide) { env["server"] = "unsupported"; + } fileOut["env"] = env; diff --git a/launcher/ui/pages/modplatform/ModModel.cpp b/launcher/ui/pages/modplatform/ModModel.cpp index 0d185faf8..61be1d69e 100644 --- a/launcher/ui/pages/modplatform/ModModel.cpp +++ b/launcher/ui/pages/modplatform/ModModel.cpp @@ -6,23 +6,30 @@ #include "minecraft/MinecraftInstance.h" #include "minecraft/PackProfile.h" +#include "minecraft/mod/Mod.h" #include "minecraft/mod/ModFolderModel.h" #include "modplatform/ModIndex.h" +#include "modplatform/ResourceAPI.h" +#include "modplatform/ResourceType.h" +#include "ui/pages/modplatform/ResourceModel.h" #include +#include +#include #include +#include namespace ResourceDownload { -ModModel::ModModel(BaseInstance& base_inst, ResourceAPI* api, QString debugName, QString metaEntryBase) - : ResourceModel(api), m_base_instance(base_inst), m_debugName(debugName + " (Model)"), m_metaEntryBase(metaEntryBase) +ModModel::ModModel(BaseInstance& base_inst, ResourceAPI* api, const QString& debugName, QString metaEntryBase) + : ResourceModel(api), m_base_instance(base_inst), m_debugName(debugName + " (Model)"), m_metaEntryBase(std::move(metaEntryBase)) {} /******** Make data requests ********/ ResourceAPI::SearchArgs ModModel::createSearchArguments() { - auto profile = static_cast(m_base_instance).getPackProfile(); + auto* profile = static_cast(m_base_instance).getPackProfile(); Q_ASSERT(profile); Q_ASSERT(m_filter); @@ -32,42 +39,53 @@ ResourceAPI::SearchArgs ModModel::createSearchArguments() auto loaders = profile->getSupportedModLoaders(); // Version filter - if (!m_filter->versions.empty()) + if (!m_filter->versions.empty()) { versions = m_filter->versions; - if (m_filter->loaders) + } + if (m_filter->loaders != 0U) { loaders = m_filter->loaders; - if (!m_filter->categoryIds.empty()) + } + if (!m_filter->categoryIds.empty()) { categories = m_filter->categoryIds; + } auto side = m_filter->side; auto sort = getCurrentSortingMethodByIndex(); - return { - ModPlatform::ResourceType::Mod, m_next_search_offset, m_search_term, sort, loaders, versions, side, categories, m_filter->openSource - }; + return { .type = ModPlatform::ResourceType::Mod, + .offset = m_next_search_offset, + .search = m_search_term, + .sorting = sort, + .loaders = loaders, + .versions = versions, + .side = side, + .categoryIds = categories, + .openSource = m_filter->openSource }; } -ResourceAPI::VersionSearchArgs ModModel::createVersionsArguments(const QModelIndex& entry) +ResourceAPI::VersionSearchArgs ModModel::createVersionsArguments(const QModelIndex& index) { - auto pack = m_packs[entry.row()]; - auto profile = static_cast(m_base_instance).getPackProfile(); + auto pack = m_packs[index.row()]; + auto* profile = static_cast(m_base_instance).getPackProfile(); Q_ASSERT(profile); Q_ASSERT(m_filter); std::optional> versions{}; auto loaders = profile->getSupportedModLoaders(); - if (!m_filter->versions.empty()) + if (!m_filter->versions.empty()) { versions = m_filter->versions; - if (m_filter->loaders) + } + if (m_filter->loaders != 0U) { loaders = m_filter->loaders; + } - return { pack, versions, loaders, ModPlatform::ResourceType::Mod }; + return { .pack = pack, .mcVersions = versions, .loaders = loaders, .resourceType = ModPlatform::ResourceType::Mod }; } -ResourceAPI::ProjectInfoArgs ModModel::createInfoArguments(const QModelIndex& entry) +ResourceAPI::ProjectInfoArgs ModModel::createInfoArguments(const QModelIndex& index) { - auto pack = m_packs[entry.row()]; + auto pack = m_packs[index.row()]; return { pack }; } @@ -86,9 +104,10 @@ void ModModel::searchWithTerm(const QString& term, unsigned int sort, bool filte bool ModModel::isPackInstalled(ModPlatform::IndexedPack::Ptr pack) const { auto allMods = static_cast(m_base_instance).loaderModList()->allMods(); - return std::any_of(allMods.cbegin(), allMods.cend(), [pack](Mod* mod) { - if (auto meta = mod->metadata(); meta) + return std::ranges::any_of(allMods, [pack](Mod* mod) { + if (auto meta = mod->metadata(); meta) { return meta->provider == pack->provider && meta->project_id == pack->addonId; + } return false; }); } @@ -96,7 +115,7 @@ bool ModModel::isPackInstalled(ModPlatform::IndexedPack::Ptr pack) const QVariant ModModel::getInstalledPackVersion(ModPlatform::IndexedPack::Ptr pack) const { auto allMods = static_cast(m_base_instance).loaderModList()->allMods(); - for (auto mod : allMods) { + for (auto* mod : allMods) { if (auto meta = mod->metadata(); meta && meta->provider == pack->provider && meta->project_id == pack->addonId) { return meta->version(); } @@ -104,30 +123,36 @@ QVariant ModModel::getInstalledPackVersion(ModPlatform::IndexedPack::Ptr pack) c return {}; } +namespace { + bool checkSide(ModPlatform::SideType filter, ModPlatform::SideType value) { return (filter != ModPlatform::SideType::ClientSide && filter != ModPlatform::SideType::ServerSide) || (value != ModPlatform::SideType::ClientSide && value != ModPlatform::SideType::ServerSide) || filter == value; } +} // namespace bool ModModel::checkFilters(ModPlatform::IndexedPack::Ptr pack) { - if (!m_filter) + if (!m_filter) { return true; + } return !(m_filter->hideInstalled && isPackInstalled(pack)) && checkSide(m_filter->side, pack->side); } bool ModModel::checkVersionFilters(const ModPlatform::IndexedVersion& v) { - if (!m_filter) + if (!m_filter) { return true; + } auto loaders = static_cast(m_base_instance).getPackProfile()->getSupportedModLoaders(); - if (m_filter->loaders) + if (m_filter->loaders != 0U) { loaders = m_filter->loaders; - return (!optedOut(v) && // is opted out(aka curseforge download link) - (!loaders.has_value() || !v.loaders || loaders.value() & v.loaders) && // loaders - checkSide(m_filter->side, v.side) && // side - (m_filter->releases.empty() || // releases + } + return (!optedOut(v) && // is opted out(aka curseforge download link) + (!loaders.has_value() || !v.loaders || ((loaders.value() & v.loaders) != 0U)) && // loaders + checkSide(m_filter->side, v.side) && // side + (m_filter->releases.empty() || // releases std::find(m_filter->releases.cbegin(), m_filter->releases.cend(), v.version_type) != m_filter->releases.cend()) && m_filter->checkMcVersions(v.mcVersion)); // mcVersions } diff --git a/launcher/ui/pages/modplatform/ModModel.h b/launcher/ui/pages/modplatform/ModModel.h index 873d4c1f9..08a858e22 100644 --- a/launcher/ui/pages/modplatform/ModModel.h +++ b/launcher/ui/pages/modplatform/ModModel.h @@ -5,6 +5,10 @@ #pragma once #include +#include +#include +#include +#include #include "BaseInstance.h" @@ -24,27 +28,27 @@ class ModModel : public ResourceModel { Q_OBJECT public: - ModModel(BaseInstance&, ResourceAPI* api, QString debugName, QString metaEntryBase); + ModModel(BaseInstance&, ResourceAPI* api, const QString& debugName, QString metaEntryBase); /* Ask the API for more information */ void searchWithTerm(const QString& term, unsigned int sort, bool filter_changed); - void setFilter(std::shared_ptr filter) { m_filter = filter; } - virtual QVariant getInstalledPackVersion(ModPlatform::IndexedPack::Ptr) const override; + void setFilter(std::shared_ptr filter) { m_filter = std::move(filter); } + QVariant getInstalledPackVersion(ModPlatform::IndexedPack::Ptr pack) const override; [[nodiscard]] QString debugName() const override { return m_debugName; } [[nodiscard]] QString metaEntryBase() const override { return m_metaEntryBase; } public slots: ResourceAPI::SearchArgs createSearchArguments() override; - ResourceAPI::VersionSearchArgs createVersionsArguments(const QModelIndex&) override; - ResourceAPI::ProjectInfoArgs createInfoArguments(const QModelIndex&) override; + ResourceAPI::VersionSearchArgs createVersionsArguments(const QModelIndex& index) override; + ResourceAPI::ProjectInfoArgs createInfoArguments(const QModelIndex& index) override; protected: - virtual bool isPackInstalled(ModPlatform::IndexedPack::Ptr) const override; + bool isPackInstalled(ModPlatform::IndexedPack::Ptr pack) const override; - virtual bool checkFilters(ModPlatform::IndexedPack::Ptr) override; - virtual bool checkVersionFilters(const ModPlatform::IndexedVersion&) override; + bool checkFilters(ModPlatform::IndexedPack::Ptr pack) override; + bool checkVersionFilters(const ModPlatform::IndexedVersion& version) override; protected: BaseInstance& m_base_instance;