Skip to content

Commit

Permalink
Improvements to update checking and fix for exception if there is no …
Browse files Browse the repository at this point in the history
…internet connection
  • Loading branch information
soda3x committed Aug 21, 2021
1 parent 05ba215 commit a934f0a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
12 changes: 12 additions & 0 deletions Moneybags/Main.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 13 additions & 8 deletions Moneybags/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private void AboutLabel_Click(object sender, EventArgs e)
private void CheckForUpdates()
{
string ourVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
string latestVersionString = String.Empty;
string latestVersionString;
WebClient wc = new WebClient();

// Add headers to impersonate a web browser. Some web sites
Expand All @@ -102,15 +102,20 @@ private void CheckForUpdates()
wc.Headers.Add("Accept", "*/*");
wc.Headers.Add("Accept-Language", "en-gb,en;q=0.5");
wc.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
try
{
latestVersionString = wc.DownloadString("https://raw.githubusercontent.com/soda3x/Moneybags/master/version.txt");

latestVersionString = wc.DownloadString("https://raw.githubusercontent.com/soda3x/Moneybags/master/version.txt");

var checkedVersion = new Version(latestVersionString);
var currentVersion = new Version(ourVersion);
var result = checkedVersion.CompareTo(currentVersion);
if (result > 0)
var checkedVersion = new Version(latestVersionString);
var currentVersion = new Version(ourVersion);
var result = checkedVersion.CompareTo(currentVersion);
if (result > 0)
{
new UpdateAvailableDialog(ourVersion, latestVersionString, updateNotifyLabel).ShowDialog();
}
} catch (WebException)
{
new UpdateAvailableDialog(ourVersion, latestVersionString).ShowDialog();
updateNotifyLabel.Text = "Unable to check for updates, you may not be using the latest version of Moneybags.";
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Moneybags/UpdateAvailableDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions Moneybags/UpdateAvailableDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,23 @@ namespace Moneybags
{
public partial class UpdateAvailableDialog : MetroFramework.Forms.MetroForm
{
public UpdateAvailableDialog(string currentVersion, string newVersion)
private readonly Label updateStatusLabel;

public UpdateAvailableDialog(string currentVersion, string newVersion, Label updateStatusLabel)
{
InitializeComponent();
newVersionLabel.Text = "New Version: " + newVersion;
currentVersionLabel.Text = "Current Version: " + currentVersion;
this.updateStatusLabel = updateStatusLabel;
}

private void ignoreBtn_Click(object sender, EventArgs e)
private void IgnoreBtn_Click(object sender, EventArgs e)
{
this.updateStatusLabel.Text = "You are using an outdated version of Moneybags. Update Moneybags for the best experience.";
this.Dispose();
}

private void goToUpdateBtn_Click(object sender, EventArgs e)
private void GoToUpdateBtn_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("https://github.com/soda3x/Moneybags/releases");
}
Expand Down

0 comments on commit a934f0a

Please sign in to comment.