#pragma once #include #include #include #include #include #include #include #include #include #include "Common/Data/Format/IniFile.h" // You'd think this would be simple enough to not require a manager, but we // want to provide a clean list with non-existent files removed, while never // blocking the main thread. It does get a bit complex. class RecentFilesManager { public: RecentFilesManager(); ~RecentFilesManager(); void Load(const Section *recent, int maxRecent); void Save(Section *recent, int maxRecent); void Add(std::string_view filename); void Remove(std::string_view filename); void Clean(); bool HasAny() const; void Clear(); bool ContainsFile(std::string_view filename); void EnsureThread(); std::vector GetRecentFiles() const; private: enum class RecentCmd { Exit, Clear, CleanMissing, Add, Remove, ReplaceAll, }; struct RecentCommand { RecentCmd cmd; std::unique_ptr> varg; std::unique_ptr sarg; }; void PerformCleanMissing(); void WipePendingCommandsUnderLock(); void ThreadFunc(); std::queue cmds_; mutable std::mutex recentLock_; std::vector recentFiles_; std::thread thread_; std::mutex cmdLock_; std::condition_variable cmdCondVar_; }; // Singleton, don't make more. extern RecentFilesManager g_recentFiles;