1
0
mirror of synced 2025-01-19 01:24:15 +01:00

fix: Custom data inspector rows not being writable correctly

This commit is contained in:
WerWolv 2023-03-21 13:16:22 +01:00
parent 8731b7582b
commit d82f0e952f
2 changed files with 29 additions and 19 deletions

View File

@ -39,6 +39,8 @@ namespace hex::plugin::builtin {
TaskHolder m_updateTask;
std::string m_editingValue = "";
pl::PatternLanguage m_runtime;
};
}

View File

@ -85,10 +85,9 @@ namespace hex::plugin::builtin {
{ "numberDisplayStyle", u128(numberDisplayStyle) }
};
pl::PatternLanguage runtime;
ContentRegistry::PatternLanguage::configureRuntime(runtime, nullptr);
ContentRegistry::PatternLanguage::configureRuntime(this->m_runtime, this->m_selectedProvider);
runtime.setDataSource(this->m_selectedProvider->getBaseAddress(), this->m_selectedProvider->getActualSize(),
this->m_runtime.setDataSource(this->m_selectedProvider->getBaseAddress(), this->m_selectedProvider->getActualSize(),
[this, invert](u64 offset, u8 *buffer, size_t size) {
this->m_selectedProvider->read(offset, buffer, size);
@ -98,9 +97,9 @@ namespace hex::plugin::builtin {
}
});
runtime.setDangerousFunctionCallHandler([]{ return false; });
runtime.setDefaultEndian(endian);
runtime.setStartAddress(startAddress);
this->m_runtime.setDangerousFunctionCallHandler([]{ return false; });
this->m_runtime.setDefaultEndian(endian);
this->m_runtime.setStartAddress(startAddress);
for (const auto &folderPath : fs::getDefaultPaths(fs::ImHexPath::Inspectors)) {
for (const auto &filePath : std::fs::recursive_directory_iterator(folderPath)) {
@ -112,8 +111,8 @@ namespace hex::plugin::builtin {
auto inspectorCode = file.readString();
if (!inspectorCode.empty()) {
if (runtime.executeString(inspectorCode, {}, inVariables, true)) {
const auto &patterns = runtime.getAllPatterns();
if (this->m_runtime.executeString(inspectorCode, {}, inVariables, true)) {
const auto &patterns = this->m_runtime.getAllPatterns();
for (const auto &pattern : patterns) {
if (pattern->getVisibility() == pl::ptrn::Visibility::Hidden)
@ -123,24 +122,33 @@ namespace hex::plugin::builtin {
std::optional<ContentRegistry::DataInspector::impl::EditingFunction> editingFunction;
if (!formatWriteFunction.empty()) {
editingFunction = [formatWriteFunction, &pattern](const std::string &value, std::endian) -> std::vector<u8> {
pattern->setValue(value);
try {
pattern->setValue(value);
} catch (const pl::core::err::EvaluatorError::Exception &error) {
log::error("Failed to set value of pattern '{}' to '{}': {}", pattern->getDisplayName(), value, error.what());
return { };
}
return { };
};
}
this->m_workData.push_back({
pattern->getDisplayName(),
[value = pattern->getFormattedValue()]() {
ImGui::TextUnformatted(value.c_str());
return value;
},
editingFunction,
false
});
try {
this->m_workData.push_back({
pattern->getDisplayName(),
[value = pattern->getFormattedValue()]() {
ImGui::TextUnformatted(value.c_str());
return value;
},
editingFunction,
false
});
} catch (const pl::core::err::EvaluatorError::Exception &error) {
log::error("Failed to get value of pattern '{}': {}", pattern->getDisplayName(), error.what());
}
}
} else {
const auto& error = runtime.getError();
const auto& error = this->m_runtime.getError();
log::error("Failed to execute custom inspector file '{}'!", wolv::util::toUTF8String(filePath.path()));
if (error.has_value())