Oxygen Engine
Modern C++ 3D Engine using OpenGL
Loading...
Searching...
No Matches
file_system.h
1#ifndef OE_IO_FILE_SYSTEM_H
2#define OE_IO_FILE_SYSTEM_H
3
4#include "../util/byte_array.h"
5
6#include <filesystem>
7
8#include <string>
9#include <vector>
10
11namespace oe::io
12{
49
58 {
59 public:
65 FileSystem(const char* argv0 = nullptr);
67
71 bool mount(const std::filesystem::path& real_path, const std::filesystem::path& mount_path, const bool& append = true);
72
76 bool unmount(const std::string& real_path);
77
83 bool mkdir(const std::string& path);
84
90 bool isDir(const std::string& path) const noexcept;
91
95 bool remove(const std::string& path);
96
100 size_t getFileSize(const std::string& filename) const noexcept;
101
105 size_t getLastAccessTime(const std::string& filename) const noexcept;
106
110 size_t getLastModificationTime(const std::string& filename) const noexcept;
111
115 bool fileExists(const std::string& filename) const noexcept;
116
121 ByteArray readFile(const std::string& filename);
122
127 std::string readTextFile(const std::string& filename);
128
136 std::filesystem::path getRealPath(const std::filesystem::path& path) const noexcept;
137
147 std::filesystem::space_info getDiskSpace(const std::filesystem::path& path) const noexcept;
148
155 bool setWritePath(const std::string& real_path);
156
161 std::string getWritePath() const;
162
167 std::vector<std::string> scandir(const std::filesystem::path& directory) const;
168
181 std::string getFilename(const std::string& partial_path, const std::vector<std::string>& allowed_suffixes);
182
183 std::string getBaseDir();
184
194 std::string generatePrefDir(const std::string& organization, const std::string& application);
195
202
208 std::string getLastError() const noexcept;
209
210 inline static FileSystem* getInstance()
211 {
212 return _instance;
213 }
214
215 private:
216 static FileSystem* _instance;
217 };
218}
219
220#endif
Virtual file system wrapper.
Definition file_system.h:58
bool isDir(const std::string &path) const noexcept
Check if the path points a dir in the virtual file system.
size_t getLastModificationTime(const std::string &filename) const noexcept
Get a file last modification time in UNIX timestamp.
std::string generatePrefDir(const std::string &organization, const std::string &application)
Get (and create if not already exists) the 'pref dir' where users can write personal files (preferenc...
std::vector< std::string > scandir(const std::filesystem::path &directory) const
Return list of filenames contained in the directory.
bool mount(const std::filesystem::path &real_path, const std::filesystem::path &mount_path, const bool &append=true)
Add an archive or a folder into the virtual file hierarchy.
size_t getFileSize(const std::string &filename) const noexcept
Get a file size in bytes.
std::string getFilename(const std::string &partial_path, const std::vector< std::string > &allowed_suffixes)
Get file location from partial filename without extension and a list of allowed suffixes.
FileSystemError getLastErrorCode() const noexcept
Get last error code.
FileSystem(const char *argv0=nullptr)
Creates a file system.
ByteArray readFile(const std::string &filename)
Read binary file into a ByteArray.
bool unmount(const std::string &real_path)
Remove a previously mounted folder/archive.
std::string readTextFile(const std::string &filename)
Read textual file into a string.
bool mkdir(const std::string &path)
Create a new folder.
std::filesystem::path getRealPath(const std::filesystem::path &path) const noexcept
Get actual folder on the disk where is stored the file/folder in virtual path.
bool fileExists(const std::string &filename) const noexcept
Check if a file exists.
bool remove(const std::string &path)
Remove a file.
std::filesystem::space_info getDiskSpace(const std::filesystem::path &path) const noexcept
Get space information about the disk on which the virtual path is located.
std::string getWritePath() const
Get the path used for writing.
size_t getLastAccessTime(const std::string &filename) const noexcept
Get a file last access time in UNIX timestamp.
std::string getLastError() const noexcept
Get last error description.
bool setWritePath(const std::string &real_path)
Bind a path on the actual disk where write is allowed if real_path not exists, it is recursively crea...
Input/Output abstractions (Filesystem, Network, ...)
Definition file.h:10
FileSystemError
FileSystem error.
Definition file_system.h:17