diff options
Diffstat (limited to 'src/common/file_util.h')
| -rw-r--r-- | src/common/file_util.h | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/common/file_util.h b/src/common/file_util.h index e71a9b2fa..3d617f573 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | #include <array> | 7 | #include <array> |
| 8 | #include <fstream> | 8 | #include <fstream> |
| 9 | #include <functional> | ||
| 9 | #include <cstddef> | 10 | #include <cstddef> |
| 10 | #include <cstdio> | 11 | #include <cstdio> |
| 11 | #include <string> | 12 | #include <string> |
| @@ -96,9 +97,28 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename); | |||
| 96 | // creates an empty file filename, returns true on success | 97 | // creates an empty file filename, returns true on success |
| 97 | bool CreateEmptyFile(const std::string &filename); | 98 | bool CreateEmptyFile(const std::string &filename); |
| 98 | 99 | ||
| 99 | // Scans the directory tree gets, starting from _Directory and adds the | 100 | /** |
| 100 | // results into parentEntry. Returns the number of files+directories found | 101 | * Scans the directory tree, calling the callback for each file/directory found. |
| 101 | u32 ScanDirectoryTree(const std::string &directory, FSTEntry& parentEntry); | 102 | * The callback must return the number of files and directories which the provided path contains. |
| 103 | * If the callback's return value is -1, the callback loop is broken immediately. | ||
| 104 | * If the callback's return value is otherwise negative, the callback loop is broken immediately | ||
| 105 | * and the callback's return value is returned from this function (to allow for error handling). | ||
| 106 | * @param directory the parent directory to start scanning from | ||
| 107 | * @param callback The callback which will be called for each file/directory. It is called | ||
| 108 | * with the arguments (const std::string& directory, const std::string& virtual_name). | ||
| 109 | * The `directory `parameter is the path to the directory which contains the file/directory. | ||
| 110 | * The `virtual_name` parameter is the incomplete file path, without any directory info. | ||
| 111 | * @return the total number of files/directories found | ||
| 112 | */ | ||
| 113 | int ScanDirectoryTreeAndCallback(const std::string &directory, std::function<int(const std::string&, const std::string&)> callback); | ||
| 114 | |||
| 115 | /** | ||
| 116 | * Scans the directory tree, storing the results. | ||
| 117 | * @param directory the parent directory to start scanning from | ||
| 118 | * @param parent_entry FSTEntry where the filesystem tree results will be stored. | ||
| 119 | * @return the total number of files/directories found | ||
| 120 | */ | ||
| 121 | int ScanDirectoryTree(const std::string &directory, FSTEntry& parent_entry); | ||
| 102 | 122 | ||
| 103 | // deletes the given directory and anything under it. Returns true on success. | 123 | // deletes the given directory and anything under it. Returns true on success. |
| 104 | bool DeleteDirRecursively(const std::string &directory); | 124 | bool DeleteDirRecursively(const std::string &directory); |