mirror of
https://github.com/fairyglade/ly.git
synced 2026-02-04 16:34:55 +00:00
Fix wrong session index + save file corruption
Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
@@ -5,6 +5,8 @@ const SavedUsers = @This();
|
||||
const User = struct {
|
||||
username: []const u8,
|
||||
session_index: usize,
|
||||
first_run: bool,
|
||||
allocated_username: bool,
|
||||
};
|
||||
|
||||
user_list: std.ArrayList(User),
|
||||
@@ -18,5 +20,9 @@ pub fn init() SavedUsers {
|
||||
}
|
||||
|
||||
pub fn deinit(self: *SavedUsers, allocator: std.mem.Allocator) void {
|
||||
for (self.user_list.items) |user| {
|
||||
if (user.allocated_username) allocator.free(user.username);
|
||||
}
|
||||
|
||||
self.user_list.deinit(allocator);
|
||||
}
|
||||
|
||||
@@ -238,7 +238,12 @@ pub fn tryMigrateIniSaveFile(allocator: std.mem.Allocator, save_ini: *ini.Ini(Ol
|
||||
if (std.mem.eql(u8, user, username)) saved_users.last_username_index = i;
|
||||
}
|
||||
|
||||
try saved_users.user_list.append(allocator, .{ .username = username, .session_index = save.session_index orelse 0 });
|
||||
try saved_users.user_list.append(allocator, .{
|
||||
.username = username,
|
||||
.session_index = save.session_index orelse 0,
|
||||
.first_run = false,
|
||||
.allocated_username = false,
|
||||
});
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user