diff --git a/GoToWindow/App.xaml.cs b/GoToWindow/App.xaml.cs index 202862e..b0891ab 100644 --- a/GoToWindow/App.xaml.cs +++ b/GoToWindow/App.xaml.cs @@ -39,8 +39,7 @@ private void Application_Startup(object sender, StartupEventArgs e) { MessageBox.Show( "Another Go To Window instance is already running." + Environment.NewLine + - "Exit by right-clicking the icon in the tray, and selecting 'Exit'." + Environment.NewLine + - String.Join(" ", e.Args), + "Exit by right-clicking the icon in the tray, and selecting 'Exit'.", "Go To Window", MessageBoxButton.OK, MessageBoxImage.Information @@ -100,6 +99,8 @@ private bool WaitForOtherInstancesToShutDown() private void Application_Exit(object sender, ExitEventArgs e) { + SquirrelContext.Dispose(); + if (_menu != null) { _menu.Dispose(); diff --git a/GoToWindow/Squirrel/SquirrelUpdater.cs b/GoToWindow/Squirrel/SquirrelUpdater.cs index 304203b..1885cc2 100644 --- a/GoToWindow/Squirrel/SquirrelUpdater.cs +++ b/GoToWindow/Squirrel/SquirrelUpdater.cs @@ -30,6 +30,11 @@ public static SquirrelUpdater AcquireUpdater() return Updater; } + public static void Dispose() + { + Updater.Dispose(); + } + static string GetUpdateUrl() { var args = Environment.GetCommandLineArgs(); @@ -112,28 +117,36 @@ private void DownloadReleasesCallback(Action progressCallback private void ApplyReleasesCallback(Action progressCallback, Action errCallback, string installPath) { - Log.Info("Squirrel: Update complete."); - - Log.Info("Squirrel: Launching new version."); - progressCallback(UpdateStatus.Restarting, 100); - - try - { - var executablePath = Path.Combine(installPath, "GoToWindow.exe"); - if (File.Exists(executablePath)) - { - Process.Start(executablePath, "--squirrel-firstrunafterupdate"); - } - - Log.Info("Squirrel: Shutting down."); - Application.Current.Dispatcher.InvokeAsync(() => Application.Current.Shutdown(1)); - } - catch(Exception exc) - { - HandleAsyncError(errCallback, exc); - } + progressCallback(UpdateStatus.Installing, 100); + Log.Info("Squirrel: Creating uninstall info..."); + var createUninstallerRegistryEntryTask = _updateManager.CreateUninstallerRegistryEntry(); + createUninstallerRegistryEntryTask.ContinueWith(t => CreateUninstallerRegistryEntryCallback(progressCallback, errCallback, installPath), TaskContinuationOptions.OnlyOnRanToCompletion); + createUninstallerRegistryEntryTask.ContinueWith(t => HandleAsyncError(errCallback, t.Exception), TaskContinuationOptions.OnlyOnFaulted); } + private void CreateUninstallerRegistryEntryCallback(Action progressCallback, Action errCallback, string installPath) + { + _updateManager.Dispose(); + Log.Info("Squirrel: Launching new version."); + progressCallback(UpdateStatus.Restarting, 100); + + try + { + var executablePath = Path.Combine(installPath, "GoToWindow.exe"); + if (File.Exists(executablePath)) + { + Process.Start(executablePath, "--squirrel-firstrunafterupdate"); + } + + Log.Info("Squirrel: Shutting down."); + Application.Current.Dispatcher.InvokeAsync(() => Application.Current.Shutdown(1)); + } + catch (Exception exc) + { + HandleAsyncError(errCallback, exc); + } + } + private void HandleAsyncError(Action errCallback, Exception exc) { Log.Error("Error while trying to check for updates", exc);