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 <daniel.svoboda@hotmail.com>
This commit is contained in:
kalaposfos13 2025-01-12 21:31:05 +01:00 committed by GitHub
parent c6ab149c56
commit 4f2f9494b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
34 changed files with 239 additions and 68 deletions

View file

@ -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) {