mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2026-06-29 01:54:20 +03:00
clang-tidy
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
624121f51c
commit
148b97ef94
8 changed files with 146 additions and 89 deletions
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <QtGlobal>
|
||||
#include <compare>
|
||||
#include <type_traits>
|
||||
|
||||
|
|
@ -26,6 +28,7 @@ struct EnumWrapper {
|
|||
using Enum = EnumV;
|
||||
using EnumBase = std::underlying_type_t<Enum>;
|
||||
|
||||
// NOLINTNEXTLINE(hicpp-explicit-conversions)
|
||||
constexpr EnumWrapper(Enum e = Derived::invalid()) : m_value(e) {}
|
||||
|
||||
constexpr bool isValid() const { return m_value != Derived::invalid(); }
|
||||
|
|
@ -39,9 +42,10 @@ 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,9 +53,10 @@ 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());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <utility>
|
||||
#include "EnumWrapper.h"
|
||||
|
||||
enum class MessageLevelValue : std::uint8_t {
|
||||
|
|
|
|||
|
|
@ -23,8 +23,10 @@
|
|||
#include <QMetaType>
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include "EnumWrapper.h"
|
||||
|
||||
class QIODevice;
|
||||
|
|
|
|||
|
|
@ -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,12 +90,14 @@ 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 {
|
||||
// dates are in RFC 3339 format
|
||||
|
|
@ -111,29 +116,31 @@ 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
file.addonId = Json::requireInteger(obj, "modId");
|
||||
file.fileId = Json::requireInteger(obj, "id");
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -23,11 +23,12 @@
|
|||
#include <QFileInfo>
|
||||
#include <QMessageBox>
|
||||
#include <QtConcurrentRun>
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#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<MinecraftInstance*>(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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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 <QMessageBox>
|
||||
#include <QModelIndex>
|
||||
#include <QString>
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
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<MinecraftInstance const&>(m_base_instance).getPackProfile();
|
||||
auto* profile = static_cast<const MinecraftInstance&>(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<MinecraftInstance const&>(m_base_instance).getPackProfile();
|
||||
auto pack = m_packs[index.row()];
|
||||
auto* profile = static_cast<const MinecraftInstance&>(m_base_instance).getPackProfile();
|
||||
|
||||
Q_ASSERT(profile);
|
||||
Q_ASSERT(m_filter);
|
||||
|
||||
std::optional<std::vector<Version>> 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<MinecraftInstance&>(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<MinecraftInstance&>(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,28 +123,34 @@ 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<MinecraftInstance&>(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
|
||||
(!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()) &&
|
||||
|
|
|
|||
|
|
@ -5,6 +5,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#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<ModFilterWidget::Filter> filter) { m_filter = filter; }
|
||||
virtual QVariant getInstalledPackVersion(ModPlatform::IndexedPack::Ptr) const override;
|
||||
void setFilter(std::shared_ptr<ModFilterWidget::Filter> 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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue