fix: Provider information in information view always showing info from current provider

This commit is contained in:
WerWolv 2024-01-09 16:48:49 +01:00
parent d5c8021b41
commit 58441634d6
2 changed files with 10 additions and 4 deletions

View File

@ -33,6 +33,7 @@ namespace hex::plugin::builtin {
Region m_analysisRegion = { 0, 0 };
Region m_analyzedRegion = { 0, 0 };
prv::Provider *m_analyzedProvider = nullptr;
std::string m_dataDescription;
std::string m_dataMimeType;

View File

@ -41,8 +41,11 @@ namespace hex::plugin::builtin {
}
});
EventProviderDeleted::subscribe(this, [this](const auto*) {
m_dataValid = false;
EventProviderDeleted::subscribe(this, [this](const auto *provider) {
if (provider == m_analyzedProvider) {
m_dataValid = false;
m_analyzedProvider = nullptr;
}
});
ContentRegistry::FileHandler::add({ ".mgc" }, [](const auto &path) {
@ -69,6 +72,8 @@ namespace hex::plugin::builtin {
m_analyzerTask = TaskManager::createTask("hex.builtin.view.information.analyzing", 0, [this](auto &task) {
auto provider = ImHexApi::Provider::get();
m_analyzedProvider = provider;
if ((m_analyzedRegion.getStartAddress() >= m_analyzedRegion.getEndAddress()) || (m_analyzedRegion.getEndAddress() > provider->getActualSize())) {
m_analyzedRegion = { provider->getBaseAddress(), provider->getActualSize() };
}
@ -170,7 +175,7 @@ namespace hex::plugin::builtin {
ImGui::NewLine();
}
if (!m_analyzerTask.isRunning() && m_dataValid) {
if (!m_analyzerTask.isRunning() && m_dataValid && m_analyzedProvider != nullptr) {
// Provider information
ImGuiExt::Header("hex.builtin.view.information.provider_information"_lang, true);
@ -181,7 +186,7 @@ namespace hex::plugin::builtin {
ImGui::TableNextRow();
for (auto &[name, value] : provider->getDataDescription()) {
for (auto &[name, value] : m_analyzedProvider->getDataDescription()) {
ImGui::TableNextColumn();
ImGuiExt::TextFormatted("{}", name);
ImGui::TableNextColumn();