diff options
author | Morph <39850852+Morph1984@users.noreply.github.com> | 2020-12-12 02:22:18 +0100 |
---|---|---|
committer | Morph <39850852+Morph1984@users.noreply.github.com> | 2020-12-12 02:24:22 +0100 |
commit | 4de079b256ce320c7e261a2c35b703e477e46fa5 (patch) | |
tree | 084d68f828e2cb1d26cb9b537253f6947c5ce676 /src/common/file_util.h | |
parent | Revert "Merge pull request #5174 from ReinUsesLisp/fs-fix" (diff) | |
download | yuzu-4de079b256ce320c7e261a2c35b703e477e46fa5.tar yuzu-4de079b256ce320c7e261a2c35b703e477e46fa5.tar.gz yuzu-4de079b256ce320c7e261a2c35b703e477e46fa5.tar.bz2 yuzu-4de079b256ce320c7e261a2c35b703e477e46fa5.tar.lz yuzu-4de079b256ce320c7e261a2c35b703e477e46fa5.tar.xz yuzu-4de079b256ce320c7e261a2c35b703e477e46fa5.tar.zst yuzu-4de079b256ce320c7e261a2c35b703e477e46fa5.zip |
Diffstat (limited to '')
-rw-r--r-- | src/common/file_util.h | 69 |
1 files changed, 46 insertions, 23 deletions
diff --git a/src/common/file_util.h b/src/common/file_util.h index c2ee7ca27..840cde2a6 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -6,7 +6,6 @@ #include <array> #include <cstdio> -#include <filesystem> #include <fstream> #include <functional> #include <limits> @@ -39,34 +38,48 @@ enum class UserPath { UserDir, }; -// Returns true if the path exists -[[nodiscard]] bool Exists(const std::filesystem::path& path); +// FileSystem tree node/ +struct FSTEntry { + bool isDirectory; + u64 size; // file length or number of entries from children + std::string physicalName; // name on disk + std::string virtualName; // name in FST names table + std::vector<FSTEntry> children; +}; + +// Returns true if file filename exists +[[nodiscard]] bool Exists(const std::string& filename); -// Returns true if path is a directory -[[nodiscard]] bool IsDirectory(const std::filesystem::path& path); +// Returns true if filename is a directory +[[nodiscard]] bool IsDirectory(const std::string& filename); // Returns the size of filename (64bit) -[[nodiscard]] u64 GetSize(const std::filesystem::path& path); +[[nodiscard]] u64 GetSize(const std::string& filename); + +// Overloaded GetSize, accepts file descriptor +[[nodiscard]] u64 GetSize(int fd); // Overloaded GetSize, accepts FILE* [[nodiscard]] u64 GetSize(FILE* f); // Returns true if successful, or path already exists. -bool CreateDir(const std::filesystem::path& path); +bool CreateDir(const std::string& filename); + +// Creates the full path of fullPath returns true on success +bool CreateFullPath(const std::string& fullPath); -// Creates the full path of path. Returns true on success -bool CreateFullPath(const std::filesystem::path& path); +// Deletes a given filename, return true on success +// Doesn't supports deleting a directory +bool Delete(const std::string& filename); -// Deletes a given file at the path. -// This will also delete empty directories. -// Return true on success -bool Delete(const std::filesystem::path& path); +// Deletes a directory filename, returns true on success +bool DeleteDir(const std::string& filename); -// Renames file src to dst, returns true on success -bool Rename(const std::filesystem::path& src, const std::filesystem::path& dst); +// renames file srcFilename to destFilename, returns true on success +bool Rename(const std::string& srcFilename, const std::string& destFilename); -// copies file src to dst, returns true on success -bool Copy(const std::filesystem::path& src, const std::filesystem::path& dst); +// copies file srcFilename to destFilename, returns true on success +bool Copy(const std::string& srcFilename, const std::string& destFilename); // creates an empty file filename, returns true on success bool CreateEmptyFile(const std::string& filename); @@ -93,17 +106,27 @@ using DirectoryEntryCallable = std::function<bool( bool ForeachDirectoryEntry(u64* num_entries_out, const std::string& directory, DirectoryEntryCallable callback); -// Deletes the given path and anything under it. Returns true on success. -bool DeleteDirRecursively(const std::filesystem::path& path); +/** + * Scans the directory tree, storing the results. + * @param directory the parent directory to start scanning from + * @param parent_entry FSTEntry where the filesystem tree results will be stored. + * @param recursion Number of children directories to read before giving up. + * @return the total number of files/directories found + */ +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); // Returns the current directory -[[nodiscard]] std::optional<std::filesystem::path> GetCurrentDir(); +[[nodiscard]] std::optional<std::string> GetCurrentDir(); // Create directory and copy contents (does not overwrite existing files) -void CopyDir(const std::filesystem::path& src, const std::filesystem::path& dst); +void CopyDir(const std::string& source_path, const std::string& dest_path); -// Set the current directory to given path -bool SetCurrentDir(const std::filesystem::path& path); +// Set the current directory to given directory +bool SetCurrentDir(const std::string& directory); // Returns a pointer to a string with a yuzu data dir in the user's home // directory. To be used in "multi-user" mode (that is, installed). |