From 0ba7fe4ab11d5c7a934a1b45b374f3277bc9f2cf Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 21 Jul 2018 22:36:19 -0400 Subject: file_util: Use a u64 to represent number of entries This avoids a truncating cast on size. I doubt we'd ever traverse a directory this large, however we also shouldn't truncate sizes away. --- src/common/file_util.cpp | 18 +++++++++--------- src/common/file_util.h | 8 ++++---- src/core/file_sys/vfs_real.cpp | 6 +++--- src/core/loader/deconstructed_rom_directory.cpp | 2 +- src/yuzu/game_list.cpp | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index 543adbffb..47ac8368e 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp @@ -396,12 +396,12 @@ bool CreateEmptyFile(const std::string& filename) { return true; } -bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string& directory, +bool ForeachDirectoryEntry(u64* num_entries_out, const std::string& directory, DirectoryEntryCallable callback) { LOG_TRACE(Common_Filesystem, "directory {}", directory); // How many files + directories we found - unsigned found_entries = 0; + u64 found_entries = 0; // Save the status of callback function bool callback_error = false; @@ -431,7 +431,7 @@ bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string& directo if (virtual_name == "." || virtual_name == "..") continue; - unsigned ret_entries = 0; + u64 ret_entries = 0; if (!callback(&ret_entries, directory, virtual_name)) { callback_error = true; break; @@ -455,9 +455,9 @@ bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string& directo return true; } -unsigned ScanDirectoryTree(const std::string& directory, FSTEntry& parent_entry, - unsigned int recursion) { - const auto callback = [recursion, &parent_entry](unsigned* num_entries_out, +u64 ScanDirectoryTree(const std::string& directory, FSTEntry& parent_entry, + unsigned int recursion) { + const auto callback = [recursion, &parent_entry](u64* num_entries_out, const std::string& directory, const std::string& virtual_name) -> bool { FSTEntry entry; @@ -469,7 +469,7 @@ unsigned ScanDirectoryTree(const std::string& directory, FSTEntry& parent_entry, // is a directory, lets go inside if we didn't recurse to often if (recursion > 0) { entry.size = ScanDirectoryTree(entry.physicalName, entry, recursion - 1); - *num_entries_out += (int)entry.size; + *num_entries_out += entry.size; } else { entry.size = 0; } @@ -484,12 +484,12 @@ unsigned ScanDirectoryTree(const std::string& directory, FSTEntry& parent_entry, return true; }; - unsigned num_entries; + u64 num_entries; return ForeachDirectoryEntry(&num_entries, directory, callback) ? num_entries : 0; } bool DeleteDirRecursively(const std::string& directory, unsigned int recursion) { - const auto callback = [recursion](unsigned* num_entries_out, const std::string& directory, + const auto callback = [recursion](u64* num_entries_out, const std::string& directory, const std::string& virtual_name) -> bool { std::string new_path = directory + DIR_SEP_CHR + virtual_name; diff --git a/src/common/file_util.h b/src/common/file_util.h index ff01bf0ff..090907c03 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -84,7 +84,7 @@ bool CreateEmptyFile(const std::string& filename); * @return whether handling the entry succeeded */ using DirectoryEntryCallable = std::function; + u64* num_entries_out, const std::string& directory, const std::string& virtual_name)>; /** * Scans a directory, calling the callback for each file/directory contained within. @@ -95,7 +95,7 @@ using DirectoryEntryCallable = std::function(full_path, perms)); diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp index 394963a69..18bd62a08 100644 --- a/src/core/loader/deconstructed_rom_directory.cpp +++ b/src/core/loader/deconstructed_rom_directory.cpp @@ -20,7 +20,7 @@ namespace Loader { static std::string FindRomFS(const std::string& directory) { std::string filepath_romfs; - const auto callback = [&filepath_romfs](unsigned*, const std::string& directory, + const auto callback = [&filepath_romfs](u64*, const std::string& directory, const std::string& virtual_name) -> bool { const std::string physical_name = directory + virtual_name; if (FileUtil::IsDirectory(physical_name)) { diff --git a/src/yuzu/game_list.cpp b/src/yuzu/game_list.cpp index e1ca0e77b..99e6634a1 100644 --- a/src/yuzu/game_list.cpp +++ b/src/yuzu/game_list.cpp @@ -394,7 +394,7 @@ void GameList::RefreshGameDirectory() { } void GameListWorker::AddFstEntriesToGameList(const std::string& dir_path, unsigned int recursion) { - const auto callback = [this, recursion](unsigned* num_entries_out, const std::string& directory, + const auto callback = [this, recursion](u64* num_entries_out, const std::string& directory, const std::string& virtual_name) -> bool { std::string physical_name = directory + DIR_SEP + virtual_name; -- cgit v1.2.3