Exception handling when checking for updates

This commit is contained in:
Sigmanor 2016-01-27 19:18:55 +02:00
parent 3d69fc3d4c
commit 141da9b4ee

View file

@ -882,49 +882,56 @@ private void pictureBox1_MouseLeave(object sender, EventArgs e)
public void сheckForUpdates(bool autoCheck) public void сheckForUpdates(bool autoCheck)
{ {
WebClient client = new WebClient(); try
Stream stream = client.OpenRead("https://raw.githubusercontent.com/Sigmanor/Crypto-Notepad/master/version.txt");
StreamReader reader = new StreamReader(stream);
string content = reader.ReadToEnd();
string version = Application.ProductVersion;
string exePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + @"\";
int ver = Convert.ToInt32(version.Replace(".", "")), con = Convert.ToInt32(content.Replace(".", ""));
if (con != ver)
{ {
MainMenu.Invoke((Action)delegate WebClient client = new WebClient();
Stream stream = client.OpenRead("https://raw.githubusercontent.com/Sigmanor/Crypto-Notepad/master/version.txt");
StreamReader reader = new StreamReader(stream);
string content = reader.ReadToEnd();
string version = Application.ProductVersion;
string exePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + @"\";
int ver = Convert.ToInt32(version.Replace(".", "")), con = Convert.ToInt32(content.Replace(".", ""));
if (con != ver)
{ {
using (new CenterWinDialog(this)) MainMenu.Invoke((Action)delegate
{ {
DialogResult res = new DialogResult(); using (new CenterWinDialog(this))
res = MessageBox.Show("New version is available. Install it now?", "Update", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (res == DialogResult.Yes)
{ {
File.WriteAllBytes(exePath + "Ionic.Zip.dll", Properties.Resources.Ionic_Zip); DialogResult res = new DialogResult();
File.WriteAllBytes(exePath + "Updater.exe", Properties.Resources.Updater);
var pr = new Process(); res = MessageBox.Show("New version is available. Install it now?", "Update", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
pr.StartInfo.FileName = exePath + "Updater.exe";
pr.StartInfo.Arguments = "/u"; if (res == DialogResult.Yes)
pr.Start(); {
Application.Exit(); File.WriteAllBytes(exePath + "Ionic.Zip.dll", Properties.Resources.Ionic_Zip);
File.WriteAllBytes(exePath + "Updater.exe", Properties.Resources.Updater);
var pr = new Process();
pr.StartInfo.FileName = exePath + "Updater.exe";
pr.StartInfo.Arguments = "/u";
pr.Start();
Application.Exit();
}
} }
} });
}); }
}
if (con == ver && autoCheck == true) if (con == ver && autoCheck == true)
{
MainMenu.Invoke((Action)delegate
{ {
using (new CenterWinDialog(this)) MainMenu.Invoke((Action)delegate
{ {
MessageBox.Show("Crypto Notepad is up to date.", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information); using (new CenterWinDialog(this))
} {
}); MessageBox.Show("Crypto Notepad is up to date.", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
});
}
}
catch
{
return;
} }
} }