@@ -103,12 +103,12 @@ fn run_game(cfg: &Config) {
103
103
104
104
if cfg. sandboxed {
105
105
let script = include_str ! ( "injected.lua" ) ;
106
- let main_lua = path. join ( "main .lua" ) ;
106
+ let main_lua = path. join ( "conf .lua" ) ;
107
107
let mut main_lua_contents = fs:: read_to_string ( & main_lua)
108
- . expect ( "Failed to read Techmino's main .lua file" ) ;
108
+ . expect ( "Failed to read Techmino's conf .lua file" ) ;
109
109
main_lua_contents = format ! ( "{}\n {}" , script, main_lua_contents) ;
110
110
fs:: write ( main_lua, main_lua_contents)
111
- . expect ( "Failed to write to Techmino's main .lua file" ) ;
111
+ . expect ( "Failed to write to Techmino's conf .lua file" ) ;
112
112
}
113
113
114
114
if cfg. clear_temp_dir {
@@ -133,13 +133,13 @@ fn run_game(cfg: &Config) {
133
133
) ;
134
134
}
135
135
136
- // Restore main .lua
136
+ // Restore conf .lua
137
137
let mut command = Command :: new ( "git" ) ;
138
- command. args ( [ "restore" , "main .lua" ] )
138
+ command. args ( [ "restore" , "conf .lua" ] )
139
139
. current_dir ( & path) ;
140
140
141
141
command. status ( )
142
- . expect ( "Failed to restore main .lua using git" ) ;
142
+ . expect ( "Failed to restore conf .lua using git" ) ;
143
143
}
144
144
145
145
fn mutate_config_with_cli_args ( cfg : & mut Config ) {
@@ -149,6 +149,7 @@ fn mutate_config_with_cli_args(cfg: &mut Config) {
149
149
let arg = args[ i] . as_str ( ) ;
150
150
match arg {
151
151
// TODO: simplify cli arg processing using the `clap` crate
152
+ // TODO: --use-version <version> to specify version to run
152
153
"--help" => {
153
154
println ! ( "{}" , include_str!( "help.txt" ) ) ;
154
155
std:: process:: exit ( 0 ) ;
@@ -307,9 +308,47 @@ fn safe_todo(feature: Option<&str>) {
307
308
308
309
fn open_main_window ( cfg : & Config ) -> Result < MainWindow , slint:: PlatformError > {
309
310
let main_window = MainWindow :: new ( ) ?;
310
- main_window. on_open_game ( |_| {
311
- run_game ( & Config :: load ( ) ) ;
311
+ main_window. on_open_game ( |version| {
312
+ let cfg = Config :: load ( ) ;
313
+
314
+ if !version. is_empty ( ) {
315
+
316
+ let mut reset_cmd = Command :: new ( "git" )
317
+ . args ( [ "restore" , "." ] )
318
+ . current_dir ( cfg. game_repo_path . clone ( ) )
319
+ . status ( ) ;
320
+
321
+ if let Err ( e) = reset_cmd {
322
+ open_error_window_safe (
323
+ Some ( "Failed to reset repository" . to_string ( ) ) ,
324
+ Some ( "Failed to reset repository before switching versions" . to_string ( ) ) ,
325
+ Some ( format ! ( "Git: {e}" ) )
326
+ ) ;
327
+ return ;
328
+ }
329
+
330
+
331
+ let mut cmd = Command :: new ( "git" ) ;
332
+ let status = cmd
333
+ . args ( [ "checkout" , version. as_str ( ) ] )
334
+ . current_dir ( cfg. game_repo_path . clone ( ) )
335
+ . status ( ) ;
336
+
337
+ if let Err ( e) = status {
338
+ open_error_window_safe (
339
+ Some ( "Failed to switch versions" . to_string ( ) ) ,
340
+ Some (
341
+ format ! ( "Failed to switch to version '{version}'" )
342
+ ) ,
343
+ Some ( format ! ( "Git: {e}" ) )
344
+ ) ;
345
+ return ;
346
+ }
347
+ }
348
+
349
+ run_game ( & cfg) ;
312
350
} ) ;
351
+ main_window. set_selected_version ( "" . into ( ) ) ;
313
352
main_window. set_sandbox_path (
314
353
consts:: paths:: get_sandboxed_save_path ( )
315
354
. to_string_lossy ( )
@@ -498,7 +537,7 @@ fn is_repo_valid(path: &str) -> bool {
498
537
499
538
let files = files. unwrap ( ) ;
500
539
501
- // Check for .git and main .lua
540
+ // Check for .git and conf .lua
502
541
let mut has_git = false ;
503
542
let mut has_main_lua = false ;
504
543
@@ -508,7 +547,7 @@ fn is_repo_valid(path: &str) -> bool {
508
547
let file_name = file_name. to_str ( ) . unwrap_or ( "" ) ;
509
548
if file_name == ".git" {
510
549
has_git = true ;
511
- } else if file_name == "main .lua" {
550
+ } else if file_name == "conf .lua" {
512
551
has_main_lua = true ;
513
552
}
514
553
}
0 commit comments