1
0
Fork 0
mirror of https://github.com/wagesj45/butterflow-ui.git synced 2024-11-14 05:43:33 -06:00

Add non-connection failsafe

Added a try/catch as a failsafe for non-operational networks and any other errors involving using Octokit to check for updates on github. Fixes #3.
This commit is contained in:
Jordan Wages 2019-01-05 20:39:52 -06:00
parent 43c3db77d8
commit 2d366141a9
4 changed files with 56 additions and 47 deletions

View file

@ -53,17 +53,18 @@ namespace butterflow_ui
InitializeComponent(); InitializeComponent();
// Check for updates. // Check for updates.
if (OctokitWrapper.CurrentVersionStatus == OctokitWrapper.VersionStatus.behind) if (OctokitWrapper.CurrentVersionStatus == OctokitWrapper.VersionStatus.Behind)
{ {
var updateMessageBoxResult = MessageBox.Show(string.Format("{0} {1}", Localization.Localization.BehindVersionStatusDescription, Localization.Localization.BehindVersionQuestion), Localization.Localization.UpdateAvailableLabel, MessageBoxButton.YesNo, MessageBoxImage.Information); var updateMessageBoxResult = MessageBox.Show(string.Format("{0} {1}", Localization.Localization.BehindVersionStatusDescription, Localization.Localization.BehindVersionQuestion), Localization.Localization.UpdateAvailableLabel, MessageBoxButton.YesNo, MessageBoxImage.Information);
// If the user wants to update now, take them to the latest release on github and close this window. // If the user wants to update now, take them to the latest release on github and close this window.
if(updateMessageBoxResult == MessageBoxResult.Yes) if (updateMessageBoxResult == MessageBoxResult.Yes)
{ {
Process.Start("https://github.com/wagesj45/butterflow-ui/releases/latest"); Process.Start("https://github.com/wagesj45/butterflow-ui/releases/latest");
this.Close(); this.Close();
} }
} }
} }
#region Methods #region Methods
@ -113,8 +114,8 @@ namespace butterflow_ui
this.OptionsConfiguration.Height = e.Value; this.OptionsConfiguration.Height = e.Value;
break; break;
case ButterflowWrapper.ButterflowOutputType.Progress: case ButterflowWrapper.ButterflowOutputType.Progress:
// This case doesn't need to be considered since we're binding the progress bar's value to a property on the butterflow wrapper. // This case doesn't need to be considered since we're binding the progress bar's value to a property on the butterflow wrapper.
// We may use this in the future, though. // We may use this in the future, though.
default: default:
break; break;
} }
@ -357,7 +358,7 @@ namespace butterflow_ui
{ {
var button = sender as Button; var button = sender as Button;
if(button != null) if (button != null)
{ {
if (button.Tag.GetType() == typeof(Guid)) if (button.Tag.GetType() == typeof(Guid))
{ {
@ -385,7 +386,7 @@ namespace butterflow_ui
{ {
var binaryFormatter = new BinaryFormatter(); var binaryFormatter = new BinaryFormatter();
var file = binaryFormatter.Deserialize(ofd.OpenFile()); var file = binaryFormatter.Deserialize(ofd.OpenFile());
if(file is OptionsConfigurationFile) if (file is OptionsConfigurationFile)
{ {
this.OptionsConfiguration.LoadFile((OptionsConfigurationFile)file); this.OptionsConfiguration.LoadFile((OptionsConfigurationFile)file);
} }

View file

@ -22,7 +22,7 @@ namespace butterflow_ui
private const string REGEX_VERSION = @"(?<Major>\d+ ?)\.(?<Minor>\d+ ?)\.(?<Patch>\d+ ?)"; private const string REGEX_VERSION = @"(?<Major>\d+ ?)\.(?<Minor>\d+ ?)\.(?<Patch>\d+ ?)";
/// <summary> The version status of the current installation. </summary> /// <summary> The version status of the current installation. </summary>
private static VersionStatus versionStatus = VersionStatus.unknown; private static VersionStatus versionStatus = VersionStatus.Unknown;
#endregion #endregion
@ -46,13 +46,13 @@ namespace butterflow_ui
{ {
switch (CurrentVersionStatus) switch (CurrentVersionStatus)
{ {
case VersionStatus.current: case VersionStatus.Current:
return Localization.Localization.CurrentVersionStatusDescription; return Localization.Localization.CurrentVersionStatusDescription;
case VersionStatus.behind: case VersionStatus.Behind:
return Localization.Localization.BehindVersionStatusDescription; return Localization.Localization.BehindVersionStatusDescription;
case VersionStatus.custom: case VersionStatus.Custom:
return Localization.Localization.CustomVersionStatusDescription; return Localization.Localization.CustomVersionStatusDescription;
case VersionStatus.unknown: case VersionStatus.Unknown:
default: default:
return Localization.Localization.UnknownVersionStatusDescription; return Localization.Localization.UnknownVersionStatusDescription;
} }
@ -77,44 +77,53 @@ namespace butterflow_ui
/// <returns> The current version status. </returns> /// <returns> The current version status. </returns>
private static VersionStatus GetVersionStatus() private static VersionStatus GetVersionStatus()
{ {
var interpreter = new InputInterpreter(); try
var client = new GitHubClient(new ProductHeaderValue("butterflow-ui"));
var releases = client.Repository.Release.GetAll("wagesj45", "butterflow-ui").Result;
if (releases.Any())
{ {
var latest = releases.First(); var interpreter = new InputInterpreter();
decimal latestMajor = 0, latestMinor = 0, latestPatch = 0, currentMajor = 0, currentMinor = 0, currentPatch = 0; var client = new GitHubClient(new ProductHeaderValue("butterflow-ui"));
var releases = client.Repository.Release.GetAll("wagesj45", "butterflow-ui").Result;
var regex = new Regex(REGEX_VERSION); if (releases.Any())
foreach (Match match in regex.Matches(latest.TagName))
{ {
latestMajor = interpreter.ComputeExpression(match.Groups["Major"].Value); var latest = releases.First();
latestMinor = interpreter.ComputeExpression(match.Groups["Minor"].Value); decimal latestMajor = 0, latestMinor = 0, latestPatch = 0, currentMajor = 0, currentMinor = 0, currentPatch = 0;
latestPatch = interpreter.ComputeExpression(match.Groups["Patch"].Value);
}
foreach (Match match in regex.Matches(Assembly.GetExecutingAssembly().GetName().Version.ToString())) var regex = new Regex(REGEX_VERSION);
{ foreach (Match match in regex.Matches(latest.TagName))
currentMajor = interpreter.ComputeExpression(match.Groups["Major"].Value); {
currentMinor = interpreter.ComputeExpression(match.Groups["Minor"].Value); latestMajor = interpreter.ComputeExpression(match.Groups["Major"].Value);
currentPatch = interpreter.ComputeExpression(match.Groups["Patch"].Value); latestMinor = interpreter.ComputeExpression(match.Groups["Minor"].Value);
} latestPatch = interpreter.ComputeExpression(match.Groups["Patch"].Value);
}
if (latestMajor == currentMajor && latestMinor == currentMinor && latestPatch == currentPatch) foreach (Match match in regex.Matches(Assembly.GetExecutingAssembly().GetName().Version.ToString()))
{ {
return VersionStatus.current; currentMajor = interpreter.ComputeExpression(match.Groups["Major"].Value);
} currentMinor = interpreter.ComputeExpression(match.Groups["Minor"].Value);
currentPatch = interpreter.ComputeExpression(match.Groups["Patch"].Value);
}
if (latestMajor >= currentMajor && latestMinor >= currentMinor && latestPatch >= currentPatch) if (latestMajor == currentMajor && latestMinor == currentMinor && latestPatch == currentPatch)
{ {
return VersionStatus.behind; return VersionStatus.Current;
} }
return VersionStatus.custom; if (latestMajor >= currentMajor && latestMinor >= currentMinor && latestPatch >= currentPatch)
{
return VersionStatus.Behind;
}
return VersionStatus.Custom;
}
}
catch(Exception e)
{
//There was an issue connecting to Github. This could be caused by a missing network connection.
//We can safely ignore an error in this process and proceed, falling through to the default connection
//value of Unknown.
} }
return VersionStatus.unknown; return VersionStatus.Unknown;
} }
#endregion #endregion
@ -125,13 +134,13 @@ namespace butterflow_ui
public enum VersionStatus public enum VersionStatus
{ {
/// <summary> The current version is up to date with the github repository. </summary> /// <summary> The current version is up to date with the github repository. </summary>
current, Current,
/// <summary> The current version is behind the github repository and should be updated. </summary> /// <summary> The current version is behind the github repository and should be updated. </summary>
behind, Behind,
/// <summary> The current version is ahead of the github repository, or is a custom version of butterflow-ui that cannot be compared to the github repository. </summary> /// <summary> The current version is ahead of the github repository, or is a custom version of butterflow-ui that cannot be compared to the github repository. </summary>
custom, Custom,
/// <summary> Github failed to respond with the current version. This could be because of rate limits or a network failure. </summary> /// <summary> Github failed to respond with the current version. This could be because of rate limits or a network failure. </summary>
unknown Unknown
} }
#endregion #endregion

View file

@ -48,6 +48,8 @@
<Reference Include="Octokit, Version=0.31.0.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Octokit, Version=0.31.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\Octokit.0.31.0\lib\net45\Octokit.dll</HintPath> <HintPath>packages\Octokit.0.31.0\lib\net45\Octokit.dll</HintPath>
</Reference> </Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
@ -60,8 +62,6 @@
<RequiredTargetFramework>4.0</RequiredTargetFramework> <RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference> </Reference>
<Reference Include="WindowsBase" /> <Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ApplicationDefinition Include="App.xaml"> <ApplicationDefinition Include="App.xaml">

View file

@ -2,5 +2,4 @@
<packages> <packages>
<package id="csmic" version="1.1.4" targetFramework="net471" /> <package id="csmic" version="1.1.4" targetFramework="net471" />
<package id="Gu.Wpf.Media" version="0.5.0.2" targetFramework="net471" /> <package id="Gu.Wpf.Media" version="0.5.0.2" targetFramework="net471" />
<package id="Octokit" version="0.31.0" targetFramework="net471" />
</packages> </packages>