mirror of
https://github.com/yuzu-mirror/yuzu.git
synced 2024-11-20 12:59:58 +00:00
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.
This commit is contained in:
parent
964154ce44
commit
0ba7fe4ab1
5 changed files with 18 additions and 18 deletions
|
@ -396,12 +396,12 @@ bool CreateEmptyFile(const std::string& filename) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string& directory,
|
bool ForeachDirectoryEntry(u64* num_entries_out, const std::string& directory,
|
||||||
DirectoryEntryCallable callback) {
|
DirectoryEntryCallable callback) {
|
||||||
LOG_TRACE(Common_Filesystem, "directory {}", directory);
|
LOG_TRACE(Common_Filesystem, "directory {}", directory);
|
||||||
|
|
||||||
// How many files + directories we found
|
// How many files + directories we found
|
||||||
unsigned found_entries = 0;
|
u64 found_entries = 0;
|
||||||
|
|
||||||
// Save the status of callback function
|
// Save the status of callback function
|
||||||
bool callback_error = false;
|
bool callback_error = false;
|
||||||
|
@ -431,7 +431,7 @@ bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string& directo
|
||||||
if (virtual_name == "." || virtual_name == "..")
|
if (virtual_name == "." || virtual_name == "..")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
unsigned ret_entries = 0;
|
u64 ret_entries = 0;
|
||||||
if (!callback(&ret_entries, directory, virtual_name)) {
|
if (!callback(&ret_entries, directory, virtual_name)) {
|
||||||
callback_error = true;
|
callback_error = true;
|
||||||
break;
|
break;
|
||||||
|
@ -455,9 +455,9 @@ bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string& directo
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned ScanDirectoryTree(const std::string& directory, FSTEntry& parent_entry,
|
u64 ScanDirectoryTree(const std::string& directory, FSTEntry& parent_entry,
|
||||||
unsigned int recursion) {
|
unsigned int recursion) {
|
||||||
const auto callback = [recursion, &parent_entry](unsigned* num_entries_out,
|
const auto callback = [recursion, &parent_entry](u64* num_entries_out,
|
||||||
const std::string& directory,
|
const std::string& directory,
|
||||||
const std::string& virtual_name) -> bool {
|
const std::string& virtual_name) -> bool {
|
||||||
FSTEntry entry;
|
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
|
// is a directory, lets go inside if we didn't recurse to often
|
||||||
if (recursion > 0) {
|
if (recursion > 0) {
|
||||||
entry.size = ScanDirectoryTree(entry.physicalName, entry, recursion - 1);
|
entry.size = ScanDirectoryTree(entry.physicalName, entry, recursion - 1);
|
||||||
*num_entries_out += (int)entry.size;
|
*num_entries_out += entry.size;
|
||||||
} else {
|
} else {
|
||||||
entry.size = 0;
|
entry.size = 0;
|
||||||
}
|
}
|
||||||
|
@ -484,12 +484,12 @@ unsigned ScanDirectoryTree(const std::string& directory, FSTEntry& parent_entry,
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned num_entries;
|
u64 num_entries;
|
||||||
return ForeachDirectoryEntry(&num_entries, directory, callback) ? num_entries : 0;
|
return ForeachDirectoryEntry(&num_entries, directory, callback) ? num_entries : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeleteDirRecursively(const std::string& directory, unsigned int recursion) {
|
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 {
|
const std::string& virtual_name) -> bool {
|
||||||
std::string new_path = directory + DIR_SEP_CHR + virtual_name;
|
std::string new_path = directory + DIR_SEP_CHR + virtual_name;
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ bool CreateEmptyFile(const std::string& filename);
|
||||||
* @return whether handling the entry succeeded
|
* @return whether handling the entry succeeded
|
||||||
*/
|
*/
|
||||||
using DirectoryEntryCallable = std::function<bool(
|
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.
|
* Scans a directory, calling the callback for each file/directory contained within.
|
||||||
|
@ -95,7 +95,7 @@ using DirectoryEntryCallable = std::function<bool(
|
||||||
* @param callback The callback which will be called for each entry
|
* @param callback The callback which will be called for each entry
|
||||||
* @return whether scanning the directory succeeded
|
* @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);
|
DirectoryEntryCallable callback);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -105,8 +105,8 @@ bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string& directo
|
||||||
* @param recursion Number of children directories to read before giving up.
|
* @param recursion Number of children directories to read before giving up.
|
||||||
* @return the total number of files/directories found
|
* @return the total number of files/directories found
|
||||||
*/
|
*/
|
||||||
unsigned ScanDirectoryTree(const std::string& directory, FSTEntry& parent_entry,
|
u64 ScanDirectoryTree(const std::string& directory, FSTEntry& parent_entry,
|
||||||
unsigned int recursion = 0);
|
unsigned int recursion = 0);
|
||||||
|
|
||||||
// deletes the given directory and anything under it. Returns true on success.
|
// deletes the given directory and anything under it. Returns true on success.
|
||||||
bool DeleteDirRecursively(const std::string& directory, unsigned int recursion = 256);
|
bool DeleteDirRecursively(const std::string& directory, unsigned int recursion = 256);
|
||||||
|
|
|
@ -92,13 +92,13 @@ RealVfsDirectory::RealVfsDirectory(const std::string& path_, Mode perms_)
|
||||||
perms(perms_) {
|
perms(perms_) {
|
||||||
if (!FileUtil::Exists(path) && (perms == Mode::Write || perms == Mode::Append))
|
if (!FileUtil::Exists(path) && (perms == Mode::Write || perms == Mode::Append))
|
||||||
FileUtil::CreateDir(path);
|
FileUtil::CreateDir(path);
|
||||||
unsigned size;
|
|
||||||
if (perms == Mode::Append)
|
if (perms == Mode::Append)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
FileUtil::ForeachDirectoryEntry(
|
FileUtil::ForeachDirectoryEntry(
|
||||||
&size, path,
|
nullptr, path,
|
||||||
[this](unsigned* entries_out, const std::string& directory, const std::string& filename) {
|
[this](u64* entries_out, const std::string& directory, const std::string& filename) {
|
||||||
std::string full_path = directory + DIR_SEP + filename;
|
std::string full_path = directory + DIR_SEP + filename;
|
||||||
if (FileUtil::IsDirectory(full_path))
|
if (FileUtil::IsDirectory(full_path))
|
||||||
subdirectories.emplace_back(std::make_shared<RealVfsDirectory>(full_path, perms));
|
subdirectories.emplace_back(std::make_shared<RealVfsDirectory>(full_path, perms));
|
||||||
|
|
|
@ -20,7 +20,7 @@ namespace Loader {
|
||||||
|
|
||||||
static std::string FindRomFS(const std::string& directory) {
|
static std::string FindRomFS(const std::string& directory) {
|
||||||
std::string filepath_romfs;
|
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& virtual_name) -> bool {
|
||||||
const std::string physical_name = directory + virtual_name;
|
const std::string physical_name = directory + virtual_name;
|
||||||
if (FileUtil::IsDirectory(physical_name)) {
|
if (FileUtil::IsDirectory(physical_name)) {
|
||||||
|
|
|
@ -394,7 +394,7 @@ void GameList::RefreshGameDirectory() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameListWorker::AddFstEntriesToGameList(const std::string& dir_path, unsigned int recursion) {
|
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 {
|
const std::string& virtual_name) -> bool {
|
||||||
std::string physical_name = directory + DIR_SEP + virtual_name;
|
std::string physical_name = directory + DIR_SEP + virtual_name;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue