public static void InstallUpdateAndRestart(DownloadedUpdate update) { try { Logger.AutoUpdate.LogDebug("Begin install"); File.Delete(TempNewAppPath); using (var tempNewAppFile = File.OpenWrite(TempNewAppPath)) update.UpdateBytes.WriteTo(tempNewAppFile); Logger.AutoUpdate.LogDebug("Extracted update"); File.Delete(TempOldAppPath); File.Move(App.Location, TempOldAppPath); File.Move(TempNewAppPath, App.Location); Logger.AutoUpdate.LogDebug("Replaced executable"); // disable settings with external state before upgrade, as the new version maybe uses a different system. StartWithSpotify.Disable(); Autostart.Disable(); Logger.AutoUpdate.LogDebug("Restarting"); Process.Start(App.Location, "/updateRestart").Dispose(); Application.Current.Dispatcher.Invoke(() => Application.Current.Shutdown()); } catch (Exception e) { Logger.AutoUpdate.LogException("Installation failed:", e); Logger.AutoUpdate.LogInfo("Starting failure cleanup"); // cleanup failed installation // try to restore app executable if (!File.Exists(App.Location)) { if (File.Exists(TempOldAppPath)) { File.Move(TempOldAppPath, App.Location); } else if (File.Exists(TempNewAppPath)) { File.Move(TempNewAppPath, App.Location); } } // delete update file if it still exists File.Delete(TempNewAppPath); Logger.AutoUpdate.LogInfo("Finished failure cleanup"); // rethrow exception throw; } finally { update.Dispose(); } }
public static void InstallUpdateAndRestart(DownloadedUpdate update) { try { Logger.LogDebug("AutoUpdate: Begin install"); File.Delete(TempNewAppPath); using (var tempNewAppFile = File.OpenWrite(TempNewAppPath)) update.UpdateBytes.WriteTo(tempNewAppFile); update.Dispose(); Logger.LogDebug("AutoUpdate: Extracted update"); File.Delete(TempOldAppPath); File.Move(App.Location, TempOldAppPath); File.Move(TempNewAppPath, App.Location); Logger.LogDebug("AutoUpdate: Replaced executable"); Logger.LogDebug("AutoUpdate: Restarting"); Process.Start(App.Location, "/updateRestart").Dispose(); Application.Current.Dispatcher.Invoke(() => { Application.Current.Shutdown(); }); } catch (Exception e) { Logger.LogException("AutoUpdate: Installation failed:", e); Logger.LogInfo("AutoUpdate: Starting failure cleanup"); // cleanup failed installation // try to restore app executable if (!File.Exists(App.Location)) { if (File.Exists(TempOldAppPath)) { File.Move(TempOldAppPath, App.Location); } else if (File.Exists(TempNewAppPath)) { File.Move(TempNewAppPath, App.Location); } } // delete update file if it still exists File.Delete(TempNewAppPath); Logger.LogInfo("AutoUpdate: Finished failure cleanup"); // rethrow exception throw; } }