@@ -6,10 +6,6 @@ const zglfw = @import("zglfw");
66const zgpu = @import ("zgpu" );
77const zgui = @import ("zgui" );
88
9- const ConverterErrors = error {
10- WeirdGameDir ,
11- };
12-
139const Settings = struct {
1410 input_folder_path : []const u8 = "" ,
1511 output_folder_path : []const u8 = "" ,
@@ -40,9 +36,9 @@ pub fn main() !void {
4036 zgui .init (gpa );
4137 defer zgui .deinit ();
4238
43- // _ = zgui.io.addFontFromFile("content /Roboto-Medium.ttf", 26.0);
44- // _ = zgui.io.addFontFromFile("content /FiraCode-Medium.ttf", 26.0);
45- _ = zgui .io .addFontFromFile ("content /ProggyClean.ttf" , 26.0 );
39+ // _ = zgui.io.addFontFromFile("fonts /Roboto-Medium.ttf", 26.0);
40+ // _ = zgui.io.addFontFromFile("fonts /FiraCode-Medium.ttf", 26.0);
41+ _ = zgui .io .addFontFromFile ("fonts /ProggyClean.ttf" , 26.0 );
4642
4743 zgui .backend .init (
4844 window ,
@@ -73,7 +69,7 @@ pub fn main() !void {
7369 @memcpy (game_executable_path_mut [0.. settings .game_executable_path .len ], settings .game_executable_path );
7470 game_executable_path_mut [settings .game_executable_path .len ] = 0 ;
7571
76- var err_msg_buf : [1337 ]u8 = undefined ;
72+ var err_msg_buf : [420420 ]u8 = undefined ;
7773 var err_msg_slice : []u8 = undefined ;
7874
7975 while (! window .shouldClose ()) {
@@ -135,36 +131,48 @@ pub fn main() !void {
135131 std .debug .print ("Done converting!\n " , .{});
136132 } else | err | {
137133 switch (err ) {
134+ error .InvalidInputPath = > {
135+ err_msg_slice = try std .fmt .bufPrint (& err_msg_buf , "Error: Invalid input path" , .{});
136+ },
137+ error .InvalidOutputPath = > {
138+ err_msg_slice = try std .fmt .bufPrint (& err_msg_buf , "Error: Invalid output path" , .{});
139+ },
140+ error .FileNotFound = > {
141+ err_msg_slice = try std .fmt .bufPrint (& err_msg_buf , "Error: Please enter valid input and output paths" , .{});
142+ },
138143 error .UnexpectedToken = > {
139- err_msg_slice = try std .fmt .bufPrint (& err_msg_buf , "Error: Unexpected token '{s}' in file {s} on line {} and column {}\n " , .{
144+ err_msg_slice = try std .fmt .bufPrint (& err_msg_buf , "Error: Unexpected token '{s}' in file {s} on line {} and column {}" , .{
140145 diagnostics .token orelse "null" ,
141146 diagnostics .file_path orelse "null" ,
142147 diagnostics .line orelse -1 ,
143148 diagnostics .column orelse -1 ,
144149 });
145150 },
151+ error .UnclosedMultiComment = > {
152+ err_msg_slice = try std .fmt .bufPrint (& err_msg_buf , "Error: Unclosed multi-line comment in file {s}" , .{
153+ diagnostics .file_path orelse "null" ,
154+ });
155+ },
146156 error .TooManyTabs = > {
147- err_msg_slice = try std .fmt .bufPrint (& err_msg_buf , "Error: Too many tabs in file {s} on line {} and column {}\n " , .{
157+ err_msg_slice = try std .fmt .bufPrint (& err_msg_buf , "Error: Too many tabs in file {s} on line {} and column {}" , .{
148158 diagnostics .file_path orelse "null" ,
149159 diagnostics .line orelse -1 ,
150160 diagnostics .column orelse -1 ,
151161 });
152162 },
153- // TODO: Add more custom error messages,
154- // by briefly commenting out this else-statement,
155- // and looking at the printed list of unhandled errors
156- else = > | e | {
157- err_msg_slice = try std .fmt .bufPrint (& err_msg_buf , "{} in file {s} \n " , .{
158- e ,
159- diagnostics . file_path orelse "null" ,
160- });
163+ error . ExpectedADataModule = > {
164+ err_msg_slice = try std . fmt . bufPrint ( & err_msg_buf , "Error: Expected a DataModule" , .{});
165+ },
166+ error . ContainsMoreThanOneDataModule = > {
167+ err_msg_slice = try std .fmt .bufPrint (& err_msg_buf , "Error: The mod contains more than one DataModule " , .{});
168+ } ,
169+ else = > | _ | {
170+ err_msg_slice = try std . fmt . bufPrint ( & err_msg_buf , "{?}" , .{ @errorReturnTrace () });
161171 },
162172 }
163173
164174 std .debug .print ("{s}\n " , .{err_msg_slice });
165175 zgui .openPopup ("error_popup" , .{});
166-
167- // return err;
168176 }
169177 }
170178 if (zgui .beginPopup ("error_popup" , .{})) {
@@ -173,18 +181,34 @@ pub fn main() !void {
173181 }
174182
175183 zgui .setNextItemWidth (@max (zgui .calcTextSize (settings .game_executable_path , .{})[0 ] + padding , min_width ));
176- if (zgui .inputTextWithHint ("Game .exe path" , .{ .hint = "Copy-paste a path from File Explorer here" , .buf = & game_executable_path_mut })) {
184+ if (zgui .inputTextWithHint ("Game executable path" , .{ .hint = "Copy-paste a path from File Explorer here" , .buf = & game_executable_path_mut })) {
177185 settings .game_executable_path = std .mem .span (@as ([* :0 ]u8 , & game_executable_path_mut ));
178186 try writeSettings (settings );
179187 }
180188
181189 if (zgui .button ("Launch" , .{ .w = 200.0 })) {
182- // TODO: Handle settings.game_executable_path not being set yet
183- try std .os .chdir (std .fs .path .dirname (settings .game_executable_path ) orelse return ConverterErrors .WeirdGameDir );
184-
185- var argv = [_ ][]const u8 {settings .game_executable_path };
186- const result = try std .ChildProcess .exec (.{ .argv = & argv , .allocator = gpa });
187- _ = result ;
190+ const dirname = std .fs .path .dirname (settings .game_executable_path ) orelse "." ;
191+
192+ if (std .os .chdir (dirname )) {
193+ var argv = [_ ][]const u8 {settings .game_executable_path };
194+ _ = std .ChildProcess .exec (.{ .argv = & argv , .allocator = gpa }) catch | err | switch (err ) {
195+ error .FileNotFound = > {
196+ err_msg_slice = try std .fmt .bufPrint (& err_msg_buf , "Error: Please enter the game executable path" , .{});
197+ zgui .openPopup ("error_popup" , .{});
198+ },
199+ else = > | e | return e ,
200+ };
201+ } else | err | switch (err ) {
202+ error .BadPathName = > {
203+ err_msg_slice = try std .fmt .bufPrint (& err_msg_buf , "Error: Please enter the game executable path" , .{});
204+ zgui .openPopup ("error_popup" , .{});
205+ },
206+ error .FileNotFound = > {
207+ err_msg_slice = try std .fmt .bufPrint (& err_msg_buf , "Error: Please enter the game executable path" , .{});
208+ zgui .openPopup ("error_popup" , .{});
209+ },
210+ else = > | e | return e ,
211+ }
188212 }
189213
190214 // if (zgui.button("Zip", .{ .w = 200.0 })) {
0 commit comments