47 if (!PHYSFS_init(
nullptr))
49 debug::log_error(
"Failed to initialize PhysicsFS: {}", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
50 throw std::runtime_error(
"Failed to initialize PhysicsFS");
64 debug::log_error(
"Failed to deinitialize PhysicsFS: {}", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
74 const std::string path_string = path.string();
78 if (!PHYSFS_mount(path_string.c_str(),
nullptr, 1))
80 debug::log_error(
"Failed to mount path \"{}\": {}", path_string, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
91 const std::string path_string = path.string();
95 if (!PHYSFS_unmount(path_string.c_str()))
97 debug::log_error(
"Failed to unmount path \"{}\": {}", path_string, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
108 const std::string path_string = path.string();
110 if (!PHYSFS_setWriteDir(path_string.c_str()))
112 debug::log_error(
"Failed set write path to \"{}\": {}", path_string, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
123 std::shared_ptr<void> resource_manager::fetch(
const std::filesystem::path& path)
const
125 if (
auto i = resource_cache.find(path); i != resource_cache.end())
127 if (!i->second.expired())
129 return i->second.lock();
133 debug::log_trace(
"Fetched expired resource from cache \"{}\"", path.string());
140 std::unique_ptr<deserialize_context> resource_manager::open_read(
const std::filesystem::path& path)
const
142 auto ctx = std::make_unique<physfs_deserialize_context>(path);
145 debug::log_error(
"Failed to open file \"{}\" for reading: {}", path.string(), PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
152 std::unique_ptr<serialize_context> resource_manager::open_write(
const std::filesystem::path& path)
const
154 auto ctx = std::make_unique<physfs_serialize_context>(path);
157 debug::log_error(
"Failed to open file \"{}\" for writing: {}", path.string(), PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
bool set_write_path(const std::filesystem::path &path)
Sets the path to a directory or archive where files can be written.
bool unmount(const std::filesystem::path &path)
Removes a directory or archive from the search path.
resource_manager()
Constructs a resource manager.
bool mount(const std::filesystem::path &path)
Adds a directory or archive to the search path.
~resource_manager()
Destructs a resource manager.
log_message< log_message_severity::trace, Args... > log_trace
Formats and logs a trace message.
log_message< log_message_severity::error, Args... > log_error
Formats and logs an error message.