return 101 when restart is required after self-update

This commit is contained in:
mxve 2023-08-17 18:32:32 +02:00
parent f787feed05
commit 58423863f5
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 ```update``` will stop the launcher from launching the game
- ```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)]
fn self_update() {
fn self_update(update_only: bool) {
let working_dir = std::env::current_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();
fs::remove_file(&file_path).unwrap();
println!("Launcher updated. Please run it again.");
std::io::stdin().read_line(&mut String::new()).unwrap();
std::process::exit(0);
if !update_only {
std::io::stdin().read_line(&mut String::new()).unwrap();
}
std::process::exit(101);
}
}
@ -260,8 +262,16 @@ fn launch(file_path: &PathBuf) {
fn main() {
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")) {
self_update();
self_update(update_only);
} else {
args.iter()
.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: 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();
if args.len() > 1 {
game = String::from(&args[1]);