diff options
Diffstat (limited to 'src/core/file_sys/vfs.h')
| -rw-r--r-- | src/core/file_sys/vfs.h | 66 |
1 files changed, 63 insertions, 3 deletions
diff --git a/src/core/file_sys/vfs.h b/src/core/file_sys/vfs.h index fab9e2b45..141a053ce 100644 --- a/src/core/file_sys/vfs.h +++ b/src/core/file_sys/vfs.h | |||
| @@ -11,14 +11,74 @@ | |||
| 11 | #include <vector> | 11 | #include <vector> |
| 12 | #include "boost/optional.hpp" | 12 | #include "boost/optional.hpp" |
| 13 | #include "common/common_types.h" | 13 | #include "common/common_types.h" |
| 14 | #include "core/file_sys/mode.h" | ||
| 14 | 15 | ||
| 15 | namespace FileSys { | 16 | namespace FileSys { |
| 17 | |||
| 18 | struct VfsFilesystem; | ||
| 16 | struct VfsFile; | 19 | struct VfsFile; |
| 17 | struct VfsDirectory; | 20 | struct VfsDirectory; |
| 18 | 21 | ||
| 19 | // Convenience typedefs to use VfsDirectory and VfsFile | 22 | // Convenience typedefs to use Vfs* interfaces |
| 20 | using VirtualDir = std::shared_ptr<FileSys::VfsDirectory>; | 23 | using VirtualFilesystem = std::shared_ptr<VfsFilesystem>; |
| 21 | using VirtualFile = std::shared_ptr<FileSys::VfsFile>; | 24 | using VirtualDir = std::shared_ptr<VfsDirectory>; |
| 25 | using VirtualFile = std::shared_ptr<VfsFile>; | ||
| 26 | |||
| 27 | // An enumeration representing what can be at the end of a path in a VfsFilesystem | ||
| 28 | enum class VfsEntryType { | ||
| 29 | None, | ||
| 30 | File, | ||
| 31 | Directory, | ||
| 32 | }; | ||
| 33 | |||
| 34 | // A class representing an abstract filesystem. A default implementation given the root VirtualDir | ||
| 35 | // is provided for convenience, but if the Vfs implementation has any additional state or | ||
| 36 | // functionality, they will need to override. | ||
| 37 | struct VfsFilesystem : NonCopyable { | ||
| 38 | VfsFilesystem(VirtualDir root); | ||
| 39 | virtual ~VfsFilesystem(); | ||
| 40 | |||
| 41 | // Gets the friendly name for the filesystem. | ||
| 42 | virtual std::string GetName() const; | ||
| 43 | |||
| 44 | // Return whether or not the user has read permissions on this filesystem. | ||
| 45 | virtual bool IsReadable() const; | ||
| 46 | // Return whether or not the user has write permission on this filesystem. | ||
| 47 | virtual bool IsWritable() const; | ||
| 48 | |||
| 49 | // Determine if the entry at path is non-existant, a file, or a directory. | ||
| 50 | virtual VfsEntryType GetEntryType(std::string_view path) const; | ||
| 51 | |||
| 52 | // Opens the file with path relative to root. If it doesn't exist, returns nullptr. | ||
| 53 | virtual VirtualFile OpenFile(std::string_view path, Mode perms); | ||
| 54 | // Creates a new, empty file at path | ||
| 55 | virtual VirtualFile CreateFile(std::string_view path, Mode perms); | ||
| 56 | // Copies the file from old_path to new_path, returning the new file on success and nullptr on | ||
| 57 | // failure. | ||
| 58 | virtual VirtualFile CopyFile(std::string_view old_path, std::string_view new_path); | ||
| 59 | // Moves the file from old_path to new_path, returning the moved file on success and nullptr on | ||
| 60 | // failure. | ||
| 61 | virtual VirtualFile MoveFile(std::string_view old_path, std::string_view new_path); | ||
| 62 | // Deletes the file with path relative to root, returing true on success. | ||
| 63 | virtual bool DeleteFile(std::string_view path); | ||
| 64 | |||
| 65 | // Opens the directory with path relative to root. If it doesn't exist, returns nullptr. | ||
| 66 | virtual VirtualDir OpenDirectory(std::string_view path, Mode perms); | ||
| 67 | // Creates a new, empty directory at path | ||
| 68 | virtual VirtualDir CreateDirectory(std::string_view path, Mode perms); | ||
| 69 | // Copies the directory from old_path to new_path, returning the new directory on success and | ||
| 70 | // nullptr on failure. | ||
| 71 | virtual VirtualDir CopyDirectory(std::string_view old_path, std::string_view new_path); | ||
| 72 | // Moves the directory from old_path to new_path, returning the moved directory on success and | ||
| 73 | // nullptr on failure. | ||
| 74 | virtual VirtualDir MoveDirectory(std::string_view old_path, std::string_view new_path); | ||
| 75 | // Deletes the directory with path relative to root, returing true on success. | ||
| 76 | virtual bool DeleteDirectory(std::string_view path); | ||
| 77 | |||
| 78 | protected: | ||
| 79 | // Root directory in default implementation. | ||
| 80 | VirtualDir root; | ||
| 81 | }; | ||
| 22 | 82 | ||
| 23 | // A class representing a file in an abstract filesystem. | 83 | // A class representing a file in an abstract filesystem. |
| 24 | struct VfsFile : NonCopyable { | 84 | struct VfsFile : NonCopyable { |