fix: Saving layout now picks the first path in the list (#2208)

<!--
Please provide as much information as possible about what your PR aims
to do.
PRs with no description will most likely be closed until more
information is provided.
If you're planing on changing fundamental behaviour or add big new
features, please open a GitHub Issue first before starting to work on
it.
If it's not something big and you still want to contact us about it,
feel free to do so !
-->

### 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
<!-- If your change is visual, take a screenshot showing it. Ideally,
make before/after sceenshots -->

### Additional things
<!-- Anything else you would like to say -->
This commit is contained in:
PietHelzel
2025-04-08 21:47:20 +02:00
committed by GitHub
parent 379d826f18
commit f6c25b30ae

View File

@@ -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() {