From 58b6e0eb48b4d4b201613f1062796a9af68fe454 Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Wed, 20 Jan 2021 18:16:20 +0100 Subject: Increase robustness of mods priority in profile. --- src/modinfo.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/modinfo.h') diff --git a/src/modinfo.h b/src/modinfo.h index c9b74a66..621a0443 100644 --- a/src/modinfo.h +++ b/src/modinfo.h @@ -103,6 +103,12 @@ public: // Type definitions: MOD_CC }; + // the priority of backups and overwrite from a mod list point of + // view, these do not correspond to the actual priority in the profile + // + static constexpr int BACKUP_PRIORITY = -1; + static constexpr int OVERWRITE_PRIORITY = std::numeric_limits::max(); + public: // Static functions: @@ -602,12 +608,9 @@ public: // Methods after this do not come from IModInterface: */ virtual void ignoreUpdate(bool ignore) = 0; - /** - * @return the fixed priority of mods of this type or INT_MIN if the priority of mods - * needs to be user-modifiable. Can be < 0 to force a priority below user-modifable mods - * or INT_MAX to force priority above all user-modifiables. - */ - virtual int getFixedPriority() const = 0; + // check if this mod has a fixed priority (i.e. that cannot be modified by users) + // + bool isFixedPriority() const { return isBackup() || isOverwrite(); } /** * @return true if the mod is always enabled. -- cgit v1.3.1 From 0e7fed0e32cf7cd6ff342493621287e0040e51ad Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Wed, 20 Jan 2021 21:01:49 +0100 Subject: Move backup and overwrite priority to ModList. --- src/modinfo.h | 6 ------ src/modlist.cpp | 8 ++++---- src/modlist.h | 9 +++++++-- 3 files changed, 11 insertions(+), 12 deletions(-) (limited to 'src/modinfo.h') diff --git a/src/modinfo.h b/src/modinfo.h index 621a0443..0fbcd1c0 100644 --- a/src/modinfo.h +++ b/src/modinfo.h @@ -103,12 +103,6 @@ public: // Type definitions: MOD_CC }; - // the priority of backups and overwrite from a mod list point of - // view, these do not correspond to the actual priority in the profile - // - static constexpr int BACKUP_PRIORITY = -1; - static constexpr int OVERWRITE_PRIORITY = std::numeric_limits::max(); - public: // Static functions: diff --git a/src/modlist.cpp b/src/modlist.cpp index 4518f2e9..073dbfd3 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -337,10 +337,10 @@ QVariant ModList::data(const QModelIndex &modelIndex, int role) const } else if (column == COL_PRIORITY) { if (modInfo->isBackup()) { - return ModInfo::BACKUP_PRIORITY; + return BACKUP_PRIORITY; } else if (modInfo->isOverwrite()) { - return ModInfo::OVERWRITE_PRIORITY; + return OVERWRITE_PRIORITY; } else { return m_Profile->getModPriority(modIndex); @@ -367,10 +367,10 @@ QVariant ModList::data(const QModelIndex &modelIndex, int role) const } else if (role == PriorityRole) { if (modInfo->isBackup()) { - return ModInfo::BACKUP_PRIORITY; + return BACKUP_PRIORITY; } else if (modInfo->isOverwrite()) { - return ModInfo::OVERWRITE_PRIORITY; + return OVERWRITE_PRIORITY; } else { return m_Profile->getModPriority(modIndex); diff --git a/src/modlist.h b/src/modlist.h index 5c7f28ee..8d0a2384 100644 --- a/src/modlist.h +++ b/src/modlist.h @@ -366,10 +366,15 @@ private: // int dropPriority(int row, const QModelIndex& parent) const; -private slots: - private: + // the priority of backups and overwrite for sorting (and display, although + // those are not displayed), these do not correspond to the actual priority + // in the mod list + // + static constexpr int BACKUP_PRIORITY = -1; + static constexpr int OVERWRITE_PRIORITY = std::numeric_limits::max(); + struct TModInfo { TModInfo(unsigned int index, ModInfo::Ptr modInfo) : modInfo(modInfo), nameOrder(index), priorityOrder(0), modIDOrder(0), categoryOrder(0) {} -- cgit v1.3.1 From 34c87a0efa18ad77cbf773bc99bd9f08082b27e9 Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Thu, 21 Jan 2021 21:12:46 +0100 Subject: Prevent backups from being enabled. --- src/modinfo.h | 6 +++--- src/modinfobackup.h | 1 + src/profile.cpp | 9 ++++++++- 3 files changed, 12 insertions(+), 4 deletions(-) (limited to 'src/modinfo.h') diff --git a/src/modinfo.h b/src/modinfo.h index 0fbcd1c0..ff6c4001 100644 --- a/src/modinfo.h +++ b/src/modinfo.h @@ -606,10 +606,10 @@ public: // Methods after this do not come from IModInterface: // bool isFixedPriority() const { return isBackup() || isOverwrite(); } - /** - * @return true if the mod is always enabled. - */ + // check if this mod should always be enabled or disabled + // virtual bool alwaysEnabled() const { return false; } + virtual bool alwaysDisabled() const { return false; } /** * @return true if the mod can be updated. diff --git a/src/modinfobackup.h b/src/modinfobackup.h index 9529855b..853a1211 100644 --- a/src/modinfobackup.h +++ b/src/modinfobackup.h @@ -20,6 +20,7 @@ public: virtual void setNexusID(int) override {} virtual void endorse(bool) override {} virtual void ignoreUpdate(bool) override {} + virtual bool alwaysDisabled() const override { return true; } virtual bool canBeUpdated() const override { return false; } virtual QDateTime getExpires() const override { return QDateTime(); } virtual bool canBeEnabled() const override { return false; } diff --git a/src/profile.cpp b/src/profile.cpp index 6b8d0709..66c23ea1 100644 --- a/src/profile.cpp +++ b/src/profile.cpp @@ -602,11 +602,15 @@ void Profile::setModEnabled(unsigned int index, bool enabled) } ModInfo::Ptr modInfo = ModInfo::getByIndex(index); + // we could quit in the following case, this shouldn't be a change anyway, // but at least this allows the situation to be fixed in case of an error if (modInfo->alwaysEnabled()) { enabled = true; } + if (modInfo->alwaysDisabled()) { + enabled = false; + } if (enabled != m_ModStatus[index].m_Enabled) { m_ModStatus[index].m_Enabled = enabled; @@ -614,7 +618,7 @@ void Profile::setModEnabled(unsigned int index, bool enabled) } } -void Profile::setModsEnabled(const QList &modsToEnable, const QList &modsToDisable) +void Profile::setModsEnabled(const QList& modsToEnable, const QList& modsToDisable) { QList dirtyMods; for (auto idx : modsToEnable) { @@ -622,6 +626,9 @@ void Profile::setModsEnabled(const QList &modsToEnable, const QLis log::error("invalid mod index: {}", idx); continue; } + if (ModInfo::getByIndex(idx)->alwaysDisabled()) { + continue; + } if (!m_ModStatus[idx].m_Enabled) { m_ModStatus[idx].m_Enabled = true; dirtyMods.append(idx); -- cgit v1.3.1 From d81fb09f33f8cd668db20b6120c481580c6c938e Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Thu, 21 Jan 2021 21:20:01 +0100 Subject: Replace isFixedPriority by hasAutomaticPriority. --- src/modinfo.h | 5 +++-- src/modlist.cpp | 4 ++-- src/profile.cpp | 8 ++++---- 3 files changed, 9 insertions(+), 8 deletions(-) (limited to 'src/modinfo.h') diff --git a/src/modinfo.h b/src/modinfo.h index ff6c4001..f93296d2 100644 --- a/src/modinfo.h +++ b/src/modinfo.h @@ -602,9 +602,10 @@ public: // Methods after this do not come from IModInterface: */ virtual void ignoreUpdate(bool ignore) = 0; - // check if this mod has a fixed priority (i.e. that cannot be modified by users) + // check if the priority of this mod is not user-modifiable (i.e. + // computed by MO2 automatically) // - bool isFixedPriority() const { return isBackup() || isOverwrite(); } + bool hasAutomaticPriority() const { return isBackup() || isOverwrite(); } // check if this mod should always be enabled or disabled // diff --git a/src/modlist.cpp b/src/modlist.cpp index 6637f48a..e2a443bd 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -197,7 +197,7 @@ QVariant ModList::data(const QModelIndex &modelIndex, int role) const return version; } else if (column == COL_PRIORITY) { - if (modInfo->isFixedPriority()) { + if (modInfo->hasAutomaticPriority()) { return QVariant(); // hide priority for mods where it's fixed } else { @@ -642,7 +642,7 @@ Qt::ItemFlags ModList::flags(const QModelIndex &modelIndex) const } if (modelIndex.isValid()) { ModInfo::Ptr modInfo = ModInfo::getByIndex(modelIndex.row()); - if (!modInfo->isFixedPriority()) { + if (!modInfo->hasAutomaticPriority()) { result |= Qt::ItemIsDragEnabled; result |= Qt::ItemIsUserCheckable; if ((modelIndex.column() == COL_PRIORITY) || diff --git a/src/profile.cpp b/src/profile.cpp index 66c23ea1..2546661b 100644 --- a/src/profile.cpp +++ b/src/profile.cpp @@ -234,7 +234,7 @@ void Profile::doWriteModlist() // the priority order was inverted on load so it has to be inverted again const auto index = iter->second; ModInfo::Ptr modInfo = ModInfo::getByIndex(index); - if (!modInfo->isFixedPriority()) { + if (!modInfo->hasAutomaticPriority()) { if (modInfo->isForeign()) { file->write("*"); } else if (m_ModStatus[index].m_Enabled) { @@ -460,7 +460,7 @@ void Profile::refreshModStatus() // find the mod and check that this is a regular mod (and not a backup) ModInfo::Ptr info = ModInfo::getByIndex(modIndex); - if (modIndex < m_ModStatus.size() && !info->isFixedPriority()) { + if (modIndex < m_ModStatus.size() && !info->hasAutomaticPriority()) { m_ModStatus[modIndex].m_Enabled = enabled; if (m_ModStatus[modIndex].m_Priority == -1) { if (static_cast(index) >= m_ModStatus.size()) { @@ -527,7 +527,7 @@ void Profile::refreshModStatus() int offset = topInsert * -1; for (size_t i = 0; i < m_ModStatus.size(); ++i) { ModInfo::Ptr modInfo = ModInfo::getByIndex(static_cast(i)); - if (modInfo->isFixedPriority()) { + if (modInfo->hasAutomaticPriority()) { continue; } @@ -674,7 +674,7 @@ int Profile::getModPriority(unsigned int index) const bool Profile::setModPriority(unsigned int index, int &newPriority) { - if (ModInfo::getByIndex(index)->isFixedPriority()) { + if (ModInfo::getByIndex(index)->hasAutomaticPriority()) { // can't change priority of overwrite/backups return false; } -- cgit v1.3.1