From 68152faf4352d92192a01ca913c518b25798b2d3 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sat, 26 May 2018 18:22:14 +0200 Subject: DolphinQt2: Show cached games before checking whether they exist on disk DolphinWX already has this improvement in startup time, and it matters a lot when you have a large game list. --- Source/Core/UICommon/GameFileCache.cpp | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'Source/Core/UICommon/GameFileCache.cpp') diff --git a/Source/Core/UICommon/GameFileCache.cpp b/Source/Core/UICommon/GameFileCache.cpp index 9dc25740f9..4302aecc44 100644 --- a/Source/Core/UICommon/GameFileCache.cpp +++ b/Source/Core/UICommon/GameFileCache.cpp @@ -73,7 +73,10 @@ std::shared_ptr GameFileCache::AddOrGet(const std::string& path, return result; } -bool GameFileCache::Update(const std::vector& all_game_paths) +bool GameFileCache::Update( + const std::vector& all_game_paths, + std::function&)> game_added_to_cache, + std::function game_removed_from_cache) { // Copy game paths into a set, except ones that match DiscIO::ShouldHideFromGameList. // TODO: Prevent DoFileSearch from looking inside /files/ directories of DirectoryBlobs at all? @@ -102,21 +105,27 @@ bool GameFileCache::Update(const std::vector& all_game_paths) } else { + if (game_removed_from_cache) + game_removed_from_cache((*it)->GetFilePath()); + cache_changed = true; --end; *it = std::move(*end); + m_cached_files.pop_back(); } } - m_cached_files.erase(it, m_cached_files.end()); } // Now that the previous loop has run, game_paths only contains paths that // aren't in m_cached_files, so we simply add all of them to m_cached_files. - for (const auto& path : game_paths) + for (const std::string& path : game_paths) { auto file = std::make_shared(path); if (file->IsValid()) { + if (game_added_to_cache) + game_added_to_cache(file); + cache_changed = true; m_cached_files.push_back(std::move(file)); } @@ -125,12 +134,19 @@ bool GameFileCache::Update(const std::vector& all_game_paths) return cache_changed; } -bool GameFileCache::UpdateAdditionalMetadata(const Core::TitleDatabase& title_database) +bool GameFileCache::UpdateAdditionalMetadata( + const Core::TitleDatabase& title_database, + std::function&)> game_updated) { bool cache_changed = false; - for (auto& file : m_cached_files) - cache_changed |= UpdateAdditionalMetadata(&file, title_database); + for (std::shared_ptr& file : m_cached_files) + { + const bool updated = UpdateAdditionalMetadata(&file, title_database); + cache_changed |= updated; + if (game_updated && updated) + game_updated(file); + } return cache_changed; } -- cgit v1.2.3 From fd651cf5e6c20b905012a9f266e90e3adace7683 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sat, 26 May 2018 19:09:33 +0200 Subject: GameFileCache: Fix a comment mistake --- Source/Core/UICommon/GameFileCache.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/UICommon/GameFileCache.cpp') diff --git a/Source/Core/UICommon/GameFileCache.cpp b/Source/Core/UICommon/GameFileCache.cpp index 4302aecc44..7f9b7015b2 100644 --- a/Source/Core/UICommon/GameFileCache.cpp +++ b/Source/Core/UICommon/GameFileCache.cpp @@ -92,7 +92,7 @@ bool GameFileCache::Update( bool cache_changed = false; // Delete paths that aren't in game_paths from m_cached_files, - // while simultaneously deleting paths that aren't in m_cached_files from game_paths. + // while simultaneously deleting paths that are in m_cached_files from game_paths. // For the sake of speed, we don't care about maintaining the order of m_cached_files. { auto it = m_cached_files.begin(); -- cgit v1.2.3