From f582cdd6252664ee693889018ad2ff7d1285920a Mon Sep 17 00:00:00 2001 From: mxve <68632137+mxve@users.noreply.github.com> Date: Mon, 6 Nov 2023 03:20:46 +0100 Subject: [PATCH 1/4] self restart --- src/main.rs | 3 ++- src/self_update.rs | 27 ++++++++++++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4fd5ea5..07afa0b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -376,6 +376,7 @@ async fn main() { setup_env(); let mut args: Vec = env::args().collect(); + let original_args = args.clone(); if arg_bool(&args, "--help") { println!("CLI Args:"); @@ -428,7 +429,7 @@ async fn main() { 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); + self_update::run(cfg.update_only, original_args); } else { arg_remove(&mut args, "--skip-launcher-update"); } diff --git a/src/self_update.rs b/src/self_update.rs index a8e667f..e7eb854 100644 --- a/src/self_update.rs +++ b/src/self_update.rs @@ -13,7 +13,7 @@ pub fn self_update_available() -> bool { } #[cfg(not(windows))] -pub fn run(_update_only: bool) { +pub fn run(_update_only: bool, _args: Vec) { if self_update_available() { println!("A new version of the AlterWare launcher is available."); println!( @@ -26,7 +26,20 @@ pub fn run(_update_only: bool) { } #[cfg(windows)] -pub fn run(update_only: bool) { +pub fn restart(args: Vec) -> std::io::Error { + use std::os::windows::process::CommandExt; + match std::process::Command::new(std::env::current_exe().unwrap()) + .args(args.into_iter().skip(1)) + .creation_flags(0x00000010) // CREATE_NEW_CONSOLE + .spawn() + { + Ok(_) => std::process::exit(0), + Err(err) => err, + } +} + +#[cfg(windows)] +pub fn run(update_only: bool, args: Vec) { use std::{fs, path::PathBuf}; use crate::http; @@ -85,12 +98,12 @@ pub fn run(update_only: bool) { self_replace::self_replace("alterware-launcher-update.exe").unwrap(); fs::remove_file(&file_path).unwrap(); - println!( - "Launcher updated. View the changelog at https://github.com/{}/{}/releases/latest", - GH_OWNER, GH_REPO, - ); - println!("Please restart the launcher."); + + // restarting spawns a new console, automation should manually restart on exit code 201 if !update_only { + let restart_error = restart(args).to_string(); + println!("Failed to restart launcher: {}", restart_error); + println!("Please restart the launcher manually."); misc::stdin(); } std::process::exit(201); From 1e62b5ffad5caa8217c84266926d737790162092 Mon Sep 17 00:00:00 2001 From: mxve <68632137+mxve@users.noreply.github.com> Date: Mon, 6 Nov 2023 22:27:09 +0100 Subject: [PATCH 2/4] cleanup --- src/main.rs | 4 +--- src/self_update.rs | 10 +++++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 07afa0b..3d4f301 100644 --- a/src/main.rs +++ b/src/main.rs @@ -374,9 +374,7 @@ fn arg_remove_value(args: &mut Vec, arg: &str) { async fn main() { #[cfg(windows)] setup_env(); - let mut args: Vec = env::args().collect(); - let original_args = args.clone(); if arg_bool(&args, "--help") { println!("CLI Args:"); @@ -429,7 +427,7 @@ async fn main() { 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, original_args); + self_update::run(cfg.update_only); } else { arg_remove(&mut args, "--skip-launcher-update"); } diff --git a/src/self_update.rs b/src/self_update.rs index e7eb854..554f57d 100644 --- a/src/self_update.rs +++ b/src/self_update.rs @@ -26,10 +26,10 @@ pub fn run(_update_only: bool, _args: Vec) { } #[cfg(windows)] -pub fn restart(args: Vec) -> std::io::Error { +pub fn restart() -> std::io::Error { use std::os::windows::process::CommandExt; match std::process::Command::new(std::env::current_exe().unwrap()) - .args(args.into_iter().skip(1)) + .args(std::env::args().skip(1)) .creation_flags(0x00000010) // CREATE_NEW_CONSOLE .spawn() { @@ -39,7 +39,7 @@ pub fn restart(args: Vec) -> std::io::Error { } #[cfg(windows)] -pub fn run(update_only: bool, args: Vec) { +pub fn run(update_only: bool) { use std::{fs, path::PathBuf}; use crate::http; @@ -81,7 +81,7 @@ pub fn run(update_only: bool, args: Vec) { } else { "alterware-launcher.exe" }; - println!("{}", launcher_name); + http::download_file( &format!( "{}/download/{}", @@ -101,7 +101,7 @@ pub fn run(update_only: bool, args: Vec) { // restarting spawns a new console, automation should manually restart on exit code 201 if !update_only { - let restart_error = restart(args).to_string(); + let restart_error = restart().to_string(); println!("Failed to restart launcher: {}", restart_error); println!("Please restart the launcher manually."); misc::stdin(); From 09cec3f1adead9851df32ed47c9d572cc46350fd Mon Sep 17 00:00:00 2001 From: mxve <68632137+mxve@users.noreply.github.com> Date: Mon, 6 Nov 2023 22:27:53 +0100 Subject: [PATCH 3/4] v0.6.2 --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 01a56e2..f3fb938 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -28,7 +28,7 @@ dependencies = [ [[package]] name = "alterware-launcher" -version = "0.6.1" +version = "0.6.2" dependencies = [ "colored", "futures-util", diff --git a/Cargo.toml b/Cargo.toml index 385d024..1a95be7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "alterware-launcher" -version = "0.6.1" +version = "0.6.2" edition = "2021" build = "res/build.rs" From 9fe9f58e70f64ca473950602d847d7f2aac19a4e Mon Sep 17 00:00:00 2001 From: mxve <68632137+mxve@users.noreply.github.com> Date: Mon, 6 Nov 2023 22:33:58 +0100 Subject: [PATCH 4/4] fix linux --- src/self_update.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/self_update.rs b/src/self_update.rs index 554f57d..1a736a9 100644 --- a/src/self_update.rs +++ b/src/self_update.rs @@ -13,7 +13,7 @@ pub fn self_update_available() -> bool { } #[cfg(not(windows))] -pub fn run(_update_only: bool, _args: Vec) { +pub fn run(_update_only: bool) { if self_update_available() { println!("A new version of the AlterWare launcher is available."); println!(