Skip to content

Commit b1e2185

Browse files
authored
fix: Always order recent providers (#2490)
1 parent 5d77402 commit b1e2185

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

plugins/builtin/source/content/recent.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ namespace hex::plugin::builtin::recent {
180180
return std::fs::last_write_time(a) > std::fs::last_write_time(b);
181181
});
182182

183-
std::unordered_set<RecentEntry, RecentEntry::HashFunction> uniqueProviders;
183+
std::unordered_set<RecentEntry, RecentEntry::HashFunction> alreadyAddedProviders;
184184
for (const auto &path : recentFilePaths) {
185-
if (uniqueProviders.size() >= MaxRecentEntries)
185+
if (s_recentEntries.size() >= MaxRecentEntries)
186186
break;
187187

188188
try {
@@ -197,12 +197,19 @@ namespace hex::plugin::builtin::recent {
197197
}
198198

199199
auto jsonData = nlohmann::json::parse(content);
200-
uniqueProviders.insert(RecentEntry {
200+
201+
auto entry = RecentEntry {
201202
.displayName = jsonData.at("displayName"),
202203
.type = jsonData.at("type"),
203204
.entryFilePath = path,
204205
.data = jsonData
205-
});
206+
};
207+
208+
// Do not add entry twice
209+
if (!alreadyAddedProviders.insert(entry).second)
210+
continue;
211+
212+
s_recentEntries.push_back(entry);
206213
} catch (const std::exception &e) {
207214
log::error("Failed to parse recent file: {}", e.what());
208215
}
@@ -211,7 +218,7 @@ namespace hex::plugin::builtin::recent {
211218
// Delete all recent provider files that are not in the list
212219
for (const auto &path : recentFilePaths) {
213220
bool found = false;
214-
for (const auto &provider : uniqueProviders) {
221+
for (const auto &provider : s_recentEntries) {
215222
if (path == provider.entryFilePath) {
216223
found = true;
217224
break;
@@ -222,8 +229,6 @@ namespace hex::plugin::builtin::recent {
222229
wolv::io::fs::remove(path);
223230
}
224231

225-
std::copy(uniqueProviders.begin(), uniqueProviders.end(), std::front_inserter(s_recentEntries));
226-
227232
s_autoBackupsFound = false;
228233
for (const auto &backupPath : paths::Backups.read()) {
229234
for (const auto &entry : std::fs::directory_iterator(backupPath)) {

0 commit comments

Comments
 (0)