From f0f23a2c61d0d3506799448c20eb6e17e3d1e075 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 9 Jul 2022 20:41:52 +1000 Subject: [PATCH] Qt: Elide redundant scan progress updates Fixes UI locking up for ages when switching theme. --- pcsx2-qt/MainWindow.cpp | 7 +++++-- pcsx2/Frontend/GameList.cpp | 8 +++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pcsx2-qt/MainWindow.cpp b/pcsx2-qt/MainWindow.cpp index 7448bce271..6fa4cf944c 100644 --- a/pcsx2-qt/MainWindow.cpp +++ b/pcsx2-qt/MainWindow.cpp @@ -204,6 +204,8 @@ void MainWindow::setupAdditionalUi() m_status_progress_widget = new QProgressBar(m_ui.statusBar); m_status_progress_widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); m_status_progress_widget->setFixedSize(140, 16); + m_status_progress_widget->setMinimum(0); + m_status_progress_widget->setMaximum(100); m_status_progress_widget->hide(); m_status_verbose_widget = new QLabel(m_ui.statusBar); @@ -820,8 +822,9 @@ void MainWindow::updateWindowState(bool force_visible) void MainWindow::setProgressBar(int current, int total) { - m_status_progress_widget->setValue(current); - m_status_progress_widget->setMaximum(total); + const int value = (current * 100) / total; + if (m_status_progress_widget->value() != value) + m_status_progress_widget->setValue(value); if (m_status_progress_widget->isVisible()) return; diff --git a/pcsx2/Frontend/GameList.cpp b/pcsx2/Frontend/GameList.cpp index a0b011f19c..998982b06d 100644 --- a/pcsx2/Frontend/GameList.cpp +++ b/pcsx2/Frontend/GameList.cpp @@ -547,11 +547,14 @@ void GameList::ScanDirectory(const char* path, bool recursive, bool only_cache, (FILESYSTEM_FIND_FILES | FILESYSTEM_FIND_HIDDEN_FILES), &files); + u32 files_scanned = 0; progress->SetProgressRange(static_cast(files.size())); progress->SetProgressValue(0); for (FILESYSTEM_FIND_DATA& ffd : files) { + files_scanned++; + if (progress->IsCancelled() || !GameList::IsScannableFilename(ffd.FileName) || IsPathExcluded(excluded_paths, ffd.FileName)) { @@ -564,7 +567,6 @@ void GameList::ScanDirectory(const char* path, bool recursive, bool only_cache, AddFileFromCache(ffd.FileName, ffd.ModificationTime) || only_cache) { - progress->IncrementProgressValue(); continue; } } @@ -572,10 +574,10 @@ void GameList::ScanDirectory(const char* path, bool recursive, bool only_cache, // ownership of fp is transferred progress->SetFormattedStatusText("Scanning '%s'...", FileSystem::GetDisplayNameFromPath(ffd.FileName).c_str()); ScanFile(std::move(ffd.FileName), ffd.ModificationTime); - progress->IncrementProgressValue(); + progress->SetProgressValue(files_scanned); } - progress->SetProgressValue(static_cast(files.size())); + progress->SetProgressValue(files_scanned); progress->PopState(); }