From 844845223f49077ab5bc4ecf5a1b3576f43deac4 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Wed, 16 Mar 2022 13:23:36 +0100 Subject: [PATCH] fix: Saving interface.ini file failing if imhex is installed in a non-writable location Fixes #473 --- main/source/window/window.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/main/source/window/window.cpp b/main/source/window/window.cpp index 7c535a1bd..2e8a1ea48 100644 --- a/main/source/window/window.cpp +++ b/main/source/window/window.cpp @@ -119,7 +119,9 @@ namespace hex { constexpr auto CrashBackupFileName = "crash_backup.hexproj"; - EventManager::subscribe(this, [CrashBackupFileName](int signal) { + EventManager::subscribe(this, [this, CrashBackupFileName](int signal) { + ImGui::SaveIniSettingsToDisk(this->m_imguiSettingsPath.string().c_str()); + if (!ProjectFile::hasUnsavedChanges()) return; @@ -603,7 +605,7 @@ namespace hex { return; for (u32 i = 0; i < count; i++) { - auto path = std::filesystem::path(reinterpret_cast(paths[i])); + auto path = std::fs::path(reinterpret_cast(paths[i])); bool handled = false; for (const auto &[extensions, handler] : ContentRegistry::FileHandler::getEntries()) { @@ -721,12 +723,12 @@ namespace hex { ImGui::GetCurrentContext()->SettingsHandlers.push_back(handler); for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Config)) { - if (std::filesystem::exists(dir)) { + if (std::fs::exists(dir) && fs::isPathWritable(dir)) { this->m_imguiSettingsPath = dir / "interface.ini"; + io.IniFilename = nullptr; break; } } - io.IniFilename = nullptr; if (!this->m_imguiSettingsPath.empty() && fs::exists(this->m_imguiSettingsPath)) ImGui::LoadIniSettingsFromDisk(this->m_imguiSettingsPath.string().c_str());