~mil/mepo

ref: 5c7d6783b93b00725b59c63fe1e3c88b7f0e407a mepo/src/api/filedump.zig -rw-r--r-- 1.1 KiB
5c7d6783Miles Alan Add doc comments for info on what needs to be looped to saved to mepolang 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const Mepo = @import("../Mepo.zig");
const types = @import("../types.zig");
const std = @import("std");
const utilfile = @import("../util/utilfile.zig");

pub const spec = .{
    .name = "filedump",
    .desc = "Save the current state of all preferences to a file.",
    .args = (&[_]types.MepoFnSpecArg{
        .{ .tag = .Text, .name = "filepath", .desc = "Path to file to save state to" },
    })[0..],
    .execute = execute,
};

fn execute(mepo: *Mepo, args: [types.MepoFnNargs]types.MepoArg) !void {
    const filepath = args[0].Text;
    try filedump(mepo, filepath);
}

fn filedump(mepo: *Mepo, filepath: []const u8) !void {
    const expanded_path = try utilfile.wordexp_filepath(mepo.allocator, filepath);
    defer mepo.allocator.free(expanded_path);
    const mepolang_file = try std.fs.openFileAbsolute(expanded_path, .{ .write = true });
    defer mepolang_file.close();

    // Save tables:
    //   bind_button
    //   bind_gesture
    //   bind_click
    //   bind_key
    //   bind_signal
    // Save prefs:
    //   loop prefs
    //   TODO: rework for pin_groups prefs merge into prefs system
    // Save pins:
    //   loop pins
}