From ca64734bcdf8a74532b8202e5cf68eebc9b5b212 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 26 Mar 2025 16:52:35 +0100 Subject: [PATCH] Hide the file name resolution behind the interface --- Core/Config.cpp | 6 ++---- Core/Util/RecentFiles.cpp | 26 ++++++++++++++++---------- Core/Util/RecentFiles.h | 4 ++-- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index 7b1d0d150d..028bcdcf43 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -1578,8 +1578,7 @@ void Config::AddRecent(const std::string &filename) { return; // We'll add it back below. This makes sure it's at the front, and only once. - const std::string resolvedFilename = File::ResolvePath(filename); - AddRecentResolved(resolvedFilename, iMaxRecent); + ::AddRecent(filename, iMaxRecent); } void Config::RemoveRecent(const std::string &filename) { @@ -1587,8 +1586,7 @@ void Config::RemoveRecent(const std::string &filename) { return; } - std::string resolvedFilename = File::ResolvePath(filename); - RemoveRecentResolved(resolvedFilename); + ::RemoveRecent(filename); } // On iOS, the path to the app documents directory changes on each launch. diff --git a/Core/Util/RecentFiles.cpp b/Core/Util/RecentFiles.cpp index c46142829b..82e3ce550d 100644 --- a/Core/Util/RecentFiles.cpp +++ b/Core/Util/RecentFiles.cpp @@ -77,16 +77,6 @@ void SaveRecentIsos(Section *recent, int maxRecent) { } } -void AddRecentResolved(const std::string &resolvedFilename, int maxRecent) { - RemoveRecentResolved(resolvedFilename); - - ResetRecentIsosThread(); - std::lock_guard guard(recentIsosLock); - recentIsos.insert(recentIsos.begin(), resolvedFilename); - if ((int)recentIsos.size() > maxRecent) - recentIsos.resize(maxRecent); -} - void RemoveRecentResolved(const std::string &resolvedFilename) { ResetRecentIsosThread(); @@ -99,6 +89,22 @@ void RemoveRecentResolved(const std::string &resolvedFilename) { recentIsos.erase(iter, recentIsos.end()); } +void AddRecent(const std::string &filename, int maxRecent) { + std::string resolvedFilename = File::ResolvePath(filename); + RemoveRecentResolved(resolvedFilename); + + ResetRecentIsosThread(); + std::lock_guard guard(recentIsosLock); + recentIsos.insert(recentIsos.begin(), resolvedFilename); + if ((int)recentIsos.size() > maxRecent) + recentIsos.resize(maxRecent); +} + +void RemoveRecent(const std::string &filename) { + std::string resolvedFilename = File::ResolvePath(filename); + RemoveRecentResolved(resolvedFilename); +} + void CleanRecentIsos() { SetRecentIsosThread([] { SetCurrentThreadName("RecentISOs"); diff --git a/Core/Util/RecentFiles.h b/Core/Util/RecentFiles.h index 9f3d03ae4f..bca48f0d32 100644 --- a/Core/Util/RecentFiles.h +++ b/Core/Util/RecentFiles.h @@ -10,8 +10,8 @@ void ResetRecentIsosThread(); void SetRecentIsosThread(std::function f); void LoadRecentIsos(const Section *recent, int maxRecent); void SaveRecentIsos(Section *recent, int maxRecent); -void AddRecentResolved(const std::string &resolvedFilename, int maxRecent); -void RemoveRecentResolved(const std::string &resolvedFilename); +void AddRecent(const std::string &resolvedFilename, int maxRecent); +void RemoveRecent(const std::string &resolvedFilename); void CleanRecentIsos(); std::vector GetRecentIsos(); bool HasRecentIsos();