diff options
Diffstat (limited to 'src/common/file_util.h')
| -rw-r--r-- | src/common/file_util.h | 62 |
1 files changed, 19 insertions, 43 deletions
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 { | |||
| 39 | UserDir, | 39 | UserDir, |
| 40 | }; | 40 | }; |
| 41 | 41 | ||
| 42 | // FileSystem tree node/ | 42 | // Returns true if the path exists |
| 43 | struct FSTEntry { | ||
| 44 | bool isDirectory; | ||
| 45 | u64 size; // file length or number of entries from children | ||
| 46 | std::string physicalName; // name on disk | ||
| 47 | std::string virtualName; // name in FST names table | ||
| 48 | std::vector<FSTEntry> children; | ||
| 49 | }; | ||
| 50 | |||
| 51 | // Returns true if the exists | ||
| 52 | [[nodiscard]] bool Exists(const std::filesystem::path& path); | 43 | [[nodiscard]] bool Exists(const std::filesystem::path& path); |
| 53 | 44 | ||
| 54 | // Returns true if path is a directory | 45 | // Returns true if path is a directory |
| 55 | [[nodiscard]] bool IsDirectory(const std::filesystem::path& path); | 46 | [[nodiscard]] bool IsDirectory(const std::filesystem::path& path); |
| 56 | 47 | ||
| 57 | // Returns the size of filename (64bit) | 48 | // Returns the size of filename (64bit) |
| 58 | [[nodiscard]] u64 GetSize(const std::string& filename); | 49 | [[nodiscard]] u64 GetSize(const std::filesystem::path& path); |
| 59 | |||
| 60 | // Overloaded GetSize, accepts file descriptor | ||
| 61 | [[nodiscard]] u64 GetSize(int fd); | ||
| 62 | 50 | ||
| 63 | // Overloaded GetSize, accepts FILE* | 51 | // Overloaded GetSize, accepts FILE* |
| 64 | [[nodiscard]] u64 GetSize(FILE* f); | 52 | [[nodiscard]] u64 GetSize(FILE* f); |
| 65 | 53 | ||
| 66 | // Returns true if successful, or path already exists. | 54 | // Returns true if successful, or path already exists. |
| 67 | bool CreateDir(const std::string& filename); | 55 | bool CreateDir(const std::filesystem::path& path); |
| 68 | |||
| 69 | // Creates the full path of fullPath returns true on success | ||
| 70 | bool CreateFullPath(const std::string& fullPath); | ||
| 71 | 56 | ||
| 72 | // Deletes a given filename, return true on success | 57 | // Creates the full path of path. Returns true on success |
| 73 | // Doesn't supports deleting a directory | 58 | bool CreateFullPath(const std::filesystem::path& path); |
| 74 | bool Delete(const std::string& filename); | ||
| 75 | 59 | ||
| 76 | // Deletes a directory filename, returns true on success | 60 | // Deletes a given file at the path. |
| 77 | bool DeleteDir(const std::string& filename); | 61 | // This will also delete empty directories. |
| 62 | // Return true on success | ||
| 63 | bool Delete(const std::filesystem::path& path); | ||
| 78 | 64 | ||
| 79 | // renames file srcFilename to destFilename, returns true on success | 65 | // Renames file src to dst, returns true on success |
| 80 | bool Rename(const std::string& srcFilename, const std::string& destFilename); | 66 | bool Rename(const std::filesystem::path& src, const std::filesystem::path& dst); |
| 81 | 67 | ||
| 82 | // copies file srcFilename to destFilename, returns true on success | 68 | // copies file src to dst, returns true on success |
| 83 | bool Copy(const std::string& srcFilename, const std::string& destFilename); | 69 | bool Copy(const std::filesystem::path& src, const std::filesystem::path& dst); |
| 84 | 70 | ||
| 85 | // creates an empty file filename, returns true on success | 71 | // creates an empty file filename, returns true on success |
| 86 | bool CreateEmptyFile(const std::string& filename); | 72 | bool CreateEmptyFile(const std::string& filename); |
| @@ -107,27 +93,17 @@ using DirectoryEntryCallable = std::function<bool( | |||
| 107 | bool ForeachDirectoryEntry(u64* num_entries_out, const std::string& directory, | 93 | bool ForeachDirectoryEntry(u64* num_entries_out, const std::string& directory, |
| 108 | DirectoryEntryCallable callback); | 94 | DirectoryEntryCallable callback); |
| 109 | 95 | ||
| 110 | /** | 96 | // Deletes the given path and anything under it. Returns true on success. |
| 111 | * Scans the directory tree, storing the results. | 97 | bool DeleteDirRecursively(const std::filesystem::path& path); |
| 112 | * @param directory the parent directory to start scanning from | ||
| 113 | * @param parent_entry FSTEntry where the filesystem tree results will be stored. | ||
| 114 | * @param recursion Number of children directories to read before giving up. | ||
| 115 | * @return the total number of files/directories found | ||
| 116 | */ | ||
| 117 | u64 ScanDirectoryTree(const std::string& directory, FSTEntry& parent_entry, | ||
| 118 | unsigned int recursion = 0); | ||
| 119 | |||
| 120 | // deletes the given directory and anything under it. Returns true on success. | ||
| 121 | bool DeleteDirRecursively(const std::string& directory, unsigned int recursion = 256); | ||
| 122 | 98 | ||
| 123 | // Returns the current directory | 99 | // Returns the current directory |
| 124 | [[nodiscard]] std::optional<std::string> GetCurrentDir(); | 100 | [[nodiscard]] std::optional<std::filesystem::path> GetCurrentDir(); |
| 125 | 101 | ||
| 126 | // Create directory and copy contents (does not overwrite existing files) | 102 | // Create directory and copy contents (does not overwrite existing files) |
| 127 | void CopyDir(const std::string& source_path, const std::string& dest_path); | 103 | void CopyDir(const std::filesystem::path& src, const std::filesystem::path& dst); |
| 128 | 104 | ||
| 129 | // Set the current directory to given directory | 105 | // Set the current directory to given path |
| 130 | bool SetCurrentDir(const std::string& directory); | 106 | bool SetCurrentDir(const std::filesystem::path& path); |
| 131 | 107 | ||
| 132 | // Returns a pointer to a string with a yuzu data dir in the user's home | 108 | // Returns a pointer to a string with a yuzu data dir in the user's home |
| 133 | // directory. To be used in "multi-user" mode (that is, installed). | 109 | // directory. To be used in "multi-user" mode (that is, installed). |