Skip to content

Commit f717d1d

Browse files
committed
Add Zip button
1 parent e792b9f commit f717d1d

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed

build.zig

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,32 @@ pub fn build(b: *std.Build) void {
4848
zgpu_pkg.link(exe);
4949

5050
const converter = b.addModule("converter", .{
51-
// TODO: Stop hardcoding
52-
.source_file = .{ .path = "I:/Programming/Cortex-Command-Mod-Converter-Engine/src/convert.zig" },
51+
// TODO: Don't hardcode the path
52+
.source_file = .{ .path = "I:/Programming/Cortex-Command-Mod-Converter-Engine/src/main.zig" },
53+
// .source_file = .{ .path = "I:/Programming/Cortex-Command-Mod-Converter-Engine/build.zig" },
5354
});
5455
exe.addModule("converter", converter);
5556

57+
// Strip debug symbols by default
58+
// Should be disabled during development/debugging
59+
// Source: https://github.com/theseyan/bkg/blob/38663d8ed0257f45d37ce003a7e2cafd0f278951/build.zig#L15
60+
exe.strip = false;
61+
62+
exe.linkLibC();
63+
64+
exe.addCSourceFile(.{
65+
.file = .{ .path = "I:/Programming/Cortex-Command-Mod-Converter-Engine/submodules/zip/src/zip.c" },
66+
.flags = &.{
67+
"-O3",
68+
"-fno-sanitize=undefined", // Necessary to prevent "Illegal instruction" error
69+
},
70+
});
71+
72+
exe.addIncludePath(.{ .path = "I:/Programming/Cortex-Command-Mod-Converter-Engine/submodules/zip/src" });
73+
74+
// exe.addLibraryPath("I:/Programming/Cortex-Command-Mod-Converter-Engine/zig-out/lib/Cortex-Command-Mod-Converter-Engine.lib");
75+
// exe.linkLibrary(lib: *Compile);
76+
5677
// This declares intent for the executable to be installed into the
5778
// standard location when the user invokes the "install" step (the default
5879
// step when running `zig build`).

src/main.zig

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@ pub fn main() !void {
6868
const cwd = std.fs.cwd();
6969

7070
var input_mod_path_buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined;
71-
const input_mod_path = try cwd.realpath("I:/Programming/Cortex-Command-Mod-Converter-Engine/tests/mod/in", &input_mod_path_buffer);
71+
// const input_mod_path = try cwd.realpath("I:/Programming/Cortex-Command-Mod-Converter-Engine/tests/mod/in", &input_mod_path_buffer);
72+
const input_mod_path = try cwd.realpath("I:/Programming/Cortex-Command-Community-Project-Data/LegacyModConverter-v1.0-pre5.2/Input", &input_mod_path_buffer);
7273

7374
var output_mod_path_buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined;
74-
const output_mod_path = try cwd.realpath("I:/Programming/Cortex-Command-Mod-Converter-Engine/tests/mod/out", &output_mod_path_buffer);
75+
// const output_mod_path = try cwd.realpath("I:/Programming/Cortex-Command-Mod-Converter-Engine/tests/mod/out", &output_mod_path_buffer);
76+
const output_mod_path = try cwd.realpath("I:/Programming/Cortex-Command-Community-Project-Data/Mods", &output_mod_path_buffer);
7577

7678
var diagnostics: converter.Diagnostics = .{};
7779
converter.convert(
@@ -86,7 +88,7 @@ pub fn main() !void {
8688
const line = diagnostics.line orelse -1;
8789
const column = diagnostics.column orelse -1;
8890

89-
std.debug.print("Error: Unexpected token\nToken: '{s}'\nFile path: {s}\nLine: {}\nColumn: {} (roughly)\n", .{
91+
std.debug.print("Error: Unexpected '{s}' at {s}:{}:{}\n", .{
9092
token,
9193
file_path,
9294
line,
@@ -98,7 +100,7 @@ pub fn main() !void {
98100
const line = diagnostics.line orelse -1;
99101
const column = diagnostics.column orelse -1;
100102

101-
std.debug.print("Error: Too many tabs\nFile path: {s}\nLine: {} (roughly)\nColumn: {} (roughly)\n", .{
103+
std.debug.print("Error: Too many tabs at {s}:{}:{}\n", .{
102104
file_path,
103105
line,
104106
column,
@@ -116,6 +118,23 @@ pub fn main() !void {
116118
const result = try std.ChildProcess.exec(.{ .argv = &argv, .allocator = gpa });
117119
_ = result;
118120
}
121+
if (zgui.button("Zip", .{ .w = 200.0 })) {
122+
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
123+
defer arena.deinit();
124+
var allocator = arena.allocator();
125+
126+
// TODO: Why am I using cwd.realpath()?
127+
128+
const cwd = std.fs.cwd();
129+
130+
var input_mod_path_buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined;
131+
const input_mod_path = try cwd.realpath("I:/Programming/Cortex-Command-Community-Project-Data/LegacyModConverter-v1.0-pre5.2/Input", &input_mod_path_buffer);
132+
133+
var output_mod_path_buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined;
134+
const output_mod_path = try cwd.realpath("I:/Programming/Cortex-Command-Community-Project-Data/Mods", &output_mod_path_buffer);
135+
136+
try converter.zip_mods(input_mod_path, output_mod_path, allocator);
137+
}
119138
}
120139
zgui.end();
121140

0 commit comments

Comments
 (0)