From 9bf97886897952a83e4e54eab35611ca7012cfb9 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 12 Dec 2021 21:46:48 +0100 Subject: [PATCH] fix: Error when opening a file --- plugins/builtin/source/content/providers.cpp | 2 +- .../content/providers/file_provider.cpp | 2 +- .../source/content/views/view_hexeditor.cpp | 4 +++- .../source/content/views/view_settings.cpp | 2 -- source/window/window.cpp | 20 ++++++++++--------- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/plugins/builtin/source/content/providers.cpp b/plugins/builtin/source/content/providers.cpp index 973e25b61..50b260de8 100644 --- a/plugins/builtin/source/content/providers.cpp +++ b/plugins/builtin/source/content/providers.cpp @@ -8,7 +8,7 @@ namespace hex::plugin::builtin { void registerProviders() { - ContentRegistry::Provider::add("hex.builtin.provider.file", false); + ContentRegistry::Provider::add("hex.builtin.provider.file", false); ContentRegistry::Provider::add("hex.builtin.provider.gdb"); ContentRegistry::Provider::add("hex.builtin.provider.disk"); diff --git a/plugins/builtin/source/content/providers/file_provider.cpp b/plugins/builtin/source/content/providers/file_provider.cpp index c9e3e2247..1ea87684d 100644 --- a/plugins/builtin/source/content/providers/file_provider.cpp +++ b/plugins/builtin/source/content/providers/file_provider.cpp @@ -20,7 +20,7 @@ namespace hex::plugin::builtin::prv { bool FileProvider::isAvailable() const { #if defined(OS_WINDOWS) - return this->m_file != nullptr && this->m_mapping != nullptr && this->m_mappedFile != nullptr; + return this->m_file != INVALID_HANDLE_VALUE && this->m_mapping != INVALID_HANDLE_VALUE && this->m_mappedFile != nullptr; #else return this->m_file != -1 && this->m_mappedFile != nullptr; #endif diff --git a/plugins/builtin/source/content/views/view_hexeditor.cpp b/plugins/builtin/source/content/views/view_hexeditor.cpp index 615732de4..0933b0be9 100644 --- a/plugins/builtin/source/content/views/view_hexeditor.cpp +++ b/plugins/builtin/source/content/views/view_hexeditor.cpp @@ -481,7 +481,7 @@ namespace hex::plugin::builtin { saveAs(); } - if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.close"_lang, "", false, providerValid && provider->isAvailable())) { + if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.close"_lang, "", false, providerValid)) { EventManager::post(); ImHexApi::Provider::remove(ImHexApi::Provider::get()); providerValid = false; @@ -728,6 +728,8 @@ namespace hex::plugin::builtin { fileProvider->setPath(path); if (!fileProvider->open()) { View::showErrorPopup("hex.builtin.view.hexeditor.error.open"_lang); + ImHexApi::Provider::remove(provider); + return; } } diff --git a/plugins/builtin/source/content/views/view_settings.cpp b/plugins/builtin/source/content/views/view_settings.cpp index 47542e37c..596de3add 100644 --- a/plugins/builtin/source/content/views/view_settings.cpp +++ b/plugins/builtin/source/content/views/view_settings.cpp @@ -21,8 +21,6 @@ namespace hex::plugin::builtin { void ViewSettings::drawContent() { - ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, FLT_MAX)); - ImGui::SetNextWindowSize(ImVec2(500, 300) * SharedData::globalScale, ImGuiCond_Always); if (ImGui::BeginPopupModal(View::toWindowName("hex.builtin.view.settings.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoResize)) { if (ImGui::BeginTabBar("settings")) { diff --git a/source/window/window.cpp b/source/window/window.cpp index 5f7cf2b94..654358327 100644 --- a/source/window/window.cpp +++ b/source/window/window.cpp @@ -484,26 +484,28 @@ namespace hex { call(); View::getDeferedCalls().clear(); + View::drawCommonInterfaces(); + for (auto &view : ContentRegistry::Views::getEntries()) { - GImGui->NextWindowData.ClearFlags(); + ImGui::GetCurrentContext()->NextWindowData.ClearFlags(); + view->drawAlwaysVisible(); if (!view->shouldProcess()) continue; - auto minSize = view->getMinSize(); - minSize.x *= SharedData::globalScale; - minSize.y *= SharedData::globalScale; + if (view->isAvailable()) { + auto minSize = view->getMinSize(); + minSize.x *= SharedData::globalScale; + minSize.y *= SharedData::globalScale; - ImGui::SetNextWindowSizeConstraints(minSize, view->getMaxSize()); - view->drawContent(); - GImGui->NextWindowData.ClearFlags(); + ImGui::SetNextWindowSizeConstraints(minSize, view->getMaxSize()); + view->drawContent(); + } view->handleShortcut(pressedKeys, ImGui::GetIO().KeyCtrl, ImGui::GetIO().KeyShift, ImGui::GetIO().KeyAlt); } - View::drawCommonInterfaces(); - #ifdef DEBUG if (this->m_demoWindowOpen) { ImGui::ShowDemoWindow(&this->m_demoWindowOpen);