From f46ffc004a42f6eeadf9647e3654bbbcae70e85e Mon Sep 17 00:00:00 2001 From: Bruno Date: Tue, 27 Apr 2021 23:20:18 +0200 Subject: [PATCH] Validate list of filenames --- Settings.cpp | 33 +++++++++++++++++++++++++++++++++ Settings.h | 23 +++-------------------- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/Settings.cpp b/Settings.cpp index 1c01820..cfc9dd8 100644 --- a/Settings.cpp +++ b/Settings.cpp @@ -455,6 +455,39 @@ void Settings::Load() } +void Settings::History::push(const string &filename) +{ + if (filename.empty()) { + front_is_valid = false; + return; + } + filenames.remove(filename); + filenames.push_front(filename); + if (filenames.size() > MAX_RECENT_HISTORY) + filenames.pop_back(); + front_is_valid = true; + changed = true; +} + +void Settings::History::remove(const std::string &filename) +{ + if (filename.empty()) + return; + if (filenames.front() == filename) + front_is_valid = false; + filenames.remove(filename); + changed = true; +} + +void Settings::History::validate() +{ + for (auto fit = filenames.begin(); fit != filenames.end();) { + if ( SystemToolkit::file_exists( *fit )) + ++fit; + else + fit = filenames.erase(fit); + } +} void Settings::Lock() { diff --git a/Settings.h b/Settings.h index 237859c..874d256 100644 --- a/Settings.h +++ b/Settings.h @@ -93,26 +93,9 @@ struct History save_on_exit = false; changed = false; } - void push(const std::string &filename) { - if (filename.empty()) { - front_is_valid = false; - return; - } - filenames.remove(filename); - filenames.push_front(filename); - if (filenames.size() > MAX_RECENT_HISTORY) - filenames.pop_back(); - front_is_valid = true; - changed = true; - } - void remove(const std::string &filename) { - if (filename.empty()) - return; - if (filenames.front() == filename) - front_is_valid = false; - filenames.remove(filename); - changed = true; - } + void push(const std::string &filename); + void remove(const std::string &filename); + void validate(); }; struct TransitionConfig