summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner2016-06-19 00:09:16 -0700
committerGravatar Yuri Kunde Schlesner2016-06-19 00:12:15 -0700
commitd6792632f0a426247167fc91c12c1f640748464f (patch)
treeacf52c2afb186071142991e852c9bda645f56c41 /src
parentMerge pull request #1877 from wwylele/wait-fix-timeout (diff)
downloadyuzu-d6792632f0a426247167fc91c12c1f640748464f.tar.gz
yuzu-d6792632f0a426247167fc91c12c1f640748464f.tar.xz
yuzu-d6792632f0a426247167fc91c12c1f640748464f.zip
Fix recursive scanning of directories
ForeachDirectoryEntry didn't actually do anything with the `recursive` parameter, and the corresponding callback parameter was shadowing the actual recursion counters in the user functions.
Diffstat (limited to 'src')
-rw-r--r--src/citra_qt/game_list.cpp8
-rw-r--r--src/common/file_util.cpp22
-rw-r--r--src/common/file_util.h7
3 files changed, 15 insertions, 22 deletions
diff --git a/src/citra_qt/game_list.cpp b/src/citra_qt/game_list.cpp
index 15484fae3..1910da3ac 100644
--- a/src/citra_qt/game_list.cpp
+++ b/src/citra_qt/game_list.cpp
@@ -120,11 +120,9 @@ void GameList::LoadInterfaceLayout()
120 120
121void GameListWorker::AddFstEntriesToGameList(const std::string& dir_path, unsigned int recursion) 121void GameListWorker::AddFstEntriesToGameList(const std::string& dir_path, unsigned int recursion)
122{ 122{
123 const auto callback = [&](unsigned* num_entries_out, 123 const auto callback = [this, recursion](unsigned* num_entries_out,
124 const std::string& directory, 124 const std::string& directory,
125 const std::string& virtual_name, 125 const std::string& virtual_name) -> bool {
126 unsigned int recursion) -> bool {
127
128 std::string physical_name = directory + DIR_SEP + virtual_name; 126 std::string physical_name = directory + DIR_SEP + virtual_name;
129 127
130 if (stop_processing) 128 if (stop_processing)
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp
index 17af7c385..84fe95c8c 100644
--- a/src/common/file_util.cpp
+++ b/src/common/file_util.cpp
@@ -434,7 +434,7 @@ bool CreateEmptyFile(const std::string &filename)
434} 434}
435 435
436 436
437bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string &directory, DirectoryEntryCallable callback, unsigned int recursion) 437bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string &directory, DirectoryEntryCallable callback)
438{ 438{
439 LOG_TRACE(Common_Filesystem, "directory %s", directory.c_str()); 439 LOG_TRACE(Common_Filesystem, "directory %s", directory.c_str());
440 440
@@ -472,7 +472,7 @@ bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string &directo
472 continue; 472 continue;
473 473
474 unsigned ret_entries = 0; 474 unsigned ret_entries = 0;
475 if (!callback(&ret_entries, directory, virtual_name, recursion)) { 475 if (!callback(&ret_entries, directory, virtual_name)) {
476 callback_error = true; 476 callback_error = true;
477 break; 477 break;
478 } 478 }
@@ -497,10 +497,9 @@ bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string &directo
497 497
498unsigned ScanDirectoryTree(const std::string &directory, FSTEntry& parent_entry, unsigned int recursion) 498unsigned ScanDirectoryTree(const std::string &directory, FSTEntry& parent_entry, unsigned int recursion)
499{ 499{
500 const auto callback = [&parent_entry](unsigned* num_entries_out, 500 const auto callback = [recursion, &parent_entry](unsigned* num_entries_out,
501 const std::string& directory, 501 const std::string& directory,
502 const std::string& virtual_name, 502 const std::string& virtual_name) -> bool {
503 unsigned int recursion) -> bool {
504 FSTEntry entry; 503 FSTEntry entry;
505 entry.virtualName = virtual_name; 504 entry.virtualName = virtual_name;
506 entry.physicalName = directory + DIR_SEP + virtual_name; 505 entry.physicalName = directory + DIR_SEP + virtual_name;
@@ -526,16 +525,15 @@ unsigned ScanDirectoryTree(const std::string &directory, FSTEntry& parent_entry,
526 }; 525 };
527 526
528 unsigned num_entries; 527 unsigned num_entries;
529 return ForeachDirectoryEntry(&num_entries, directory, callback, recursion) ? num_entries : 0; 528 return ForeachDirectoryEntry(&num_entries, directory, callback) ? num_entries : 0;
530} 529}
531 530
532 531
533bool DeleteDirRecursively(const std::string &directory, unsigned int recursion) 532bool DeleteDirRecursively(const std::string &directory, unsigned int recursion)
534{ 533{
535 const static auto callback = [](unsigned* num_entries_out, 534 const auto callback = [recursion](unsigned* num_entries_out,
536 const std::string& directory, 535 const std::string& directory,
537 const std::string& virtual_name, 536 const std::string& virtual_name) -> bool {
538 unsigned int recursion) -> bool {
539 std::string new_path = directory + DIR_SEP_CHR + virtual_name; 537 std::string new_path = directory + DIR_SEP_CHR + virtual_name;
540 538
541 if (IsDirectory(new_path)) { 539 if (IsDirectory(new_path)) {
@@ -546,7 +544,7 @@ bool DeleteDirRecursively(const std::string &directory, unsigned int recursion)
546 return Delete(new_path); 544 return Delete(new_path);
547 }; 545 };
548 546
549 if (!ForeachDirectoryEntry(nullptr, directory, callback, recursion)) 547 if (!ForeachDirectoryEntry(nullptr, directory, callback))
550 return false; 548 return false;
551 549
552 // Delete the outermost directory 550 // Delete the outermost directory
diff --git a/src/common/file_util.h b/src/common/file_util.h
index 32ae2dc57..7ad7ee829 100644
--- a/src/common/file_util.h
+++ b/src/common/file_util.h
@@ -105,13 +105,11 @@ bool CreateEmptyFile(const std::string &filename);
105 * @param num_entries_out to be assigned by the callable with the number of iterated directory entries, never null 105 * @param num_entries_out to be assigned by the callable with the number of iterated directory entries, never null
106 * @param directory the path to the enclosing directory 106 * @param directory the path to the enclosing directory
107 * @param virtual_name the entry name, without any preceding directory info 107 * @param virtual_name the entry name, without any preceding directory info
108 * @param recursion Number of children directory to read before giving up
109 * @return whether handling the entry succeeded 108 * @return whether handling the entry succeeded
110 */ 109 */
111using DirectoryEntryCallable = std::function<bool(unsigned* num_entries_out, 110using DirectoryEntryCallable = std::function<bool(unsigned* num_entries_out,
112 const std::string& directory, 111 const std::string& directory,
113 const std::string& virtual_name, 112 const std::string& virtual_name)>;
114 unsigned int recursion)>;
115 113
116/** 114/**
117 * Scans a directory, calling the callback for each file/directory contained within. 115 * Scans a directory, calling the callback for each file/directory contained within.
@@ -119,10 +117,9 @@ using DirectoryEntryCallable = std::function<bool(unsigned* num_entries_out,
119 * @param num_entries_out assigned by the function with the number of iterated directory entries, can be null 117 * @param num_entries_out assigned by the function with the number of iterated directory entries, can be null
120 * @param directory the directory to scan 118 * @param directory the directory to scan
121 * @param callback The callback which will be called for each entry 119 * @param callback The callback which will be called for each entry
122 * @param recursion Number of children directories to read before giving up
123 * @return whether scanning the directory succeeded 120 * @return whether scanning the directory succeeded
124 */ 121 */
125bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string &directory, DirectoryEntryCallable callback, unsigned int recursion = 0); 122bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string &directory, DirectoryEntryCallable callback);
126 123
127/** 124/**
128 * Scans the directory tree, storing the results. 125 * Scans the directory tree, storing the results.