fix: Always order recent providers (#2490)

This commit is contained in:
iTrooz
2025-10-31 22:01:30 +01:00
committed by GitHub
parent 5d77402211
commit b1e2185966

View File

@@ -180,9 +180,9 @@ namespace hex::plugin::builtin::recent {
return std::fs::last_write_time(a) > std::fs::last_write_time(b);
});
std::unordered_set<RecentEntry, RecentEntry::HashFunction> uniqueProviders;
std::unordered_set<RecentEntry, RecentEntry::HashFunction> alreadyAddedProviders;
for (const auto &path : recentFilePaths) {
if (uniqueProviders.size() >= MaxRecentEntries)
if (s_recentEntries.size() >= MaxRecentEntries)
break;
try {
@@ -197,12 +197,19 @@ namespace hex::plugin::builtin::recent {
}
auto jsonData = nlohmann::json::parse(content);
uniqueProviders.insert(RecentEntry {
auto entry = RecentEntry {
.displayName = jsonData.at("displayName"),
.type = jsonData.at("type"),
.entryFilePath = path,
.data = jsonData
});
};
// Do not add entry twice
if (!alreadyAddedProviders.insert(entry).second)
continue;
s_recentEntries.push_back(entry);
} catch (const std::exception &e) {
log::error("Failed to parse recent file: {}", e.what());
}
@@ -211,7 +218,7 @@ namespace hex::plugin::builtin::recent {
// Delete all recent provider files that are not in the list
for (const auto &path : recentFilePaths) {
bool found = false;
for (const auto &provider : uniqueProviders) {
for (const auto &provider : s_recentEntries) {
if (path == provider.entryFilePath) {
found = true;
break;
@@ -222,8 +229,6 @@ namespace hex::plugin::builtin::recent {
wolv::io::fs::remove(path);
}
std::copy(uniqueProviders.begin(), uniqueProviders.end(), std::front_inserter(s_recentEntries));
s_autoBackupsFound = false;
for (const auto &backupPath : paths::Backups.read()) {
for (const auto &entry : std::fs::directory_iterator(backupPath)) {