From f6c25b30aead9220b608a2b5e52795c1d99b2646 Mon Sep 17 00:00:00 2001 From: PietHelzel <55491906+PietHelzel@users.noreply.github.com> Date: Tue, 8 Apr 2025 21:47:20 +0200 Subject: [PATCH] fix: Saving layout now picks the first path in the list (#2208) ### Problem description Saving a layout using the "Workspace -> Layout -> Save Layout ..." button saved to the last writable path in the list that can be found in the "Help -> About" menu. Instead, it should write to the first working path encountered. ### Implementation description Getting all of the writable paths, then picking the first one. ### Screenshots ### Additional things --- lib/libimhex/source/api/layout_manager.cpp | 26 +++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/libimhex/source/api/layout_manager.cpp b/lib/libimhex/source/api/layout_manager.cpp index fa2beaf97..41a95ea31 100644 --- a/lib/libimhex/source/api/layout_manager.cpp +++ b/lib/libimhex/source/api/layout_manager.cpp @@ -43,19 +43,25 @@ namespace hex { std::fs::path layoutPath; for (const auto &path : paths::Layouts.write()) { - layoutPath = path / fileName; - } + size_t outSize = 0; + const char* iniData = ImGui::SaveIniSettingsToMemory(&outSize); - if (layoutPath.empty()) { - log::error("Failed to save layout '{}'. No writable path found", name); + layoutPath = path / fileName; + wolv::io::File file = wolv::io::File(layoutPath, wolv::io::File::Mode::Write); + if (!file.isValid()) { + log::warn("Failed to save layout '{}'. Could not open file '{}', continuing with next path", name, layoutPath.c_str()); + continue; + } + size_t written = file.writeBuffer((const u8*) iniData, outSize); + if (written != outSize) { + log::warn("Failed to save layout '{}'. Could not write file '{}', continuing with next path", name, layoutPath.c_str()); + continue; + } + log::info("Layout '{}' saved to '{}'", name, layoutPath.c_str()); + LayoutManager::reload(); return; } - - const auto pathString = wolv::util::toUTF8String(layoutPath); - ImGui::SaveIniSettingsToDisk(pathString.c_str()); - log::info("Layout '{}' saved to {}", name, pathString); - - LayoutManager::reload(); + log::error("Failed to save layout '{}'. No writable path found", name); } std::string LayoutManager::saveToString() {