diff --git a/src-tauri/src/commands/install/launch_options.rs b/src-tauri/src/commands/install/launch_options.rs index c1e2bb9..c51d810 100644 --- a/src-tauri/src/commands/install/launch_options.rs +++ b/src-tauri/src/commands/install/launch_options.rs @@ -1,5 +1,4 @@ use super::InstallErr; -use crate::util; use std::fs; use std::os::unix::prelude::PermissionsExt; @@ -27,15 +26,6 @@ pub async fn unix_launch_option_setup( } }; - // - // Skip if launch option is already set - // - - if is_already_set() { - println!("Steam launch option is already set. Skipping."); - return Ok(()); - } - // // make run_bepinex.sh executable // @@ -88,70 +78,3 @@ pub async fn unix_launch_option_setup( println!("Prompting to set launch option."); return Err(InstallErr::LaunchOptionNotSet); } - -fn is_already_set() -> bool { - // - // get localconfig.vdf path - // - - let localconfig_path = match get_localconfig_path() { - Some(localconfig_path) => localconfig_path, - - None => { - println!("Failed to locate localconfig.vdf"); - return false; - } - }; - - // - // check if launch option is set - // - - match fs::read_to_string(localconfig_path) { - Ok(_content) => { - // todo: improve logic - - // 1. find line only containing "750470" - // 2. find next closest line only containing "}" - // 3. check if section has line containing both "run_bepinex.sh" and "%command%" - - return true; - } - - Err(err) => { - println!("Failed to read localconfig.vdf: {:#?}", err); - return false; - } - }; -} - -fn get_localconfig_path() -> Option { - match util::get_default_steam_path() { - // using forward slash because this part of the code is only reachable in linux and macOS - Some(steam_path) => { - // get steam user ID - - let paths = std::fs::read_dir(format!("{}/userdata", steam_path)).unwrap(); - let mut user_path: &str = ""; - let mut _user_path_buf: std::path::PathBuf; - - let mut count = 0; - for path in paths { - count += 1; - - _user_path_buf = path.unwrap().path(); - user_path = _user_path_buf.to_str().unwrap(); - } - - if count > 1 { - // todo: choose steam user ID when there's multiple - println!("Failed to get steam user"); - return None; - } - - return Some(format!("{}/config/localconfig.vdf", user_path)); - } - - None => return None, - }; -} diff --git a/src-tauri/src/commands/install/mod.rs b/src-tauri/src/commands/install/mod.rs index 39ce6e2..fda2b82 100644 --- a/src-tauri/src/commands/install/mod.rs +++ b/src-tauri/src/commands/install/mod.rs @@ -9,8 +9,6 @@ mod launch_options; use types::InstallErr; -// todo: show current step in the frontend - /// automated version of the [manual installation](https://github.com/War-Brokers-Mods/WBM#installation). /// /// This function exits if it requires a user input and is called again with the user input as its arguments. @@ -20,9 +18,14 @@ use types::InstallErr; /// /// ## Arguments /// -/// * `game_path` - absolute path to the game folder/directory. +/// * `game_path` - Absolute path to the game folder/directory. +/// * `is_launch_option_set` - Whether if steam launch option is already set or not. #[tauri::command] -pub async fn install(window: tauri::Window, game_path: String) -> Result<(), InstallErr> { +pub async fn install( + window: tauri::Window, + game_path: String, + is_launch_option_set: bool, +) -> Result<(), InstallErr> { println!("install command called"); // @@ -88,9 +91,11 @@ pub async fn install(window: tauri::Window, game_path: String) -> Result<(), Ins // Set steam launch option if OS is linux or macOS // - match launch_options::unix_launch_option_setup(&window, game_path).await { - Ok(_) => {} - Err(err) => return Err(err), + if !is_launch_option_set { + match launch_options::unix_launch_option_setup(&window, game_path).await { + Ok(_) => {} + Err(err) => return Err(err), + } } // diff --git a/src/pages/Operation/Install.svelte b/src/pages/Operation/Install.svelte index 0912a26..07f0dd7 100644 --- a/src/pages/Operation/Install.svelte +++ b/src/pages/Operation/Install.svelte @@ -44,7 +44,7 @@