diff options
| author | Chris Bessent <lost.dragonist@gmail.com> | 2021-01-16 19:00:09 -0700 |
|---|---|---|
| committer | Chris Bessent <lost.dragonist@gmail.com> | 2021-01-16 19:20:51 -0700 |
| commit | 1010b5958b59086d5558698455d9349dcc26514e (patch) | |
| tree | d0eaacc066b58e67c3440a6899aaba2ecba337db /src/pluginlist.cpp | |
| parent | 2b1f01cba2a50a17db69187a1b4cbecf5a0fb65d (diff) | |
Add error checking to lockedorder.txt processing
Errors now checked:
1. Plugin listed in lockedorder.txt does not exist
2. Priority in lockedorder.txt is negative
3. Priority in lockedorder.txt is greater than the total number of plugins
Note that lockedorder.txt is not rewritten after these errors occur as
that seems most likely to be the desired behavior...? That is, preserving
the state of lockedorder.txt is more important than anything making sense.
Though negative priorities don't make sense and never will so just get rid
of that if the lockedorder.txt is written to at some point.
Diffstat (limited to 'src/pluginlist.cpp')
| -rw-r--r-- | src/pluginlist.cpp | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/src/pluginlist.cpp b/src/pluginlist.cpp index b5241f8f..6f93c352 100644 --- a/src/pluginlist.cpp +++ b/src/pluginlist.cpp @@ -496,21 +496,38 @@ void PluginList::readLockedOrderFrom(const QString &fileName) if (fields.count() == 2) {
int priority = fields.at(1).trimmed().toInt();
QString name = QString::fromUtf8(fields.at(0));
- // Avoid locking a force-enabled plugin
- if (!m_ESPs[m_ESPsByName.at(name)].forceEnabled) {
- // Is this an open and unclaimed priority?
- if (m_ESPs[m_ESPsByPriority.at(priority)].forceEnabled ||
- std::find_if(m_LockedOrder.begin(), m_LockedOrder.end(), [&](const std::pair<QString, int> &a) { return a.second == priority; }) != m_LockedOrder.end()) {
- // Attempt to find a priority but step over force-enabled plugins and already-set locks
- int calcPriority = priority;
- do {
- ++calcPriority;
- } while (calcPriority < m_ESPsByPriority.size() || (m_ESPs[m_ESPsByPriority.at(calcPriority)].forceEnabled &&
- std::find_if(m_LockedOrder.begin(), m_LockedOrder.end(), [&](const std::pair<QString, int> &a) { return a.second == calcPriority; }) != m_LockedOrder.end()));
- // If we have a match, we can reassign the priority...
- if (calcPriority < m_ESPsByPriority.size())
- m_LockedOrder[name] = calcPriority;
- } else {
+ int pluginIndex = 0;
+ try {
+ pluginIndex = m_ESPsByName.at(name);
+ }
+ catch (...) {
+ // Plugin does not exist anymore. Go ahead and set it as locked.
+ m_LockedOrder[name] = priority;
+ continue;
+ }
+ // Avoid locking a force-enabled plugin or invalid priorities
+ if (!m_ESPs[pluginIndex].forceEnabled && priority >= 0) {
+ // Is the priority off the charts?
+ if (priority < m_ESPsByPriority.size()) {
+ // Is this an open and unclaimed priority?
+ if (m_ESPs[m_ESPsByPriority.at(priority)].forceEnabled ||
+ std::find_if(m_LockedOrder.begin(), m_LockedOrder.end(), [&](const std::pair<QString, int> &a) { return a.second == priority; }) != m_LockedOrder.end()) {
+ // Attempt to find a priority but step over force-enabled plugins and already-set locks
+ int calcPriority = priority;
+ do {
+ ++calcPriority;
+ } while (calcPriority < m_ESPsByPriority.size() && (m_ESPs[m_ESPsByPriority.at(calcPriority)].forceEnabled &&
+ std::find_if(m_LockedOrder.begin(), m_LockedOrder.end(), [&](const std::pair<QString, int> &a) { return a.second == calcPriority; }) != m_LockedOrder.end()));
+ // If we have a match, we can reassign the priority...
+ if (calcPriority < m_ESPsByPriority.size())
+ m_LockedOrder[name] = calcPriority;
+ } else {
+ m_LockedOrder[name] = priority;
+ }
+ }
+ else {
+ // Priority is larger than the plugin list. Go ahead set it as locked at that priority.
+ // It'll be added to the end of the priority list later on.
m_LockedOrder[name] = priority;
}
}
|
