1
0
mirror of synced 2024-11-24 15:50:16 +01:00

impr: Harden settings store function

This commit is contained in:
WerWolv 2023-12-27 16:53:03 +01:00
parent 74b5c93caf
commit 874619f62e

View File

@ -89,16 +89,21 @@ namespace hex {
}
void store() {
auto settingsData = getSettingsData();
// During a crash settings can be empty, causing them to be overwritten.
if(getSettingsData().empty()) {
if (settingsData.empty()) {
return;
}
for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Config)) {
wolv::io::File file(dir / SettingsFile, wolv::io::File::Mode::Create);
wolv::io::File file(dir / SettingsFile, wolv::io::File::Mode::Write);
if (file.isValid()) {
file.writeString(getSettingsData().dump(4));
auto result = settingsData.dump(4);
file.setSize(0);
file.writeString(result);
break;
}
}