Preserve unknown entries in settings (#1696)

Fixes #1675
This commit is contained in:
codemob 2025-07-20 17:29:50 -04:00 committed by GitHub
parent 7aa35798be
commit df0af7afbc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 3 deletions

View File

@ -217,7 +217,18 @@ pub fn save() void { // MARK: save()
guiZon.put(window.id, windowZon);
}
main.files.cubyzDir().writeZon("gui_layout.zig.zon", guiZon) catch |err| {
// Merge with the old settings file to preserve unknown settings.
const oldZon: ZonElement = main.files.cubyzDir().readToZon(main.stackAllocator, "gui_layout.zig.zon") catch |err| blk: {
if(err != error.FileNotFound) {
std.log.err("Could not read gui_layout.zig.zon: {s}", .{@errorName(err)});
}
break :blk .null;
};
defer oldZon.deinit(main.stackAllocator);
oldZon.join(guiZon);
main.files.cubyzDir().writeZon("gui_layout.zig.zon", oldZon) catch |err| {
std.log.err("Could not write gui_layout.zig.zon: {s}", .{@errorName(err)});
};
}

View File

@ -153,8 +153,18 @@ pub fn save() void {
}
zonObject.put("keyboard", keyboard);
// Write to file:
main.files.cubyzDir().writeZon(settingsFile, zonObject) catch |err| {
// Merge with the old settings file to preserve unknown settings.
const oldZonObject: ZonElement = main.files.cubyzDir().readToZon(main.stackAllocator, settingsFile) catch |err| blk: {
if(err != error.FileNotFound) {
std.log.err("Could not read settings file: {s}", .{@errorName(err)});
}
break :blk .null;
};
defer oldZonObject.deinit(main.stackAllocator);
oldZonObject.join(zonObject);
main.files.cubyzDir().writeZon(settingsFile, oldZonObject) catch |err| {
std.log.err("Couldn't write settings to file: {s}", .{@errorName(err)});
};
}