mirror of
https://github.com/yuzu-emu/liftinstall.git
synced 2024-11-29 08:44:22 +01:00
Launch existing maintenance tool if it exists in the default install folder
This commit is contained in:
parent
732e344605
commit
6cae746192
31
src/main.rs
31
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());
|
||||
|
@ -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<String, String> {
|
||||
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,
|
||||
|
@ -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<TaskParamType>,
|
||||
_: Vec<TaskParamType>,
|
||||
context: &mut InstallerFramework,
|
||||
messenger: &dyn Fn(&TaskMessage),
|
||||
_: &dyn Fn(&TaskMessage),
|
||||
) -> Result<TaskParamType, String> {
|
||||
let pkg = &context.database.packages.first();
|
||||
if pkg.is_none() {
|
||||
|
Loading…
Reference in New Issue
Block a user