From 64c3d01551117c418347ce8c2dc5f480cbcbec24 Mon Sep 17 00:00:00 2001 From: spycrab Date: Fri, 6 Jul 2018 20:18:45 +0200 Subject: [PATCH 1/2] Qt/GameTracker: Remove workaround --- .../Core/DolphinQt2/GameList/GameTracker.cpp | 37 +++---------------- 1 file changed, 6 insertions(+), 31 deletions(-) diff --git a/Source/Core/DolphinQt2/GameList/GameTracker.cpp b/Source/Core/DolphinQt2/GameList/GameTracker.cpp index 19e468aa30..c80e3fa664 100644 --- a/Source/Core/DolphinQt2/GameList/GameTracker.cpp +++ b/Source/Core/DolphinQt2/GameList/GameTracker.cpp @@ -13,6 +13,8 @@ #include "DiscIO/DirectoryBlob.h" #include "DolphinQt2/QtUtils/QueueOnObject.h" +#include "DolphinQt2/QtUtils/RunOnObject.h" + #include "DolphinQt2/Settings.h" // NOTE: Qt likes to be case-sensitive here even though it shouldn't be thus this ugly regex hack @@ -119,37 +121,10 @@ void GameTracker::StartInternal() m_cache.Save(); } -// Works around a bug in QtCore that will cause crashes when QFileSystemWatcher::addPath -// is called on a directory that is located on a removable device -static bool IsOnRemovableMedia(const QString& dir) -{ -#ifdef _WIN32 - const QString absolute_dir = QFileInfo(dir).absolutePath(); - if (absolute_dir.startsWith(QStringLiteral("//"))) - return true; - const QString root_dir = QDir::toNativeSeparators(absolute_dir.left(3)); - auto type = GetDriveType(root_dir.toStdWString().c_str()); - - switch (type) - { - case DRIVE_REMOVABLE: - case DRIVE_REMOTE: - case DRIVE_CDROM: - case DRIVE_UNKNOWN: - case DRIVE_NO_ROOT_DIR: - return true; - default: - return false; - } -#else - return false; -#endif -} - bool GameTracker::AddPath(const QString& dir) { - if (Settings::Instance().IsAutoRefreshEnabled() && !IsOnRemovableMedia(dir)) - return addPath(dir); + if (Settings::Instance().IsAutoRefreshEnabled()) + RunOnObject(this, [this, dir] { return addPath(dir); }); m_tracked_paths.push_back(dir); @@ -158,8 +133,8 @@ bool GameTracker::AddPath(const QString& dir) bool GameTracker::RemovePath(const QString& dir) { - if (Settings::Instance().IsAutoRefreshEnabled() && !IsOnRemovableMedia(dir)) - return removePath(dir); + if (Settings::Instance().IsAutoRefreshEnabled()) + RunOnObject(this, [this, dir] { return removePath(dir); }); const auto index = m_tracked_paths.indexOf(dir); From bb8b8728637326b85fa86b8026388b33d8f405b7 Mon Sep 17 00:00:00 2001 From: spycrab Date: Fri, 6 Jul 2018 20:27:07 +0200 Subject: [PATCH 2/2] Qt: Refresh Gamelist more thoroughly --- Source/Core/DolphinQt2/GameList/GameListModel.cpp | 4 ++-- Source/Core/DolphinQt2/GameList/GameTracker.cpp | 14 +++++++++++--- Source/Core/DolphinQt2/GameList/GameTracker.h | 2 +- Source/Core/DolphinQt2/MainWindow.cpp | 4 +--- Source/Core/DolphinQt2/Settings.cpp | 4 ++-- Source/Core/DolphinQt2/Settings.h | 4 ++-- Source/Core/DolphinQt2/Settings/PathPane.cpp | 3 +-- 7 files changed, 20 insertions(+), 15 deletions(-) diff --git a/Source/Core/DolphinQt2/GameList/GameListModel.cpp b/Source/Core/DolphinQt2/GameList/GameListModel.cpp index 2b6b130dfd..dc5d1b191f 100644 --- a/Source/Core/DolphinQt2/GameList/GameListModel.cpp +++ b/Source/Core/DolphinQt2/GameList/GameListModel.cpp @@ -25,8 +25,8 @@ GameListModel::GameListModel(QObject* parent) : QAbstractTableModel(parent) connect(&m_tracker, &GameTracker::GameRemoved, this, &GameListModel::RemoveGame); connect(&Settings::Instance(), &Settings::PathAdded, &m_tracker, &GameTracker::AddDirectory); connect(&Settings::Instance(), &Settings::PathRemoved, &m_tracker, &GameTracker::RemoveDirectory); - connect(&Settings::Instance(), &Settings::PathReloadRequested, &m_tracker, - &GameTracker::ReloadDirectory); + connect(&Settings::Instance(), &Settings::GameListRefreshRequested, &m_tracker, + &GameTracker::RefreshAll); connect(&Settings::Instance(), &Settings::TitleDBReloadRequested, this, [this] { m_title_database = Core::TitleDatabase(); }); diff --git a/Source/Core/DolphinQt2/GameList/GameTracker.cpp b/Source/Core/DolphinQt2/GameList/GameTracker.cpp index c80e3fa664..4fba14c4d0 100644 --- a/Source/Core/DolphinQt2/GameList/GameTracker.cpp +++ b/Source/Core/DolphinQt2/GameList/GameTracker.cpp @@ -156,10 +156,18 @@ void GameTracker::RemoveDirectory(const QString& dir) m_load_thread.EmplaceItem(Command{CommandType::RemoveDirectory, dir}); } -void GameTracker::ReloadDirectory(const QString& dir) +void GameTracker::RefreshAll() { - m_load_thread.EmplaceItem(Command{CommandType::RemoveDirectory, dir}); - m_load_thread.EmplaceItem(Command{CommandType::AddDirectory, dir}); + for (auto& file : m_tracked_files.keys()) + emit GameRemoved(file.toStdString()); + + m_tracked_files.clear(); + + for (const QString& dir : Settings::Instance().GetPaths()) + { + m_load_thread.EmplaceItem(Command{CommandType::RemoveDirectory, dir}); + m_load_thread.EmplaceItem(Command{CommandType::AddDirectory, dir}); + } } void GameTracker::UpdateDirectory(const QString& dir) diff --git a/Source/Core/DolphinQt2/GameList/GameTracker.h b/Source/Core/DolphinQt2/GameList/GameTracker.h index 9a1e9f353a..51fdacf4c5 100644 --- a/Source/Core/DolphinQt2/GameList/GameTracker.h +++ b/Source/Core/DolphinQt2/GameList/GameTracker.h @@ -36,7 +36,7 @@ public: void AddDirectory(const QString& dir); void RemoveDirectory(const QString& dir); - void ReloadDirectory(const QString& dir); + void RefreshAll(); signals: void GameLoaded(const std::shared_ptr& game); diff --git a/Source/Core/DolphinQt2/MainWindow.cpp b/Source/Core/DolphinQt2/MainWindow.cpp index 73954c225f..333dd983bd 100644 --- a/Source/Core/DolphinQt2/MainWindow.cpp +++ b/Source/Core/DolphinQt2/MainWindow.cpp @@ -533,9 +533,7 @@ void MainWindow::ConnectStack() void MainWindow::RefreshGameList() { Settings::Instance().ReloadTitleDB(); - - for (const auto& path : Settings::Instance().GetPaths()) - Settings::Instance().ReloadPath(path); + Settings::Instance().RefreshGameList(); } QString MainWindow::PromptFileName() diff --git a/Source/Core/DolphinQt2/Settings.cpp b/Source/Core/DolphinQt2/Settings.cpp index 65097a2825..c04e57ec2a 100644 --- a/Source/Core/DolphinQt2/Settings.cpp +++ b/Source/Core/DolphinQt2/Settings.cpp @@ -123,9 +123,9 @@ void Settings::RemovePath(const QString& qpath) emit PathRemoved(qpath); } -void Settings::ReloadPath(const QString& qpath) +void Settings::RefreshGameList() { - emit PathReloadRequested(qpath); + emit GameListRefreshRequested(); } void Settings::ReloadTitleDB() diff --git a/Source/Core/DolphinQt2/Settings.h b/Source/Core/DolphinQt2/Settings.h index 9e9a8fb9a0..ba6facb87c 100644 --- a/Source/Core/DolphinQt2/Settings.h +++ b/Source/Core/DolphinQt2/Settings.h @@ -69,7 +69,7 @@ public: void SetPreferredView(bool list); QString GetDefaultGame() const; void SetDefaultGame(QString path); - void ReloadPath(const QString& qpath); + void RefreshGameList(); void ReloadTitleDB(); bool IsAutoRefreshEnabled() const; void SetAutoRefreshEnabled(bool enabled); @@ -137,7 +137,7 @@ signals: void PathAdded(const QString&); void PathRemoved(const QString&); void DefaultGameChanged(const QString&); - void PathReloadRequested(const QString&); + void GameListRefreshRequested(); void TitleDBReloadRequested(); void AutoRefreshToggled(bool enabled); void HideCursorChanged(); diff --git a/Source/Core/DolphinQt2/Settings/PathPane.cpp b/Source/Core/DolphinQt2/Settings/PathPane.cpp index e7f9f042e5..4f6099dabc 100644 --- a/Source/Core/DolphinQt2/Settings/PathPane.cpp +++ b/Source/Core/DolphinQt2/Settings/PathPane.cpp @@ -137,8 +137,7 @@ QGroupBox* PathPane::MakeGameFolderBox() connect(recursive_checkbox, &QCheckBox::toggled, this, [](bool checked) { SConfig::GetInstance().m_RecursiveISOFolder = checked; - for (const auto& path : Settings::Instance().GetPaths()) - Settings::Instance().ReloadPath(path); + Settings::Instance().RefreshGameList(); }); connect(auto_checkbox, &QCheckBox::toggled, &Settings::Instance(),