From 65f05a5a1cf97bb677d772079339fb41bc5f891b Mon Sep 17 00:00:00 2001 From: mxve <68632137+mxve@users.noreply.github.com> Date: Thu, 14 Sep 2023 09:44:35 +0200 Subject: [PATCH] add --path, -p --- README.md | 2 ++ src/main.rs | 23 +++++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index f2d145b..c209f6e 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,8 @@ - Download bonus content - ```--force```, ```-f``` - Force file hash recheck +- ```--path```, ```-p``` + - Set the game path Example: ```alterware-launcher.exe iw4x --bonus -u``` diff --git a/src/main.rs b/src/main.rs index 045a125..95608e8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -104,7 +104,6 @@ fn windows_launcher_install(games: &Vec) { let installed_games = get_installed_games(games); if !installed_games.is_empty() { - // if current directory is in the steamapps/common folder of a game, use that game let current_dir = std::env::current_dir().unwrap(); for (id, path) in installed_games.iter() { if current_dir.starts_with(path) { @@ -282,7 +281,8 @@ fn setup_env() { } fn arg_value(args: &[String], arg: &str) -> Option { - let val = args.iter() + let val = args + .iter() .position(|r| r == arg) .map(|e| args[e + 1].clone()); if let Some(ref val) = val { @@ -331,6 +331,17 @@ fn main() { arg_remove(&mut args, "-f"); } + let install_path: PathBuf; + if let Some(path) = arg_value(&args, "--path") { + install_path = PathBuf::from(path); + arg_remove(&mut args, "--path"); + } else if let Some(path) = arg_value(&args, "-p") { + install_path = PathBuf::from(path); + arg_remove(&mut args, "-p"); + } else { + install_path = std::env::current_dir().unwrap(); + } + let games_json = http::get_body_string(format!("{}/games.json", MASTER).as_str()); let games: Vec = serde_json::from_str(&games_json).unwrap(); @@ -374,12 +385,12 @@ fn main() { let input = misc::stdin().to_ascii_lowercase(); cfg.download_bonus_content = input != "n"; config::save_value( - PathBuf::from("alterware-launcher.json"), + install_path.join("alterware-launcher.json"), "download_bonus_content", cfg.download_bonus_content, ); config::save_value( - PathBuf::from("alterware-launcher.json"), + install_path.join("alterware-launcher.json"), "ask_bonus_content", false, ); @@ -387,12 +398,12 @@ fn main() { update( g, - &std::env::current_dir().unwrap(), + install_path.as_path(), cfg.download_bonus_content, cfg.force_update, ); if !cfg.update_only { - launch(&PathBuf::from(format!("{}.exe", c))); + launch(&install_path.join(format!("{}.exe", c))); } return; }