mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2026-07-01 19:06:58 +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
|
|
@ -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,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<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
|
||||
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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue