fix: Potential crash when loading incorrect data processor node files
This commit is contained in:
parent
aac9bf3896
commit
52c517d38d
@ -1,4 +1,5 @@
|
|||||||
#include "content/views/view_data_processor.hpp"
|
#include "content/views/view_data_processor.hpp"
|
||||||
|
#include "content/popups/popup_notification.hpp"
|
||||||
|
|
||||||
#include <hex/api/content_registry.hpp>
|
#include <hex/api/content_registry.hpp>
|
||||||
|
|
||||||
@ -7,6 +8,7 @@
|
|||||||
#include <hex/providers/provider.hpp>
|
#include <hex/providers/provider.hpp>
|
||||||
#include <hex/api/project_file_manager.hpp>
|
#include <hex/api/project_file_manager.hpp>
|
||||||
|
|
||||||
|
|
||||||
#include <imnodes.h>
|
#include <imnodes.h>
|
||||||
#include <imnodes_internal.h>
|
#include <imnodes_internal.h>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
@ -358,7 +360,7 @@ namespace hex::plugin::builtin {
|
|||||||
ViewDataProcessor::processNodes(*this->m_workspaceStack->back());
|
ViewDataProcessor::processNodes(*this->m_workspaceStack->back());
|
||||||
});
|
});
|
||||||
|
|
||||||
/* Import bookmarks */
|
/* Import Nodes */
|
||||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.menu.file.import", "hex.builtin.menu.file.import.data_processor" }, 4050, Shortcut::None, [this]{
|
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.menu.file.import", "hex.builtin.menu.file.import.data_processor" }, 4050, Shortcut::None, [this]{
|
||||||
fs::openFileBrowser(fs::DialogMode::Open, { {"hex.builtin.view.data_processor.name"_lang, "hexnode" } },
|
fs::openFileBrowser(fs::DialogMode::Open, { {"hex.builtin.view.data_processor.name"_lang, "hexnode" } },
|
||||||
[&](const std::fs::path &path) {
|
[&](const std::fs::path &path) {
|
||||||
@ -370,7 +372,7 @@ namespace hex::plugin::builtin {
|
|||||||
});
|
});
|
||||||
}, ImHexApi::Provider::isValid);
|
}, ImHexApi::Provider::isValid);
|
||||||
|
|
||||||
/* Export bookmarks */
|
/* Export Nodes */
|
||||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.menu.file.export", "hex.builtin.menu.file.export.data_processor" }, 8050, Shortcut::None, [this]{
|
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.menu.file.export", "hex.builtin.menu.file.export.data_processor" }, 8050, Shortcut::None, [this]{
|
||||||
fs::openFileBrowser(fs::DialogMode::Save, { {"hex.builtin.view.data_processor.name"_lang, "hexnode" } },
|
fs::openFileBrowser(fs::DialogMode::Save, { {"hex.builtin.view.data_processor.name"_lang, "hexnode" } },
|
||||||
[&, this](const std::fs::path &path) {
|
[&, this](const std::fs::path &path) {
|
||||||
@ -940,6 +942,7 @@ namespace hex::plugin::builtin {
|
|||||||
workspace.endNodes.clear();
|
workspace.endNodes.clear();
|
||||||
workspace.links.clear();
|
workspace.links.clear();
|
||||||
|
|
||||||
|
try {
|
||||||
for (auto &node : jsonData["nodes"]) {
|
for (auto &node : jsonData["nodes"]) {
|
||||||
auto newNode = loadNode(node);
|
auto newNode = loadNode(node);
|
||||||
if (newNode == nullptr)
|
if (newNode == nullptr)
|
||||||
@ -1021,6 +1024,9 @@ namespace hex::plugin::builtin {
|
|||||||
dp::Link::setIdCounter(maxLinkId + 1);
|
dp::Link::setIdCounter(maxLinkId + 1);
|
||||||
|
|
||||||
ViewDataProcessor::processNodes(workspace);
|
ViewDataProcessor::processNodes(workspace);
|
||||||
|
} catch (nlohmann::json::exception &e) {
|
||||||
|
PopupError::open(hex::format("Failed to load nodes: {}", e.what()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user