Split up FileUtil::ScanDirectoryTree to be able to use callbacks for custom behavior

Converted FileUtil::ScanDirectoryTree and FileUtil::DeleteDirRecursively
to use the new ScanDirectoryTreeAndCallback function internally.
This commit is contained in:
archshift 2015-08-31 18:29:23 -07:00
parent bba12520c4
commit 7134a17fc6
2 changed files with 86 additions and 106 deletions

View file

@ -6,6 +6,7 @@
#include <array>
#include <fstream>
#include <functional>
#include <cstddef>
#include <cstdio>
#include <string>
@ -96,9 +97,28 @@ 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);
// Scans the directory tree gets, starting from _Directory and adds the
// results into parentEntry. Returns the number of files+directories found
u32 ScanDirectoryTree(const std::string &directory, FSTEntry& parentEntry);
/**
* Scans the directory tree, calling the callback for each file/directory found.
* The callback must return the number of files and directories which the provided path contains.
* If the callback's return value is -1, the callback loop is broken immediately.
* If the callback's return value is otherwise negative, the callback loop is broken immediately
* and the callback's return value is returned from this function (to allow for error handling).
* @param directory the parent directory to start scanning from
* @param callback The callback which will be called for each file/directory. It is called
* with the arguments (const std::string& directory, const std::string& virtual_name).
* The `directory `parameter is the path to the directory which contains the file/directory.
* The `virtual_name` parameter is the incomplete file path, without any directory info.
* @return the total number of files/directories found
*/
int ScanDirectoryTreeAndCallback(const std::string &directory, std::function<int(const std::string&, const std::string&)> callback);
/**
* 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.
* @return the total number of files/directories found
*/
int ScanDirectoryTree(const std::string &directory, FSTEntry& parent_entry);
// deletes the given directory and anything under it. Returns true on success.
bool DeleteDirRecursively(const std::string &directory);