summaryrefslogtreecommitdiff
path: root/src/modlistsortproxy.cpp
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2019-11-27 17:14:44 -0500
committerisanae <14251494+isanae@users.noreply.github.com>2019-11-27 17:14:44 -0500
commitecaf75c4531a79b1bdfe65eb60f257ac04422956 (patch)
treece6b7a20b80174cca8f3304a979b82ac622d7627 /src/modlistsortproxy.cpp
parentd5e38fca6b3a8c7bf90c5a3d8ec779752a22c61d (diff)
refactored matching into one function instead of repeating them for OR and AND
Diffstat (limited to 'src/modlistsortproxy.cpp')
-rw-r--r--src/modlistsortproxy.cpp154
1 files changed, 70 insertions, 84 deletions
diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp
index 805e77f4..0984d415 100644
--- a/src/modlistsortproxy.cpp
+++ b/src/modlistsortproxy.cpp
@@ -278,52 +278,15 @@ bool ModListSortProxy::hasConflictFlag(const std::vector<ModInfo::EFlag> &flags)
bool ModListSortProxy::filterMatchesModAnd(ModInfo::Ptr info, bool enabled) const
{
for (auto iter = m_CategoryFilter.begin(); iter != m_CategoryFilter.end(); ++iter) {
- switch (*iter) {
- case CategoryFactory::CATEGORY_SPECIAL_CHECKED: {
- if (!enabled && !info->alwaysEnabled() && !info->hasFlag(ModInfo::FLAG_SEPARATOR)) return false;
- } break;
- case CategoryFactory::CATEGORY_SPECIAL_UNCHECKED: {
- if (enabled || info->alwaysEnabled()) return false;
- } break;
- case CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE: {
- if (!info->updateAvailable() && !info->downgradeAvailable()) return false;
- } break;
- case CategoryFactory::CATEGORY_SPECIAL_NOCATEGORY: {
- if (info->getCategories().size() > 0) return false;
- } break;
- case CategoryFactory::CATEGORY_SPECIAL_CONFLICT: {
- if (!hasConflictFlag(info->getFlags())) return false;
- } break;
- case CategoryFactory::CATEGORY_SPECIAL_NOTENDORSED: {
- ModInfo::EEndorsedState state = info->endorsedState();
- if (state != ModInfo::ENDORSED_FALSE) return false;
- } break;
- case CategoryFactory::CATEGORY_SPECIAL_BACKUP: {
- if (!info->hasFlag(ModInfo::FLAG_BACKUP)) return false;
- } break;
- case CategoryFactory::CATEGORY_SPECIAL_MANAGED: {
- if (info->hasFlag(ModInfo::FLAG_FOREIGN)) return false;
- } break;
- case CategoryFactory::CATEGORY_SPECIAL_UNMANAGED: {
- if (!info->hasFlag(ModInfo::FLAG_FOREIGN)) return false;
- } break;
- case CategoryFactory::CATEGORY_SPECIAL_NOGAMEDATA: {
- if (!info->hasFlag(ModInfo::FLAG_INVALID)) return false;
- } break;
- case CategoryFactory::CATEGORY_SPECIAL_NONEXUSID: {
- if (!(info->getNexusID() == -1 && !info->hasFlag(ModInfo::FLAG_FOREIGN) &&
- !info->hasFlag(ModInfo::FLAG_BACKUP) &&
- !info->hasFlag(ModInfo::FLAG_SEPARATOR) &&
- !info->hasFlag(ModInfo::FLAG_OVERWRITE))) return false;
- } break;
- default: {
- if (!info->categorySet(*iter)) return false;
- } break;
+ if (!categoryMatchesMod(info, enabled, *iter)) {
+ return false;
}
}
foreach (int content, m_ContentFilter) {
- if (!info->hasContent(static_cast<ModInfo::EContent>(content))) return false;
+ if (!contentMatchesMod(info, enabled, content)) {
+ return false;
+ }
}
return true;
@@ -332,57 +295,80 @@ bool ModListSortProxy::filterMatchesModAnd(ModInfo::Ptr info, bool enabled) cons
bool ModListSortProxy::filterMatchesModOr(ModInfo::Ptr info, bool enabled) const
{
for (auto iter = m_CategoryFilter.begin(); iter != m_CategoryFilter.end(); ++iter) {
- switch (*iter) {
- case CategoryFactory::CATEGORY_SPECIAL_CHECKED: {
- if (enabled || info->alwaysEnabled()) return true;
- } break;
- case CategoryFactory::CATEGORY_SPECIAL_UNCHECKED: {
- if (!enabled && !info->alwaysEnabled()) return true;
- } break;
- case CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE: {
- if (info->updateAvailable() || info->downgradeAvailable()) return true;
- } break;
- case CategoryFactory::CATEGORY_SPECIAL_NOCATEGORY: {
- if (info->getCategories().size() == 0) return true;
- } break;
- case CategoryFactory::CATEGORY_SPECIAL_CONFLICT: {
- if (hasConflictFlag(info->getFlags())) return true;
- } break;
- case CategoryFactory::CATEGORY_SPECIAL_NOTENDORSED: {
- ModInfo::EEndorsedState state = info->endorsedState();
- if ((state == ModInfo::ENDORSED_FALSE) || (state == ModInfo::ENDORSED_NEVER)) return true;
- } break;
- case CategoryFactory::CATEGORY_SPECIAL_BACKUP: {
- if (info->hasFlag(ModInfo::FLAG_BACKUP)) return true;
- } break;
- case CategoryFactory::CATEGORY_SPECIAL_MANAGED: {
- if (!info->hasFlag(ModInfo::FLAG_FOREIGN)) return true;
- } break;
- case CategoryFactory::CATEGORY_SPECIAL_UNMANAGED: {
- if (info->hasFlag(ModInfo::FLAG_FOREIGN)) return true;
- } break;
- case CategoryFactory::CATEGORY_SPECIAL_NOGAMEDATA: {
- if (info->hasFlag(ModInfo::FLAG_INVALID)) return true;
- } break;
- case CategoryFactory::CATEGORY_SPECIAL_NONEXUSID: {
- if ((info->getNexusID() == -1 && !info->hasFlag(ModInfo::FLAG_FOREIGN) &&
- !info->hasFlag(ModInfo::FLAG_BACKUP) &&
- !info->hasFlag(ModInfo::FLAG_SEPARATOR) &&
- !info->hasFlag(ModInfo::FLAG_OVERWRITE))) return true;
- } break;
- default: {
- if (info->categorySet(*iter)) return true;
- } break;
+ if (categoryMatchesMod(info, enabled, *iter)) {
+ return true;
}
}
foreach (int content, m_ContentFilter) {
- if (info->hasContent(static_cast<ModInfo::EContent>(content))) return true;
+ if (contentMatchesMod(info, enabled, content)) {
+ return true;
+ }
}
return m_CategoryFilter.empty() && m_ContentFilter.empty();
}
+bool ModListSortProxy::categoryMatchesMod(
+ ModInfo::Ptr info, bool enabled, int category) const
+{
+ switch (category)
+ {
+ case CategoryFactory::CATEGORY_SPECIAL_CHECKED:
+ return (enabled || info->alwaysEnabled());
+
+ case CategoryFactory::CATEGORY_SPECIAL_UNCHECKED:
+ return (!enabled && !info->alwaysEnabled());
+
+ case CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE:
+ return (info->updateAvailable() || info->downgradeAvailable());
+
+ case CategoryFactory::CATEGORY_SPECIAL_NOCATEGORY:
+ return (info->getCategories().size() == 0);
+
+ case CategoryFactory::CATEGORY_SPECIAL_CONFLICT:
+ return (hasConflictFlag(info->getFlags()));
+
+ case CategoryFactory::CATEGORY_SPECIAL_NOTENDORSED:
+ {
+ ModInfo::EEndorsedState state = info->endorsedState();
+ return ((state == ModInfo::ENDORSED_FALSE) || (state == ModInfo::ENDORSED_NEVER));
+ }
+
+ case CategoryFactory::CATEGORY_SPECIAL_BACKUP:
+ return (info->hasFlag(ModInfo::FLAG_BACKUP));
+
+ case CategoryFactory::CATEGORY_SPECIAL_MANAGED:
+ return (!info->hasFlag(ModInfo::FLAG_FOREIGN));
+
+ case CategoryFactory::CATEGORY_SPECIAL_UNMANAGED:
+ return (info->hasFlag(ModInfo::FLAG_FOREIGN));
+
+ case CategoryFactory::CATEGORY_SPECIAL_NOGAMEDATA:
+ return (info->hasFlag(ModInfo::FLAG_INVALID));
+
+ case CategoryFactory::CATEGORY_SPECIAL_NONEXUSID:
+ {
+ return (
+ info->getNexusID() == -1 &&
+ !info->hasFlag(ModInfo::FLAG_FOREIGN) &&
+ !info->hasFlag(ModInfo::FLAG_BACKUP) &&
+ !info->hasFlag(ModInfo::FLAG_SEPARATOR) &&
+ !info->hasFlag(ModInfo::FLAG_OVERWRITE));
+ }
+
+ default:
+ {
+ return (info->categorySet(category));
+ }
+ }
+}
+
+bool ModListSortProxy::contentMatchesMod(ModInfo::Ptr info, bool enabled, int content) const
+{
+ return info->hasContent(static_cast<ModInfo::EContent>(content));
+}
+
bool ModListSortProxy::filterMatchesMod(ModInfo::Ptr info, bool enabled) const
{
if (!m_CurrentFilter.isEmpty()) {