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 "../common.h"
5#include "../util/byte_array.h"
6
7#include <cstdint>
8
9#include <filesystem>
10
11#include <string>
12#include <vector>
13
14namespace oe::io
15{
52
61 {
62 public:
68 FileSystem(const char* argv0 = nullptr);
70
74 bool mount(const std::filesystem::path& real_path, const std::filesystem::path& mount_path, const bool& append = true);
75
79 bool unmount(const std::string& real_path);
80
86 bool mkdir(const std::string& path);
87
93 bool isDir(const std::string& path) const noexcept;
94
98 bool remove(const std::string& path);
99
103 size_t getFileSize(const std::string& filename) const noexcept;
104
108 size_t getLastAccessTime(const std::string& filename) const noexcept;
109
113 size_t getLastModificationTime(const std::string& filename) const noexcept;
114
118 bool fileExists(const std::string& filename) const noexcept;
119
124 ByteArray readFile(const std::string& filename);
125
130 std::string readTextFile(const std::string& filename);
131
139 std::filesystem::path getRealPath(const std::filesystem::path& path) const noexcept;
140
150 std::filesystem::space_info getDiskSpace(const std::filesystem::path& path) const noexcept;
151
158 bool setWritePath(const std::string& real_path);
159
164 std::string getWritePath() const;
165
170 std::vector<std::string> scandir(const std::filesystem::path& directory) const;
171
184 std::string getFilename(const std::string& partial_path, const std::vector<std::string>& allowed_suffixes);
185
186 std::string getBaseDir();
187
197 std::string generatePrefDir(const std::string& organization, const std::string& application);
198
205
211 std::string getLastError() const noexcept;
212
213 inline static FileSystem* getInstance()
214 {
215 return _instance;
216 }
217
218 private:
219 static FileSystem* _instance;
220 };
221}
222
223#endif
Virtual file system wrapper.
Definition file_system.h:61
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:14
FileSystemError
FileSystem error.
Definition file_system.h:20