From df5069f8c06beb82cd8dd27751e784eda31e2476 Mon Sep 17 00:00:00 2001
From: Lioncash <mathew1800@gmail.com>
Date: Sat, 21 Jul 2018 22:36:19 -0400
Subject: [PATCH] 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/citra_qt/game_list.cpp |  2 +-
 src/common/file_util.cpp   | 18 +++++++++---------
 src/common/file_util.h     |  8 ++++----
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/src/citra_qt/game_list.cpp b/src/citra_qt/game_list.cpp
index b1fa73c88..0ee0d7a4a 100644
--- a/src/citra_qt/game_list.cpp
+++ b/src/citra_qt/game_list.cpp
@@ -630,7 +630,7 @@ void GameList::RefreshGameDirectory() {
 
 void GameListWorker::AddFstEntriesToGameList(const std::string& dir_path, unsigned int recursion,
                                              GameListDir* parent_dir) {
-    const auto callback = [this, recursion, parent_dir](unsigned* num_entries_out,
+    const auto callback = [this, recursion, parent_dir](u64* num_entries_out,
                                                         const std::string& directory,
                                                         const std::string& virtual_name) -> bool {
         std::string physical_name = directory + DIR_SEP + virtual_name;
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp
index 5b1d66daa..f0c34448c 100644
--- a/src/common/file_util.cpp
+++ b/src/common/file_util.cpp
@@ -394,12 +394,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;
@@ -429,7 +429,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;
@@ -453,9 +453,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;
@@ -467,7 +467,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;
             }
@@ -482,12 +482,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 ef2f5e8db..0f4a416ca 100644
--- a/src/common/file_util.h
+++ b/src/common/file_util.h
@@ -85,7 +85,7 @@ bool CreateEmptyFile(const std::string& filename);
  * @return whether handling the entry succeeded
  */
 using DirectoryEntryCallable = std::function<bool(
-    unsigned* num_entries_out, const std::string& directory, const std::string& virtual_name)>;
+    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.
@@ -96,7 +96,7 @@ using DirectoryEntryCallable = std::function<bool(
  * @param callback The callback which will be called for each entry
  * @return whether scanning the directory succeeded
  */
-bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string& directory,
+bool ForeachDirectoryEntry(u64* num_entries_out, const std::string& directory,
                            DirectoryEntryCallable callback);
 
 /**
@@ -106,8 +106,8 @@ bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string& directo
  * @param recursion Number of children directories to read before giving up.
  * @return the total number of files/directories found
  */
-unsigned ScanDirectoryTree(const std::string& directory, FSTEntry& parent_entry,
-                           unsigned int recursion = 0);
+u64 ScanDirectoryTree(const std::string& directory, FSTEntry& parent_entry,
+                      unsigned int recursion = 0);
 
 // deletes the given directory and anything under it. Returns true on success.
 bool DeleteDirRecursively(const std::string& directory, unsigned int recursion = 256);