From 256cdb8df709855fd8501e60565a136585fc5ec2 Mon Sep 17 00:00:00 2001 From: Tannin Date: Mon, 9 May 2016 20:36:13 +0200 Subject: [PATCH] fixed priority ordering after enabling/disabling mod --- src/pluginlist.cpp | 36 +++++++++++++++++++++++++++++++++++- src/pluginlist.h | 2 ++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/pluginlist.cpp b/src/pluginlist.cpp index 8110cdf2..0622f729 100644 --- a/src/pluginlist.cpp +++ b/src/pluginlist.cpp @@ -118,6 +118,8 @@ void PluginList::refresh(const QString &profileName m_CurrentProfile = profileName; + QStringList availablePlugins; + std::vector files = baseDirectory.getFiles(); for (FileEntry::Ptr current : files) { if (current.get() == nullptr) { @@ -125,6 +127,8 @@ void PluginList::refresh(const QString &profileName } QString filename = ToQString(current->getName()); + availablePlugins.append(filename.toLower()); + if (m_ESPsByName.find(filename.toLower()) != m_ESPsByName.end()) { continue; } @@ -150,12 +154,21 @@ void PluginList::refresh(const QString &profileName } m_ESPs.push_back(ESPInfo(filename, forceEnabled, originName, ToQString(current->getFullPath()), hasIni)); + m_ESPs.rbegin()->m_Priority = -1; } catch (const std::exception &e) { reportError(tr("failed to update esp info for file %1 (source id: %2), error: %3").arg(filename).arg(current->getOrigin(archive)).arg(e.what())); } } } + for (const auto &espName : m_ESPsByName) { + if (!availablePlugins.contains(espName.first)) { + m_ESPs.erase(m_ESPs.begin() + espName.second); + } + } + + fixPriorities(); + // functions in GamePlugins will use the IPluginList interface of this, so // indices need to work. priority will be off however updateIndices(); @@ -178,6 +191,27 @@ void PluginList::refresh(const QString &profileName m_Refreshed(); } +void PluginList::fixPriorities() +{ + std::vector> espPrios; + + for (int i = 0; i < m_ESPs.size(); ++i) { + int prio = m_ESPs[i].m_Priority; + if (prio == -1) { + prio = INT_MAX; + } + espPrios.push_back(std::make_pair(prio, i)); + } + + std::sort(espPrios.begin(), espPrios.end(), + [](const std::pair &lhs, const std::pair &rhs) { + return lhs.first < rhs.first; + }); + + for (int i = 0; i < espPrios.size(); ++i) { + m_ESPs[espPrios[i].second].m_Priority = i; + } +} void PluginList::enableESP(const QString &name, bool enable) { @@ -964,7 +998,7 @@ bool PluginList::dropMimeData(const QMimeData *mimeData, Qt::DropAction action, row = parent.row(); } - int newPriority = 0; + int newPriority; if ((row < 0) || (row >= static_cast(m_ESPs.size()))) { diff --git a/src/pluginlist.h b/src/pluginlist.h index 2c2ba295..c6927353 100644 --- a/src/pluginlist.h +++ b/src/pluginlist.h @@ -304,6 +304,8 @@ public slots: void testMasters(); + void fixPriorities(); + private: std::vector m_ESPs;