using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; using Katteker.Gui.Properties; namespace Katteker.Gui { /// /// The wrapper to add Squirrel-capability to older Programs. /// public static class Wrapper { /// /// Checks for Updates. /// /// Task public static Task CheckForUpdateAsync() => CheckForUpdateAsync(false); /// /// Checks for Updates. /// /// Is this Method called on Startup of the Program. /// Task public static async Task CheckForUpdateAsync(bool isStartup) { using (var window = new UpdateWindow()) { var dialogResult = DialogResult.Cancel; if (!UpdateManager.TryCreate(out var manager)) { if (!isStartup) { MessageBox.Show(Resources.SquirrelWrapper_CheckForUpdate, Resources.SquirrelWrapper_CheckForUpdate_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } return; } var releases = (await manager.CheckForUpdateAsync().ConfigureAwait(true)).ToArray(); window.UpdateManager = manager; window.ReleaseEntry = releases.LastOrDefault(); if (isStartup) { if (releases?.Any() == true) { dialogResult = window.ShowDialog(); } } else { dialogResult = window.ShowDialog(); } if (dialogResult == DialogResult.OK) { manager.RestartApp(); } } } } }