mirror of
https://github.com/yuzu-emu/liftinstall.git
synced 2024-11-22 12:35:39 +01:00
Merge pull request #26 from jroweboy/replace-old
Change updater to replace the existing installer.
This commit is contained in:
commit
ef71b707cb
66
src/main.rs
66
src/main.rs
@ -72,6 +72,7 @@ use clap::Arg;
|
|||||||
|
|
||||||
use config::BaseAttributes;
|
use config::BaseAttributes;
|
||||||
use std::process::{Command, Stdio, exit};
|
use std::process::{Command, Stdio, exit};
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
static RAW_CONFIG: &'static str = include_str!(concat!(env!("OUT_DIR"), "/bootstrap.toml"));
|
static RAW_CONFIG: &'static str = include_str!(concat!(env!("OUT_DIR"), "/bootstrap.toml"));
|
||||||
|
|
||||||
@ -135,26 +136,9 @@ fn main() {
|
|||||||
// check for existing installs if we are running as a fresh install
|
// check for existing installs if we are running as a fresh install
|
||||||
let installed_path = PathBuf::from(framework.get_default_path().unwrap());
|
let installed_path = PathBuf::from(framework.get_default_path().unwrap());
|
||||||
if fresh_install && installed_path.join("metadata.json").exists() {
|
if fresh_install && installed_path.join("metadata.json").exists() {
|
||||||
info!("Existing install detected! Trying to launch this install instead");
|
info!("Existing install detected! Copying Trying to launch this install instead");
|
||||||
// Generate installer path
|
// Ignore the return value from this since it should exit the application if its successful
|
||||||
let platform_extension = if cfg!(windows) {
|
let _ = replace_existing_install(¤t_exe, &installed_path);
|
||||||
"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") {
|
let is_launcher = if let Some(string) = matches.value_of("launcher") {
|
||||||
@ -168,3 +152,45 @@ fn main() {
|
|||||||
// Start up the UI
|
// Start up the UI
|
||||||
frontend::launch(&app_name, is_launcher, framework);
|
frontend::launch(&app_name, is_launcher, framework);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn replace_existing_install(current_exe: &PathBuf, installed_path: &PathBuf) -> Result<(), String> {
|
||||||
|
// Generate installer path
|
||||||
|
let platform_extension = if cfg!(windows) {
|
||||||
|
"maintenancetool.exe"
|
||||||
|
} else {
|
||||||
|
"maintenancetool"
|
||||||
|
};
|
||||||
|
|
||||||
|
let new_tool = if cfg!(windows) {
|
||||||
|
"maintenancetool_new.exe"
|
||||||
|
} else {
|
||||||
|
"maintenancetool_new"
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Err(v) = fs::copy(current_exe, installed_path.join(new_tool)) {
|
||||||
|
return Err(format!("Unable to copy installer binary: {:?}", v));
|
||||||
|
}
|
||||||
|
|
||||||
|
let existing = installed_path.join(platform_extension).into_os_string().into_string();
|
||||||
|
let new = installed_path.join(new_tool).into_os_string().into_string();
|
||||||
|
if existing.is_ok() && new.is_ok() {
|
||||||
|
// Remove NTFS alternate stream which tells the operating system that the updater was downloaded from the internet
|
||||||
|
if cfg!(windows) {
|
||||||
|
let _ = fs::remove_file(installed_path.join("maintenancetool_new.exe:Zone.Identifier:$DATA"));
|
||||||
|
}
|
||||||
|
info!("Launching {:?}", existing);
|
||||||
|
let success = Command::new(new.unwrap())
|
||||||
|
.arg("--swap")
|
||||||
|
.arg(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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user