Skip to content

Commit

Permalink
Add uninstall registry entries, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
christianrondeau committed Sep 27, 2014
1 parent f9f74df commit f18a7f0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 22 deletions.
5 changes: 3 additions & 2 deletions GoToWindow/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -100,6 +99,8 @@ private bool WaitForOtherInstancesToShutDown()

private void Application_Exit(object sender, ExitEventArgs e)
{
SquirrelContext.Dispose();

if (_menu != null)
{
_menu.Dispose();
Expand Down
53 changes: 33 additions & 20 deletions GoToWindow/Squirrel/SquirrelUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public static SquirrelUpdater AcquireUpdater()
return Updater;
}

public static void Dispose()
{
Updater.Dispose();
}

static string GetUpdateUrl()
{
var args = Environment.GetCommandLineArgs();
Expand Down Expand Up @@ -112,28 +117,36 @@ private void DownloadReleasesCallback(Action<UpdateStatus, int> progressCallback

private void ApplyReleasesCallback(Action<UpdateStatus, int> progressCallback, Action<Exception> 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<UpdateStatus, int> progressCallback, Action<Exception> 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<Exception> errCallback, Exception exc)
{
Log.Error("Error while trying to check for updates", exc);
Expand Down

0 comments on commit f18a7f0

Please sign in to comment.