mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Apply error handling for elevated process
This commit is contained in:
@@ -51,14 +51,29 @@ pub fn apply_package_impl(old_locator: &VelopackLocator, package: &PathBuf, run_
|
||||
} else {
|
||||
info!("Re-launching as administrator to update in {:?}", root_path);
|
||||
|
||||
let args: Vec<OsString> = vec!["--norestart".into(), "--package".into(), package.into()];
|
||||
let args: Vec<OsString> = vec!["--norestart".into(), "--package".into(), package.into(), "--root".into(), root_path.into()];
|
||||
let exe_path = std::env::current_exe()?;
|
||||
let work_dir: Option<String> = None; // same as this process
|
||||
let process_handle = process::run_process_as_admin(&exe_path, args, work_dir, false)?;
|
||||
|
||||
info!("Waiting (up to 10 minutes) for elevated process to exit...");
|
||||
let result = process::wait_for_process_to_exit(process_handle, Some(Duration::from_secs(10 * 60)))?;
|
||||
info!("Elevated process has exited ({:?}).", result);
|
||||
|
||||
match result {
|
||||
process::WaitResult::WaitTimeout => {
|
||||
bail!("Elevated process has not exited within 10 minutes. (TIMEOUT)");
|
||||
}
|
||||
process::WaitResult::ExitCode(code) => {
|
||||
if code != 0 {
|
||||
bail!("Elevated process has exited with ERROR: {}.", code);
|
||||
} else {
|
||||
info!("Elevated process has run successfully.");
|
||||
}
|
||||
}
|
||||
process::WaitResult::NoWaitRequired => {
|
||||
info!("Elevated process has not required waiting.");
|
||||
}
|
||||
}
|
||||
return Ok(new_locator);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ namespace Velopack.Locators
|
||||
var tempTargetUpdateExe = Path.Combine(TempAppRootDirectory, "Update.exe");
|
||||
if (File.Exists(UpdateExePath) && !File.Exists(tempTargetUpdateExe)) {
|
||||
initLog.Warn("Application directory is not writable. Copying Update.exe to temp location: " + tempTargetUpdateExe);
|
||||
Debugger.Launch();
|
||||
// Debugger.Launch();
|
||||
Directory.CreateDirectory(TempAppRootDirectory);
|
||||
File.Copy(UpdateExePath, tempTargetUpdateExe);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user