Implement first pass of Oar archive reading mechanism
This commit is contained in:
parent
c42885bf61
commit
9ae6e8b4a7
16
src/main.zig
16
src/main.zig
|
@ -21,29 +21,29 @@ test {
|
|||
_ = sys;
|
||||
}
|
||||
|
||||
fn run(ev: *sys.EventLoop, fs: *const sys.FileSystem, gr: *sys.GraphicsContext) anyerror!void {
|
||||
fn run(app: *sys.App, graphics: *sys.GraphicsContext) anyerror!void {
|
||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
|
||||
defer _ = gpa.deinit();
|
||||
|
||||
{
|
||||
const file_access = try ev.open(.readonly, try fs.data.joinedPath(&.{"ona.lua"}));
|
||||
const file_access = try (try app.data().joinedPath(&.{"ona.lua"})).open(app, .readonly);
|
||||
|
||||
defer ev.close(file_access);
|
||||
defer file_access.close(app);
|
||||
|
||||
const file_size = try file_access.size(ev);
|
||||
const file_size = try file_access.queryLength(app);
|
||||
const allocator = gpa.allocator();
|
||||
const buffer = try allocator.alloc(u8, file_size);
|
||||
|
||||
defer allocator.free(buffer);
|
||||
|
||||
if ((try ev.readFile(file_access, buffer)) != file_size)
|
||||
if ((try file_access.read(app, buffer)) != file_size)
|
||||
return error.ScriptLoadFailure;
|
||||
|
||||
ev.log(.debug, buffer);
|
||||
sys.Log.debug.write(app, buffer);
|
||||
}
|
||||
|
||||
while (gr.poll()) |_| {
|
||||
gr.present();
|
||||
while (graphics.poll()) |_| {
|
||||
graphics.present();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
///
|
||||
/// Rounds the `Number` `value` up to the nearest `multiple`.
|
||||
///
|
||||
pub fn roundUp(comptime Number: type, value: Number, multiple: Number) Number {
|
||||
return value + @mod(@mod(multiple - value, multiple), multiple);
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
const std = @import("std");
|
||||
const sys = @import("./sys.zig");
|
||||
|
||||
///
|
||||
/// An entry block of an Oar archive file.
|
||||
///
|
||||
/// Typically, following this block in memory is the file data it holds the meta-information for.
|
||||
///
|
||||
pub const Entry = extern struct {
|
||||
name_length: u8,
|
||||
name_buffer: [255]u8 = std.mem.zeroes([255]u8),
|
||||
file_size: u64,
|
||||
padding: [248]u8,
|
||||
};
|
1044
src/sys.zig
1044
src/sys.zig
File diff suppressed because it is too large
Load Diff
29
src/tar.zig
29
src/tar.zig
|
@ -1,29 +0,0 @@
|
|||
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