From feb411fb2a320284cb01ee9f5ca13baf105c1f29 Mon Sep 17 00:00:00 2001 From: Chris Bessent Date: Sun, 23 Jan 2022 08:25:58 -0700 Subject: Force priority of primary plugins This fixes a problem with new instances where the primary plugins would be ordered alphabetically instead of in the correct order. --- src/pluginlist.cpp | 39 +++++++++++++++++++++++++++++++++++---- src/pluginlist.h | 3 ++- 2 files changed, 37 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/pluginlist.cpp b/src/pluginlist.cpp index 3812143a..692d03dd 100644 --- a/src/pluginlist.cpp +++ b/src/pluginlist.cpp @@ -272,6 +272,8 @@ void PluginList::refresh(const QString &profileName gamePlugins->readPluginLists(m_Organizer.managedGameOrganizer()->pluginList()); } + fixPrimaryPlugins(); + testMasters(); updateIndices(); @@ -287,6 +289,35 @@ void PluginList::refresh(const QString &profileName m_Refreshed(); } +void PluginList::fixPrimaryPlugins() +{ + if (!m_Organizer.settings().game().forceEnableCoreFiles()) { + return; + } + + // This function ensures that the primary plugins are first and in the correct order + QStringList primaryPlugins = m_Organizer.managedGame()->primaryPlugins(); + int prio = 0; + bool somethingChanged = false; + for (QString plugin : primaryPlugins) { + std::map::iterator iter = m_ESPsByName.find(plugin); + // Plugin is present? + if (iter != m_ESPsByName.end()) { + if (prio != m_ESPs[iter->second].priority) { + // Priority is wrong! Fix it! + int newPrio = prio; + setPluginPriority(iter->second, newPrio, true /* isForced */); + somethingChanged = true; + } + prio++; + } + } + + if (somethingChanged) { + writePluginsList(); + } +} + void PluginList::fixPriorities() { std::vector> espPrios; @@ -1423,7 +1454,7 @@ Qt::ItemFlags PluginList::flags(const QModelIndex &modelIndex) const return result; } -void PluginList::setPluginPriority(int row, int &newPriority) +void PluginList::setPluginPriority(int row, int &newPriority, bool isForced) { int newPriorityTemp = newPriority; @@ -1490,11 +1521,11 @@ void PluginList::changePluginPriority(std::vector rows, int newPriority) // don't try to move plugins before force-enabled plugins for (std::vector::const_iterator iter = m_ESPs.begin(); - iter != m_ESPs.end(); ++iter) { + iter != m_ESPs.end(); ++iter) { if (iter->forceEnabled) { - newPriority = std::max(newPriority, iter->priority+1); + newPriority = std::max(newPriority, iter->priority + 1); } - maxPriority = std::max(maxPriority, iter->priority+1); + maxPriority = std::max(maxPriority, iter->priority + 1); minPriority = std::min(minPriority, iter->priority); } diff --git a/src/pluginlist.h b/src/pluginlist.h index a4310d2a..a6efa71b 100644 --- a/src/pluginlist.h +++ b/src/pluginlist.h @@ -353,11 +353,12 @@ private: void writeLockedOrder(const QString &fileName) const; void readLockedOrderFrom(const QString &fileName); - void setPluginPriority(int row, int &newPriority); + void setPluginPriority(int row, int &newPriority, bool isForced=false); void changePluginPriority(std::vector rows, int newPriority); void testMasters(); + void fixPrimaryPlugins(); void fixPriorities(); int findPluginByPriority(int priority); -- cgit v1.3.1 From 0783eb373b4c00ce1f943e41583c97b664fe29b8 Mon Sep 17 00:00:00 2001 From: Chris Bessent Date: Sun, 23 Jan 2022 08:41:54 -0700 Subject: Fix possible NPE when booting up --- src/pluginlistview.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/pluginlistview.cpp b/src/pluginlistview.cpp index e27d7e66..6e0e8f93 100644 --- a/src/pluginlistview.cpp +++ b/src/pluginlistview.cpp @@ -305,8 +305,7 @@ bool PluginListView::toggleSelectionState() bool PluginListView::event(QEvent* event) { - auto* profile = m_core->currentProfile(); - if (event->type() == QEvent::KeyPress && profile) { + if (event->type() == QEvent::KeyPress) { QKeyEvent* keyEvent = static_cast(event); if (keyEvent->modifiers() == Qt::ControlModifier -- cgit v1.3.1 From cee8d5ed72299a34f7b2ccd4c31e35f9eff0801d Mon Sep 17 00:00:00 2001 From: Chris Bessent Date: Sun, 23 Jan 2022 09:47:25 -0700 Subject: Enforce relationships between plugins Masters must be above their children and children must be below their masters. Currently only applies when trying to move plugins. --- src/pluginlist.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/pluginlist.cpp b/src/pluginlist.cpp index 692d03dd..657ada17 100644 --- a/src/pluginlist.cpp +++ b/src/pluginlist.cpp @@ -1485,8 +1485,35 @@ void PluginList::setPluginPriority(int row, int &newPriority, bool isForced) } } + int oldPriority = m_ESPs.at(row).priority; + if (newPriorityTemp < oldPriority) { // moving up + // don't allow plugins to be moved above their masters + for (auto master : m_ESPs[row].masters) { + auto iter = m_ESPsByName.find(master); + if (iter != m_ESPsByName.end()) { + int masterPriority = m_ESPs[iter->second].priority; + if (masterPriority >= newPriorityTemp) + { + newPriorityTemp = masterPriority + 1; + } + } + } + } + else if (newPriorityTemp > oldPriority) { // moving down + // don't allow masters to be moved below their children + //for (auto idx : m_ESPsByPriority) { + for (int i = oldPriority + 1; i <= newPriorityTemp; i++) { + PluginList::ESPInfo* otherInfo = &m_ESPs.at(m_ESPsByPriority[i]); + for (auto master : otherInfo->masters) { + if (master.compare(m_ESPs[row].name, Qt::CaseInsensitive) == 0) { + newPriorityTemp = otherInfo->priority - 1; + break; + } + } + } + } + try { - int oldPriority = m_ESPs.at(row).priority; if (newPriorityTemp > oldPriority) { // priority is higher than the old, so the gap we left is in lower priorities for (int i = oldPriority + 1; i <= newPriorityTemp; ++i) { -- cgit v1.3.1 From 0b14cc4753f2a5c359b842f2573124bdabb6d0b3 Mon Sep 17 00:00:00 2001 From: Chris Bessent Date: Sun, 23 Jan 2022 11:09:56 -0700 Subject: Enforce the priority rules on every refresh --- src/pluginlist.cpp | 77 ++++++++++++++++++++++++++++++++++++++++++++---------- src/pluginlist.h | 1 + 2 files changed, 64 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/pluginlist.cpp b/src/pluginlist.cpp index 657ada17..52434e89 100644 --- a/src/pluginlist.cpp +++ b/src/pluginlist.cpp @@ -273,6 +273,7 @@ void PluginList::refresh(const QString &profileName } fixPrimaryPlugins(); + fixPluginRelationships(); testMasters(); @@ -318,6 +319,51 @@ void PluginList::fixPrimaryPlugins() } } +void PluginList::fixPluginRelationships() +{ + TimeThis timer("PluginList::fixPluginRelationships"); + + // Count the types of plugins + int masterCount = 0; + for (auto plugin : m_ESPs) { + if (plugin.isLight || plugin.isMaster) { + masterCount++; + } + } + + // Ensure masters are up top and normal plugins are down below + for (int i = 0; i < m_ESPs.size(); i++) { + ESPInfo& plugin = m_ESPs[i]; + if (plugin.isLight || plugin.isMaster) { + if (plugin.priority > masterCount) { + int newPriority = masterCount + 1; + setPluginPriority(i, newPriority); + } + } + else { + if (plugin.priority < masterCount) { + int newPriority = masterCount + 1; + setPluginPriority(i, newPriority); + } + } + } + + // Ensure master/child relationships are observed + for (int i = 0; i < m_ESPs.size(); i++) { + ESPInfo& plugin = m_ESPs[i]; + int newPriority = plugin.priority; + for (auto master : plugin.masters) { + auto iter = m_ESPsByName.find(master); + if (iter != m_ESPsByName.end()) { + newPriority = std::max(newPriority, m_ESPs[iter->second].priority); + } + } + if (newPriority != plugin.priority) { + setPluginPriority(i, newPriority); + } + } +} + void PluginList::fixPriorities() { std::vector> espPrios; @@ -1514,23 +1560,26 @@ void PluginList::setPluginPriority(int row, int &newPriority, bool isForced) } try { - if (newPriorityTemp > oldPriority) { - // priority is higher than the old, so the gap we left is in lower priorities - for (int i = oldPriority + 1; i <= newPriorityTemp; ++i) { - --m_ESPs.at(m_ESPsByPriority.at(i)).priority; + if (newPriorityTemp != oldPriority) { + if (newPriorityTemp > oldPriority) { + // priority is higher than the old, so the gap we left is in lower priorities + for (int i = oldPriority + 1; i <= newPriorityTemp; ++i) { + --m_ESPs.at(m_ESPsByPriority.at(i)).priority; + } + emit dataChanged(index(oldPriority + 1, 0), index(newPriorityTemp, columnCount())); } - emit dataChanged(index(oldPriority + 1, 0), index(newPriorityTemp, columnCount())); - } else { - for (int i = newPriorityTemp; i < oldPriority; ++i) { - ++m_ESPs.at(m_ESPsByPriority.at(i)).priority; + else { + for (int i = newPriorityTemp; i < oldPriority; ++i) { + ++m_ESPs.at(m_ESPsByPriority.at(i)).priority; + } + emit dataChanged(index(newPriorityTemp, 0), index(oldPriority - 1, columnCount())); + ++newPriority; } - emit dataChanged(index(newPriorityTemp, 0), index(oldPriority - 1, columnCount())); - ++newPriority; - } - m_ESPs.at(row).priority = newPriorityTemp; - emit dataChanged(index(row, 0), index(row, columnCount())); - m_PluginMoved(m_ESPs[row].name, oldPriority, newPriorityTemp); + m_ESPs.at(row).priority = newPriorityTemp; + emit dataChanged(index(row, 0), index(row, columnCount())); + m_PluginMoved(m_ESPs[row].name, oldPriority, newPriorityTemp); + } } catch (const std::out_of_range&) { reportError(tr("failed to restore load order for %1").arg(m_ESPs[row].name)); } diff --git a/src/pluginlist.h b/src/pluginlist.h index a6efa71b..af70396e 100644 --- a/src/pluginlist.h +++ b/src/pluginlist.h @@ -360,6 +360,7 @@ private: void fixPrimaryPlugins(); void fixPriorities(); + void fixPluginRelationships(); int findPluginByPriority(int priority); -- cgit v1.3.1 From da4a013590d89de8aa26551733deb04a4a629e19 Mon Sep 17 00:00:00 2001 From: Chris Bessent Date: Sun, 23 Jan 2022 11:29:53 -0700 Subject: Update version to 2.4.5alpha1 --- src/version.rc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/version.rc b/src/version.rc index d4ed8c24..d6c609f1 100644 --- a/src/version.rc +++ b/src/version.rc @@ -3,14 +3,14 @@ // If VS_FF_PRERELEASE is not set, MO labels the build as a release and uses VER_FILEVERSION to determine version number. // Otherwise, if letters are used in VER_FILEVERSION_STR, uses the full MOBase::VersionInfo parser // Otherwise, uses the numbers from VER_FILEVERSION and sets the release type as pre-alpha -#define VER_FILEVERSION 2,4,4 -#define VER_FILEVERSION_STR "2.4.4\0" +#define VER_FILEVERSION 2,4,5 +#define VER_FILEVERSION_STR "2.4.5alpha1\0" VS_VERSION_INFO VERSIONINFO FILEVERSION VER_FILEVERSION PRODUCTVERSION VER_FILEVERSION FILEFLAGSMASK VS_FFI_FILEFLAGSMASK -FILEFLAGS (0) +FILEFLAGS VS_FF_PRERELEASE FILEOS VOS__WINDOWS32 FILETYPE VFT_APP FILESUBTYPE (0) @@ -24,7 +24,7 @@ BEGIN VALUE "FileDescription", "Mod Organizer 2 GUI\0" VALUE "OriginalFilename", "ModOrganizer.exe\0" VALUE "InternalName", "ModOrganizer2\0" - VALUE "LegalCopyright", "Copyright 2011-2016 Sebastian Herbord\r\nCopyright 2016-2021 Mod Organizer 2 contributors\0" + VALUE "LegalCopyright", "Copyright 2011-2016 Sebastian Herbord\r\nCopyright 2016-2022 Mod Organizer 2 contributors\0" VALUE "ProductName", "Mod Organizer 2\0" VALUE "ProductVersion", VER_FILEVERSION_STR END -- cgit v1.3.1