From 382a27cb2f449c96fab65d8f1dba24e2ed9e50c8 Mon Sep 17 00:00:00 2001 From: Elad Ashkenazi Date: Fri, 30 Dec 2022 10:34:35 +0200 Subject: [PATCH] Allow to cancel dir size calculation (#13134) --- Utilities/File.cpp | 7 ++++++- Utilities/File.h | 2 +- rpcs3/rpcs3qt/game_list_frame.cpp | 13 +++++++++++-- rpcs3/rpcs3qt/game_list_frame.h | 1 + 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Utilities/File.cpp b/Utilities/File.cpp index 8b0b90d52a..67f6d417da 100644 --- a/Utilities/File.cpp +++ b/Utilities/File.cpp @@ -1924,7 +1924,7 @@ bool fs::remove_all(const std::string& path, bool remove_root, bool is_no_dir_ok return true; } -u64 fs::get_dir_size(const std::string& path, u64 rounding_alignment) +u64 fs::get_dir_size(const std::string& path, u64 rounding_alignment, atomic_t* cancel_flag) { u64 result = 0; @@ -1937,6 +1937,11 @@ u64 fs::get_dir_size(const std::string& path, u64 rounding_alignment) for (const auto& entry : root_dir) { + if (cancel_flag && *cancel_flag) + { + return umax; + } + if (entry.name == "." || entry.name == "..") { continue; diff --git a/Utilities/File.h b/Utilities/File.h index 7a6b4d5fd5..169eb5b589 100644 --- a/Utilities/File.h +++ b/Utilities/File.h @@ -669,7 +669,7 @@ namespace fs bool remove_all(const std::string& path, bool remove_root = true, bool is_no_dir_ok = false); // Get size of all files recursively - u64 get_dir_size(const std::string& path, u64 rounding_alignment = 1); + u64 get_dir_size(const std::string& path, u64 rounding_alignment = 1, atomic_t* cancel_flag = nullptr); enum class error : uint { diff --git a/rpcs3/rpcs3qt/game_list_frame.cpp b/rpcs3/rpcs3qt/game_list_frame.cpp index 1f4c06bddb..9d28f4fc5e 100644 --- a/rpcs3/rpcs3qt/game_list_frame.cpp +++ b/rpcs3/rpcs3qt/game_list_frame.cpp @@ -156,6 +156,13 @@ game_list_frame::game_list_frame(std::shared_ptr gui_settings, std item->call_icon_func(); } }); + connect(&m_size_watcher, &QFutureWatcher::canceled, this, [this]() + { + if (m_size_watcher_cancel) + { + *m_size_watcher_cancel = true; + } + }); connect(&m_size_watcher, &QFutureWatcher::finished, this, [this]() { Refresh(); @@ -779,9 +786,11 @@ void game_list_frame::OnRefreshFinished() Refresh(); - m_size_watcher.setFuture(QtConcurrent::map(m_game_data, [this](const game_info& game) -> void + m_size_watcher_cancel = std::make_shared>(false); + + m_size_watcher.setFuture(QtConcurrent::map(m_game_data, [this, cancel = m_size_watcher_cancel](const game_info& game) -> void { - if (game) game->info.size_on_disk = fs::get_dir_size(game->info.path); + if (game) game->info.size_on_disk = fs::get_dir_size(game->info.path, 1, cancel.get()); })); } diff --git a/rpcs3/rpcs3qt/game_list_frame.h b/rpcs3/rpcs3qt/game_list_frame.h index fe91eb2033..0395476bc1 100644 --- a/rpcs3/rpcs3qt/game_list_frame.h +++ b/rpcs3/rpcs3qt/game_list_frame.h @@ -161,6 +161,7 @@ private: QFutureWatcher m_size_watcher; QFutureWatcher m_refresh_watcher; QFutureWatcher m_repaint_watcher; + std::shared_ptr> m_size_watcher_cancel; QSet m_hidden_list; bool m_show_hidden{false};