Skip to content

Commit

Permalink
catch no internet exception
Browse files Browse the repository at this point in the history
  • Loading branch information
JensKrumsieck committed Aug 6, 2021
1 parent 0c2f35a commit 9f7218c
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions PorphyStruct.WPF/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Sockets;
using System.Reflection;
using System.Text.Json;
using System.Threading.Tasks;
Expand Down Expand Up @@ -40,18 +41,23 @@ public async Task<bool> CheckVersion()
BaseAddress = new Uri(baseAddr),
Timeout = TimeSpan.FromSeconds(1)
};

client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("PorphyStruct", version));
var response = await client.GetAsync(url);
if (response.IsSuccessStatusCode)
{
using var responseStream = await response.Content.ReadAsStreamAsync();
var res = await JsonSerializer.DeserializeAsync
<Dictionary<string, object>>(responseStream);
Latest = res["tag_name"].ToString()[1..];
var latest = Version.Parse(Latest);
var current = Version.Parse(version);
return current >= latest;
try {
var response = await client.GetAsync(url);

if (response.IsSuccessStatusCode)
{
using var responseStream = await response.Content.ReadAsStreamAsync();
var res = await JsonSerializer.DeserializeAsync
<Dictionary<string, object>>(responseStream);
Latest = res["tag_name"].ToString()[1..];
var latest = Version.Parse(Latest);
var current = Version.Parse(version);
return current >= latest;
}
}
catch(Exception) { return true; }//no internet => ignore!
//return true if no response could be made
return true;
}
Expand Down

0 comments on commit 9f7218c

Please sign in to comment.