2022-08-08 21:23:52 +02:00
|
|
|
#include <hex/api/project_file_manager.hpp>
|
|
|
|
|
2024-01-30 15:50:00 +01:00
|
|
|
#include <hex/helpers/auto_reset.hpp>
|
|
|
|
|
2023-03-12 18:27:29 +01:00
|
|
|
#include <wolv/io/fs.hpp>
|
|
|
|
|
2022-08-08 21:23:52 +02:00
|
|
|
namespace hex {
|
|
|
|
|
2023-07-26 13:50:51 +02:00
|
|
|
namespace {
|
2022-08-08 21:23:52 +02:00
|
|
|
|
2024-01-30 11:21:34 +01:00
|
|
|
AutoReset<std::vector<ProjectFile::Handler>> s_handlers;
|
|
|
|
AutoReset<std::vector<ProjectFile::ProviderHandler>> s_providerHandlers;
|
2023-07-26 13:50:51 +02:00
|
|
|
|
2024-01-30 11:21:34 +01:00
|
|
|
AutoReset<std::fs::path> s_currProjectPath;
|
2023-07-26 13:50:51 +02:00
|
|
|
|
2024-01-30 11:21:34 +01:00
|
|
|
AutoReset<std::function<bool(const std::fs::path&)>> s_loadProjectFunction;
|
|
|
|
AutoReset<std::function<bool(std::optional<std::fs::path>, bool)>> s_storeProjectFunction;
|
2023-07-26 13:50:51 +02:00
|
|
|
|
|
|
|
}
|
2022-08-08 21:23:52 +02:00
|
|
|
|
2022-09-20 15:33:36 +02:00
|
|
|
|
2023-06-21 20:07:36 +02:00
|
|
|
void ProjectFile::setProjectFunctions(
|
|
|
|
const std::function<bool(const std::fs::path&)> &loadFun,
|
2023-07-01 12:32:28 +02:00
|
|
|
const std::function<bool(std::optional<std::fs::path>, bool)> &storeFun
|
2023-06-21 20:07:36 +02:00
|
|
|
) {
|
2023-07-26 13:50:51 +02:00
|
|
|
s_loadProjectFunction = loadFun;
|
|
|
|
s_storeProjectFunction = storeFun;
|
2023-06-21 20:07:36 +02:00
|
|
|
}
|
2023-01-11 23:31:25 +01:00
|
|
|
|
2023-06-21 20:07:36 +02:00
|
|
|
bool ProjectFile::load(const std::fs::path &filePath) {
|
2024-01-30 11:21:34 +01:00
|
|
|
return (*s_loadProjectFunction)(filePath);
|
2022-08-08 21:23:52 +02:00
|
|
|
}
|
|
|
|
|
2023-07-01 12:32:28 +02:00
|
|
|
bool ProjectFile::store(std::optional<std::fs::path> filePath, bool updateLocation) {
|
2024-01-30 11:21:34 +01:00
|
|
|
return (*s_storeProjectFunction)(std::move(filePath), updateLocation);
|
2022-08-08 21:23:52 +02:00
|
|
|
}
|
|
|
|
|
2022-11-25 10:47:11 +01:00
|
|
|
bool ProjectFile::hasPath() {
|
2024-01-30 11:21:34 +01:00
|
|
|
return !s_currProjectPath->empty();
|
2022-11-25 10:47:11 +01:00
|
|
|
}
|
|
|
|
|
2023-01-07 17:31:22 +01:00
|
|
|
void ProjectFile::clearPath() {
|
2024-01-30 11:21:34 +01:00
|
|
|
s_currProjectPath->clear();
|
2023-01-07 17:31:22 +01:00
|
|
|
}
|
2023-02-12 17:52:09 +01:00
|
|
|
|
2023-01-07 17:31:22 +01:00
|
|
|
std::fs::path ProjectFile::getPath() {
|
2023-07-26 13:50:51 +02:00
|
|
|
return s_currProjectPath;
|
2023-01-07 17:31:22 +01:00
|
|
|
}
|
|
|
|
|
2023-02-12 17:52:09 +01:00
|
|
|
void ProjectFile::setPath(const std::fs::path &path) {
|
2023-07-26 13:50:51 +02:00
|
|
|
s_currProjectPath = path;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<ProjectFile::Handler> &ProjectFile::getHandlers() {
|
|
|
|
return s_handlers;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<ProjectFile::ProviderHandler> &ProjectFile::getProviderHandlers() {
|
|
|
|
return s_providerHandlers;
|
2023-02-12 17:52:09 +01:00
|
|
|
}
|
|
|
|
|
2022-08-08 21:23:52 +02:00
|
|
|
}
|