const std = @import("std"); const config = @import("../config.zig"); const prompt = @import("../prompt.zig"); pub const User = @import("user.zig"); const Self = @This(); dir: std.fs.Dir, pub fn init(allocator: std.mem.Allocator) !Self { const dir = std.fs.cwd().openDir(config.storage_path, .{}) catch blk: { try std.fs.cwd().makeDir(config.storage_path); break :blk try std.fs.cwd().openDir(config.storage_path, .{}); }; var self = Self { .dir = dir }; dir.access("user", .{}) catch |err| switch (err) { error.FileNotFound => { const name = try prompt.read("Username", allocator); defer allocator.free(name); const full_name = try prompt.read("Full Name", allocator); defer allocator.free(full_name); const birthday = try prompt.read("Birthday", allocator); defer allocator.free(birthday); const password = try prompt.read("Password", allocator); defer allocator.free(password); try self.dir.makeDir("user"); var user: User = try .new( &self, name, full_name, birthday, password, true, allocator, ); defer user.deinit(); try user.sync(); }, else => return err, }; return self; } pub fn deinit(self: *Self) void { self.dir.close(); self.* = undefined; }