From 4f2f9494b02305a1b5d39e94eda63933972e15d9 Mon Sep 17 00:00:00 2001 From: kalaposfos13 <153381648+kalaposfos13@users.noreply.github.com> Date: Sun, 12 Jan 2025 21:31:05 +0100 Subject: [PATCH] GUI: Speed up GUI loading by caching game sizes (#2130) * Add show game size toggle * Fix (#7) * Fix I removed the gameSizeCheckBox from the 'Emulator' group and put it in 'GUI settings' hLayoutTrophy which contains the Trophy information was inside the GUIMusicLayout, so I fixed that too. * TR * Use cached sizes if the feature is enabled --------- Co-authored-by: DanielSvoboda --- src/common/config.cpp | 11 +++ src/common/config.h | 2 + src/qt_gui/game_list_frame.cpp | 2 + src/qt_gui/game_list_utils.h | 35 ++++++++ src/qt_gui/settings_dialog.cpp | 2 + src/qt_gui/settings_dialog.ui | 143 ++++++++++++++++--------------- src/qt_gui/translations/ar.ts | 4 + src/qt_gui/translations/da_DK.ts | 4 + src/qt_gui/translations/de.ts | 4 + src/qt_gui/translations/el.ts | 4 + src/qt_gui/translations/en.ts | 4 + src/qt_gui/translations/es_ES.ts | 4 + src/qt_gui/translations/fa_IR.ts | 4 + src/qt_gui/translations/fi.ts | 4 + src/qt_gui/translations/fr.ts | 4 + src/qt_gui/translations/hu_HU.ts | 4 + src/qt_gui/translations/id.ts | 4 + src/qt_gui/translations/it.ts | 4 + src/qt_gui/translations/ja_JP.ts | 4 + src/qt_gui/translations/ko_KR.ts | 4 + src/qt_gui/translations/lt_LT.ts | 4 + src/qt_gui/translations/nb.ts | 4 + src/qt_gui/translations/nl.ts | 4 + src/qt_gui/translations/pl_PL.ts | 4 + src/qt_gui/translations/pt_BR.ts | 4 + src/qt_gui/translations/ro_RO.ts | 4 + src/qt_gui/translations/ru_RU.ts | 4 + src/qt_gui/translations/sq.ts | 4 + src/qt_gui/translations/sv.ts | 4 + src/qt_gui/translations/tr_TR.ts | 4 + src/qt_gui/translations/uk_UA.ts | 4 + src/qt_gui/translations/vi_VN.ts | 4 + src/qt_gui/translations/zh_CN.ts | 4 + src/qt_gui/translations/zh_TW.ts | 4 + 34 files changed, 239 insertions(+), 68 deletions(-) diff --git a/src/common/config.cpp b/src/common/config.cpp index b46ab8d6..158bfedd 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -72,6 +72,7 @@ static bool checkCompatibilityOnStartup = false; static std::string trophyKey; // Gui +static bool load_game_size = true; std::vector settings_install_dirs = {}; std::filesystem::path settings_addon_install_dir = {}; u32 main_window_geometry_x = 400; @@ -102,6 +103,14 @@ void setTrophyKey(std::string key) { trophyKey = key; } +bool GetLoadGameSizeEnabled() { + return load_game_size; +} + +void setLoadGameSizeEnabled(bool enable) { + load_game_size = enable; +} + bool isNeoModeConsole() { return isNeo; } @@ -650,6 +659,7 @@ void load(const std::filesystem::path& path) { if (data.contains("GUI")) { const toml::value& gui = data.at("GUI"); + load_game_size = toml::find_or(gui, "loadGameSizeEnabled", true); m_icon_size = toml::find_or(gui, "iconSize", 0); m_icon_size_grid = toml::find_or(gui, "iconSizeGrid", 0); m_slider_pos = toml::find_or(gui, "sliderPos", 0); @@ -755,6 +765,7 @@ void save(const std::filesystem::path& path) { install_dirs.emplace_back(std::string{fmt::UTF(dirString.u8string()).data}); } data["GUI"]["installDirs"] = install_dirs; + data["GUI"]["loadGameSizeEnabled"] = load_game_size; data["GUI"]["addonInstallDir"] = std::string{fmt::UTF(settings_addon_install_dir.u8string()).data}; diff --git a/src/common/config.h b/src/common/config.h index 6e6a5d96..c86e35eb 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -17,6 +17,8 @@ void saveMainWindow(const std::filesystem::path& path); std::string getTrophyKey(); void setTrophyKey(std::string key); +bool GetLoadGameSizeEnabled(); +void setLoadGameSizeEnabled(bool enable); bool getIsFullscreen(); std::string getFullscreenMode(); bool isNeoModeConsole(); diff --git a/src/qt_gui/game_list_frame.cpp b/src/qt_gui/game_list_frame.cpp index b1cd0721..9753f511 100644 --- a/src/qt_gui/game_list_frame.cpp +++ b/src/qt_gui/game_list_frame.cpp @@ -106,6 +106,8 @@ void GameListFrame::PlayBackgroundMusic(QTableWidgetItem* item) { void GameListFrame::PopulateGameList() { // Do not show status column if it is not enabled this->setColumnHidden(2, !Config::getCompatibilityEnabled()); + this->setColumnHidden(6, !Config::GetLoadGameSizeEnabled()); + this->setRowCount(m_game_info->m_games.size()); ResizeIcons(icon_size); diff --git a/src/qt_gui/game_list_utils.h b/src/qt_gui/game_list_utils.h index ab923388..581a8a55 100644 --- a/src/qt_gui/game_list_utils.h +++ b/src/qt_gui/game_list_utils.h @@ -62,11 +62,46 @@ public: QDir dir(dirPath); QDirIterator it(dir.absolutePath(), QDirIterator::Subdirectories); qint64 total = 0; + + if (!Config::GetLoadGameSizeEnabled()) { + game.size = FormatSize(0).toStdString(); + return; + } + + // Cache path + QFile size_cache_file(Common::FS::GetUserPath(Common::FS::PathType::MetaDataDir) / + game.serial / "size_cache.txt"); + QFileInfo cacheInfo(size_cache_file); + QFileInfo dirInfo(dirPath); + + // Check if cache file exists and is valid + if (size_cache_file.exists() && cacheInfo.lastModified() >= dirInfo.lastModified()) { + if (size_cache_file.open(QIODevice::ReadOnly | QIODevice::Text)) { + QTextStream in(&size_cache_file); + QString cachedSize = in.readLine(); + size_cache_file.close(); + + if (!cachedSize.isEmpty()) { + game.size = cachedSize.toStdString(); + return; + } + } + } + + // Cache is invalid or does not exist; calculate size while (it.hasNext()) { it.next(); total += it.fileInfo().size(); } + game.size = FormatSize(total).toStdString(); + + // Save new cache + if (size_cache_file.open(QIODevice::WriteOnly | QIODevice::Text)) { + QTextStream out(&size_cache_file); + out << QString::fromStdString(game.size) << "\n"; + size_cache_file.close(); + } } static QString GetRegion(char region) { diff --git a/src/qt_gui/settings_dialog.cpp b/src/qt_gui/settings_dialog.cpp index 3f4970da..a4b58429 100644 --- a/src/qt_gui/settings_dialog.cpp +++ b/src/qt_gui/settings_dialog.cpp @@ -315,6 +315,7 @@ void SettingsDialog::LoadValuesFromConfig() { toml::find_or(data, "General", "FullscreenMode", "Borderless"))); ui->separateUpdatesCheckBox->setChecked( toml::find_or(data, "General", "separateUpdateEnabled", false)); + ui->gameSizeCheckBox->setChecked(toml::find_or(data, "GUI", "loadGameSizeEnabled", true)); ui->showSplashCheckBox->setChecked(toml::find_or(data, "General", "showSplash", false)); ui->logTypeComboBox->setCurrentText( QString::fromStdString(toml::find_or(data, "General", "logType", "async"))); @@ -568,6 +569,7 @@ void SettingsDialog::UpdateSettings() { Config::setDumpShaders(ui->dumpShadersCheckBox->isChecked()); Config::setNullGpu(ui->nullGpuCheckBox->isChecked()); Config::setSeparateUpdateEnabled(ui->separateUpdatesCheckBox->isChecked()); + Config::setLoadGameSizeEnabled(ui->gameSizeCheckBox->isChecked()); Config::setShowSplash(ui->showSplashCheckBox->isChecked()); Config::setDebugDump(ui->debugDump->isChecked()); Config::setVkValidation(ui->vkValidationCheckBox->isChecked()); diff --git a/src/qt_gui/settings_dialog.ui b/src/qt_gui/settings_dialog.ui index 089158fd..8d68d1c9 100644 --- a/src/qt_gui/settings_dialog.ui +++ b/src/qt_gui/settings_dialog.ui @@ -68,7 +68,7 @@ 0 0 946 - 536 + 586 @@ -134,7 +134,7 @@ - + Fullscreen Mode @@ -483,6 +483,13 @@ 11 + + + + Show Game Size In List + + + @@ -557,59 +564,59 @@ + + + + + + 6 + + + 0 + + + 50 + - - - 6 - - - 0 - - - 80 - + - - - - - Trophy - - - - - - Disable Trophy Pop-ups - - - - - - - Trophy Key - - - - - - - - 0 - 0 - - - - - 10 - false - - - - - - - - + + + Trophy + + + + + + Disable Trophy Pop-ups + + + + + + + Trophy Key + + + + + + + + 0 + 0 + + + + + 10 + false + + + + + + @@ -637,8 +644,8 @@ 0 0 - 926 - 536 + 946 + 586 @@ -853,13 +860,13 @@ - - - - Enable Motion Controls - - - + + + + Enable Motion Controls + + + @@ -935,8 +942,8 @@ 0 0 - 926 - 536 + 946 + 586 @@ -1186,8 +1193,8 @@ 0 0 - 926 - 536 + 946 + 586 @@ -1259,8 +1266,8 @@ 0 0 - 926 - 536 + 946 + 586 diff --git a/src/qt_gui/translations/ar.ts b/src/qt_gui/translations/ar.ts index 4fc9c2de..a4dadcb1 100644 --- a/src/qt_gui/translations/ar.ts +++ b/src/qt_gui/translations/ar.ts @@ -540,6 +540,10 @@ Enable Separate Update Folder Enable Separate Update Folder + + Show Game Size In List + عرض حجم اللعبة في القائمة + Show Splash إظهار شاشة البداية diff --git a/src/qt_gui/translations/da_DK.ts b/src/qt_gui/translations/da_DK.ts index ef1ae27a..70b7d3ec 100644 --- a/src/qt_gui/translations/da_DK.ts +++ b/src/qt_gui/translations/da_DK.ts @@ -540,6 +540,10 @@ Enable Separate Update Folder Enable Separate Update Folder + + Show Game Size In List + Vis vis spilstørrelse i listen + Show Splash Show Splash diff --git a/src/qt_gui/translations/de.ts b/src/qt_gui/translations/de.ts index 2fc6a29f..7f1de3af 100644 --- a/src/qt_gui/translations/de.ts +++ b/src/qt_gui/translations/de.ts @@ -540,6 +540,10 @@ Enable Separate Update Folder Enable Separate Update Folder + + Show Game Size In List + Zeigen Sie die Spielgröße in der Liste + Show Splash Startbildschirm anzeigen diff --git a/src/qt_gui/translations/el.ts b/src/qt_gui/translations/el.ts index 8d388580..84165536 100644 --- a/src/qt_gui/translations/el.ts +++ b/src/qt_gui/translations/el.ts @@ -540,6 +540,10 @@ Enable Separate Update Folder Enable Separate Update Folder + + Show Game Size In List + Εμφάνιση Μεγέθους Παιχνιδιού στη Λίστα + Show Splash Show Splash diff --git a/src/qt_gui/translations/en.ts b/src/qt_gui/translations/en.ts index 0262ee14..fad185d4 100644 --- a/src/qt_gui/translations/en.ts +++ b/src/qt_gui/translations/en.ts @@ -540,6 +540,10 @@ Enable Separate Update Folder Enable Separate Update Folder + + Show Game Size In List + Show Game Size In List + Show Splash Show Splash diff --git a/src/qt_gui/translations/es_ES.ts b/src/qt_gui/translations/es_ES.ts index a25ff639..a97d3d3c 100644 --- a/src/qt_gui/translations/es_ES.ts +++ b/src/qt_gui/translations/es_ES.ts @@ -540,6 +540,10 @@ Enable Separate Update Folder Enable Separate Update Folder + + Show Game Size In List + Mostrar Tamaño del Juego en la Lista + Show Splash Mostrar splash diff --git a/src/qt_gui/translations/fa_IR.ts b/src/qt_gui/translations/fa_IR.ts index 52aa4b17..697e615f 100644 --- a/src/qt_gui/translations/fa_IR.ts +++ b/src/qt_gui/translations/fa_IR.ts @@ -540,6 +540,10 @@ Enable Separate Update Folder فعال‌سازی پوشه جداگانه برای به‌روزرسانی + + Show Game Size In List + نمایش اندازه بازی در لیست + Show Splash Splash نمایش diff --git a/src/qt_gui/translations/fi.ts b/src/qt_gui/translations/fi.ts index 97fee5df..51e85dfb 100644 --- a/src/qt_gui/translations/fi.ts +++ b/src/qt_gui/translations/fi.ts @@ -540,6 +540,10 @@ Enable Separate Update Folder Ota Käyttöön Erillinen Päivityshakemisto + + Show Game Size In List + Näytä pelin koko luettelossa + Show Splash Näytä Aloitusnäyttö diff --git a/src/qt_gui/translations/fr.ts b/src/qt_gui/translations/fr.ts index d25ad30f..35f3eb55 100644 --- a/src/qt_gui/translations/fr.ts +++ b/src/qt_gui/translations/fr.ts @@ -540,6 +540,10 @@ Enable Separate Update Folder Dossier séparé pour les mises à jours + + Show Game Size In List + Afficher la taille du jeu dans la liste + Show Splash Afficher l'image du jeu diff --git a/src/qt_gui/translations/hu_HU.ts b/src/qt_gui/translations/hu_HU.ts index 6ecc3fc9..a2bd9c1d 100644 --- a/src/qt_gui/translations/hu_HU.ts +++ b/src/qt_gui/translations/hu_HU.ts @@ -540,6 +540,10 @@ Enable Separate Update Folder Külön Frissítési Mappa Engedélyezése + + Show Game Size In List + Játékméret megjelenítése a listában + Show Splash Indítóképernyő Mutatása diff --git a/src/qt_gui/translations/id.ts b/src/qt_gui/translations/id.ts index fc5ad4a9..b97914ca 100644 --- a/src/qt_gui/translations/id.ts +++ b/src/qt_gui/translations/id.ts @@ -540,6 +540,10 @@ Enable Separate Update Folder Enable Separate Update Folder + + Show Game Size In List + Tampilkan Ukuran Game di Daftar + Show Splash Show Splash diff --git a/src/qt_gui/translations/it.ts b/src/qt_gui/translations/it.ts index f7ba3661..d4ea1c7e 100644 --- a/src/qt_gui/translations/it.ts +++ b/src/qt_gui/translations/it.ts @@ -540,6 +540,10 @@ Enable Separate Update Folder Abilita Cartella Aggiornamenti Separata + + Show Game Size In List + Mostra la dimensione del gioco nell'elenco + Show Splash Mostra Schermata Iniziale diff --git a/src/qt_gui/translations/ja_JP.ts b/src/qt_gui/translations/ja_JP.ts index 21c8145e..35995576 100644 --- a/src/qt_gui/translations/ja_JP.ts +++ b/src/qt_gui/translations/ja_JP.ts @@ -540,6 +540,10 @@ Enable Separate Update Folder Enable Separate Update Folder + + Show Game Size In List + ゲームサイズをリストに表示 + Show Splash スプラッシュを表示する diff --git a/src/qt_gui/translations/ko_KR.ts b/src/qt_gui/translations/ko_KR.ts index fea8d55b..9cca0b65 100644 --- a/src/qt_gui/translations/ko_KR.ts +++ b/src/qt_gui/translations/ko_KR.ts @@ -540,6 +540,10 @@ Enable Separate Update Folder Enable Separate Update Folder + + Show Game Size In List + 게임 크기를 목록에 표시 + Show Splash Show Splash diff --git a/src/qt_gui/translations/lt_LT.ts b/src/qt_gui/translations/lt_LT.ts index eaf51a97..0594bcbd 100644 --- a/src/qt_gui/translations/lt_LT.ts +++ b/src/qt_gui/translations/lt_LT.ts @@ -540,6 +540,10 @@ Enable Separate Update Folder Enable Separate Update Folder + + Show Game Size In List + Rodyti žaidimo dydį sąraše + Show Splash Show Splash diff --git a/src/qt_gui/translations/nb.ts b/src/qt_gui/translations/nb.ts index 83dbf7dd..8ca8246b 100644 --- a/src/qt_gui/translations/nb.ts +++ b/src/qt_gui/translations/nb.ts @@ -540,6 +540,10 @@ Enable Separate Update Folder Aktiver seperat oppdateringsmappe + + Show Game Size In List + Vis spillstørrelse i listen + Show Splash Vis velkomstbilde diff --git a/src/qt_gui/translations/nl.ts b/src/qt_gui/translations/nl.ts index 3142a17e..12d64445 100644 --- a/src/qt_gui/translations/nl.ts +++ b/src/qt_gui/translations/nl.ts @@ -540,6 +540,10 @@ Enable Separate Update Folder Enable Separate Update Folder + + Show Game Size In List + Toon grootte van het spel in de lijst + Show Splash Show Splash diff --git a/src/qt_gui/translations/pl_PL.ts b/src/qt_gui/translations/pl_PL.ts index 378673a3..782db12e 100644 --- a/src/qt_gui/translations/pl_PL.ts +++ b/src/qt_gui/translations/pl_PL.ts @@ -540,6 +540,10 @@ Enable Separate Update Folder Enable Separate Update Folder + + Show Game Size In List + Pokaż rozmiar gry na liście + Show Splash Pokaż ekran powitania diff --git a/src/qt_gui/translations/pt_BR.ts b/src/qt_gui/translations/pt_BR.ts index 5d9c8476..94bbf028 100644 --- a/src/qt_gui/translations/pt_BR.ts +++ b/src/qt_gui/translations/pt_BR.ts @@ -540,6 +540,10 @@ Enable Separate Update Folder Habilitar pasta de atualização separada + + Show Game Size In List + Mostrar Tamanho do Jogo na Lista + Show Splash Mostrar Splash Inicial diff --git a/src/qt_gui/translations/ro_RO.ts b/src/qt_gui/translations/ro_RO.ts index 71354fb0..3bd8e38b 100644 --- a/src/qt_gui/translations/ro_RO.ts +++ b/src/qt_gui/translations/ro_RO.ts @@ -540,6 +540,10 @@ Enable Separate Update Folder Enable Separate Update Folder + + Show Game Size In List + Afișează dimensiunea jocului în listă + Show Splash Show Splash diff --git a/src/qt_gui/translations/ru_RU.ts b/src/qt_gui/translations/ru_RU.ts index 0e803ea4..a38e2fd9 100644 --- a/src/qt_gui/translations/ru_RU.ts +++ b/src/qt_gui/translations/ru_RU.ts @@ -540,6 +540,10 @@ Enable Separate Update Folder Отдельная папка обновлений + + Show Game Size In List + Показать размер игры в списке + Show Splash Показывать заставку diff --git a/src/qt_gui/translations/sq.ts b/src/qt_gui/translations/sq.ts index 7354b4bd..a83dc982 100644 --- a/src/qt_gui/translations/sq.ts +++ b/src/qt_gui/translations/sq.ts @@ -540,6 +540,10 @@ Enable Separate Update Folder Aktivizo dosjen e ndarë të përditësimit + + Show Game Size In List + Shfaq madhësinë e lojës në listë + Show Splash Shfaq Pamjen e nisjes diff --git a/src/qt_gui/translations/sv.ts b/src/qt_gui/translations/sv.ts index 3a6f060c..9a244a9d 100644 --- a/src/qt_gui/translations/sv.ts +++ b/src/qt_gui/translations/sv.ts @@ -1032,6 +1032,10 @@ Enable Separate Update Folder Aktivera separat uppdateringsmapp + + Show Game Size In List + Visa spelstorlek i listan + Show Splash Visa startskärm diff --git a/src/qt_gui/translations/tr_TR.ts b/src/qt_gui/translations/tr_TR.ts index 4596000f..be50f935 100644 --- a/src/qt_gui/translations/tr_TR.ts +++ b/src/qt_gui/translations/tr_TR.ts @@ -540,6 +540,10 @@ Enable Separate Update Folder Enable Separate Update Folder + + Show Game Size In List + Göster oyun boyutunu listede + Show Splash Başlangıç Ekranını Göster diff --git a/src/qt_gui/translations/uk_UA.ts b/src/qt_gui/translations/uk_UA.ts index 5b260050..ff4e48e8 100644 --- a/src/qt_gui/translations/uk_UA.ts +++ b/src/qt_gui/translations/uk_UA.ts @@ -540,6 +540,10 @@ Enable Separate Update Folder Увімкнути окрему папку оновлень + + Show Game Size In List + Показати розмір гри в списку + Show Splash Показувати заставку diff --git a/src/qt_gui/translations/vi_VN.ts b/src/qt_gui/translations/vi_VN.ts index 7fcac6d7..e546d955 100644 --- a/src/qt_gui/translations/vi_VN.ts +++ b/src/qt_gui/translations/vi_VN.ts @@ -540,6 +540,10 @@ Enable Separate Update Folder Enable Separate Update Folder + + Show Game Size In List + Hiển thị Kích thước Game trong Danh sách + Show Splash Show Splash diff --git a/src/qt_gui/translations/zh_CN.ts b/src/qt_gui/translations/zh_CN.ts index bb4476b9..ece5f949 100644 --- a/src/qt_gui/translations/zh_CN.ts +++ b/src/qt_gui/translations/zh_CN.ts @@ -540,6 +540,10 @@ Enable Separate Update Folder 启用单独的更新目录 + + Show Game Size In List + 显示游戏大小在列表中 + Show Splash 显示启动画面 diff --git a/src/qt_gui/translations/zh_TW.ts b/src/qt_gui/translations/zh_TW.ts index 49d419d8..11642d52 100644 --- a/src/qt_gui/translations/zh_TW.ts +++ b/src/qt_gui/translations/zh_TW.ts @@ -540,6 +540,10 @@ Enable Separate Update Folder Enable Separate Update Folder + + Show Game Size In List + 顯示遊戲大小在列表中 + Show Splash Show Splash