@@ -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
182216void 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 ()))) {
0 commit comments