8#include <entt/locator/locator.hpp>
11#include <tinyfiledialogs.h>
21#ifdef GALAXY_WIN_PLATFORM
38 PHYSFS_Allocator a = {};
43 a.Realloc = mi_realloc;
49 PHYSFS_permitSymbolicLinks(
false);
52 write_dir.make_preferred();
56 read_dir.make_preferred();
87 PHYSFS_File* f = PHYSFS_openRead(file.c_str());
90 const auto len = PHYSFS_fileLength(f);
123 PHYSFS_File* f = PHYSFS_openRead(file.c_str());
126 const auto len = PHYSFS_fileLength(f);
130 std::vector<std::uint8_t> buffer;
159 return write_raw(data.data(), data.size() *
sizeof(
char), file);
164 return write_raw(data.data(), data.size_bytes(), file);
169 auto path = std::filesystem::path(file);
170 if (path.is_absolute())
172 path = path.filename();
175 PHYSFS_File* f = PHYSFS_openWrite(path.string().c_str());
178 const auto len = PHYSFS_fileLength(f);
214 return PHYSFS_exists(file.c_str());
219 return PHYSFS_isDirectory(path.c_str());
224 std::vector<std::string>
list;
228 [](
void* data,
const char* origdir,
const char* fname) -> PHYSFS_EnumerateCallbackResult {
229 if (data != nullptr && fname != nullptr)
231 std::string o = origdir;
232 std::string f = fname;
234 auto* my_list = static_cast<std::vector<std::string>*>(data);
235 my_list->emplace_back(o + f);
238 return PHYSFS_ENUM_OK;
246 void VirtualFileSystem::alert() noexcept
251 void VirtualFileSystem::notification(
const std::string& title,
const std::string& msg,
const DialogIcon icon)
noexcept
253 std::string tinyfd_icon {magic_enum::enum_name(icon)};
254 tinyfd_notifyPopup(title.c_str(), msg.c_str(), tinyfd_icon.c_str());
259 std::string tinyfd_type {magic_enum::enum_name(type)};
260 std::string tinyfd_icon {magic_enum::enum_name(icon)};
262 return tinyfd_messageBox(title.c_str(), msg.c_str(), tinyfd_type.c_str(), tinyfd_icon.c_str(),
static_cast<int>(btn));
265 std::string VirtualFileSystem::input_box(
const std::string& title,
const std::string& msg,
const std::string& default_text,
const bool password)
noexcept
267 const char* dt = password ? nullptr : default_text.c_str();
268 return tinyfd_inputBox(title.c_str(), msg.c_str(), dt);
271 std::string VirtualFileSystem::open_save_dialog(
const std::string& default_filename,
const std::vector<const char*>& filters)
273 const char*
const* filter_patterns = (filters.size() > 0) ? filters.data() :
nullptr;
274 const char* result = tinyfd_saveFileDialog(
"Save file", default_filename.c_str(),
static_cast<int>(filters.size()), filter_patterns,
nullptr);
276 if (result !=
nullptr)
286 std::string VirtualFileSystem::open_file_dialog(
const std::vector<const char*>& filters,
const std::string& def_path)
288 const auto default_path = (Settings::root_dir() / def_path).
string();
290 const char*
const* filter_patterns = (filters.size() > 0) ? filters.data() :
nullptr;
291 const char* result = tinyfd_openFileDialog(
"Open file", default_path.c_str(),
static_cast<int>(filters.size()), filter_patterns,
"Select a file",
false);
293 if (result !=
nullptr)
303 std::string VirtualFileSystem::select_folder_dialog(
const std::string& def_path)
305 const auto default_path = (Settings::root_dir() / def_path).
string();
306 const char* result = tinyfd_selectFolderDialog(
"Select folder", default_path.c_str());
308 if (result !=
nullptr)
319#ifdef GALAXY_WIN_PLATFORM
#define GALAXY_LOG(level, msg,...)
#define GALAXY_DISABLE_WARNING_POP
#define GALAXY_DISABLE_WARNING(x)
#define GALAXY_DISABLE_WARNING_PUSH
Macro for windows platform detection.
~VirtualFileSystem() noexcept
Destructor.
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.
bool exists(const std::string &file) noexcept
Does the file exist in the vfs.
void remove(const std::string &path) noexcept
Delete a file or folder.
VirtualFileSystem() noexcept
Constructor.
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.
bool physfs_check(const int code) noexcept
Call a physfs function with error handling and logs a message for you.
DialogButton
Type of button for tinyfd boxes.
DialogType
Type of dialog box for use with tinyfd.
DialogIcon
Type of native system icon to display on file dialogs.
static auto root_dir() noexcept -> std::filesystem::path
Current root directory of application, unless it has been changed.
static auto assets_dir_prefabs() noexcept -> const std::string &
Prefab asset location.
static auto assets_dir_texture() noexcept -> const std::string &
Textures asset location.
static auto assets_dir_voice() noexcept -> const std::string &
Voice asset location.
static auto assets_dir_shaders() noexcept -> const std::string &
Shaders asset location.
static auto assets_dir_ui() noexcept -> const std::string &
UI asset location.
static auto use_loose_assets() noexcept -> bool
Should asset data be read from pack or assets dir.
static auto assets_dir_animation() noexcept -> const std::string &
Animation data location.
static auto assets_dir_script() noexcept -> const std::string &
Scripts asset location.
static auto assets_dir_music() noexcept -> const std::string &
Music asset location.
static auto assets_dir() noexcept -> std::filesystem::path
Main data directory.
static auto asset_pack() noexcept -> const std::string &
Name of packed assets file.
static auto assets_dir_sfx() noexcept -> const std::string &
SFX asset location.
static auto assets_dir_maps() noexcept -> const std::string &
Maps asset location.
static auto assets_dir_video() noexcept -> const std::string &
Video asset location.
static auto assets_dir_font() noexcept -> const std::string &
Font asset location.