Update zigini (fixes incorrect comment parsing)

Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
AnErrupTion 2024-07-30 09:43:56 +02:00
parent 48185bdfe0
commit 5f2f21620a
No known key found for this signature in database
GPG Key ID: 3E85EB44F610AD7F
4 changed files with 25 additions and 12 deletions

View File

@ -8,8 +8,8 @@
.hash = "122062d301a203d003547b414237229b09a7980095061697349f8bef41be9c30266b",
},
.zigini = .{
.url = "https://github.com/Kawaii-Ash/zigini/archive/refs/tags/0.2.2.tar.gz",
.hash = "1220afda2f3258cd0bb042dd3c2d5a35069ce1785c11325e65f136c5220013b36d00",
.url = "https://github.com/Kawaii-Ash/zigini/archive/bdb6fd15c6dcedb0c6c2a46381f2d298e2f05fff.tar.gz",
.hash = "12203feb831e21bec081af6aae70dd19b127f1627aa55f3415bd1fa476c174a511cc",
},
},
.paths = .{""},

View File

@ -1,7 +1,19 @@
// The migrator ensures compatibility with <=0.6.0 configuration files
const std = @import("std");
const ini = @import("zigini");
const Save = @import("Save.zig");
pub fn configFieldHandler(_: std.mem.Allocator, field: ini.IniField) ?ini.IniField {
var mapped_field = field;
if (std.mem.eql(u8, field.key, "blank_password")) {
mapped_field.key = "clear_password";
}
return mapped_field;
}
pub fn tryMigrateSaveFile(user_buf: *[32]u8, path: []const u8) Save {
var save = Save{};

View File

@ -92,8 +92,7 @@ pub fn main() !void {
if (save_path_alloc) allocator.free(save_path);
}
// Compatibility with v0.6.0
const mapped_config_fields = .{.{ "blank_password", "clear_password" }};
const comment_characters = "#";
if (res.args.config) |s| {
const trailing_slash = if (s[s.len - 1] != '/') "/" else "";
@ -101,7 +100,7 @@ pub fn main() !void {
const config_path = try std.fmt.allocPrint(allocator, "{s}{s}config.ini", .{ s, trailing_slash });
defer allocator.free(config_path);
config = config_ini.readFileToStructWithMap(config_path, mapped_config_fields) catch _config: {
config = config_ini.readFileToStruct(config_path, comment_characters, migrator.configFieldHandler) catch _config: {
// We're using a literal error message here since the language file hasn't yet been loaded
try info_line.addMessage("unable to parse config file", @intCast(interop.termbox.TB_DEFAULT), @intCast(interop.termbox.TB_RED | interop.termbox.TB_BOLD));
break :_config Config{};
@ -110,17 +109,19 @@ pub fn main() !void {
const lang_path = try std.fmt.allocPrint(allocator, "{s}{s}lang/{s}.ini", .{ s, trailing_slash, config.lang });
defer allocator.free(lang_path);
lang = lang_ini.readFileToStruct(lang_path) catch Lang{};
lang = lang_ini.readFileToStruct(lang_path, comment_characters, null) catch Lang{};
if (config.load) {
save_path = try std.fmt.allocPrint(allocator, "{s}{s}save.ini", .{ s, trailing_slash });
save_path_alloc = true;
var user_buf: [32]u8 = undefined;
save = save_ini.readFileToStruct(save_path) catch migrator.tryMigrateSaveFile(&user_buf, config.save_file);
save = save_ini.readFileToStruct(save_path, comment_characters, null) catch migrator.tryMigrateSaveFile(&user_buf, config.save_file);
}
} else {
config = config_ini.readFileToStructWithMap(build_options.data_directory ++ "/config.ini", mapped_config_fields) catch _config: {
const config_path = build_options.data_directory ++ "/config.ini";
config = config_ini.readFileToStruct(config_path, comment_characters, migrator.configFieldHandler) catch _config: {
// literal error message, due to language file not yet available
try info_line.addMessage("unable to parse config file", @intCast(interop.termbox.TB_DEFAULT), @intCast(interop.termbox.TB_RED | interop.termbox.TB_BOLD));
break :_config Config{};
@ -129,11 +130,11 @@ pub fn main() !void {
const lang_path = try std.fmt.allocPrint(allocator, "{s}/lang/{s}.ini", .{ build_options.data_directory, config.lang });
defer allocator.free(lang_path);
lang = lang_ini.readFileToStruct(lang_path) catch Lang{};
lang = lang_ini.readFileToStruct(lang_path, comment_characters, null) catch Lang{};
if (config.load) {
var user_buf: [32]u8 = undefined;
save = save_ini.readFileToStruct(save_path) catch migrator.tryMigrateSaveFile(&user_buf, config.save_file);
save = save_ini.readFileToStruct(save_path, comment_characters, null) catch migrator.tryMigrateSaveFile(&user_buf, config.save_file);
}
}
@ -590,7 +591,7 @@ pub fn main() !void {
.user = login.text.items,
.session_index = desktop.current,
};
ini.writeFromStruct(save_data, file.writer(), null) catch break :save_last_settings;
ini.writeFromStruct(save_data, file.writer(), null, true, .{}) catch break :save_last_settings;
}
var shared_err = try SharedError.init();

View File

@ -150,7 +150,7 @@ pub fn crawl(self: *Desktop, path: []const u8, display_server: DisplayServer) !v
const entry_path = try std.fmt.allocPrint(self.allocator, "{s}/{s}", .{ path, item.name });
defer self.allocator.free(entry_path);
var entry_ini = Ini(Entry).init(self.allocator);
_ = try entry_ini.readFileToStruct(entry_path);
_ = try entry_ini.readFileToStruct(entry_path, "#", null);
errdefer entry_ini.deinit();
var xdg_session_desktop: []const u8 = undefined;