Skip to content

Commit

Permalink
fixed priority ordering after enabling/disabling mod
Browse files Browse the repository at this point in the history
  • Loading branch information
TanninOne committed May 9, 2016
1 parent 32480f7 commit 256cdb8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/pluginlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,17 @@ void PluginList::refresh(const QString &profileName

m_CurrentProfile = profileName;

QStringList availablePlugins;

std::vector<FileEntry::Ptr> files = baseDirectory.getFiles();
for (FileEntry::Ptr current : files) {
if (current.get() == nullptr) {
continue;
}
QString filename = ToQString(current->getName());

availablePlugins.append(filename.toLower());

if (m_ESPsByName.find(filename.toLower()) != m_ESPsByName.end()) {
continue;
}
Expand All @@ -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();
Expand All @@ -178,6 +191,27 @@ void PluginList::refresh(const QString &profileName
m_Refreshed();
}

void PluginList::fixPriorities()
{
std::vector<std::pair<int, int>> 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<int, int> &lhs, const std::pair<int, int> &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)
{
Expand Down Expand Up @@ -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<int>(m_ESPs.size()))) {
Expand Down
2 changes: 2 additions & 0 deletions src/pluginlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ public slots:

void testMasters();

void fixPriorities();

private:

std::vector<ESPInfo> m_ESPs;
Expand Down

0 comments on commit 256cdb8

Please sign in to comment.