@@ -6,10 +6,6 @@ const zglfw = @import("zglfw");
6
6
const zgpu = @import ("zgpu" );
7
7
const zgui = @import ("zgui" );
8
8
9
- const ConverterErrors = error {
10
- WeirdGameDir ,
11
- };
12
-
13
9
const Settings = struct {
14
10
input_folder_path : []const u8 = "" ,
15
11
output_folder_path : []const u8 = "" ,
@@ -40,9 +36,9 @@ pub fn main() !void {
40
36
zgui .init (gpa );
41
37
defer zgui .deinit ();
42
38
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 );
46
42
47
43
zgui .backend .init (
48
44
window ,
@@ -73,7 +69,7 @@ pub fn main() !void {
73
69
@memcpy (game_executable_path_mut [0.. settings .game_executable_path .len ], settings .game_executable_path );
74
70
game_executable_path_mut [settings .game_executable_path .len ] = 0 ;
75
71
76
- var err_msg_buf : [1337 ]u8 = undefined ;
72
+ var err_msg_buf : [420420 ]u8 = undefined ;
77
73
var err_msg_slice : []u8 = undefined ;
78
74
79
75
while (! window .shouldClose ()) {
@@ -135,36 +131,48 @@ pub fn main() !void {
135
131
std .debug .print ("Done converting!\n " , .{});
136
132
} else | err | {
137
133
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
+ },
138
143
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 {}" , .{
140
145
diagnostics .token orelse "null" ,
141
146
diagnostics .file_path orelse "null" ,
142
147
diagnostics .line orelse -1 ,
143
148
diagnostics .column orelse -1 ,
144
149
});
145
150
},
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
+ },
146
156
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 {}" , .{
148
158
diagnostics .file_path orelse "null" ,
149
159
diagnostics .line orelse -1 ,
150
160
diagnostics .column orelse -1 ,
151
161
});
152
162
},
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 () });
161
171
},
162
172
}
163
173
164
174
std .debug .print ("{s}\n " , .{err_msg_slice });
165
175
zgui .openPopup ("error_popup" , .{});
166
-
167
- // return err;
168
176
}
169
177
}
170
178
if (zgui .beginPopup ("error_popup" , .{})) {
@@ -173,18 +181,34 @@ pub fn main() !void {
173
181
}
174
182
175
183
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 })) {
177
185
settings .game_executable_path = std .mem .span (@as ([* :0 ]u8 , & game_executable_path_mut ));
178
186
try writeSettings (settings );
179
187
}
180
188
181
189
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
+ }
188
212
}
189
213
190
214
// if (zgui.button("Zip", .{ .w = 200.0 })) {
0 commit comments