1
0
mirror of synced 2024-11-28 09:30:51 +01:00

ux: Improve loading of encoding files, make advanced encoding enabled by default

This commit is contained in:
WerWolv 2022-01-15 23:44:15 +01:00
parent 1f65fbf422
commit 8a6b110d0b
5 changed files with 14 additions and 3 deletions

View File

@ -54,6 +54,7 @@ namespace hex::plugin::builtin {
u8 m_highlightAlpha = 0x80; u8 m_highlightAlpha = 0x80;
bool m_processingImportExport = false; bool m_processingImportExport = false;
bool m_advancedDecodingEnabled = false;
void drawSearchPopup(); void drawSearchPopup();
void drawGotoPopup(); void drawGotoPopup();

View File

@ -177,7 +177,7 @@ namespace hex::plugin::builtin {
return false; return false;
}); });
ContentRegistry::Settings::add("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.advanced_decoding", 0, [](auto name, nlohmann::json &setting) { ContentRegistry::Settings::add("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.advanced_decoding", 1, [](auto name, nlohmann::json &setting) {
static bool advancedDecoding = static_cast<int>(setting); static bool advancedDecoding = static_cast<int>(setting);
if (ImGui::Checkbox(name.data(), &advancedDecoding)) { if (ImGui::Checkbox(name.data(), &advancedDecoding)) {

View File

@ -179,6 +179,8 @@ namespace hex::plugin::builtin {
this->m_memoryEditor.DrawWindow(View::toWindowName("hex.builtin.view.hexeditor.name").c_str(), &this->getWindowOpenState(), this, dataSize, dataSize == 0 ? 0x00 : provider->getBaseAddress() + provider->getCurrentPageAddress()); this->m_memoryEditor.DrawWindow(View::toWindowName("hex.builtin.view.hexeditor.name").c_str(), &this->getWindowOpenState(), this, dataSize, dataSize == 0 ? 0x00 : provider->getBaseAddress() + provider->getCurrentPageAddress());
if (dataSize != 0x00) { if (dataSize != 0x00) {
this->m_memoryEditor.OptShowAdvancedDecoding = this->m_advancedDecodingEnabled && this->m_currEncodingFile.valid();
if (ImGui::Begin(View::toWindowName("hex.builtin.view.hexeditor.name").c_str())) { if (ImGui::Begin(View::toWindowName("hex.builtin.view.hexeditor.name").c_str())) {
if (ImGui::IsMouseReleased(ImGuiMouseButton_Right) && ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows)) if (ImGui::IsMouseReleased(ImGuiMouseButton_Right) && ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows))
@ -421,7 +423,7 @@ namespace hex::plugin::builtin {
} }
if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.load_encoding_file"_lang)) { if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.load_encoding_file"_lang)) {
hex::openFileBrowser("hex.builtin.view.hexeditor.load_enconding_file"_lang, DialogMode::Open, { }, [this](auto path) { hex::openFileBrowser("hex.builtin.view.hexeditor.load_enconding_file"_lang, DialogMode::Open, { { "Thingy Table File", "tbl" } }, [this](auto path) {
this->m_currEncodingFile = EncodingFile(EncodingFile::Type::Thingy, path); this->m_currEncodingFile = EncodingFile(EncodingFile::Type::Thingy, path);
}); });
} }
@ -1133,7 +1135,7 @@ namespace hex::plugin::builtin {
auto advancedDecoding = ContentRegistry::Settings::getSetting("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.advanced_decoding"); auto advancedDecoding = ContentRegistry::Settings::getSetting("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.advanced_decoding");
if (advancedDecoding.is_number()) if (advancedDecoding.is_number())
this->m_memoryEditor.OptShowAdvancedDecoding = static_cast<int>(advancedDecoding); this->m_advancedDecodingEnabled = static_cast<int>(advancedDecoding);
} }
{ {

View File

@ -28,9 +28,15 @@ namespace hex {
[[nodiscard]] std::pair<std::string_view, size_t> getEncodingFor(const std::vector<u8> &buffer) const; [[nodiscard]] std::pair<std::string_view, size_t> getEncodingFor(const std::vector<u8> &buffer) const;
[[nodiscard]] size_t getLongestSequence() const { return this->m_longestSequence; } [[nodiscard]] size_t getLongestSequence() const { return this->m_longestSequence; }
bool valid() const {
return this->m_valid;
}
private: private:
void parseThingyFile(std::ifstream &content); void parseThingyFile(std::ifstream &content);
bool m_valid = false;
std::map<u32, std::map<std::vector<u8>, std::string>> m_mapping; std::map<u32, std::map<std::vector<u8>, std::string>> m_mapping;
size_t m_longestSequence = 0; size_t m_longestSequence = 0;
}; };

View File

@ -13,6 +13,8 @@ namespace hex {
case Type::Thingy: parseThingyFile(encodingFile); break; case Type::Thingy: parseThingyFile(encodingFile); break;
default: throw std::runtime_error("Invalid encoding file type"); default: throw std::runtime_error("Invalid encoding file type");
} }
this->m_valid = true;
} }
std::pair<std::string_view, size_t> EncodingFile::getEncodingFor(const std::vector<u8> &buffer) const { std::pair<std::string_view, size_t> EncodingFile::getEncodingFor(const std::vector<u8> &buffer) const {