Add stubs for Tar-based file system logic
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
1289e9634b
commit
c42885bf61
62
src/sys.zig
62
src/sys.zig
|
@ -6,14 +6,14 @@ const io = @import("./io.zig");
|
||||||
const mem = @import("./mem.zig");
|
const mem = @import("./mem.zig");
|
||||||
const stack = @import("./stack.zig");
|
const stack = @import("./stack.zig");
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
const tar = @import("./tar.zig");
|
||||||
|
|
||||||
///
|
///
|
||||||
/// A thread-safe platform abstraction over multiplexing system I/O processing and event handling.
|
/// A thread-safe platform abstraction over multiplexing system I/O processing and event handling.
|
||||||
///
|
///
|
||||||
pub const EventLoop = opaque {
|
pub const App = opaque {
|
||||||
///
|
///
|
||||||
/// Linked list of messages chained together to be processed by the internal file system message
|
/// Linked list of tasks chained together to be processed by the work processor.
|
||||||
/// processor of an [EventLoop].
|
|
||||||
///
|
///
|
||||||
const FileSystemMessage = struct {
|
const FileSystemMessage = struct {
|
||||||
next: ?*FileSystemMessage = null,
|
next: ?*FileSystemMessage = null,
|
||||||
|
@ -34,7 +34,7 @@ pub const EventLoop = opaque {
|
||||||
open: struct {
|
open: struct {
|
||||||
mode: OpenMode,
|
mode: OpenMode,
|
||||||
file_system_path: *const FileSystem.Path,
|
file_system_path: *const FileSystem.Path,
|
||||||
result: OpenError!*FileAccess = error.NotFound,
|
result: OpenError!*FileAccess = error.FileNotFound,
|
||||||
},
|
},
|
||||||
|
|
||||||
read_file: struct {
|
read_file: struct {
|
||||||
|
@ -436,11 +436,8 @@ pub const FileSystem = struct {
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
pub const Root = union(enum) {
|
pub const Root = union(enum) {
|
||||||
native: struct {
|
native: []const u8,
|
||||||
prefix: []const u8,
|
archive: *tar.Archive,
|
||||||
},
|
|
||||||
|
|
||||||
tar: struct {},
|
|
||||||
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
|
@ -552,12 +549,12 @@ pub const LogKind = enum(u32) {
|
||||||
};
|
};
|
||||||
|
|
||||||
///
|
///
|
||||||
/// [OpenError.NotFound] is a catch-all for when a file could not be located to be opened. This
|
/// [OpenError.FileNotFound] is a catch-all for when a file could not be located to be opened. This
|
||||||
/// may be as simple as it doesn't exist or the because the underlying file-system will not /
|
/// may be as simple as it doesn't exist or the because the underlying file-system will not /
|
||||||
/// cannot give access to it at this time.
|
/// cannot give access to it at this time.
|
||||||
///
|
///
|
||||||
pub const OpenError = error {
|
pub const OpenError = error {
|
||||||
NotFound,
|
FileNotFound,
|
||||||
};
|
};
|
||||||
|
|
||||||
///
|
///
|
||||||
|
@ -625,24 +622,26 @@ pub fn log(kind: LogKind, message: []const u8) void {
|
||||||
///
|
///
|
||||||
pub fn open(mode: OpenMode, file_system_path: FileSystem.Path) OpenError!*FileAccess {
|
pub fn open(mode: OpenMode, file_system_path: FileSystem.Path) OpenError!*FileAccess {
|
||||||
switch (file_system_path.root.*) {
|
switch (file_system_path.root.*) {
|
||||||
.tar => {
|
.archive => |archive| {
|
||||||
// TODO: Implement.
|
// TODO: Implement.
|
||||||
return error.NotFound;
|
_ = archive;
|
||||||
|
|
||||||
|
return error.FileNotFound;
|
||||||
},
|
},
|
||||||
|
|
||||||
.native => |native| {
|
.native => |native| {
|
||||||
var path_buffer = std.mem.zeroes([4096]u8);
|
var path_buffer = std.mem.zeroes([4096]u8);
|
||||||
var path = stack.Fixed(u8){.buffer = path_buffer[0 .. ]};
|
var path = stack.Fixed(u8){.buffer = path_buffer[0 .. ]};
|
||||||
|
|
||||||
path.pushAll(native.prefix) catch return error.NotFound;
|
path.pushAll(native) catch return error.FileNotFound;
|
||||||
|
|
||||||
if (file_system_path.write(path.writer())) return error.NotFound;
|
if (file_system_path.write(path.writer())) return error.FileNotFound;
|
||||||
|
|
||||||
return @ptrCast(?*FileAccess, ext.SDL_RWFromFile(&path_buffer, switch (mode) {
|
return @ptrCast(?*FileAccess, ext.SDL_RWFromFile(&path_buffer, switch (mode) {
|
||||||
.readonly => "rb",
|
.readonly => "rb",
|
||||||
.overwrite => "wb",
|
.overwrite => "wb",
|
||||||
.append => "ab",
|
.append => "ab",
|
||||||
})) orelse error.NotFound;
|
})) orelse error.FileNotFound;
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -650,7 +649,9 @@ pub fn open(mode: OpenMode, file_system_path: FileSystem.Path) OpenError!*FileAc
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
pub fn runGraphics(comptime Errors: anytype, comptime run: GraphicsRunner(Errors)) (RunError || Errors)!void {
|
pub fn runGraphics(comptime Errors: anytype, allocator: std.mem.Allocator,
|
||||||
|
comptime run: GraphicsRunner(Errors)) (RunError || Errors)!void {
|
||||||
|
|
||||||
if (ext.SDL_Init(ext.SDL_INIT_EVERYTHING) != 0) {
|
if (ext.SDL_Init(ext.SDL_INIT_EVERYTHING) != 0) {
|
||||||
ext.SDL_LogCritical(ext.SDL_LOG_CATEGORY_APPLICATION, "Failed to initialize runtime");
|
ext.SDL_LogCritical(ext.SDL_LOG_CATEGORY_APPLICATION, "Failed to initialize runtime");
|
||||||
|
|
||||||
|
@ -693,22 +694,25 @@ pub fn runGraphics(comptime Errors: anytype, comptime run: GraphicsRunner(Errors
|
||||||
|
|
||||||
defer ext.SDL_free(user_prefix);
|
defer ext.SDL_free(user_prefix);
|
||||||
|
|
||||||
|
var data_archive = tar.Archive.init(allocator);
|
||||||
|
|
||||||
|
data_archive.load("./data.tar") catch |err| switch (err) {
|
||||||
|
error.FileNotFound => {
|
||||||
|
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
var file_system = FileSystem{
|
var file_system = FileSystem{
|
||||||
.user = .{.native = .{.prefix = user_prefix[0 .. std.mem.len(user_prefix)]}},
|
.user = .{.native = user_prefix[0 .. std.mem.len(user_prefix)]},
|
||||||
.data = .{.tar = .{}},
|
.data = .{.archive = &data_archive},
|
||||||
};
|
};
|
||||||
|
|
||||||
var event_loop = EventLoop.Implementation.init() catch |err| {
|
var event_loop = EventLoop.Implementation.init() catch |err| {
|
||||||
switch (err) {
|
ext.SDL_LogCritical(ext.SDL_LOG_CATEGORY_APPLICATION, switch (err) {
|
||||||
error.OutOfMemory => ext.SDL_LogCritical(ext.SDL_LOG_CATEGORY_APPLICATION,
|
error.OutOfMemory => "Failed to allocate necessary memory",
|
||||||
"Failed to allocate necessary memory"),
|
error.OutOfMutexes => "Failed to create file-system work lock",
|
||||||
|
error.OutOfSemaphores => "Failed to create file-system work scheduler",
|
||||||
error.OutOfMutexes => ext.SDL_LogCritical(ext.SDL_LOG_CATEGORY_APPLICATION,
|
});
|
||||||
"Failed to create file-system work lock"),
|
|
||||||
|
|
||||||
error.OutOfSemaphores => ext.SDL_LogCritical(ext.SDL_LOG_CATEGORY_APPLICATION,
|
|
||||||
"Failed to create file-system work scheduler"),
|
|
||||||
}
|
|
||||||
|
|
||||||
return error.InitFailure;
|
return error.InitFailure;
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
const std = @import("std");
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
pub const Archive = struct {
|
||||||
|
allocator: std.mem.Allocator,
|
||||||
|
|
||||||
|
pub const LoadError = error {
|
||||||
|
FileNotFound,
|
||||||
|
};
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
pub fn init(allocator: std.mem.Allocator) Archive {
|
||||||
|
return Archive{
|
||||||
|
.allocator = allocator,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
pub fn load(archive: *Archive, file_path: []const u8) LoadError!void {
|
||||||
|
_ = file_path;
|
||||||
|
_ = archive;
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue