Initial commit
This commit is contained in:
60
Katteker.Gui/Wrapper.cs
Normal file
60
Katteker.Gui/Wrapper.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user