add --pass to allow passing args to the client
This commit is contained in:
parent
b830ab7085
commit
be3c45b79d
@ -29,8 +29,10 @@
|
|||||||
- ```--path```, ```-p```
|
- ```--path```, ```-p```
|
||||||
- Set the game path
|
- Set the game path
|
||||||
- Do not include a trailing backslash in the path
|
- Do not include a trailing backslash in the path
|
||||||
|
-- ```--pass```
|
||||||
|
- Pass additional arguments to the game
|
||||||
|
|
||||||
Example: ```alterware-launcher.exe iw4x --bonus -u --path "C:\Games\IW4x"```
|
Example: ```alterware-launcher.exe iw4x --bonus -u --path "C:\Games\IW4x" --pass "-console"```
|
||||||
|
|
||||||
Some arguments can be set in alterware-launcher.json, args generally override the values of the config.
|
Some arguments can be set in alterware-launcher.json, args generally override the values of the config.
|
||||||
|
|
||||||
|
28
src/main.rs
28
src/main.rs
@ -263,9 +263,10 @@ fn update(game: &Game, dir: &Path, bonus_content: bool, force: bool) {
|
|||||||
fs::write(dir.join(".sha-sums"), hash_file_content).unwrap();
|
fs::write(dir.join(".sha-sums"), hash_file_content).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn launch(file_path: &PathBuf) {
|
fn launch(file_path: &PathBuf, args: &str) {
|
||||||
println!("Launching {}...", file_path.display());
|
println!("Launching {}...", file_path.display());
|
||||||
std::process::Command::new(file_path)
|
std::process::Command::new(file_path)
|
||||||
|
.args(args.split(' '))
|
||||||
.spawn()
|
.spawn()
|
||||||
.expect("Failed to launch the game")
|
.expect("Failed to launch the game")
|
||||||
.wait()
|
.wait()
|
||||||
@ -281,16 +282,9 @@ fn setup_env() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn arg_value(args: &[String], arg: &str) -> Option<String> {
|
fn arg_value(args: &[String], arg: &str) -> Option<String> {
|
||||||
let val = args
|
args.iter()
|
||||||
.iter()
|
|
||||||
.position(|r| r == arg)
|
.position(|r| r == arg)
|
||||||
.map(|e| args[e + 1].clone());
|
.map(|e| args[e + 1].clone())
|
||||||
if let Some(ref val) = val {
|
|
||||||
if val.starts_with('-') {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn arg_bool(args: &[String], arg: &str) -> bool {
|
fn arg_bool(args: &[String], arg: &str) -> bool {
|
||||||
@ -302,10 +296,10 @@ fn arg_remove(args: &mut Vec<String>, arg: &str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn arg_remove_value(args: &mut Vec<String>, arg: &str) {
|
fn arg_remove_value(args: &mut Vec<String>, arg: &str) {
|
||||||
args.iter().position(|r| r == arg).map(|e| {
|
if let Some(e) = args.iter().position(|r| r == arg) {
|
||||||
args.remove(e);
|
args.remove(e);
|
||||||
args.remove(e);
|
args.remove(e);
|
||||||
});
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -350,6 +344,14 @@ fn main() {
|
|||||||
arg_remove(&mut args, "-f");
|
arg_remove(&mut args, "-f");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let client_args: String;
|
||||||
|
if let Some(pass) = arg_value(&args, "--pass") {
|
||||||
|
client_args = pass;
|
||||||
|
arg_remove_value(&mut args, "--pass");
|
||||||
|
} else {
|
||||||
|
client_args = String::new();
|
||||||
|
}
|
||||||
|
|
||||||
let games_json = http::get_body_string(format!("{}/games.json", MASTER).as_str());
|
let games_json = http::get_body_string(format!("{}/games.json", MASTER).as_str());
|
||||||
let games: Vec<Game> = serde_json::from_str(&games_json).unwrap();
|
let games: Vec<Game> = serde_json::from_str(&games_json).unwrap();
|
||||||
|
|
||||||
@ -411,7 +413,7 @@ fn main() {
|
|||||||
cfg.force_update,
|
cfg.force_update,
|
||||||
);
|
);
|
||||||
if !cfg.update_only {
|
if !cfg.update_only {
|
||||||
launch(&install_path.join(format!("{}.exe", c)));
|
launch(&install_path.join(format!("{}.exe", c)), &client_args);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user