summaryrefslogtreecommitdiff
path: root/Source/Core/UICommon/GameFileCache.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Core/UICommon/GameFileCache.cpp')
-rw-r--r--Source/Core/UICommon/GameFileCache.cpp30
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;
}