Skip to content

Commit 256cdb8

Browse files
committed
fixed priority ordering after enabling/disabling mod
1 parent 32480f7 commit 256cdb8

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/pluginlist.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,17 @@ void PluginList::refresh(const QString &profileName
118118

119119
m_CurrentProfile = profileName;
120120

121+
QStringList availablePlugins;
122+
121123
std::vector<FileEntry::Ptr> files = baseDirectory.getFiles();
122124
for (FileEntry::Ptr current : files) {
123125
if (current.get() == nullptr) {
124126
continue;
125127
}
126128
QString filename = ToQString(current->getName());
127129

130+
availablePlugins.append(filename.toLower());
131+
128132
if (m_ESPsByName.find(filename.toLower()) != m_ESPsByName.end()) {
129133
continue;
130134
}
@@ -150,12 +154,21 @@ void PluginList::refresh(const QString &profileName
150154
}
151155

152156
m_ESPs.push_back(ESPInfo(filename, forceEnabled, originName, ToQString(current->getFullPath()), hasIni));
157+
m_ESPs.rbegin()->m_Priority = -1;
153158
} catch (const std::exception &e) {
154159
reportError(tr("failed to update esp info for file %1 (source id: %2), error: %3").arg(filename).arg(current->getOrigin(archive)).arg(e.what()));
155160
}
156161
}
157162
}
158163

164+
for (const auto &espName : m_ESPsByName) {
165+
if (!availablePlugins.contains(espName.first)) {
166+
m_ESPs.erase(m_ESPs.begin() + espName.second);
167+
}
168+
}
169+
170+
fixPriorities();
171+
159172
// functions in GamePlugins will use the IPluginList interface of this, so
160173
// indices need to work. priority will be off however
161174
updateIndices();
@@ -178,6 +191,27 @@ void PluginList::refresh(const QString &profileName
178191
m_Refreshed();
179192
}
180193

194+
void PluginList::fixPriorities()
195+
{
196+
std::vector<std::pair<int, int>> espPrios;
197+
198+
for (int i = 0; i < m_ESPs.size(); ++i) {
199+
int prio = m_ESPs[i].m_Priority;
200+
if (prio == -1) {
201+
prio = INT_MAX;
202+
}
203+
espPrios.push_back(std::make_pair(prio, i));
204+
}
205+
206+
std::sort(espPrios.begin(), espPrios.end(),
207+
[](const std::pair<int, int> &lhs, const std::pair<int, int> &rhs) {
208+
return lhs.first < rhs.first;
209+
});
210+
211+
for (int i = 0; i < espPrios.size(); ++i) {
212+
m_ESPs[espPrios[i].second].m_Priority = i;
213+
}
214+
}
181215

182216
void PluginList::enableESP(const QString &name, bool enable)
183217
{
@@ -964,7 +998,7 @@ bool PluginList::dropMimeData(const QMimeData *mimeData, Qt::DropAction action,
964998
row = parent.row();
965999
}
9661000

967-
int newPriority = 0;
1001+
int newPriority;
9681002

9691003
if ((row < 0) ||
9701004
(row >= static_cast<int>(m_ESPs.size()))) {

src/pluginlist.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ public slots:
304304

305305
void testMasters();
306306

307+
void fixPriorities();
308+
307309
private:
308310

309311
std::vector<ESPInfo> m_ESPs;

0 commit comments

Comments
 (0)