Skip to content

Commit

Permalink
#176 Fix to update checks when internet is not available.
Browse files Browse the repository at this point in the history
  • Loading branch information
midspace committed Jun 20, 2019
1 parent 8b6778e commit 1beebc7
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
18 changes: 18 additions & 0 deletions Main/SEToolbox/SEToolbox/Properties/Resources.Designer.cs

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

6 changes: 6 additions & 0 deletions Main/SEToolbox/SEToolbox/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3079,4 +3079,10 @@ Reason: {1}</value>
<data name="DialogPrereleaseVersionMessage" xml:space="preserve">
<value>You are running a prerelease version of SEToolbox.</value>
</data>
<data name="DialogNoNetworkMessage" xml:space="preserve">
<value>SEToolbox could not connect to the internet to check for an update. Please check your internet connection or filewall settings before trying again.</value>
</data>
<data name="DialogNoNetworkTitle" xml:space="preserve">
<value>Can not find update</value>
</data>
</root>
19 changes: 18 additions & 1 deletion Main/SEToolbox/SEToolbox/Support/CodeRepositoryReleases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using Octokit;
using System;
using System.Diagnostics;
using System.Net;
using System.Net.Http;
using System.Text.RegularExpressions;

/// <summary>
Expand All @@ -26,7 +28,22 @@ public static ApplicationRelease CheckForUpdates(Version currentVersion, bool do

// Accessing GitHub API directly for updates.
GitHubClient client = new GitHubClient(new ProductHeaderValue("SEToolbox-Updater"));
Release latest = client.Repository.Release.GetLatest("midspace", "SEToolbox").Result;
Release latest;
try
{
latest = client.Repository.Release.GetLatest("midspace", "SEToolbox").Result;
}
catch (Exception ex)
{
// Network connection error.
if (ex?.InnerException is HttpRequestException ||
ex?.InnerException?.InnerException is WebException)
{
return null;
}

throw;
}

var item = new ApplicationRelease { Name = latest.Name, Link = latest.HtmlUrl, Version = GetVersion(latest.TagName) };
Version ignoreVersion;
Expand Down
6 changes: 5 additions & 1 deletion Main/SEToolbox/SEToolbox/ViewModels/ExplorerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,11 @@ public bool OpenUpdatesLinkCanExecute()
public void OpenUpdatesLinkExecuted()
{
var update = CodeRepositoryReleases.CheckForUpdates(new Version(), true);
if (update.Version == GlobalSettings.GetAppVersion())
if (update == null)
{
MessageBox.Show(Res.DialogNoNetworkMessage, Res.DialogNoNetworkTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if (update.Version == GlobalSettings.GetAppVersion())
{
MessageBox.Show(Res.DialogLatestVersionMessage, Res.DialogNoNewVersionTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Expand Down

0 comments on commit 1beebc7

Please sign in to comment.