mirror of
https://github.com/fairyglade/ly.git
synced 2025-12-20 19:24:53 +00:00
Remove config.save_file
Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
@@ -105,12 +105,6 @@ load = true
|
|||||||
# Save the current desktop and login as defaults
|
# Save the current desktop and login as defaults
|
||||||
save = true
|
save = true
|
||||||
|
|
||||||
# Deprecated - Will be removed in a future version
|
|
||||||
# New save files are now loaded from the same directory as the config
|
|
||||||
# Currently used to migrate old save files to the new version
|
|
||||||
# File in which to save and load the default desktop and login
|
|
||||||
save_file = $CONFIG_DIRECTORY/ly/save
|
|
||||||
|
|
||||||
# Remove power management command hints
|
# Remove power management command hints
|
||||||
hide_key_hints = false
|
hide_key_hints = false
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ path: ?[:0]const u8 = "/sbin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/
|
|||||||
restart_cmd: []const u8 = "/sbin/shutdown -r now",
|
restart_cmd: []const u8 = "/sbin/shutdown -r now",
|
||||||
restart_key: []const u8 = "F2",
|
restart_key: []const u8 = "F2",
|
||||||
save: bool = true,
|
save: bool = true,
|
||||||
save_file: []const u8 = build_options.config_directory ++ "/ly/save",
|
|
||||||
service_name: [:0]const u8 = "ly",
|
service_name: [:0]const u8 = "ly",
|
||||||
shutdown_cmd: []const u8 = "/sbin/shutdown -a now",
|
shutdown_cmd: []const u8 = "/sbin/shutdown -a now",
|
||||||
shutdown_key: []const u8 = "F1",
|
shutdown_key: []const u8 = "F1",
|
||||||
|
|||||||
@@ -5,7 +5,10 @@ const ini = @import("zigini");
|
|||||||
const Save = @import("Save.zig");
|
const Save = @import("Save.zig");
|
||||||
const enums = @import("../enums.zig");
|
const enums = @import("../enums.zig");
|
||||||
|
|
||||||
var maybe_animate: ?bool = null;
|
var temporary_allocator = std.heap.page_allocator;
|
||||||
|
|
||||||
|
pub var maybe_animate: ?bool = null;
|
||||||
|
pub var maybe_save_file: ?[]const u8 = null;
|
||||||
|
|
||||||
pub var mapped_config_fields = false;
|
pub var mapped_config_fields = false;
|
||||||
|
|
||||||
@@ -59,6 +62,14 @@ pub fn configFieldHandler(_: std.mem.Allocator, field: ini.IniField) ?ini.IniFie
|
|||||||
return mapped_field;
|
return mapped_field;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (std.mem.eql(u8, field.key, "save_file")) {
|
||||||
|
// The option doesn't exist anymore, but we save its value for migration later on
|
||||||
|
maybe_save_file = temporary_allocator.dupe(u8, field.value) catch return null;
|
||||||
|
|
||||||
|
mapped_config_fields = true;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (std.mem.eql(u8, field.key, "wayland_specifier") or
|
if (std.mem.eql(u8, field.key, "wayland_specifier") or
|
||||||
std.mem.eql(u8, field.key, "max_desktop_len") or
|
std.mem.eql(u8, field.key, "max_desktop_len") or
|
||||||
std.mem.eql(u8, field.key, "max_login_len") or
|
std.mem.eql(u8, field.key, "max_login_len") or
|
||||||
@@ -78,34 +89,38 @@ pub fn configFieldHandler(_: std.mem.Allocator, field: ini.IniField) ?ini.IniFie
|
|||||||
// This is the stuff we only handle after reading the config.
|
// This is the stuff we only handle after reading the config.
|
||||||
// For example, the "animate" field could come after "animation"
|
// For example, the "animate" field could come after "animation"
|
||||||
pub fn lateConfigFieldHandler(animation: *enums.Animation) void {
|
pub fn lateConfigFieldHandler(animation: *enums.Animation) void {
|
||||||
if (maybe_animate == null) return;
|
if (maybe_animate) |animate| {
|
||||||
|
if (!animate) animation.* = .none;
|
||||||
if (!maybe_animate.?) animation.* = .none;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tryMigrateSaveFile(user_buf: *[32]u8, path: []const u8) Save {
|
pub fn tryMigrateSaveFile(user_buf: *[32]u8) Save {
|
||||||
var save = Save{};
|
var save = Save{};
|
||||||
|
|
||||||
var file = std.fs.openFileAbsolute(path, .{}) catch return save;
|
if (maybe_save_file) |path| {
|
||||||
defer file.close();
|
defer temporary_allocator.free(path);
|
||||||
|
|
||||||
const reader = file.reader();
|
var file = std.fs.openFileAbsolute(path, .{}) catch return save;
|
||||||
|
defer file.close();
|
||||||
|
|
||||||
var user_fbs = std.io.fixedBufferStream(user_buf);
|
const reader = file.reader();
|
||||||
reader.streamUntilDelimiter(user_fbs.writer(), '\n', 32) catch return save;
|
|
||||||
const user = user_fbs.getWritten();
|
|
||||||
if (user.len > 0) save.user = user;
|
|
||||||
|
|
||||||
var session_buf: [20]u8 = undefined;
|
var user_fbs = std.io.fixedBufferStream(user_buf);
|
||||||
var session_fbs = std.io.fixedBufferStream(&session_buf);
|
reader.streamUntilDelimiter(user_fbs.writer(), '\n', 32) catch return save;
|
||||||
reader.streamUntilDelimiter(session_fbs.writer(), '\n', 20) catch {};
|
const user = user_fbs.getWritten();
|
||||||
|
if (user.len > 0) save.user = user;
|
||||||
|
|
||||||
const session_index_str = session_fbs.getWritten();
|
var session_buf: [20]u8 = undefined;
|
||||||
var session_index: ?usize = null;
|
var session_fbs = std.io.fixedBufferStream(&session_buf);
|
||||||
if (session_index_str.len > 0) {
|
reader.streamUntilDelimiter(session_fbs.writer(), '\n', 20) catch {};
|
||||||
session_index = std.fmt.parseUnsigned(usize, session_index_str, 10) catch return save;
|
|
||||||
|
const session_index_str = session_fbs.getWritten();
|
||||||
|
var session_index: ?usize = null;
|
||||||
|
if (session_index_str.len > 0) {
|
||||||
|
session_index = std.fmt.parseUnsigned(usize, session_index_str, 10) catch return save;
|
||||||
|
}
|
||||||
|
save.session_index = session_index;
|
||||||
}
|
}
|
||||||
save.session_index = session_index;
|
|
||||||
|
|
||||||
return save;
|
return save;
|
||||||
}
|
}
|
||||||
|
|||||||
36
src/main.zig
36
src/main.zig
@@ -142,20 +142,10 @@ pub fn main() !void {
|
|||||||
save_path_alloc = true;
|
save_path_alloc = true;
|
||||||
|
|
||||||
var user_buf: [32]u8 = undefined;
|
var user_buf: [32]u8 = undefined;
|
||||||
save = save_ini.readFileToStruct(save_path, comment_characters, null) catch migrator.tryMigrateSaveFile(&user_buf, config.save_file);
|
save = save_ini.readFileToStruct(save_path, comment_characters, null) catch migrator.tryMigrateSaveFile(&user_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
migrator.lateConfigFieldHandler(&config.animation);
|
migrator.lateConfigFieldHandler(&config.animation);
|
||||||
|
|
||||||
// if (migrator.mapped_config_fields) save_migrated_config: {
|
|
||||||
// var file = try std.fs.cwd().createFile(config_path, .{});
|
|
||||||
// defer file.close();
|
|
||||||
|
|
||||||
// const writer = file.writer();
|
|
||||||
// ini.writeFromStruct(config, writer, null, true, .{}) catch {
|
|
||||||
// break :save_migrated_config;
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
} else {
|
} else {
|
||||||
const config_path = build_options.config_directory ++ "/ly/config.ini";
|
const config_path = build_options.config_directory ++ "/ly/config.ini";
|
||||||
|
|
||||||
@@ -171,22 +161,22 @@ pub fn main() !void {
|
|||||||
|
|
||||||
if (config.load) {
|
if (config.load) {
|
||||||
var user_buf: [32]u8 = undefined;
|
var user_buf: [32]u8 = undefined;
|
||||||
save = save_ini.readFileToStruct(save_path, comment_characters, null) catch migrator.tryMigrateSaveFile(&user_buf, config.save_file);
|
save = save_ini.readFileToStruct(save_path, comment_characters, null) catch migrator.tryMigrateSaveFile(&user_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
migrator.lateConfigFieldHandler(&config.animation);
|
migrator.lateConfigFieldHandler(&config.animation);
|
||||||
|
|
||||||
// if (migrator.mapped_config_fields) save_migrated_config: {
|
|
||||||
// var file = try std.fs.cwd().createFile(config_path, .{});
|
|
||||||
// defer file.close();
|
|
||||||
|
|
||||||
// const writer = file.writer();
|
|
||||||
// ini.writeFromStruct(config, writer, null, true, .{}) catch {
|
|
||||||
// break :save_migrated_config;
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if (migrator.mapped_config_fields) save_migrated_config: {
|
||||||
|
// var file = try std.fs.cwd().createFile(config_path, .{});
|
||||||
|
// defer file.close();
|
||||||
|
|
||||||
|
// const writer = file.writer();
|
||||||
|
// ini.writeFromStruct(config, writer, null, true, .{}) catch {
|
||||||
|
// break :save_migrated_config;
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
|
||||||
// These strings only end up getting freed if the user quits Ly using Ctrl+C, which is fine since in the other cases
|
// These strings only end up getting freed if the user quits Ly using Ctrl+C, which is fine since in the other cases
|
||||||
// we end up shutting down or restarting the system
|
// we end up shutting down or restarting the system
|
||||||
shutdown_cmd = try temporary_allocator.dupe(u8, config.shutdown_cmd);
|
shutdown_cmd = try temporary_allocator.dupe(u8, config.shutdown_cmd);
|
||||||
@@ -669,7 +659,7 @@ pub fn main() !void {
|
|||||||
ini.writeFromStruct(save_data, file.writer(), null, true, .{}) catch break :save_last_settings;
|
ini.writeFromStruct(save_data, file.writer(), null, true, .{}) catch break :save_last_settings;
|
||||||
|
|
||||||
// Delete previous save file if it exists
|
// Delete previous save file if it exists
|
||||||
std.fs.cwd().deleteFile(config.save_file) catch {};
|
if (migrator.maybe_save_file) |path| std.fs.cwd().deleteFile(path) catch {};
|
||||||
}
|
}
|
||||||
|
|
||||||
var shared_err = try SharedError.init();
|
var shared_err = try SharedError.init();
|
||||||
|
|||||||
Reference in New Issue
Block a user