return 101 when restart is required after self-update

This commit is contained in:
mxve 2023-08-17 18:32:32 +02:00
parent 9598ec3dfe
commit f7635d4089
2 changed files with 17 additions and 12 deletions

View File

@ -9,3 +9,6 @@
- Passing ```iw4-sp```, ```iw5-mod```, ```iw6-mod``` or ```s1-mod``` as the first argument will skip automatic game detection - Passing ```iw4-sp```, ```iw5-mod```, ```iw6-mod``` or ```s1-mod``` as the first argument will skip automatic game detection
- Passing ```update``` will stop the launcher from launching the game - Passing ```update``` will stop the launcher from launching the game
- ```skip-launcher-update``` skips self-update - ```skip-launcher-update``` skips self-update
### Note for server owners:
When the launcher updates itself it needs to be restarted. It will return exit code 101 in this case.

View File

@ -63,7 +63,7 @@ fn self_update() {
} }
#[cfg(windows)] #[cfg(windows)]
fn self_update() { fn self_update(update_only: bool) {
let working_dir = std::env::current_dir().unwrap(); let working_dir = std::env::current_dir().unwrap();
let files = fs::read_dir(&working_dir).unwrap(); let files = fs::read_dir(&working_dir).unwrap();
@ -106,8 +106,10 @@ fn self_update() {
self_replace::self_replace("alterware-launcher-update.exe").unwrap(); self_replace::self_replace("alterware-launcher-update.exe").unwrap();
fs::remove_file(&file_path).unwrap(); fs::remove_file(&file_path).unwrap();
println!("Launcher updated. Please run it again."); println!("Launcher updated. Please run it again.");
std::io::stdin().read_line(&mut String::new()).unwrap(); if !update_only {
std::process::exit(0); std::io::stdin().read_line(&mut String::new()).unwrap();
}
std::process::exit(101);
} }
} }
@ -260,8 +262,16 @@ fn launch(file_path: &PathBuf) {
fn main() { fn main() {
let mut args: Vec<String> = std::env::args().collect(); let mut args: Vec<String> = std::env::args().collect();
let mut update_only = false;
if args.contains(&String::from("update")) {
update_only = true;
args.iter()
.position(|r| r == "update")
.map(|e| args.remove(e));
}
if !args.contains(&String::from("skip-launcher-update")) { if !args.contains(&String::from("skip-launcher-update")) {
self_update(); self_update(update_only);
} else { } else {
args.iter() args.iter()
.position(|r| r == "skip-launcher-update") .position(|r| r == "skip-launcher-update")
@ -271,14 +281,6 @@ fn main() {
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();
let mut update_only = false;
if args.contains(&String::from("update")) {
update_only = true;
args.iter()
.position(|r| r == "update")
.map(|e| args.remove(e));
}
let mut game: String = String::new(); let mut game: String = String::new();
if args.len() > 1 { if args.len() > 1 {
game = String::from(&args[1]); game = String::from(&args[1]);