Fixed a lot of "in the wild" problems.

This commit is contained in:
2018-08-02 12:55:50 +02:00
parent d85858b0c1
commit ec576558c8
10 changed files with 59 additions and 41 deletions

View File

@@ -90,30 +90,27 @@ namespace Katteker
}
changelogContent = changelogContent.ChangelogAsHtml(Path.GetExtension(Changelog));
Invoke(new Action(() => changelogBrowser.DocumentText = changelogContent));
InvokeOnGui(() => changelogBrowser.DocumentText = changelogContent);
if (_entry == null)
{
Invoke(new Action(() => { WriteTitle(Resources.No_update_available); }));
WriteTitle(Resources.No_update_available);
}
else
{
var latest = _entry.Version;
Invoke(new Action(() =>
{
WriteTitle(Resources.You_can_update_to_Version + latest);
updBtn.Visible = true;
}));
WriteTitle(Resources.You_can_update_to_Version + latest);
InvokeOnGui(() => updBtn.Visible = true);
}
}
private async void UpdBtn_Click(object sender, EventArgs e)
{
Invoke(new Action(() => progressBar1.Visible = true));
InvokeOnGui(() => progressBar1.Visible = true);
try
{
var progress = new Progress<int>(x => Invoke(new Action(() => { progressBar1.Value = x; })));
var progress = new Progress<int>(x => InvokeOnGui(() => progressBar1.Value = x));
await _updateManager.UpdateAppAsync(progress).ConfigureAwait(false);
WriteTitle(Resources.You_re_up_to_date);
@@ -124,8 +121,12 @@ namespace Katteker
MessageBoxIcon.Question);
if (messResult == DialogResult.Yes)
{
DialogResult = DialogResult.OK;
Close();
InvokeOnGui(() =>
{
DialogResult = DialogResult.OK;
Close();
});
return;
}
}
catch (Exception ex)
@@ -134,23 +135,34 @@ namespace Katteker
Resources.Updater, MessageBoxButtons.OK, MessageBoxIcon.Error);
WriteTitle(Resources.Updater);
}
finally
InvokeOnGui(() =>
{
Invoke(new Action(() =>
{
progressBar1.Visible = false;
updBtn.Visible = false;
}));
}
progressBar1.Visible = false;
updBtn.Visible = false;
});
}
private void WriteTitle(string text)
{
Invoke(new Action(() =>
InvokeOnGui(() =>
{
Text = text;
titlebar.Text = text;
}));
});
}
private void InvokeOnGui(Action action)
{
if (Disposing || IsDisposed) return;
if (InvokeRequired)
{
Invoke(action);
}
else
{
action();
}
}
}
}