Make "Clear shader cache" clear all caches, not just the first (#6538)

* Use QFileInfo::suffix to obtain and check for file extension when clearing caches

* Clear all shader caches for the game, not just the first
This commit is contained in:
Silent 2019-09-13 09:14:52 +02:00 committed by Megamouse
parent 32a4c2242b
commit 3e9ed9a17d

View file

@ -1127,6 +1127,9 @@ bool game_list_frame::RemoveShadersCache(const std::string& base_dir, bool is_in
if (is_interactive && QMessageBox::question(this, tr("Confirm Removal"), tr("Remove shaders cache?")) != QMessageBox::Yes) if (is_interactive && QMessageBox::question(this, tr("Confirm Removal"), tr("Remove shaders cache?")) != QMessageBox::Yes)
return true; return true;
u32 caches_removed = 0;
u32 caches_total = 0;
QDirIterator dir_iter(qstr(base_dir), QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories); QDirIterator dir_iter(qstr(base_dir), QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
while (dir_iter.hasNext()) while (dir_iter.hasNext())
{ {
@ -1136,18 +1139,25 @@ bool game_list_frame::RemoveShadersCache(const std::string& base_dir, bool is_in
{ {
if (QDir(filepath).removeRecursively()) if (QDir(filepath).removeRecursively())
{ {
LOG_SUCCESS(GENERAL, "Removed shaders cache dir: %s", sstr(filepath)); ++caches_removed;
LOG_NOTICE(GENERAL, "Removed shaders cache dir: %s", sstr(filepath));
} }
else else
{ {
LOG_FATAL(GENERAL, "Could not completely remove shaders cache file: %s", sstr(filepath)); LOG_WARNING(GENERAL, "Could not completely remove shaders cache dir: %s", sstr(filepath));
return false;
} }
break; ++caches_total;
} }
} }
return true; const bool success = caches_total == caches_removed;
if (success)
LOG_SUCCESS(GENERAL, "Removed shaders cache in %s", base_dir);
else
LOG_FATAL(GENERAL, "Only %d/%d shaders cache dirs could be removed in %s", caches_removed, caches_total, base_dir);
return success;
} }
bool game_list_frame::RemovePPUCache(const std::string& base_dir, bool is_interactive) bool game_list_frame::RemovePPUCache(const std::string& base_dir, bool is_interactive)
@ -1166,7 +1176,7 @@ bool game_list_frame::RemovePPUCache(const std::string& base_dir, bool is_intera
{ {
const QString filepath = dir_iter.next(); const QString filepath = dir_iter.next();
if (dir_iter.fileInfo().absoluteFilePath().endsWith(".obj", Qt::CaseInsensitive)) if (QString::compare(dir_iter.fileInfo().suffix(), QStringLiteral("obj"), Qt::CaseInsensitive) == 0)
{ {
if (QFile::remove(filepath)) if (QFile::remove(filepath))
{ {
@ -1207,7 +1217,7 @@ bool game_list_frame::RemoveSPUCache(const std::string& base_dir, bool is_intera
{ {
const QString filepath = dir_iter.next(); const QString filepath = dir_iter.next();
if (dir_iter.fileInfo().absoluteFilePath().endsWith(".dat", Qt::CaseInsensitive)) if (QString::compare(dir_iter.fileInfo().suffix(), QStringLiteral("dat"), Qt::CaseInsensitive) == 0)
{ {
if (QFile::remove(filepath)) if (QFile::remove(filepath))
{ {