Update checking now async

This commit is contained in:
Alexander 2019-11-22 17:39:10 +02:00
parent 1f3a6ba959
commit e3e5449bb9

View file

@ -284,14 +284,16 @@ private void SaveConfirm()
} }
} }
private void CheckForUpdates(bool autoCheck) private async Task CheckForUpdates(bool autoCheck)
{ {
try try
{ {
PublicVar.messageBoxCenterParent = true;
WebClient client = new WebClient(); WebClient client = new WebClient();
Stream stream = client.OpenRead("https://raw.githubusercontent.com/Crypto-Notepad/Crypto-Notepad/master/version.txt"); Uri updateUrl = new Uri("https://raw.githubusercontent.com/Crypto-Notepad/Crypto-Notepad/master/version.txt", UriKind.Absolute);
Stream stream = await client.OpenReadTaskAsync(updateUrl);
StreamReader reader = new StreamReader(stream); StreamReader reader = new StreamReader(stream);
string content = reader.ReadToEnd(); string content = await reader.ReadToEndAsync();
string version = Application.ProductVersion; string version = Application.ProductVersion;
string exePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + @"\"; string exePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + @"\";
int appVersion = Convert.ToInt32(version.Replace(".", "")), serverVersion = Convert.ToInt32(content.Replace(".", "")); int appVersion = Convert.ToInt32(version.Replace(".", "")), serverVersion = Convert.ToInt32(content.Replace(".", ""));
@ -541,10 +543,6 @@ private void LoadSettings()
{ {
insertMainMenu.ShortcutKeys = Keys.None; insertMainMenu.ShortcutKeys = Keys.None;
} }
if (settings.autoCheckUpdate)
{
CheckForUpdates(false);
}
if (settings.windowLocation.ToString() != "{X=0,Y=0}") if (settings.windowLocation.ToString() != "{X=0,Y=0}")
{ {
Location = settings.windowLocation; Location = settings.windowLocation;
@ -624,7 +622,7 @@ public void MenuIcons(bool menuIcons)
aboutMainMenu.Image = Resources.information; aboutMainMenu.Image = Resources.information;
alwaysOnTopMainMenu.Image = Resources.applications_blue; alwaysOnTopMainMenu.Image = Resources.applications_blue;
saveCloseFileMainMenu.Image = Resources.disk__minus; saveCloseFileMainMenu.Image = Resources.disk__minus;
passwordGeneratorMainMenu.Image = Resources.key__plus; passwordGeneratorMainMenu.Image = Resources.key_plus;
} }
else else
{ {
@ -848,7 +846,7 @@ private void MainForm_Shown(object sender, EventArgs e)
} }
} }
private void MainWindow_Load(object sender, EventArgs e) private async void MainWindow_Load(object sender, EventArgs e)
{ {
Visible = false; Visible = false;
LoadSettings(); LoadSettings();
@ -875,6 +873,10 @@ private void MainWindow_Load(object sender, EventArgs e)
{ {
ContextMenuEncryptReplace(); ContextMenuEncryptReplace();
} }
if (settings.autoCheckUpdate)
{
await CheckForUpdates(false);
}
} }
private void RichTextBox_SelectionChanged(object sender, EventArgs e) private void RichTextBox_SelectionChanged(object sender, EventArgs e)
@ -1464,9 +1466,9 @@ private void DocumentationMainMenu_Click(object sender, EventArgs e)
Process.Start("https://github.com/Crypto-Notepad/Crypto-Notepad/wiki/Documentation"); Process.Start("https://github.com/Crypto-Notepad/Crypto-Notepad/wiki/Documentation");
} }
private void CheckForUpdatesMainMenu_Click(object sender, EventArgs e) private async void CheckForUpdatesMainMenu_Click(object sender, EventArgs e)
{ {
CheckForUpdates(true); await CheckForUpdates(true);
} }
private void AboutMainMenu_Click(object sender, EventArgs e) private void AboutMainMenu_Click(object sender, EventArgs e)