Skip to content

Commit

Permalink
fix: Fix ArgumentOutOfBoundException in updater
Browse files Browse the repository at this point in the history
Don't rely on presence of hyphen for version parsing.

Fixes #289
  • Loading branch information
qdot committed Sep 16, 2017
1 parent 2a225eb commit cb707b4
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 43 deletions.
90 changes: 47 additions & 43 deletions Buttplug.Components.Controls/ButtplugAboutControl.xaml.cs
Expand Up @@ -170,60 +170,64 @@ private void CheckForUpdates_Click(object sender, RoutedEventArgs e)

var json = JObject.Parse(html);
var latest = json[_appName]["version"]?.ToString();
if (latest != null)
if (latest == null)
{
var numericVer = AboutVersionNumber.Text.Substring(0, AboutVersionNumber.Text.IndexOf('-'));
var cVer = Version.Parse(numericVer);
var lVer = Version.Parse(latest);

// Reverse this sign to test
if (cVer.CompareTo(lVer) < 0)
return;
}
// Why isn't this just using the AssemblyVersion?!?!
var dashPosition = AboutVersionNumber.Text.IndexOf('-');
string numericVer;
numericVer = dashPosition >= 0 ? AboutVersionNumber.Text.Substring(0, dashPosition) : AboutVersionNumber.Text;
var cVer = Version.Parse(numericVer);
var lVer = Version.Parse(latest);

// Reverse this sign to test
if (cVer.CompareTo(lVer) < 0)
{
// Update available
UpdateCheckStatus.Text = "Update Available! (" + DateTime.Now.ToString() + ")";
Hyperlink hyperlink = null;
try
{
// Update available
UpdateCheckStatus.Text = "Update Available! (" + DateTime.Now.ToString() + ")";
Hyperlink hyperlink = null;
try
var location = json[_appName]["location"]?.ToString();
if (location != null)
{
var location = json[_appName]["location"]?.ToString();
if (location != null)
hyperlink = new Hyperlink(new Run(location))
{
hyperlink = new Hyperlink(new Run(location))
{
NavigateUri = new Uri(location),
};
hyperlink.RequestNavigate += Hyperlink_RequestNavigate;
UpdateCheckStatus.Text += "\n";
UpdateCheckStatus.Inlines.Add(hyperlink);
}
}
catch
{
// noop - there was an update, we just don't know where
NavigateUri = new Uri(location),
};
hyperlink.RequestNavigate += Hyperlink_RequestNavigate;
UpdateCheckStatus.Text += "\n";
UpdateCheckStatus.Inlines.Add(hyperlink);
}
}
catch
{
// noop - there was an update, we just don't know where
}

if (MessageBox.Show("A new buttplug update is available! Would you like to go to the update site?",
"Buttplug Update",
MessageBoxButton.YesNo,
MessageBoxImage.Asterisk) == MessageBoxResult.Yes)
{
hyperlink?.DoClick();
}
if (MessageBox.Show("A new buttplug update is available! Would you like to go to the update site?",
"Buttplug Update",
MessageBoxButton.YesNo,
MessageBoxImage.Asterisk) == MessageBoxResult.Yes)
{
hyperlink?.DoClick();
}

try
{
((TabControl)((TabItem)Parent).Parent).SelectedItem = Parent;
UpdateCheckStatus.Focus();
}
catch
{
// noop - things went bang
}
try
{
((TabControl)((TabItem)Parent).Parent).SelectedItem = Parent;
UpdateCheckStatus.Focus();
}
else
catch
{
UpdateCheckStatus.Text = "No new updates! (" + DateTime.Now.ToString() + ")";
// noop - things went bang
}
}
else
{
UpdateCheckStatus.Text = "No new updates! (" + DateTime.Now.ToString() + ")";
}
}
catch (Exception ex)
{
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,9 @@
# 0.1.2 (2017-09-15)

## Bugfixes

- Fix ArgumentOutOfBoundsException in updater

# 0.1.1 (2017-09-15)

## Features
Expand Down

0 comments on commit cb707b4

Please sign in to comment.