feat: improve build script
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
LordMZTE 2022-08-09 16:33:06 +02:00
parent 8b3f5ce53a
commit cd515d9ace
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
2 changed files with 30 additions and 18 deletions

View file

@ -45,18 +45,25 @@ pub fn main() !void {
var walker = try overrides.walk(std.heap.c_allocator); var walker = try overrides.walk(std.heap.c_allocator);
defer walker.deinit(); defer walker.deinit();
const stdout = std.io.getStdOut().writer();
while (try walker.next()) |e| { while (try walker.next()) |e| {
switch (e.kind) { switch (e.kind) {
.Directory => { .Directory => {
const path = try std.mem.concat( stdout.print(
"Writing Directory\t\x1b[34m{s}/\x1b[0m\n",
.{e.path},
) catch {};
const path = try std.mem.concatWithSentinel(
std.heap.c_allocator, std.heap.c_allocator,
u8, u8,
&[_][]const u8{ "minecraft/", e.path, "/\x00" }, &[_][]const u8{ "minecraft/", e.path },
0,
); );
defer std.heap.c_allocator.free(path); defer std.heap.c_allocator.free(path);
try archiveCreateDir(zip.?, entry.?, path.ptr); try archiveCreateDir(zip.?, entry.?, path.ptr);
}, },
.File => { .File => {
stdout.print("Writing File\t\t\x1b[34m{s}\x1b[0m\n", .{e.path}) catch {};
const path = try std.mem.concatWithSentinel( const path = try std.mem.concatWithSentinel(
std.heap.c_allocator, std.heap.c_allocator,
u8, u8,
@ -81,11 +88,10 @@ pub fn main() !void {
try installMmcPackJson(zip.?, entry.?); try installMmcPackJson(zip.?, entry.?);
const instance_cfg_data = "InstanceType=OneSix";
c.archive_entry_set_pathname(entry, "instance.cfg"); c.archive_entry_set_pathname(entry, "instance.cfg");
c.archive_entry_set_size(entry, instance_cfg_data.len); c.archive_entry_set_size(entry, settings.instance_cfg_data.len);
try handleArchiveErr(c.archive_write_header(zip, entry), zip); try handleArchiveErr(c.archive_write_header(zip, entry), zip);
try writer.writeAll(instance_cfg_data); try writer.writeAll(settings.instance_cfg_data);
var mods_arena = std.heap.ArenaAllocator.init(std.heap.c_allocator); var mods_arena = std.heap.ArenaAllocator.init(std.heap.c_allocator);
defer mods_arena.deinit(); defer mods_arena.deinit();
@ -132,11 +138,9 @@ fn archiveFile(
try handleArchiveErr(c.archive_write_header(archive, entry), archive); try handleArchiveErr(c.archive_write_header(archive, entry), archive);
const writer = ArchiveWriter{ .context = archive }; const writer = ArchiveWriter{ .context = archive };
var read = try file.read(buf); try std.fifo.LinearFifo(u8, .Slice)
while (read != 0) { .init(buf)
try writer.writeAll(buf[0..read]); .pump(file.reader(), writer);
read = try file.read(buf);
}
} }
/// `name` must end with '/'! /// `name` must end with '/'!
@ -271,6 +275,7 @@ const CurlInfo = struct {
filename: []const u8, filename: []const u8,
index: usize, index: usize,
total: usize, total: usize,
mod_number_width: usize,
}; };
fn curlInfoCallback( fn curlInfoCallback(
@ -283,12 +288,13 @@ fn curlInfoCallback(
_ = ultotal; _ = ultotal;
_ = ulnow; _ = ulnow;
std.io.getStdOut().writer().print( std.io.getStdOut().writer().print(
"\r\x1b[34m[{d}/{d}] \x1b[97m{s} \x1b[32m{}%", "\r\x1b[34m[{d:[4]}/{d}] \x1b[97m{s} \x1b[32m{}%",
.{ .{
info.index, info.index,
info.total, info.total,
info.filename, info.filename,
if (dltotal != 0) @divTrunc(dlnow * 100, dltotal) else 0, if (dltotal != 0) @divTrunc(dlnow * 100, dltotal) else 0,
info.mod_number_width,
}, },
) catch {}; ) catch {};
return 0; return 0;
@ -317,6 +323,8 @@ fn downloadMods(
try handleCurlErr(c.curl_easy_setopt(curl, c.CURLOPT_NOPROGRESS, @as(c_long, 0))); try handleCurlErr(c.curl_easy_setopt(curl, c.CURLOPT_NOPROGRESS, @as(c_long, 0)));
try handleCurlErr(c.curl_easy_setopt(curl, c.CURLOPT_FOLLOWLOCATION, @as(c_long, 1))); try handleCurlErr(c.curl_easy_setopt(curl, c.CURLOPT_FOLLOWLOCATION, @as(c_long, 1)));
const mod_number_width = std.math.log10(mods.len) + 1;
const writer = ArchiveWriter{ .context = zip }; const writer = ArchiveWriter{ .context = zip };
var mod_buf = std.ArrayList(u8).init(std.heap.c_allocator); var mod_buf = std.ArrayList(u8).init(std.heap.c_allocator);
defer mod_buf.deinit(); defer mod_buf.deinit();
@ -324,6 +332,7 @@ fn downloadMods(
.filename = "", .filename = "",
.index = 0, .index = 0,
.total = mods.len, .total = mods.len,
.mod_number_width = mod_number_width,
}; };
try handleCurlErr(c.curl_easy_setopt(curl, c.CURLOPT_XFERINFODATA, &info)); try handleCurlErr(c.curl_easy_setopt(curl, c.CURLOPT_XFERINFODATA, &info));
// hide cursor // hide cursor
@ -376,8 +385,8 @@ fn downloadMods(
try handleCurlErr(c.curl_easy_perform(curl)); try handleCurlErr(c.curl_easy_perform(curl));
std.io.getStdOut().writer().print( std.io.getStdOut().writer().print(
"\r\x1b[34m[{d}/{d}] \x1b[97m{s} \x1b[31mZipping...", "\r\x1b[34m[{d:[3]}/{d}] \x1b[97m{s} \x1b[31mZipping...",
.{ info.index, info.total, info.filename }, .{ info.index, info.total, info.filename, mod_number_width },
) catch {}; ) catch {};
var archive_path = try std.mem.concatWithSentinel( var archive_path = try std.mem.concatWithSentinel(
@ -393,8 +402,8 @@ fn downloadMods(
try handleArchiveErr(c.archive_write_header(zip, entry), zip); try handleArchiveErr(c.archive_write_header(zip, entry), zip);
try writer.writeAll(mod_buf.items); try writer.writeAll(mod_buf.items);
std.io.getStdOut().writer().print( std.io.getStdOut().writer().print(
"\x1b[2K\r\x1b[34m[{d}/{d}] \x1b[97m{s}\n", "\x1b[2K\r\x1b[34m[{d:[3]}/{d}] \x1b[97m{s}\n",
.{ info.index, info.total, info.filename }, .{ info.index, info.total, info.filename, mod_number_width },
) catch {}; ) catch {};
} }
} }

View file

@ -1,8 +1,11 @@
// Version number used for the archive name /// Version number used for the archive name
pub const version = "1.4.1"; pub const version = "1.4.1";
pub const build_dir = "build"; pub const build_dir = "build";
pub const minecraft_version = "1.18.2"; pub const minecraft_version = "1.18.2";
pub const fabric_loader_version = "0.14.8"; pub const fabric_loader_version = "0.14.8";
// zip compression level. 9 is max. ask libarchive why this is a string. /// the data for the `instance.cfg` file
pub const instance_cfg_data =
\\InstanceType=OneSix
;
/// zip compression level. 9 is max. ask libarchive why this is a string.
pub const compression_level = "9"; pub const compression_level = "9";