Moved ChangelogHelper and MarkdownSharp.cs to Katteker Lib, polish up the Gui.

This commit is contained in:
2018-03-23 14:07:24 +01:00
parent 6fafdd3090
commit 54979f9a69
14 changed files with 128 additions and 173 deletions

View File

@@ -8,14 +8,18 @@ namespace Katteker.Gui
{
public sealed partial class UpdateWindow : Form
{
private readonly UpdateManager _updateManager;
private readonly ReleaseEntry _entry;
private const int HTCAPTION = 0x2;
private const int WM_NCLBUTTONDOWN = 0xA1;
/// <summary>
/// The Update Window
/// </summary>
public UpdateWindow()
public UpdateWindow(UpdateManager updateManager, ReleaseEntry entry)
{
_updateManager = updateManager;
_entry = entry;
Font = SystemFonts.MessageBoxFont;
Application.EnableVisualStyles();
if (Environment.OSVersion.Version.Major >= 6)
@@ -23,19 +27,9 @@ namespace Katteker.Gui
InitializeComponent();
}
private string Changelog => UpdateManager.ChangelogFilename;
/// <summary>
/// Last release entry.
/// </summary>
public ReleaseEntry ReleaseEntry { get; set; }
private string Changelog => _updateManager.ChangelogFilename;
/// <summary>
/// Update manager
/// </summary>
public UpdateManager UpdateManager { get; set; }
private string PublishPath => UpdateManager.UrlOrPath;
private string PublishPath => _updateManager.UrlOrPath;
/// <inheritdoc />
/// <summary>
@@ -76,22 +70,40 @@ namespace Katteker.Gui
private void Titlebar_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && e.Clicks >= 2)
{
MaximizeBtn_Click(sender, e);
return;
}
if (e.Button != MouseButtons.Left) return;
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
}
private void UpdateWindow_Activated(object sender, EventArgs e)
{
titleLayoutPanel.BackColor = SystemColors.ControlDarkDark;
titleLayoutPanel.ForeColor = SystemColors.Control;
}
private void UpdateWindow_Deactivate(object sender, EventArgs e)
{
titleLayoutPanel.BackColor = SystemColors.Control;
titleLayoutPanel.ForeColor = SystemColors.ControlText;
}
private async void UpdateWindow_Load(object sender, EventArgs e)
{
var changelog = await ChangelogHelper.LoadChangelogAsync(Changelog, PublishPath).ConfigureAwait(false);
Invoke(new Action(() => changelogBrowser.DocumentText = changelog));
if (ReleaseEntry == null)
if (_entry == null)
{
Invoke(new Action(() => { WriteTitle(Resources.No_update_available); }));
}
else
{
var latest = ReleaseEntry.Version;
var latest = _entry.Version;
Invoke(new Action(() =>
{
WriteTitle(Resources.You_can_update_to_Version + latest);
@@ -107,13 +119,25 @@ namespace Katteker.Gui
try
{
var progress = new Progress<int>(x => Invoke(new Action(() => { progressBar1.Value = x; })));
await UpdateManager.UpdateAppAsync(progress).ConfigureAwait(false);
await _updateManager.UpdateAppAsync(progress).ConfigureAwait(false);
WriteTitle(Resources.You_re_up_to_date);
var messResult = MessageBox.Show(
Resources.Installed_new_Version,
Resources.New_Version,
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (messResult == DialogResult.Yes)
{
DialogResult = DialogResult.OK;
Close();
}
}
catch (Exception ex)
{
WriteTitle(ex.Message);
MessageBox.Show(Resources.CouldNotUpdateYourApplication + Environment.NewLine + ex.Message, Gui.Properties.Resources.Updater, MessageBoxButtons.OK, MessageBoxIcon.Error);
WriteTitle(Resources.Updater);
}
finally
{
@@ -121,19 +145,10 @@ namespace Katteker.Gui
{
progressBar1.Visible = false;
updBtn.Visible = false;
var messResult = MessageBox.Show(
Resources.Installed_new_Version,
Resources.New_Version,
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (messResult == DialogResult.Yes)
{
DialogResult = DialogResult.OK;
Close();
}
}));
}
}
private void WriteTitle(string text)
{
Invoke(new Action(() =>