Qt: check dir size async

This commit is contained in:
Megamouse 2022-12-17 14:58:08 +01:00
parent b2962e0522
commit 8ec01450f8
4 changed files with 46 additions and 38 deletions

View File

@ -6,42 +6,20 @@
struct GameInfo struct GameInfo
{ {
std::string path; std::string path;
std::string icon_path; std::string icon_path;
std::string name;
std::string serial; std::string name = "Unknown";
std::string app_ver; std::string serial = "Unknown";
std::string version; std::string app_ver = "Unknown";
std::string category; std::string version = "Unknown";
std::string fw; std::string category = "Unknown";
std::string fw = "Unknown";
u32 attr = 0; u32 attr = 0;
u32 bootable = 0; u32 bootable = 0;
u32 parental_lvl = 0; u32 parental_lvl = 0;
u32 sound_format = 0; u32 sound_format = 0;
u32 resolution = 0; u32 resolution = 0;
usz size_on_disk = umax; usz size_on_disk = umax;
GameInfo()
{
Reset();
}
void Reset()
{
path.clear();
name = "Unknown";
serial = "Unknown";
app_ver = "Unknown";
version = "Unknown";
category = "Unknown";
fw = "Unknown";
attr = 0;
bootable = 0;
parental_lvl = 0;
sound_format = 0;
resolution = 0;
}
}; };

View File

@ -12,7 +12,7 @@ class movie_item;
/* Having the icons associated with the game info simplifies logic internally */ /* Having the icons associated with the game info simplifies logic internally */
struct gui_game_info struct gui_game_info
{ {
GameInfo info; GameInfo info{};
QString localized_category; QString localized_category;
compat::status compat; compat::status compat;
QPixmap icon; QPixmap icon;

View File

@ -139,6 +139,12 @@ game_list_frame::game_list_frame(std::shared_ptr<gui_settings> gui_settings, std
connect(&m_refresh_watcher, &QFutureWatcher<void>::finished, this, &game_list_frame::OnRefreshFinished); connect(&m_refresh_watcher, &QFutureWatcher<void>::finished, this, &game_list_frame::OnRefreshFinished);
connect(&m_refresh_watcher, &QFutureWatcher<void>::canceled, this, [this]() connect(&m_refresh_watcher, &QFutureWatcher<void>::canceled, this, [this]()
{ {
if (m_size_watcher.isRunning())
{
m_size_watcher.cancel();
m_size_watcher.waitForFinished();
}
if (m_repaint_watcher.isRunning()) if (m_repaint_watcher.isRunning())
{ {
m_repaint_watcher.cancel(); m_repaint_watcher.cancel();
@ -159,6 +165,10 @@ game_list_frame::game_list_frame(std::shared_ptr<gui_settings> gui_settings, std
item->call_icon_func(); item->call_icon_func();
} }
}); });
connect(&m_size_watcher, &QFutureWatcher<void>::finished, this, [this]()
{
Refresh();
});
connect(m_game_list, &QTableWidget::customContextMenuRequested, this, &game_list_frame::ShowContextMenu); connect(m_game_list, &QTableWidget::customContextMenuRequested, this, &game_list_frame::ShowContextMenu);
connect(m_game_list, &QTableWidget::itemSelectionChanged, this, &game_list_frame::ItemSelectionChangedSlot); connect(m_game_list, &QTableWidget::itemSelectionChanged, this, &game_list_frame::ItemSelectionChangedSlot);
@ -424,6 +434,12 @@ std::string game_list_frame::GetDataDirBySerial(const std::string& serial)
void game_list_frame::Refresh(const bool from_drive, const bool scroll_after) void game_list_frame::Refresh(const bool from_drive, const bool scroll_after)
{ {
if (m_size_watcher.isRunning())
{
m_size_watcher.cancel();
m_size_watcher.waitForFinished();
}
if (m_repaint_watcher.isRunning()) if (m_repaint_watcher.isRunning())
{ {
m_repaint_watcher.cancel(); m_repaint_watcher.cancel();
@ -596,7 +612,7 @@ void game_list_frame::Refresh(const bool from_drive, const bool scroll_after)
return; return;
} }
GameInfo game; GameInfo game{};
game.path = dir; game.path = dir;
game.serial = std::string(title_id); game.serial = std::string(title_id);
game.name = std::string(psf::get_string(psf, "TITLE", cat_unknown_localized)); game.name = std::string(psf::get_string(psf, "TITLE", cat_unknown_localized));
@ -609,7 +625,6 @@ void game_list_frame::Refresh(const bool from_drive, const bool scroll_after)
game.sound_format = psf::get_integer(psf, "SOUND_FORMAT", 0); game.sound_format = psf::get_integer(psf, "SOUND_FORMAT", 0);
game.bootable = psf::get_integer(psf, "BOOTABLE", 0); game.bootable = psf::get_integer(psf, "BOOTABLE", 0);
game.attr = psf::get_integer(psf, "ATTRIBUTE", 0); game.attr = psf::get_integer(psf, "ATTRIBUTE", 0);
game.size_on_disk = fs::get_dir_size(dir);
if (m_show_custom_icons) if (m_show_custom_icons)
{ {
@ -674,12 +689,15 @@ void game_list_frame::Refresh(const bool from_drive, const bool scroll_after)
m_mutex_cat.unlock(); m_mutex_cat.unlock();
const auto compat = m_game_compat->GetCompatibility(game.serial); gui_game_info info{};
const bool hasCustomConfig = fs::is_file(rpcs3::utils::get_custom_config_path(game.serial)); info.info = game;
const bool hasCustomPadConfig = fs::is_file(rpcs3::utils::get_custom_input_config_path(game.serial)); info.localized_category = qt_cat;
const bool has_hover_gif = fs::is_file(game_icon_path + game.serial + "/hover.gif"); info.compat = m_game_compat->GetCompatibility(game.serial);
info.hasCustomConfig = fs::is_file(rpcs3::utils::get_custom_config_path(game.serial));
info.hasCustomPadConfig = fs::is_file(rpcs3::utils::get_custom_input_config_path(game.serial));
info.has_hover_gif = fs::is_file(game_icon_path + game.serial + "/hover.gif");
m_games.push(std::make_shared<gui_game_info>(gui_game_info{game, qt_cat, compat, {}, {}, hasCustomConfig, hasCustomPadConfig, has_hover_gif, nullptr})); m_games.push(std::make_shared<gui_game_info>(std::move(info)));
})); }));
return; return;
@ -711,6 +729,12 @@ void game_list_frame::Refresh(const bool from_drive, const bool scroll_after)
void game_list_frame::OnRefreshFinished() void game_list_frame::OnRefreshFinished()
{ {
if (m_size_watcher.isRunning())
{
m_size_watcher.cancel();
m_size_watcher.waitForFinished();
}
if (m_repaint_watcher.isRunning()) if (m_repaint_watcher.isRunning())
{ {
m_repaint_watcher.cancel(); m_repaint_watcher.cancel();
@ -785,6 +809,11 @@ void game_list_frame::OnRefreshFinished()
m_path_list.clear(); m_path_list.clear();
Refresh(); Refresh();
m_size_watcher.setFuture(QtConcurrent::map(m_game_data, [this](const game_info& game) -> void
{
if (game) game->info.size_on_disk = fs::get_dir_size(game->info.path);
}));
} }
void game_list_frame::OnRepaintFinished() void game_list_frame::OnRepaintFinished()

View File

@ -158,6 +158,7 @@ private:
QSet<QString> m_serials; QSet<QString> m_serials;
QMutex m_mutex_cat; QMutex m_mutex_cat;
lf_queue<game_info> m_games; lf_queue<game_info> m_games;
QFutureWatcher<void> m_size_watcher;
QFutureWatcher<void> m_refresh_watcher; QFutureWatcher<void> m_refresh_watcher;
QFutureWatcher<movie_item*> m_repaint_watcher; QFutureWatcher<movie_item*> m_repaint_watcher;
QSet<QString> m_hidden_list; QSet<QString> m_hidden_list;