1#ifndef OE_IO_FILE_SYSTEM_H
2#define OE_IO_FILE_SYSTEM_H
4#include "../util/byte_array.h"
71 bool mount(
const std::filesystem::path& real_path,
const std::filesystem::path& mount_path,
const bool& append =
true);
76 bool unmount(
const std::string& real_path);
83 bool mkdir(
const std::string& path);
90 bool isDir(
const std::string& path)
const noexcept;
95 bool remove(
const std::string& path);
136 std::filesystem::path
getRealPath(
const std::filesystem::path& path)
const noexcept;
147 std::filesystem::space_info
getDiskSpace(
const std::filesystem::path& path)
const noexcept;
167 std::vector<std::string>
scandir(
const std::filesystem::path& directory)
const;
181 std::string
getFilename(
const std::string& partial_path,
const std::vector<std::string>& allowed_suffixes);
183 std::string getBaseDir();
194 std::string
generatePrefDir(
const std::string& organization,
const std::string& application);
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
@ NOT_INITIALIZED
Definition file_system.h:21
@ BAD_FILENAME
Definition file_system.h:41
@ OPEN_FOR_WRITING
Definition file_system.h:33
@ UNSUPPORTED
Definition file_system.h:24
@ READ_ONLY
Definition file_system.h:35
@ NO_WRITE_DIR
Definition file_system.h:31
@ OTHER_ERROR
Definition file_system.h:19
@ DUPLICATE
Definition file_system.h:45
@ NOT_A_FILE
Definition file_system.h:34
@ PERMISSION
Definition file_system.h:39
@ BUSY
Definition file_system.h:42
@ NOT_FOUND
Definition file_system.h:29
@ BAD_PASSWORD
Definition file_system.h:46
@ FILES_STILL_OPEN
Definition file_system.h:26
@ NO_SPACE_LEFT
Definition file_system.h:40
@ NOT_MOUNTED
Definition file_system.h:28
@ PAST_EOF
Definition file_system.h:25
@ OS_ERROR
Definition file_system.h:44
@ IS_INITIALIZED
Definition file_system.h:22
@ SYMLINK_FORBIDDEN
Definition file_system.h:30
@ APP_CALLBACK
Definition file_system.h:47
@ OUT_OF_MEMORY
Definition file_system.h:20
@ OPEN_FOR_READING
Definition file_system.h:32
@ IO
Definition file_system.h:38
@ NO_ERROR
Definition file_system.h:18
@ ARGV0_IS_NULL
Definition file_system.h:23
@ INVALID_ARGUMENT
Definition file_system.h:27
@ SYMLINK_LOOP
Definition file_system.h:37
@ DIR_NOT_EMPTY
Definition file_system.h:43
@ CORRUPT
Definition file_system.h:36