1
0
mirror of synced 2024-11-15 11:33:23 +01:00
ImHex/include/helpers/project_file_handler.hpp

105 lines
2.9 KiB
C++
Raw Normal View History

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>
#include <filesystem>
2020-11-30 00:03:12 +01:00
namespace hex {
class ProjectFile {
public:
ProjectFile() = delete;
static bool load(std::string_view filePath);
static bool store(std::string_view filePath = "");
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)
EventManager::post<RequestChangeWindowTitle>(std::filesystem::path(getFilePath()).filename().string());
}
[[nodiscard]] static std::string getProjectFilePath() {
return ProjectFile::s_currProjectFilePath;
}
static void clearProjectFilePath() {
ProjectFile::s_currProjectFilePath.clear();
}
2021-08-17 13:41:19 +02:00
[[nodiscard]] static std::string getFilePath() {
return ProjectFile::s_filePath;
}
static void setFilePath(std::string_view filePath) {
ProjectFile::s_filePath = filePath;
EventManager::post<RequestChangeWindowTitle>(std::filesystem::path(filePath).filename().string());
}
[[nodiscard]] static std::string getPattern() {
return ProjectFile::s_pattern;
}
static void setPattern(std::string_view pattern) {
markDirty();
ProjectFile::s_pattern = pattern;
}
[[nodiscard]] static const Patches& getPatches() {
return ProjectFile::s_patches;
}
static void setPatches(const Patches &patches) {
markDirty();
ProjectFile::s_patches = patches;
}
2020-11-30 00:03:12 +01:00
2021-08-17 13:41:19 +02:00
[[nodiscard]] static const std::list<ImHexApi::Bookmarks::Entry>& getBookmarks() {
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
2021-08-17 13:41:19 +02:00
[[nodiscard]] static const std::string_view getDataProcessorContent() {
return ProjectFile::s_dataProcessorContent;
}
2020-11-30 00:03:12 +01:00
2021-08-17 13:41:19 +02:00
static void setDataProcessorContent(std::string_view json) {
markDirty();
ProjectFile::s_dataProcessorContent = json;
}
2020-11-30 00:03:12 +01:00
private:
static inline std::string s_currProjectFilePath;
static inline bool s_hasUnsavedChanged = false;
static inline std::string s_filePath;
static inline std::string s_pattern;
static inline Patches s_patches;
2021-01-20 20:16:24 +01:00
static inline std::list<ImHexApi::Bookmarks::Entry> s_bookmarks;
static inline std::string s_dataProcessorContent;
2020-11-30 00:03:12 +01:00
};
}