libdonut 2.3.6
Application framework for cross-platform game development in C++20
Loading...
Searching...
No Matches
Filesystem.hpp
Go to the documentation of this file.
1#ifndef DONUT_FILESYSTEM_HPP
2#define DONUT_FILESYSTEM_HPP
3
4#include <donut/File.hpp>
5
6#include <span> // std::span
7#include <string> // std::string
8#include <vector> // std::vector
9
10namespace donut {
11
22 LOWER,
23
29 HIGHER,
30};
31
174
186public:
207 explicit Filesystem(const char* programFilepath, const FilesystemOptions& options = {});
208
211
213 Filesystem(const Filesystem&) = delete;
214
217
219 Filesystem& operator=(const Filesystem&) = delete;
220
223
252 [[nodiscard]] std::string getStandardOutputDirectory(const char* organizationName, const char* applicationName) const;
253
263 [[nodiscard]] std::string getOutputDirectory() const;
264
283 void setOutputDirectory(std::string path);
284
302
315 void unmountArchive(const char* path);
316
350 std::vector<std::string> mountArchives(const char* filepath, const char* archiveFileExtension, FilesystemMountPriority priority = FilesystemMountPriority::HIGHER);
351
366 void unmountArchives(std::span<const std::string> paths);
367
384 [[nodiscard]] const char* findArchiveOfFile(const char* filepath) const;
385
396 void createDirectory(const char* filepath);
397
420 void deleteFile(const char* filepath);
421
433 [[nodiscard]] bool fileExists(const char* filepath) const;
434
447 [[nodiscard]] File::Metadata getFileMetadata(const char* filepath) const;
448
475 [[nodiscard]] std::vector<std::string> getFilenamesInDirectory(const char* filepath) const;
476
492 [[nodiscard]] File openFile(const char* filepath) const;
493
518 [[nodiscard]] File createFile(const char* filepath);
519
544 [[nodiscard]] File appendFile(const char* filepath);
545
546private:
547 std::string outputDirectory{};
548};
549
550} // namespace donut
551
552#endif
Unique handle to a file in the virtual Filesystem.
Definition File.hpp:25
Persistent system for managing the virtual filesystem.
Definition Filesystem.hpp:185
File openFile(const char *filepath) const
Open a file in the virtual filesystem for reading.
Filesystem(Filesystem &&)=delete
Moving a filesystem is not allowed, since it manages global state.
std::vector< std::string > mountArchives(const char *filepath, const char *archiveFileExtension, FilesystemMountPriority priority=FilesystemMountPriority::HIGHER)
Mount all archives in a given directory on the host filesystem to the root directory of the virtual f...
void unmountArchives(std::span< const std::string > paths)
Unmount multiple archives.
Filesystem & operator=(Filesystem &&)=delete
Moving a filesystem is not allowed, since it manages global state.
std::string getStandardOutputDirectory(const char *organizationName, const char *applicationName) const
Get a suitable output directory for configuration files and other save data on the host platform,...
File appendFile(const char *filepath)
Open a file in the output directory specified by the virtual filesystem for appended writing.
~Filesystem()
Destructor.
File::Metadata getFileMetadata(const char *filepath) const
Get the metadata of a file that is mounted at a given virtual filepath.
void mountArchive(const char *path, FilesystemMountPriority priority=FilesystemMountPriority::HIGHER)
Mount a directory or archive on the host filesystem to the root directory of the virtual filesystem.
std::vector< std::string > getFilenamesInDirectory(const char *filepath) const
Get a list of the filenames of all readable virtual filepaths that are direct children of a given dir...
bool fileExists(const char *filepath) const
Check if a given virtual filepath has a corresponding host file mounted.
Filesystem(const Filesystem &)=delete
Copying a filesystem is not allowed, since it manages global state.
Filesystem & operator=(const Filesystem &)=delete
Copying a filesystem is not allowed, since it manages global state.
Filesystem(const char *programFilepath, const FilesystemOptions &options={})
Initialize the virtual filesystem.
File createFile(const char *filepath)
Create a file in the output directory and open it for writing, overwriting any existing file at the s...
std::string getOutputDirectory() const
Get the current output directory of the virtual filesystem.
void createDirectory(const char *filepath)
Create a new host directory in the output directory.
void deleteFile(const char *filepath)
Delete a host file or directory in the output directory.
void unmountArchive(const char *path)
Unmount a previously mounted directory or archive on the host filesystem from the virtual filesystem.
const char * findArchiveOfFile(const char *filepath) const
Get the host filepath of the mounted archive on the host filesystem that contains a given virtual fil...
void setOutputDirectory(std::string path)
Set the output directory of the virtual filesystem, where all output files will be written.
Definition Application.hpp:9
FilesystemMountPriority
Mount priority for a newly mounted archive to a virtual Filesystem, relative to all previously mounte...
Definition Filesystem.hpp:16
@ HIGHER
Mount the archive at a higher priority than any previously mounted archive, meaning files in the new ...
@ LOWER
Mount the archive at a lower priority than any previously mounted archive, meaning files in already m...
Record of metadata for a specific virtual file.
Definition File.hpp:52
Configuration options for a virtual Filesystem.
Definition Filesystem.hpp:35
FilesystemMountPriority mountPriorityOfArchiveSearchRelativeToDataDirectory
Mount priority of the additional initial archives relative to the main data directory.
Definition Filesystem.hpp:159
FilesystemMountPriority mountPriorityOfArchiveSearchRelativeToOutputDirectory
Mount priority of the additional initial archives relative to the initial write directory.
Definition Filesystem.hpp:147
FilesystemMountPriority mountPriorityOfDataDirectoryRelativeToOutputDirectory
Mount priority of the main data directory relative to the initial write directory.
Definition Filesystem.hpp:135
const char * organizationName
Non-owning pointer to a null-terminated UTF-8 string that commonly identifies the publisher of the ap...
Definition Filesystem.hpp:57
const char * dataDirectory
Non-owning pointer to a null-terminated UTF-8 string of the host filepath to the main data directory ...
Definition Filesystem.hpp:94
const char * archiveSearchPath
Non-owning pointer to a null-terminated UTF-8 string of the virtual filepath to a directory in which ...
Definition Filesystem.hpp:106
const char * archiveSearchFileExtension
Non-owning pointer to a null-terminated UTF-8 string of the filename extension of initial archives to...
Definition Filesystem.hpp:121
const char * applicationName
Non-owning pointer to a null-terminated UTF-8 string that uniquely identifies the application among a...
Definition Filesystem.hpp:80
bool mountOutputDirectory
Mount the initial output directory for reading in addition to writing.
Definition Filesystem.hpp:172