diff options
| author | spycrab <spycrab@users.noreply.github.com> | 2018-05-27 04:31:32 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-05-27 04:31:32 +0200 |
| commit | 7b07424885fa2a71f8a08e1d86e7fb65dfb815be (patch) | |
| tree | 1205defdb4d458261012b98df8ab68a02d0f5c4d /Source/Core/UICommon/GameFileCache.cpp | |
| parent | 0c2538f17f49772e6573939f85118aa8384a8ac4 (diff) | |
| parent | fd651cf5e6c20b905012a9f266e90e3adace7683 (diff) | |
Merge pull request #6975 from JosJuice/qt-fast-gamelist
DolphinQt2: Show cached games before checking whether they exist on disk
Diffstat (limited to 'Source/Core/UICommon/GameFileCache.cpp')
| -rw-r--r-- | Source/Core/UICommon/GameFileCache.cpp | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/Source/Core/UICommon/GameFileCache.cpp b/Source/Core/UICommon/GameFileCache.cpp index 9dc25740f9..7f9b7015b2 100644 --- a/Source/Core/UICommon/GameFileCache.cpp +++ b/Source/Core/UICommon/GameFileCache.cpp @@ -73,7 +73,10 @@ std::shared_ptr<const GameFile> GameFileCache::AddOrGet(const std::string& path, return result; } -bool GameFileCache::Update(const std::vector<std::string>& all_game_paths) +bool GameFileCache::Update( + const std::vector<std::string>& all_game_paths, + std::function<void(const std::shared_ptr<const GameFile>&)> game_added_to_cache, + std::function<void(const std::string&)> 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? @@ -89,7 +92,7 @@ bool GameFileCache::Update(const std::vector<std::string>& all_game_paths) 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(); @@ -102,21 +105,27 @@ bool GameFileCache::Update(const std::vector<std::string>& 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<GameFile>(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<std::string>& all_game_paths) return cache_changed; } -bool GameFileCache::UpdateAdditionalMetadata(const Core::TitleDatabase& title_database) +bool GameFileCache::UpdateAdditionalMetadata( + const Core::TitleDatabase& title_database, + std::function<void(const std::shared_ptr<const GameFile>&)> game_updated) { bool cache_changed = false; - for (auto& file : m_cached_files) - cache_changed |= UpdateAdditionalMetadata(&file, title_database); + for (std::shared_ptr<GameFile>& file : m_cached_files) + { + const bool updated = UpdateAdditionalMetadata(&file, title_database); + cache_changed |= updated; + if (game_updated && updated) + game_updated(file); + } return cache_changed; } |
