From 75b1d6254b275f52ef17ad077bb45d959f2ed451 Mon Sep 17 00:00:00 2001 From: mxve <68632137+mxve@users.noreply.github.com> Date: Thu, 14 Sep 2023 10:08:26 +0200 Subject: [PATCH] strip value AND arg :expressionless: --- README.md | 3 ++- src/main.rs | 35 ++++++++++++++++++++++------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index c209f6e..20dbaf7 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,9 @@ - Force file hash recheck - ```--path```, ```-p``` - Set the game path + - Do not include a trailing backslash in the path -Example: ```alterware-launcher.exe iw4x --bonus -u``` +Example: ```alterware-launcher.exe iw4x --bonus -u --path "C:\Games\IW4x"``` Some arguments can be set in alterware-launcher.json, args generally override the values of the config. diff --git a/src/main.rs b/src/main.rs index 95608e8..c88a1ab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -301,12 +301,31 @@ fn arg_remove(args: &mut Vec, arg: &str) { args.iter().position(|r| r == arg).map(|e| args.remove(e)); } +fn arg_remove_value(args: &mut Vec, arg: &str) { + args.iter().position(|r| r == arg).map(|e| { + args.remove(e); + args.remove(e); + }); +} + fn main() { #[cfg(windows)] setup_env(); let mut args: Vec = std::env::args().collect(); - let mut cfg = config::load(PathBuf::from("alterware-launcher.json")); + + let install_path: PathBuf; + if let Some(path) = arg_value(&args, "--path") { + install_path = PathBuf::from(path); + arg_remove_value(&mut args, "--path"); + } else if let Some(path) = arg_value(&args, "-p") { + install_path = PathBuf::from(path); + arg_remove_value(&mut args, "-p"); + } else { + install_path = std::env::current_dir().unwrap(); + } + + let mut cfg = config::load(install_path.join("alterware-launcher.json")); if !arg_bool(&args, "--skip-launcher-update") && !cfg.skip_self_update { self_update::run(cfg.update_only); @@ -331,17 +350,6 @@ 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(); @@ -351,7 +359,8 @@ fn main() { } else { 'main: for g in games.iter() { for r in g.references.iter() { - if std::path::Path::new(r).exists() { + println!("{:?}", install_path.join(r)); + if install_path.join(r).exists() { if g.client.len() > 1 { if cfg.update_only { game = String::from(g.client[0]);