2020-11-30 00:03:12 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <string>
|
|
|
|
#include <string_view>
|
|
|
|
|
|
|
|
#include "patches.hpp"
|
2021-01-20 20:16:24 +01:00
|
|
|
#include <hex/api/imhex_api.hpp>
|
2021-08-17 13:41:19 +02:00
|
|
|
#include <hex/api/event.hpp>
|
|
|
|
|
2022-03-04 11:36:37 +01:00
|
|
|
#include <hex/helpers/fs.hpp>
|
2020-11-30 00:03:12 +01:00
|
|
|
|
|
|
|
namespace hex {
|
|
|
|
|
|
|
|
class ProjectFile {
|
|
|
|
public:
|
|
|
|
ProjectFile() = delete;
|
|
|
|
|
2022-03-04 11:36:37 +01:00
|
|
|
static bool load(const std::fs::path &filePath);
|
|
|
|
static bool store(std::fs::path filePath = {});
|
2020-11-30 00:03:12 +01:00
|
|
|
|
2021-08-17 13:41:19 +02:00
|
|
|
[[nodiscard]] static bool hasUnsavedChanges() {
|
|
|
|
return ProjectFile::s_hasUnsavedChanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void markDirty() {
|
|
|
|
bool setWindowTitle = !hasUnsavedChanges();
|
|
|
|
|
|
|
|
ProjectFile::s_hasUnsavedChanged = true;
|
|
|
|
|
|
|
|
if (setWindowTitle)
|
2022-03-04 11:36:37 +01:00
|
|
|
EventManager::post<RequestChangeWindowTitle>(std::fs::path(getFilePath()).filename().string());
|
2021-08-17 13:41:19 +02:00
|
|
|
}
|
|
|
|
|
2022-03-04 11:36:37 +01:00
|
|
|
[[nodiscard]] static const std::fs::path &getProjectFilePath() {
|
2021-08-17 13:41:19 +02:00
|
|
|
return ProjectFile::s_currProjectFilePath;
|
|
|
|
}
|
|
|
|
|
2021-08-17 22:54:09 +02:00
|
|
|
static void clearProjectFilePath() {
|
|
|
|
ProjectFile::s_currProjectFilePath.clear();
|
|
|
|
}
|
|
|
|
|
2021-08-17 13:41:19 +02:00
|
|
|
|
2022-03-04 11:36:37 +01:00
|
|
|
[[nodiscard]] static const std::fs::path &getFilePath() {
|
2021-08-17 13:41:19 +02:00
|
|
|
return ProjectFile::s_filePath;
|
|
|
|
}
|
|
|
|
|
2022-03-04 11:36:37 +01:00
|
|
|
static void setFilePath(const std::fs::path &filePath) {
|
2021-08-17 13:41:19 +02:00
|
|
|
ProjectFile::s_filePath = filePath;
|
|
|
|
|
2022-01-16 01:51:31 +01:00
|
|
|
EventManager::post<RequestChangeWindowTitle>(filePath.filename().string());
|
2021-08-17 13:41:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
[[nodiscard]] static const std::string &getPattern() {
|
2021-08-17 13:41:19 +02:00
|
|
|
return ProjectFile::s_pattern;
|
|
|
|
}
|
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
static void setPattern(const std::string &pattern) {
|
2021-08-17 13:41:19 +02:00
|
|
|
markDirty();
|
|
|
|
ProjectFile::s_pattern = pattern;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
[[nodiscard]] static const Patches &getPatches() {
|
2021-08-17 13:41:19 +02:00
|
|
|
return ProjectFile::s_patches;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setPatches(const Patches &patches) {
|
|
|
|
markDirty();
|
|
|
|
ProjectFile::s_patches = patches;
|
|
|
|
}
|
2020-11-30 00:03:12 +01:00
|
|
|
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
[[nodiscard]] static const std::list<ImHexApi::Bookmarks::Entry> &getBookmarks() {
|
2021-08-17 13:41:19 +02:00
|
|
|
return ProjectFile::s_bookmarks;
|
|
|
|
}
|
2020-11-30 00:03:12 +01:00
|
|
|
|
2021-08-17 13:41:19 +02:00
|
|
|
static void setBookmarks(const std::list<ImHexApi::Bookmarks::Entry> &bookmarks) {
|
|
|
|
markDirty();
|
|
|
|
ProjectFile::s_bookmarks = bookmarks;
|
|
|
|
}
|
2020-11-30 00:03:12 +01:00
|
|
|
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
[[nodiscard]] static const std::string &getDataProcessorContent() {
|
2021-08-17 13:41:19 +02:00
|
|
|
return ProjectFile::s_dataProcessorContent;
|
|
|
|
}
|
2020-11-30 00:03:12 +01:00
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
static void setDataProcessorContent(const std::string &json) {
|
2021-08-17 13:41:19 +02:00
|
|
|
markDirty();
|
|
|
|
ProjectFile::s_dataProcessorContent = json;
|
|
|
|
}
|
2021-05-18 18:06:47 +02:00
|
|
|
|
2020-11-30 00:03:12 +01:00
|
|
|
private:
|
2022-03-04 11:36:37 +01:00
|
|
|
static std::fs::path s_currProjectFilePath;
|
2021-12-16 10:07:31 +01:00
|
|
|
static bool s_hasUnsavedChanged;
|
|
|
|
|
2022-03-04 11:36:37 +01:00
|
|
|
static std::fs::path s_filePath;
|
2021-12-16 10:07:31 +01:00
|
|
|
static std::string s_pattern;
|
|
|
|
static Patches s_patches;
|
|
|
|
static std::list<ImHexApi::Bookmarks::Entry> s_bookmarks;
|
|
|
|
static std::string s_dataProcessorContent;
|
2020-11-30 00:03:12 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|