From 7455c9bf51113f18440699ebf657b5398c04d73e Mon Sep 17 00:00:00 2001 From: spycrab Date: Tue, 2 May 2017 17:38:47 +0200 Subject: [PATCH] Qt: Fix gamelist updating --- .../DolphinQt2/GameList/GameListModel.cpp | 2 + .../Core/DolphinQt2/GameList/GameTracker.cpp | 48 +++++++++++++++++-- Source/Core/DolphinQt2/GameList/GameTracker.h | 7 +-- 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/Source/Core/DolphinQt2/GameList/GameListModel.cpp b/Source/Core/DolphinQt2/GameList/GameListModel.cpp index 97a9337add..8cd4d66926 100644 --- a/Source/Core/DolphinQt2/GameList/GameListModel.cpp +++ b/Source/Core/DolphinQt2/GameList/GameListModel.cpp @@ -90,6 +90,8 @@ void GameListModel::UpdateGame(QSharedPointer game) int entry = FindGame(path); if (entry < 0) entry = m_games.size(); + else + return; beginInsertRows(QModelIndex(), entry, entry); m_games.insert(entry, game); diff --git a/Source/Core/DolphinQt2/GameList/GameTracker.cpp b/Source/Core/DolphinQt2/GameList/GameTracker.cpp index 30b73da389..c4d133f916 100644 --- a/Source/Core/DolphinQt2/GameList/GameTracker.cpp +++ b/Source/Core/DolphinQt2/GameList/GameTracker.cpp @@ -55,8 +55,8 @@ void GameTracker::RemoveDirectory(const QString& dir) QString path = QFileInfo(it.next()).canonicalFilePath(); if (m_tracked_files.contains(path)) { - m_tracked_files[path]--; - if (m_tracked_files[path] == 0) + m_tracked_files[path].remove(dir); + if (m_tracked_files[path].empty()) { removePath(path); m_tracked_files.remove(path); @@ -72,23 +72,63 @@ void GameTracker::UpdateDirectory(const QString& dir) while (it.hasNext()) { QString path = QFileInfo(it.next()).canonicalFilePath(); + auto& tracked_file = m_tracked_files[path]; + if (m_tracked_files.contains(path)) { - m_tracked_files[path]++; + if (!tracked_file.contains(dir)) + tracked_file.insert(dir); } else { addPath(path); - m_tracked_files[path] = 1; + m_tracked_files[path] = QSet{dir}; emit PathChanged(path); } } + + for (const auto& missing : FindMissingFiles(dir)) + { + auto& tracked_file = m_tracked_files[missing]; + + tracked_file.remove(dir); + if (tracked_file.empty()) + { + m_tracked_files.remove(missing); + GameRemoved(missing); + } + } +} + +QSet GameTracker::FindMissingFiles(const QString& dir) +{ + QDirIterator it(dir, game_filters, QDir::NoFilter, QDirIterator::Subdirectories); + + QSet missing_files; + + for (const auto& key : m_tracked_files.keys()) + { + if (m_tracked_files[key].contains(dir)) + missing_files.insert(key); + } + + while (it.hasNext()) + { + QString path = QFileInfo(it.next()).canonicalFilePath(); + if (m_tracked_files.contains(path)) + missing_files.remove(path); + } + + return missing_files; } void GameTracker::UpdateFile(const QString& file) { if (QFileInfo(file).exists()) { + GameRemoved(file); + addPath(file); + emit PathChanged(file); } else if (removePath(file)) diff --git a/Source/Core/DolphinQt2/GameList/GameTracker.h b/Source/Core/DolphinQt2/GameList/GameTracker.h index 2a39bbdf14..60ca290589 100644 --- a/Source/Core/DolphinQt2/GameList/GameTracker.h +++ b/Source/Core/DolphinQt2/GameList/GameTracker.h @@ -6,13 +6,13 @@ #include #include +#include #include #include #include #include #include "DolphinQt2/GameList/GameFile.h" -#include "DolphinQt2/GameList/GameTracker.h" class GameLoader; @@ -42,9 +42,10 @@ signals: private: void UpdateDirectory(const QString& dir); void UpdateFile(const QString& path); + QSet FindMissingFiles(const QString& dir); - // game path -> number of directories that track it - QMap m_tracked_files; + // game path -> directories that track it + QMap> m_tracked_files; QThread m_loader_thread; GameLoader* m_loader; };