1
0
mirror of synced 2024-12-01 02:37:18 +01:00
ImHex/include/helpers/project_file_handler.hpp
WerWolv e74c0f5cf5 sys: Tons of long overdue cleanup
- std::string -> const std::string& where needed
- Added a FileIO abstraction class
- Fixed recent files not updating
- Removed localization file from global include
- Renamed lang to pattern_language/pl
- Renamed EventFileDropped to RequestFileOpen
2021-09-08 15:18:24 +02:00

105 lines
2.9 KiB
C++

#pragma once
#include <list>
#include <string>
#include <string_view>
#include "patches.hpp"
#include <hex/api/imhex_api.hpp>
#include <hex/api/event.hpp>
#include <filesystem>
namespace hex {
class ProjectFile {
public:
ProjectFile() = delete;
static bool load(const std::string &filePath);
static bool store(std::string filePath = "");
[[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 const std::string& getProjectFilePath() {
return ProjectFile::s_currProjectFilePath;
}
static void clearProjectFilePath() {
ProjectFile::s_currProjectFilePath.clear();
}
[[nodiscard]] static const std::string& getFilePath() {
return ProjectFile::s_filePath;
}
static void setFilePath(const std::string &filePath) {
ProjectFile::s_filePath = filePath;
EventManager::post<RequestChangeWindowTitle>(std::filesystem::path(filePath).filename().string());
}
[[nodiscard]] static const std::string& getPattern() {
return ProjectFile::s_pattern;
}
static void setPattern(const std::string &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;
}
[[nodiscard]] static const std::list<ImHexApi::Bookmarks::Entry>& getBookmarks() {
return ProjectFile::s_bookmarks;
}
static void setBookmarks(const std::list<ImHexApi::Bookmarks::Entry> &bookmarks) {
markDirty();
ProjectFile::s_bookmarks = bookmarks;
}
[[nodiscard]] static const std::string& getDataProcessorContent() {
return ProjectFile::s_dataProcessorContent;
}
static void setDataProcessorContent(const std::string &json) {
markDirty();
ProjectFile::s_dataProcessorContent = json;
}
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;
static inline std::list<ImHexApi::Bookmarks::Entry> s_bookmarks;
static inline std::string s_dataProcessorContent;
};
}