From 6cae7461929428804c870961c74705e8b96febfa Mon Sep 17 00:00:00 2001 From: James Rowe Date: Fri, 6 Dec 2019 22:31:37 -0700 Subject: [PATCH] Launch existing maintenance tool if it exists in the default install folder --- src/main.rs | 31 ++++++++++++++++++++++++++- src/native/mod.rs | 6 +++--- src/tasks/launch_installed_on_exit.rs | 6 ++---- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2643c3c..b0956a0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,11 +65,13 @@ mod tasks; use installer::InstallerFramework; use logging::LoggingErrors; +use std::path::PathBuf; use clap::App; use clap::Arg; use config::BaseAttributes; +use std::process::{Command, Stdio, exit}; static RAW_CONFIG: &'static str = include_str!(concat!(env!("OUT_DIR"), "/bootstrap.toml")); @@ -106,12 +108,12 @@ fn main() { info!("{} installer", app_name); - // Handle self-updating if needed let current_exe = std::env::current_exe().log_expect("Current executable could not be found"); let current_path = current_exe .parent() .log_expect("Parent directory of executable could not be found"); + // Handle self-updating if needed self_update::perform_swap(¤t_exe, matches.value_of("swap")); if let Some(new_matches) = self_update::check_args(reinterpret_app, current_path) { matches = new_matches; @@ -119,15 +121,42 @@ fn main() { self_update::cleanup(current_path); // Load in metadata + setup the installer framework + let mut fresh_install = false; let metadata_file = current_path.join("metadata.json"); let mut framework = if metadata_file.exists() { info!("Using pre-existing metadata file: {:?}", metadata_file); InstallerFramework::new_with_db(config, current_path).log_expect("Unable to parse metadata") } else { info!("Starting fresh install"); + fresh_install = true; InstallerFramework::new(config) }; + // check for existing installs if we are running as a fresh install + let installed_path = PathBuf::from(framework.get_default_path().unwrap()); + if fresh_install && installed_path.join("metadata.json").exists() { + info!("Existing install detected! Trying to launch this install instead"); + // Generate installer path + let platform_extension = if cfg!(windows) { + "maintenancetool.exe" + } else { + "maintenancetool" + }; + let existing = installed_path.join(platform_extension).into_os_string().into_string(); + if existing.is_ok() { + info!("Launching {:?}", existing); + let success = Command::new(existing.unwrap()) + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .spawn(); + if success.is_ok() { + exit(0); + } else { + error!("Unable to start existing yuzu maintenance tool. Launching old one instead"); + } + } + } + let is_launcher = if let Some(string) = matches.value_of("launcher") { framework.is_launcher = true; framework.launcher_path = Some(string.to_string()); diff --git a/src/native/mod.rs b/src/native/mod.rs index 193f8c5..967b7a9 100644 --- a/src/native/mod.rs +++ b/src/native/mod.rs @@ -30,7 +30,7 @@ mod natives { HANDLE, PROCESS_QUERY_INFORMATION, PROCESS_TERMINATE, PROCESS_VM_READ, }; - use widestring::{U16CString, U16CStr}; + use widestring::{U16CString}; extern "C" { pub fn saveShortcut( @@ -65,7 +65,7 @@ mod natives { exe_path: &str, ) -> Result { let mut cmd_path = [0u16; MAX_PATH + 1]; - let result = unsafe { getDesktopFolder(cmd_path.as_mut_ptr()) }; + let _result = unsafe { getDesktopFolder(cmd_path.as_mut_ptr()) }; let source_path = format!( "{}\\{}.lnk", String::from_utf16_lossy(&cmd_path[..count_u16(&cmd_path)]).as_str(), @@ -96,7 +96,7 @@ mod natives { #[allow(unsafe_code)] fn create_shortcut_inner( source_file: String, - name: &str, + _name: &str, description: &str, target: &str, args: &str, diff --git a/src/tasks/launch_installed_on_exit.rs b/src/tasks/launch_installed_on_exit.rs index 5b7251f..5b67cf5 100644 --- a/src/tasks/launch_installed_on_exit.rs +++ b/src/tasks/launch_installed_on_exit.rs @@ -13,17 +13,15 @@ use config::PackageDescription; use logging::LoggingErrors; -use native::create_desktop_shortcut; - pub struct LaunchOnExitTask {} impl Task for LaunchOnExitTask { fn execute( &mut self, - mut input: Vec, + _: Vec, context: &mut InstallerFramework, - messenger: &dyn Fn(&TaskMessage), + _: &dyn Fn(&TaskMessage), ) -> Result { let pkg = &context.database.packages.first(); if pkg.is_none() {