Update zigini to improve compatibility with old config

pull/599/head
Kinzie 1 month ago
parent 220fbf79b0
commit 65a047ea32

@ -7,8 +7,8 @@
.hash = "1220f48518ce22882e102255ed3bcdb7aeeb4891f50b2cdd3bd74b5b2e24d3149ba2",
},
.zigini = .{
.url = "https://github.com/Kawaii-Ash/zigini/archive/91f47e46591982fc559afa3248749c1d29a0fa2a.tar.gz",
.hash = "12209908f2773f730fbca024c80dc7f48dce15a6527b2387f3768968f5bae0d3931e",
.url = "https://github.com/Kawaii-Ash/zigini/archive/e2d2bbfe1863346ad1fc6c845ce719a6eab200ab.tar.gz",
.hash = "1220f2b545cafa2b8688a69eff10b7d71e2f2ee5d9b119c4b74c873f36b4b2117157",
},
},
}

@ -90,37 +90,40 @@ 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" }};
if (res.args.config) |s| {
const trailing_slash = if (s[s.len - 1] != '/') "/" else "";
const config_path = try std.fmt.allocPrint(allocator, "{s}{s}config.ini", .{ s, trailing_slash });
defer allocator.free(config_path);
config = config_ini.readToStruct(config_path) catch Config{};
config = config_ini.readFileToStructWithMap(config_path, mapped_config_fields) catch Config{};
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.readToStruct(lang_path) catch Lang{};
lang = lang_ini.readFileToStruct(lang_path) 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.readToStruct(save_path) catch migrator.tryMigrateSaveFile(&user_buf, config.save_file, save_path);
save = save_ini.readFileToStruct(save_path) catch migrator.tryMigrateSaveFile(&user_buf, config.save_file, save_path);
}
} else {
config = config_ini.readToStruct(build_options.data_directory ++ "/config.ini") catch Config{};
config = config_ini.readFileToStructWithMap(build_options.data_directory ++ "/config.ini", mapped_config_fields) catch Config{};
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.readToStruct(lang_path) catch Lang{};
lang = lang_ini.readFileToStruct(lang_path) catch Lang{};
if (config.load) {
var user_buf: [32]u8 = undefined;
save = save_ini.readToStruct(save_path) catch migrator.tryMigrateSaveFile(&user_buf, config.save_file, save_path);
save = save_ini.readFileToStruct(save_path) catch migrator.tryMigrateSaveFile(&user_buf, config.save_file, save_path);
}
}
@ -587,12 +590,13 @@ pub fn main() !void {
try std.os.tcsetattr(std.os.STDIN_FILENO, .FLUSH, tb_termios);
termbox.tb_clear();
termbox.tb_present();
update = true;
var restore_cursor = std.ChildProcess.init(&[_][]const u8{ "/bin/sh", "-c", config.term_restore_cursor_cmd }, allocator);
_ = restore_cursor.spawnAndWait() catch .{};
termbox.tb_present();
},
else => {
if (!insert_mode) {

@ -29,7 +29,7 @@ const DesktopEntry = struct {
DesktopNames: [:0]const u8 = "",
};
pub const Entry = struct { Desktop_Entry: DesktopEntry = DesktopEntry{} };
pub const Entry = struct { @"Desktop Entry": DesktopEntry = DesktopEntry{} };
allocator: Allocator,
buffer: *TerminalBuffer,
@ -85,7 +85,7 @@ pub fn addEnvironment(self: *Desktop, entry: DesktopEntry, display_server: Displ
}
pub fn addEnvironmentWithIni(self: *Desktop, entry_ini: Ini(Entry), display_server: DisplayServer) !void {
const entry = entry_ini.data.Desktop_Entry;
const entry = entry_ini.data.@"Desktop Entry";
try self.environments.append(.{
.entry_ini = entry_ini,
.name = entry.Name,
@ -113,7 +113,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.readToStruct(entry_path);
_ = try entry_ini.readFileToStruct(entry_path);
try self.addEnvironmentWithIni(entry_ini, display_server);
}

Loading…
Cancel
Save