1
0
mirror of synced 2024-09-25 03:58:27 +02:00

fix: Loading a project crashes imhex

This commit is contained in:
WerWolv 2021-12-16 10:07:31 +01:00
parent 79ace0a106
commit 6b22464771
3 changed files with 27 additions and 14 deletions

View File

@ -31,7 +31,11 @@ namespace hex::plugin::builtin {
});
EventManager::subscribe<EventProjectFileLoad>(this, [this] {
try {
this->loadNodes(ProjectFile::getDataProcessorContent());
} catch (nlohmann::json::exception &e) {
}
});
EventManager::subscribe<EventFileLoaded>(this, [this](const std::string &path){

View File

@ -92,14 +92,14 @@ namespace hex {
}
private:
static inline std::string s_currProjectFilePath;
static inline bool s_hasUnsavedChanged = false;
static std::string s_currProjectFilePath;
static bool s_hasUnsavedChanged;
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;
static std::string s_filePath;
static std::string s_pattern;
static Patches s_patches;
static std::list<ImHexApi::Bookmarks::Entry> s_bookmarks;
static std::string s_dataProcessorContent;
};
}

View File

@ -9,6 +9,15 @@ using json = nlohmann::json;
namespace hex {
std::string ProjectFile::s_currProjectFilePath;
bool ProjectFile::s_hasUnsavedChanged = false;
std::string ProjectFile::s_filePath;
std::string ProjectFile::s_pattern;
Patches ProjectFile::s_patches;
std::list<ImHexApi::Bookmarks::Entry> ProjectFile::s_bookmarks;
std::string ProjectFile::s_dataProcessorContent;
void to_json(json& j, const ImHexApi::Bookmarks::Entry& b) {
j = json{ { "address", b.region.address }, { "size", b.region.size }, { "name", b.name.data() }, { "comment", b.comment.data() }, { "locked", b.locked }, { "color", b.color } };
}
@ -16,12 +25,12 @@ namespace hex {
void from_json(const json& j, ImHexApi::Bookmarks::Entry& b) {
std::string name, comment;
j.at("address").get_to(b.region.address);
j.at("size").get_to(b.region.size);
j.at("name").get_to(name);
j.at("comment").get_to(comment);
j.at("locked").get_to(b.locked);
j.at("color").get_to(b.color);
if (j.contains("address")) j.at("address").get_to(b.region.address);
if (j.contains("size")) j.at("size").get_to(b.region.size);
if (j.contains("name")) j.at("name").get_to(name);
if (j.contains("comment")) j.at("comment").get_to(comment);
if (j.contains("locked")) j.at("locked").get_to(b.locked);
if (j.contains("color")) j.at("color").get_to(b.color);
std::copy(name.begin(), name.end(), std::back_inserter(b.name));
b.name.push_back('\0');