60 lines
1.9 KiB
C#
60 lines
1.9 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using Katteker.Gui.Properties;
|
|
|
|
namespace Katteker.Gui
|
|
{
|
|
/// <summary>
|
|
/// The wrapper to add Squirrel-capability to older Programs.
|
|
/// </summary>
|
|
public static class Wrapper
|
|
{
|
|
/// <summary>
|
|
/// Checks for Updates.
|
|
/// </summary>
|
|
/// <returns>Task</returns>
|
|
public static Task CheckForUpdateAsync() => CheckForUpdateAsync(false);
|
|
|
|
/// <summary>
|
|
/// Checks for Updates.
|
|
/// </summary>
|
|
/// <param name="isStartup">Is this Method called on Startup of the Program.</param>
|
|
/// <returns>Task</returns>
|
|
public static async Task CheckForUpdateAsync(bool isStartup)
|
|
{
|
|
using (var window = new UpdateWindow())
|
|
{
|
|
var dialogResult = DialogResult.Cancel;
|
|
if (!UpdateManager.TryCreate(out var manager) && !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();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |