From 6ac01827846dbbaed5396fc51ae9523b8896f778 Mon Sep 17 00:00:00 2001 From: Thoronium <107363768+NotThorny@users.noreply.github.com> Date: Sat, 22 Apr 2023 15:41:54 -0600 Subject: [PATCH] Fix args --- src-tauri/src/main.rs | 20 ++++++++++++++------ src-tauri/src/system_helpers.rs | 17 +++++++++++++---- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 326e365..db518de 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -54,13 +54,18 @@ async fn parse_args(inp: &Vec) -> Result { "no-admin", "Launch without requiring admin permissions", ); - args.flag("g", "no-gui", "Run in CLI mode"); + args.flag("g", "no-gui", "Run in CLI mode. Requires -A to be passed as well."); args.flag("s", "server", "Launch the configured GC server"); args.flag( "P", "patch", "Patch your game before launching, with whatever your game version needs", ); + args.flag( + "N", + "non-elevated-game", + "Launch the game without admin permissions" + ); args.option( "H", "host", @@ -96,17 +101,20 @@ async fn parse_args(inp: &Vec) -> Result { patch::patch_game().await; } - system_helpers::run_program(game_path.to_string(), Some(game_args)) + if args.value_of("non-elevated-game")? { + system_helpers::run_un_elevated(game_path.to_string(), Some(game_args)) + } else { + system_helpers::run_program(game_path.to_string(), Some(game_args)) + } } if args.value_of("server")? { let server_jar = config.grasscutter_path; - let mut server_path = server_jar.clone(); + // Assumes grasscutter jar is named appropriately + let server_path = server_jar.trim_end_matches("grasscutter.jar"); let java_path = config.java_path; - server_path.pop(); - - system_helpers::run_jar(server_jar, server_path.to_string(), java_path); + system_helpers::run_jar(server_jar.clone(), server_path.to_string(), java_path); } if args.value_of::("host").is_ok() && !args.value_of::("host")?.is_empty() { diff --git a/src-tauri/src/system_helpers.rs b/src-tauri/src/system_helpers.rs index 7d09fa9..9197ba5 100644 --- a/src-tauri/src/system_helpers.rs +++ b/src-tauri/src/system_helpers.rs @@ -11,7 +11,16 @@ use registry::{Data, Hive, Security}; #[tauri::command] pub fn run_program(path: String, args: Option) { // Without unwrap_or, this can crash when UAC prompt is denied - open::that(format!("{} {}", &path, &args.unwrap_or_else(|| "".into()))).unwrap_or(()); + match open::with( + format!( + "{} {}", + path, args.unwrap_or_else(|| "".into()) + ), + path.clone(), + ) { + Ok(_) => (), + Err(e) => println!("Failed to open program ({}): {}", &path, e), + }; } #[tauri::command] @@ -80,12 +89,12 @@ pub fn run_jar(path: String, execute_in: String, java_path: String) { } #[tauri::command] -pub fn run_un_elevated(path: String) { +pub fn run_un_elevated(path: String, args: Option) { // Open the program non-elevated. match open::with( format!( - "cmd /min /C \"set __COMPAT_LAYER=RUNASINVOKER && start \"\" \"{}\"\"", - path + "cmd /min /C \"set __COMPAT_LAYER=RUNASINVOKER && start \"\" \"{}\"\" {}", + path, args.unwrap_or_else(|| "".into()) ), "C:\\Windows\\System32\\cmd.exe", ) {