mirror of
https://github.com/Crypto-Notepad/Crypto-Notepad.git
synced 2026-03-11 08:55:25 +00:00
Exception handling when checking for updates
This commit is contained in:
parent
3d69fc3d4c
commit
141da9b4ee
1 changed files with 41 additions and 34 deletions
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue