fix: account for subset of disallowed chars in save file names
This commit is contained in:
parent
ad9463dcb9
commit
a93b335dea
|
@ -3,6 +3,7 @@ const Allocator = std.mem.Allocator;
|
||||||
const log = std.log.scoped(.Backup);
|
const log = std.log.scoped(.Backup);
|
||||||
|
|
||||||
const correctTitle = @import("../util.zig").correctTitle;
|
const correctTitle = @import("../util.zig").correctTitle;
|
||||||
|
const safeTitle = @import("../util.zig").safeTitle;
|
||||||
|
|
||||||
const backup_kinds = [5]Needle{
|
const backup_kinds = [5]Needle{
|
||||||
.{ .str = "EEPROM_V", .kind = .Eeprom },
|
.{ .str = "EEPROM_V", .kind = .Eeprom },
|
||||||
|
@ -61,7 +62,7 @@ pub const Backup = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: Self) void {
|
pub fn deinit(self: Self) void {
|
||||||
if (self.save_path) |path| self.writeSaveToDisk(path) catch |e| log.err("Failed to save {}", .{e});
|
if (self.save_path) |path| self.writeSaveToDisk(path) catch |e| log.err("Failed to write save: {}", .{e});
|
||||||
|
|
||||||
self.alloc.free(self.buf);
|
self.alloc.free(self.buf);
|
||||||
}
|
}
|
||||||
|
@ -93,7 +94,7 @@ pub const Backup = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn getSaveFilename(self: *const Self) ![]const u8 {
|
fn getSaveFilename(self: *const Self) ![]const u8 {
|
||||||
const title = correctTitle(self.title);
|
const title = correctTitle(safeTitle(self.title));
|
||||||
return try std.mem.concat(self.alloc, u8, &[_][]const u8{ title, ".sav" });
|
return try std.mem.concat(self.alloc, u8, &[_][]const u8{ title, ".sav" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,12 +74,12 @@ pub fn correctTitle(title: [12]u8) []const u8 {
|
||||||
/// Copies a Title and returns either an identical or similar
|
/// Copies a Title and returns either an identical or similar
|
||||||
/// array consisting of ASCII that won't make any file system angry
|
/// array consisting of ASCII that won't make any file system angry
|
||||||
///
|
///
|
||||||
/// Currently Unused but I assume there's some ROM out there that will require this
|
/// e.g. POKEPIN R/S to POKEPIN R_S
|
||||||
pub fn safeTitle(title: [12]u8) [12]u8 {
|
pub fn safeTitle(title: [12]u8) [12]u8 {
|
||||||
var result: [12]u8 = title;
|
var result: [12]u8 = title;
|
||||||
|
|
||||||
for (result) |*char| {
|
for (result) |*char| {
|
||||||
if (char.* == '-') char.* = '_';
|
if (char.* == '/' or char.* == '\\') char.* = '_';
|
||||||
if (char.* == 0) break;
|
if (char.* == 0) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue