8#include <entt/locator/locator.hpp>
27 return result.value();
30 const auto&
error = result.error();
33 return error.m_reason;
38 auto& lua = entt::locator<sol::state>::value();
65 lua.new_usertype<
FileError>(
"FileError", sol::constructors<FileError(), FileError(const std::string&, const std::string&, const std::filesystem::path&)>());
69 fileerror[
"path"] = [](
const FileError& self) {
70 return self.m_path.string();
78 auto vfs_type = lua.new_usertype<
VirtualFileSystem>(
"VirtualFileSystem", sol::no_constructor);
Stores information about a File I/O error.
void log() const noexcept
Prints the file error in a nice format to the console.
std::string m_reason
Reason for file i/o failure.
std::string m_mode
File I/O mode.
static void inject_fs() noexcept
Injects VFS support into Lua.
File System to make managing files easier.
void alert() noexcept
Trigger a standard filesystem audio alert.
int message_box(const std::string &title, const std::string &msg, const DialogType type, const DialogIcon icon, const DialogButton btn) noexcept
Opens a platform specific message box.
bool is_dir(const std::string &path) noexcept
Checks if a file is a folder.
bool write_binary(std::span< std::uint8_t > data, const std::string &file)
Writes a binary file to disk.
std::vector< std::string > list(const std::string &dir)
Get assets in an asset folder.
std::string read(const std::string &file)
Read a file.
bool write_raw(const void *data, const std::size_t size, const std::string &file)
Raw data writing.
bool write(const std::string &data, const std::string &file)
Writes a file to disk.
void notification(const std::string &title, const std::string &msg, const DialogIcon icon) noexcept
Trigger a system notification.
std::string input_box(const std::string &title, const std::string &msg, const std::string &default_text="", const bool password=false) noexcept
Opens a platform specific text input box.
bool exists(const std::string &file) noexcept
Does the file exist in the vfs.
std::string open_file_dialog(const std::vector< const char * > &filters={}, const std::string &def_path="")
Open a file dialog.
std::string open_save_dialog(const std::string &default_filename, const std::vector< const char * > &filters={})
Open a save file dialog.
std::string select_folder_dialog(const std::string &def_path="")
Select a folder using a dialog.
void remove(const std::string &path) noexcept
Delete a file or folder.
std::vector< std::uint8_t > read_binary(const std::string &file)
Read a binary file.
void mkdir(const std::string &dir) noexcept
Creates an empty folder in the filesystem relative to the root.
std::optional< FileError > write(const std::string &filepath, const std::string &data)
Writes a non-binary file to disk.
void open_url(const std::string &url) noexcept
Open URL in default webbrowser.
std::optional< std::string > extension(const std::string &filepath) noexcept
Get a file or path's extension.
std::expected< std::string, FileError > read(const std::string &filepath)
Read a non-binary file on disk.
DialogButton
Type of button for tinyfd boxes.
DialogType
Type of dialog box for use with tinyfd.
std::string fileutils_read_wrapper(const std::string &filepath) noexcept
DialogIcon
Type of native system icon to display on file dialogs.