fix: In/Out variables not working, add recusive pattern scan (#579)

This commit is contained in:
Lukas Cone 2022-07-14 11:37:02 +02:00 committed by GitHub
parent 315109aa1f
commit 35c209c791
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 13 deletions

View File

@ -56,7 +56,6 @@ namespace hex::plugin::builtin {
}; };
std::map<std::string, PatternVariable> m_patternVariables; std::map<std::string, PatternVariable> m_patternVariables;
std::vector<std::string> m_patternTypes;
enum class EnvVarType enum class EnvVarType
{ {
@ -102,4 +101,4 @@ namespace hex::plugin::builtin {
void evaluatePattern(const std::string &code); void evaluatePattern(const std::string &code);
}; };
} }

View File

@ -93,9 +93,7 @@ namespace hex::plugin::builtin {
}); });
EventManager::subscribe<RequestSetPatternLanguageCode>(this, [this](const std::string &code) { EventManager::subscribe<RequestSetPatternLanguageCode>(this, [this](const std::string &code) {
this->m_textEditor.SelectAll(); this->m_textEditor.SetText(code);
this->m_textEditor.Delete();
this->m_textEditor.InsertText(code);
}); });
EventManager::subscribe<EventFileLoaded>(this, [this](const std::fs::path &path) { EventManager::subscribe<EventFileLoaded>(this, [this](const std::fs::path &path) {
@ -127,7 +125,7 @@ namespace hex::plugin::builtin {
std::error_code errorCode; std::error_code errorCode;
for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Patterns)) { for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Patterns)) {
for (auto &entry : std::fs::directory_iterator(dir, errorCode)) { for (auto &entry : std::fs::recursive_directory_iterator(dir, errorCode)) {
foundCorrectType = false; foundCorrectType = false;
if (!entry.is_regular_file()) if (!entry.is_regular_file())
continue; continue;
@ -558,25 +556,27 @@ namespace hex::plugin::builtin {
if (variable.outVariable) { if (variable.outVariable) {
ImGui::TextUnformatted(pl::Token::literalToString(variable.value, true).c_str()); ImGui::TextUnformatted(pl::Token::literalToString(variable.value, true).c_str());
} else if (variable.inVariable) { } else if (variable.inVariable) {
const std::string label { "##" + name };
if (pl::Token::isSigned(variable.type)) { if (pl::Token::isSigned(variable.type)) {
i64 value = hex::get_or<i128>(variable.value, 0); i64 value = hex::get_or<i128>(variable.value, 0);
ImGui::InputScalar("", ImGuiDataType_S64, &value); ImGui::InputScalar(label.c_str(), ImGuiDataType_S64, &value);
variable.value = i128(value); variable.value = i128(value);
} else if (pl::Token::isUnsigned(variable.type)) { } else if (pl::Token::isUnsigned(variable.type)) {
u64 value = hex::get_or<u128>(variable.value, 0); u64 value = hex::get_or<u128>(variable.value, 0);
ImGui::InputScalar("", ImGuiDataType_U64, &value); ImGui::InputScalar(label.c_str(), ImGuiDataType_U64, &value);
variable.value = u128(value); variable.value = u128(value);
} else if (pl::Token::isFloatingPoint(variable.type)) { } else if (pl::Token::isFloatingPoint(variable.type)) {
double value = hex::get_or<double>(variable.value, 0.0); double value = hex::get_or<double>(variable.value, 0.0);
ImGui::InputScalar("", ImGuiDataType_Double, &value); ImGui::InputScalar(label.c_str(), ImGuiDataType_Double, &value);
variable.value = value; variable.value = value;
} else if (variable.type == pl::Token::ValueType::Boolean) { } else if (variable.type == pl::Token::ValueType::Boolean) {
bool value = hex::get_or<bool>(variable.value, false); bool value = hex::get_or<bool>(variable.value, false);
ImGui::Checkbox("", &value); ImGui::Checkbox(label.c_str(), &value);
variable.value = value; variable.value = value;
} else if (variable.type == pl::Token::ValueType::Character) { } else if (variable.type == pl::Token::ValueType::Character) {
char buffer[2]; char buffer[2];
ImGui::InputText("", buffer, 2); ImGui::InputText(label.c_str(), buffer, 2);
variable.value = buffer[0]; variable.value = buffer[0];
} }
} }
@ -717,7 +717,6 @@ namespace hex::plugin::builtin {
auto ast = this->m_parserRuntime->parseString(code); auto ast = this->m_parserRuntime->parseString(code);
this->m_patternVariables.clear(); this->m_patternVariables.clear();
this->m_patternTypes.clear();
if (ast) { if (ast) {
for (auto &node : *ast) { for (auto &node : *ast) {
@ -752,7 +751,7 @@ namespace hex::plugin::builtin {
this->m_textEditor.SetErrorMarkers({}); this->m_textEditor.SetErrorMarkers({});
this->m_console.clear(); this->m_console.clear();
this->clearPatterns(); ImHexApi::Provider::get()->getPatternLanguageRuntime().reset();
EventManager::post<EventHighlightingChanged>(); EventManager::post<EventHighlightingChanged>();