@@ -73,6 +73,9 @@ pub fn main() !void {
73
73
@memcpy (game_executable_path_mut [0.. settings .game_executable_path .len ], settings .game_executable_path );
74
74
game_executable_path_mut [settings .game_executable_path .len ] = 0 ;
75
75
76
+ var err_msg_buf : [1337 ]u8 = undefined ;
77
+ var err_msg_slice : []u8 = undefined ;
78
+
76
79
while (! window .shouldClose ()) {
77
80
zglfw .pollEvents ();
78
81
@@ -110,57 +113,60 @@ pub fn main() !void {
110
113
var allocator = arena .allocator ();
111
114
112
115
var diagnostics : converter.Diagnostics = .{};
113
- converter .convert (
116
+ if ( converter .convert (
114
117
settings .input_folder_path ,
115
118
settings .output_folder_path ,
116
119
allocator ,
117
120
& diagnostics ,
118
- ) catch | err | switch (err ) {
119
- error .UnexpectedToken = > {
120
- const token = diagnostics .token orelse "null" ;
121
- const file_path = diagnostics .file_path orelse "null" ;
122
- const line = diagnostics .line orelse -1 ;
123
- const column = diagnostics .column orelse -1 ;
124
-
125
- std .debug .print ("Error: Unexpected '{s}' at {s}:{}:{}\n " , .{
126
- token ,
127
- file_path ,
128
- line ,
129
- column ,
130
- });
131
-
132
- return err ;
133
- },
134
- error .TooManyTabs = > {
135
- const file_path = diagnostics .file_path orelse "null" ;
136
- const line = diagnostics .line orelse -1 ;
137
- const column = diagnostics .column orelse -1 ;
138
-
139
- std .debug .print ("Error: Too many tabs at {s}:{}:{}\n " , .{
140
- file_path ,
141
- line ,
142
- column ,
143
- });
144
-
145
- return err ;
146
- },
147
- else = > | e | return e ,
148
- };
149
-
150
- try converter .beautifyLua (settings .output_folder_path , allocator );
151
-
152
- // TODO: Run .convert() in a separate thread, letting it update a passed Progress struct so we can update a progress bar here?
153
- // TODO: Check if std/Progress.zig is of use: https://ziglang.org/documentation/master/std/src/std/Progress.zig.html
154
- // TODO: Look at this example of multithreading in Zig: https://gist.github.com/cabarger/d3879745b8477670070f826cad2f027d
155
- // var progress: f32 = 0.0;
156
- // _ = progress;
157
- // zgui.pushStyleColor4f(.{ .idx = .plot_histogram, .c = .{ 0.1 + 0.5 * (1 - progress), 0.2 + 0.7 * progress, 0.3, 1.0 } });
158
- // zgui.progressBar(.{ .fraction = progress, .overlay = "" });
159
- // zgui.popStyleColor(.{});
160
- // progress += 0.01;
161
- // if (progress > 2.0) progress = 0.0;
162
-
163
- std .debug .print ("Done converting!\n " , .{});
121
+ )) {
122
+ try converter .beautifyLua (settings .output_folder_path , allocator );
123
+
124
+ // TODO: Run .convert() in a separate thread, letting it update a passed Progress struct so we can update a progress bar here?
125
+ // TODO: Check if std/Progress.zig is of use: https://ziglang.org/documentation/master/std/src/std/Progress.zig.html
126
+ // TODO: Look at this example of multithreading in Zig: https://gist.github.com/cabarger/d3879745b8477670070f826cad2f027d
127
+ // var progress: f32 = 0.0;
128
+ // _ = progress;
129
+ // zgui.pushStyleColor4f(.{ .idx = .plot_histogram, .c = .{ 0.1 + 0.5 * (1 - progress), 0.2 + 0.7 * progress, 0.3, 1.0 } });
130
+ // zgui.progressBar(.{ .fraction = progress, .overlay = "" });
131
+ // zgui.popStyleColor(.{});
132
+ // progress += 0.01;
133
+ // if (progress > 2.0) progress = 0.0;
134
+
135
+ std .debug .print ("Done converting!\n " , .{});
136
+ } else | err | {
137
+ switch (err ) {
138
+ 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 " , .{
140
+ diagnostics .token orelse "null" ,
141
+ diagnostics .file_path orelse "null" ,
142
+ diagnostics .line orelse -1 ,
143
+ diagnostics .column orelse -1 ,
144
+ });
145
+ },
146
+ 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 " , .{
148
+ diagnostics .file_path orelse "null" ,
149
+ diagnostics .line orelse -1 ,
150
+ diagnostics .column orelse -1 ,
151
+ });
152
+ },
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
+ });
161
+ },
162
+ }
163
+ std .debug .print ("{s}\n " , .{err_msg_slice });
164
+ zgui .openPopup ("error_popup" , .{});
165
+ }
166
+ }
167
+ if (zgui .beginPopup ("error_popup" , .{})) {
168
+ zgui .text ("{s}\n " , .{err_msg_slice });
169
+ zgui .endPopup ();
164
170
}
165
171
166
172
zgui .setNextItemWidth (@max (zgui .calcTextSize (settings .game_executable_path , .{})[0 ] + padding , min_width ));
@@ -172,17 +178,18 @@ pub fn main() !void {
172
178
if (zgui .button ("Launch" , .{ .w = 200.0 })) {
173
179
// TODO: Handle settings.game_executable_path not being set yet
174
180
try std .os .chdir (std .fs .path .dirname (settings .game_executable_path ) orelse return ConverterErrors .WeirdGameDir );
181
+
175
182
var argv = [_ ][]const u8 {settings .game_executable_path };
176
183
const result = try std .ChildProcess .exec (.{ .argv = & argv , .allocator = gpa });
177
184
_ = result ;
178
185
}
186
+
179
187
if (zgui .button ("Zip" , .{ .w = 200.0 })) {
180
188
var arena = std .heap .ArenaAllocator .init (std .heap .page_allocator );
181
189
defer arena .deinit ();
182
190
var allocator = arena .allocator ();
183
191
184
192
try converter .zipMods (settings .input_folder_path , settings .output_folder_path , allocator );
185
-
186
193
std .debug .print ("Done zipping!\n " , .{});
187
194
}
188
195
}
0 commit comments