1
0
Fork 0
mirror of https://github.com/wagesj45/butterflow-ui.git synced 2024-12-22 01:02:43 -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();
// 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);
// 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");
this.Close();
}
}
}
#region Methods
@ -357,7 +358,7 @@ namespace butterflow_ui
{
var button = sender as Button;
if(button != null)
if (button != null)
{
if (button.Tag.GetType() == typeof(Guid))
{
@ -385,7 +386,7 @@ namespace butterflow_ui
{
var binaryFormatter = new BinaryFormatter();
var file = binaryFormatter.Deserialize(ofd.OpenFile());
if(file is OptionsConfigurationFile)
if (file is OptionsConfigurationFile)
{
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+ ?)";
/// <summary> The version status of the current installation. </summary>
private static VersionStatus versionStatus = VersionStatus.unknown;
private static VersionStatus versionStatus = VersionStatus.Unknown;
#endregion
@ -46,13 +46,13 @@ namespace butterflow_ui
{
switch (CurrentVersionStatus)
{
case VersionStatus.current:
case VersionStatus.Current:
return Localization.Localization.CurrentVersionStatusDescription;
case VersionStatus.behind:
case VersionStatus.Behind:
return Localization.Localization.BehindVersionStatusDescription;
case VersionStatus.custom:
case VersionStatus.Custom:
return Localization.Localization.CustomVersionStatusDescription;
case VersionStatus.unknown:
case VersionStatus.Unknown:
default:
return Localization.Localization.UnknownVersionStatusDescription;
}
@ -76,6 +76,8 @@ namespace butterflow_ui
/// <summary> Gets version status from github. </summary>
/// <returns> The current version status. </returns>
private static VersionStatus GetVersionStatus()
{
try
{
var interpreter = new InputInterpreter();
var client = new GitHubClient(new ProductHeaderValue("butterflow-ui"));
@ -103,18 +105,25 @@ namespace butterflow_ui
if (latestMajor == currentMajor && latestMinor == currentMinor && latestPatch == currentPatch)
{
return VersionStatus.current;
return VersionStatus.Current;
}
if (latestMajor >= currentMajor && latestMinor >= currentMinor && latestPatch >= currentPatch)
{
return VersionStatus.behind;
return VersionStatus.Behind;
}
return VersionStatus.custom;
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
@ -125,13 +134,13 @@ namespace butterflow_ui
public enum VersionStatus
{
/// <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>
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>
custom,
Custom,
/// <summary> Github failed to respond with the current version. This could be because of rate limits or a network failure. </summary>
unknown
Unknown
}
#endregion

View file

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

View file

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