Skip to content

Commit

Permalink
Add better handling for update checker, possibly Fixes issue #557
Browse files Browse the repository at this point in the history
  • Loading branch information
jimradford committed Oct 15, 2015
1 parent 1a71106 commit 74c0966
Showing 1 changed file with 35 additions and 32 deletions.
67 changes: 35 additions & 32 deletions SuperPutty/frmSuperPutty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1563,46 +1563,49 @@ private void menuStrip1_MenuDeactivate(object sender, EventArgs e)
private void checkForUpdatesToolStripMenuItem_Click(object sender, EventArgs e)
{
Log.Info("Checking for application update");
httpRequest r = new httpRequest();
r.MakeRequest("https://api.github.com/repos/jimradford/superputty/releases/latest", delegate(bool success, string content)
{
if (success)
try {
httpRequest httpUpdateRequest = new httpRequest();
httpUpdateRequest.MakeRequest("https://api.github.com/repos/jimradford/superputty/releases/latest", delegate (bool success, string content)
{
DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(GitRelease));
MemoryStream ms = new MemoryStream(System.Text.ASCIIEncoding.ASCII.GetBytes(content));
GitRelease latest = (GitRelease)js.ReadObject(ms);
ms.Close();

if (!latest.version.Trim().Contains(SuperPuTTY.Version))
if (success)
{
Log.Info("New Application version found! " + latest.version);

if (MessageBox.Show("An updated version of SuperPuTTY (" + latest.version + ") is Available Would you like to visit the download page to upgrade?",
"SuperPutty Update Found",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1,
MessageBoxOptions.DefaultDesktopOnly) == System.Windows.Forms.DialogResult.Yes)
DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(GitRelease));
MemoryStream ms = new MemoryStream(System.Text.ASCIIEncoding.ASCII.GetBytes(content));
GitRelease latest = (GitRelease)js.ReadObject(ms);
ms.Close();

if (!latest.version.Trim().Contains(SuperPuTTY.Version))
{
Process.Start(latest.release_url);
Log.Info("New Application version found! " + latest.version);

if (MessageBox.Show("An updated version of SuperPuTTY (" + latest.version + ") is Available Would you like to visit the download page to upgrade?",
"SuperPutty Update Found",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1,
MessageBoxOptions.DefaultDesktopOnly) == System.Windows.Forms.DialogResult.Yes)
{
Process.Start(latest.release_url);
}
}
else
{
if (sender.ToString().Equals(checkForUpdatesToolStripMenuItem.Text))
{
MessageBox.Show("You are running the latest version of SuperPutty", "SuperPuTTY Update Check", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
else
{
if (sender.ToString().Equals(checkForUpdatesToolStripMenuItem.Text))
{
MessageBox.Show("You are running the latest version of SuperPutty", "SuperPuTTY Update Check", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Log.Warn("An Error occurred trying to check for program updates");
}
}
else
{
// error occurred while making api request
var foo = r;
Console.WriteLine(r);
}
});

});
}
catch (System.Net.WebException ex)
{
Log.Warn("An Exception occurred while trying to check for program updates: " + ex.ToString());
}
}
#endregion

Expand Down

0 comments on commit 74c0966

Please sign in to comment.