Moved ChangelogHelper and MarkdownSharp.cs to Katteker Lib, polish up the Gui.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Katteker.Gui.Properties;
|
||||
@@ -10,6 +11,8 @@ namespace Katteker.Gui
|
||||
/// </summary>
|
||||
public static class Wrapper
|
||||
{
|
||||
private static UpdateManager _manager;
|
||||
|
||||
/// <summary>
|
||||
/// Checks for Updates.
|
||||
/// </summary>
|
||||
@@ -23,38 +26,36 @@ namespace Katteker.Gui
|
||||
/// <returns>Task</returns>
|
||||
public static async Task CheckForUpdateAsync(bool isStartup)
|
||||
{
|
||||
using (var window = new UpdateWindow())
|
||||
if (_manager == null && !UpdateManager.TryCreate(out _manager))
|
||||
{
|
||||
var dialogResult = DialogResult.Cancel;
|
||||
if (!UpdateManager.TryCreate(out var manager))
|
||||
if (!isStartup)
|
||||
{
|
||||
if (!isStartup)
|
||||
{
|
||||
MessageBox.Show(Resources.SquirrelWrapper_CheckForUpdate,
|
||||
Resources.SquirrelWrapper_CheckForUpdate_Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
return;
|
||||
MessageBox.Show(Resources.SquirrelWrapper_CheckForUpdate,
|
||||
Resources.SquirrelWrapper_CheckForUpdate_Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var releases = (await _manager.CheckForUpdateAsync().ConfigureAwait(false)).ToArray();
|
||||
if (releases.Any() || !isStartup)
|
||||
{
|
||||
var thread = new Thread(ThreadProcess);
|
||||
thread.SetApartmentState(ApartmentState.STA);
|
||||
thread.Start(releases.LastOrDefault());
|
||||
thread.Join();
|
||||
}
|
||||
}
|
||||
|
||||
private static void ThreadProcess(object argument)
|
||||
{
|
||||
var entry = (ReleaseEntry) argument;
|
||||
using (var window = new UpdateWindow(_manager, entry))
|
||||
{
|
||||
var dialogResult = window.ShowDialog();
|
||||
if (dialogResult == DialogResult.OK)
|
||||
{
|
||||
manager.RestartApp();
|
||||
_manager.RestartApp();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user