From 20aad9e01af958b6c8bf7d18faebd498541651f5 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 8 Dec 2020 18:51:04 -0500 Subject: file_util: Migrate remaining file handling functions over to std::filesystem Converts creation and deletion functions over to std::filesystem, simplifying our file-handling code. Notably with this, CopyDir will now function on Windows. --- src/common/file_util.h | 62 ++++++++++++++++---------------------------------- 1 file changed, 19 insertions(+), 43 deletions(-) (limited to 'src/common/file_util.h') diff --git a/src/common/file_util.h b/src/common/file_util.h index be0906434..c2ee7ca27 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -39,48 +39,34 @@ enum class UserPath { UserDir, }; -// 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 children; -}; - -// Returns true if the exists +// Returns true if the path exists [[nodiscard]] bool Exists(const std::filesystem::path& path); // Returns true if path is a directory [[nodiscard]] bool IsDirectory(const std::filesystem::path& path); // Returns the size of filename (64bit) -[[nodiscard]] u64 GetSize(const std::string& filename); - -// Overloaded GetSize, accepts file descriptor -[[nodiscard]] u64 GetSize(int fd); +[[nodiscard]] u64 GetSize(const std::filesystem::path& path); // Overloaded GetSize, accepts FILE* [[nodiscard]] u64 GetSize(FILE* f); // Returns true if successful, or path already exists. -bool CreateDir(const std::string& filename); - -// Creates the full path of fullPath returns true on success -bool CreateFullPath(const std::string& fullPath); +bool CreateDir(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); +// Creates the full path of path. Returns true on success +bool CreateFullPath(const std::filesystem::path& path); -// Deletes a directory filename, returns true on success -bool DeleteDir(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); -// renames file srcFilename to destFilename, returns true on success -bool Rename(const std::string& srcFilename, const std::string& destFilename); +// Renames file src to dst, returns true on success +bool Rename(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); +// copies file src to dst, returns true on success +bool Copy(const std::filesystem::path& src, const std::filesystem::path& dst); // creates an empty file filename, returns true on success bool CreateEmptyFile(const std::string& filename); @@ -107,27 +93,17 @@ using DirectoryEntryCallable = std::function GetCurrentDir(); +[[nodiscard]] std::optional GetCurrentDir(); // Create directory and copy contents (does not overwrite existing files) -void CopyDir(const std::string& source_path, const std::string& dest_path); +void CopyDir(const std::filesystem::path& src, const std::filesystem::path& dst); -// Set the current directory to given directory -bool SetCurrentDir(const std::string& directory); +// Set the current directory to given path +bool SetCurrentDir(const std::filesystem::path& path); // 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). -- cgit v1.2.3