summaryrefslogtreecommitdiff
path: root/src/common/file_util.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2018-07-21 22:05:30 -0700
committerGravatar GitHub2018-07-21 22:05:30 -0700
commitef163c1a15e25228cc7f6777e07905778d6f4f89 (patch)
tree9a9cc973c4334d5afbaa410bac363250748082c5 /src/common/file_util.cpp
parentMerge pull request #761 from bunnei/improve-raster-cache (diff)
parentfile_util: Use a u64 to represent number of entries (diff)
downloadyuzu-ef163c1a15e25228cc7f6777e07905778d6f4f89.tar.gz
yuzu-ef163c1a15e25228cc7f6777e07905778d6f4f89.tar.xz
yuzu-ef163c1a15e25228cc7f6777e07905778d6f4f89.zip
Merge pull request #764 from lioncash/move
file_util: Minor changes to ScanDirectoryTree() and ForeachDirectoryEntry()
Diffstat (limited to 'src/common/file_util.cpp')
-rw-r--r--src/common/file_util.cpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp
index d8163a4a8..47ac8368e 100644
--- a/src/common/file_util.cpp
+++ b/src/common/file_util.cpp
@@ -396,12 +396,12 @@ bool CreateEmptyFile(const std::string& filename) {
396 return true; 396 return true;
397} 397}
398 398
399bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string& directory, 399bool ForeachDirectoryEntry(u64* num_entries_out, const std::string& directory,
400 DirectoryEntryCallable callback) { 400 DirectoryEntryCallable callback) {
401 LOG_TRACE(Common_Filesystem, "directory {}", directory); 401 LOG_TRACE(Common_Filesystem, "directory {}", directory);
402 402
403 // How many files + directories we found 403 // How many files + directories we found
404 unsigned found_entries = 0; 404 u64 found_entries = 0;
405 405
406 // Save the status of callback function 406 // Save the status of callback function
407 bool callback_error = false; 407 bool callback_error = false;
@@ -431,7 +431,7 @@ bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string& directo
431 if (virtual_name == "." || virtual_name == "..") 431 if (virtual_name == "." || virtual_name == "..")
432 continue; 432 continue;
433 433
434 unsigned ret_entries = 0; 434 u64 ret_entries = 0;
435 if (!callback(&ret_entries, directory, virtual_name)) { 435 if (!callback(&ret_entries, directory, virtual_name)) {
436 callback_error = true; 436 callback_error = true;
437 break; 437 break;
@@ -455,9 +455,9 @@ bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string& directo
455 return true; 455 return true;
456} 456}
457 457
458unsigned ScanDirectoryTree(const std::string& directory, FSTEntry& parent_entry, 458u64 ScanDirectoryTree(const std::string& directory, FSTEntry& parent_entry,
459 unsigned int recursion) { 459 unsigned int recursion) {
460 const auto callback = [recursion, &parent_entry](unsigned* num_entries_out, 460 const auto callback = [recursion, &parent_entry](u64* num_entries_out,
461 const std::string& directory, 461 const std::string& directory,
462 const std::string& virtual_name) -> bool { 462 const std::string& virtual_name) -> bool {
463 FSTEntry entry; 463 FSTEntry entry;
@@ -469,7 +469,7 @@ unsigned ScanDirectoryTree(const std::string& directory, FSTEntry& parent_entry,
469 // is a directory, lets go inside if we didn't recurse to often 469 // is a directory, lets go inside if we didn't recurse to often
470 if (recursion > 0) { 470 if (recursion > 0) {
471 entry.size = ScanDirectoryTree(entry.physicalName, entry, recursion - 1); 471 entry.size = ScanDirectoryTree(entry.physicalName, entry, recursion - 1);
472 *num_entries_out += (int)entry.size; 472 *num_entries_out += entry.size;
473 } else { 473 } else {
474 entry.size = 0; 474 entry.size = 0;
475 } 475 }
@@ -480,16 +480,16 @@ unsigned ScanDirectoryTree(const std::string& directory, FSTEntry& parent_entry,
480 (*num_entries_out)++; 480 (*num_entries_out)++;
481 481
482 // Push into the tree 482 // Push into the tree
483 parent_entry.children.push_back(entry); 483 parent_entry.children.push_back(std::move(entry));
484 return true; 484 return true;
485 }; 485 };
486 486
487 unsigned num_entries; 487 u64 num_entries;
488 return ForeachDirectoryEntry(&num_entries, directory, callback) ? num_entries : 0; 488 return ForeachDirectoryEntry(&num_entries, directory, callback) ? num_entries : 0;
489} 489}
490 490
491bool DeleteDirRecursively(const std::string& directory, unsigned int recursion) { 491bool DeleteDirRecursively(const std::string& directory, unsigned int recursion) {
492 const auto callback = [recursion](unsigned* num_entries_out, const std::string& directory, 492 const auto callback = [recursion](u64* num_entries_out, const std::string& directory,
493 const std::string& virtual_name) -> bool { 493 const std::string& virtual_name) -> bool {
494 std::string new_path = directory + DIR_SEP_CHR + virtual_name; 494 std::string new_path = directory + DIR_SEP_CHR + virtual_name;
495 495