Qt: use QDirIterator instead of fs::file stuff

This commit is contained in:
Megamouse 2018-06-15 17:29:52 +02:00 committed by Ivan
parent 68bb1bd6ee
commit e7a02f1506
3 changed files with 31 additions and 36 deletions

View file

@ -832,17 +832,18 @@ bool game_list_frame::DeleteShadersCache(const std::string& base_dir, bool is_in
if (is_interactive && QMessageBox::question(this, tr("Confirm Delete"), tr("Delete shaders cache?")) != QMessageBox::Yes) if (is_interactive && QMessageBox::question(this, tr("Confirm Delete"), tr("Delete shaders cache?")) != QMessageBox::Yes)
return false; return false;
fs::dir root = fs::dir(base_dir); QDirIterator dir_iter(qstr(base_dir), QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
fs::dir_entry tmp; while (dir_iter.hasNext())
while (root.read(tmp))
{ {
if (!fs::is_dir(base_dir + "/" + tmp.name)) const QString filepath = dir_iter.next();
continue;
const std::string shader_cache_name = base_dir + "/" + tmp.name + "/shaders_cache"; if (dir_iter.fileName() == "shaders_cache")
if (fs::is_dir(shader_cache_name)) {
fs::remove_all(shader_cache_name, true); if (QDir(filepath).removeRecursively())
LOG_NOTICE(GENERAL, "Removed shaders cache dir: %s", sstr(filepath));
else
LOG_WARNING(GENERAL, "Could not remove shaders cache file: %s", sstr(filepath));
}
} }
LOG_SUCCESS(GENERAL, "Removed shaders cache in %s", base_dir); LOG_SUCCESS(GENERAL, "Removed shaders cache in %s", base_dir);
@ -857,21 +858,21 @@ bool game_list_frame::DeleteLLVMCache(const std::string& base_dir, bool is_inter
if (is_interactive && QMessageBox::question(this, tr("Confirm Delete"), tr("Delete LLVM cache?")) != QMessageBox::Yes) if (is_interactive && QMessageBox::question(this, tr("Confirm Delete"), tr("Delete LLVM cache?")) != QMessageBox::Yes)
return false; return false;
for (auto&& subdir : fs::dir{ base_dir }) QDirIterator dir_iter(qstr(base_dir), QDir::Files | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
while (dir_iter.hasNext())
{ {
if (!subdir.is_directory || subdir.name == "." || subdir.name == "..") const QString filepath = dir_iter.next();
continue;
const std::string dir = base_dir + "/" + subdir.name; if (dir_iter.fileInfo().absoluteFilePath().endsWith(".obj", Qt::CaseInsensitive))
for (auto&& entry : fs::dir{ dir })
{ {
if (entry.name.size() >= 4 && entry.name.compare(entry.name.size() - 4, 4, ".obj", 4) == 0) if (QFile::remove(filepath))
fs::remove_file(dir + "/" + entry.name); LOG_NOTICE(GENERAL, "Removed LLVM cache file: %s", sstr(filepath));
else
LOG_WARNING(GENERAL, "Could not remove LLVM cache file: %s", sstr(filepath));
} }
} }
LOG_SUCCESS(GENERAL, "Removed llvm cache in %s", base_dir); LOG_SUCCESS(GENERAL, "Removed LLVM cache in %s", base_dir);
return true; return true;
} }

View file

@ -1620,7 +1620,8 @@ Add valid disc games to gamelist (games.yml)
*/ */
void main_window::AddGamesFromDir(const QString& path) void main_window::AddGamesFromDir(const QString& path)
{ {
if (!QFileInfo(path).isDir()) return; if (!QFileInfo(path).isDir())
return;
const std::string s_path = sstr(path); const std::string s_path = sstr(path);
@ -1631,13 +1632,10 @@ void main_window::AddGamesFromDir(const QString& path)
} }
// search direct subdirectories, that way we can drop one folder containing all games // search direct subdirectories, that way we can drop one folder containing all games
for (const auto& entry : fs::dir(s_path)) QDirIterator dir_iter(path, QDir::Dirs | QDir::NoDotAndDotDot);
while (dir_iter.hasNext())
{ {
if (entry.name == "." || entry.name == "..") continue; std::string pth = sstr(dir_iter.next());
const std::string pth = s_path + "/" + entry.name;
if (!QFileInfo(qstr(pth)).isDir()) continue;
if (Emu.BootGame(pth, false, true)) if (Emu.BootGame(pth, false, true))
{ {

View file

@ -111,14 +111,10 @@ trophy_manager_dialog::trophy_manager_dialog(std::shared_ptr<gui_settings> gui_s
m_splitter->addWidget(m_trophy_table); m_splitter->addWidget(m_trophy_table);
// Populate the trophy database // Populate the trophy database
QDirIterator dir_iter(qstr(vfs::get(m_TROPHY_DIR))); QDirIterator dir_iter(qstr(vfs::get(m_TROPHY_DIR)), QDir::Dirs | QDir::NoDotAndDotDot);
while (dir_iter.hasNext()) while (dir_iter.hasNext())
{ {
dir_iter.next(); dir_iter.next();
if (dir_iter.fileName() == "." || dir_iter.fileName() == ".." || dir_iter.fileName() == ".gitignore")
{
continue;
}
std::string dirName = sstr(dir_iter.fileName()); std::string dirName = sstr(dir_iter.fileName());
LOG_TRACE(GENERAL, "Loading trophy dir: %s", dirName); LOG_TRACE(GENERAL, "Loading trophy dir: %s", dirName);
LoadTrophyFolderToDB(dirName); LoadTrophyFolderToDB(dirName);