private async Task <UpdateResult?> GetUpdateDataIfAvailable() { if (!Core.IsNetworkAvailable || !Core.IsUpdatesAllowed) { return(null); } Logger.Info("Checking for any new version..."); try { GithubResponse response = await GetResponseAsync().ConfigureAwait(false); string?gitVersion = response.ReleaseTagName; if (string.IsNullOrEmpty(gitVersion)) { Logger.Warn("Failed to request version information."); return(null); } if (!Version.TryParse(gitVersion, out Version? latestVersion)) { Logger.Warn("Could not parse the version. Make sure the version is correct at Github project repo."); return(null); } UpdateAvailable = latestVersion > Constants.Version; IsOnPrerelease = latestVersion < Constants.Version; return(new UpdateResult(response, UpdateAvailable)); } catch (Exception e) { Logger.Error(e.ToString()); return(null); } }
internal async Task <GithubResponse> LoadAsync() { if (string.IsNullOrEmpty(Constants.GitReleaseUrl) || Client == null || Sync == null) { return(this); } await Sync.WaitAsync().ConfigureAwait(false); try { string?json = null; for (int i = 0; i < MAX_TRIES; i++) { HttpResponseMessage responseMessage = await Client.SendAsync(new HttpRequestMessage(HttpMethod.Get, Constants.GitReleaseUrl)).ConfigureAwait(false); if (responseMessage == null || responseMessage.StatusCode != System.Net.HttpStatusCode.OK || responseMessage.Content == null) { Logger.Info($"Request failed ({i})"); Logger.Info(responseMessage?.ReasonPhrase); continue; } json = await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false); if (string.IsNullOrEmpty(json)) { continue; } break; } if (string.IsNullOrEmpty(json)) { return(this); } GithubResponse obj = JsonConvert.DeserializeObject <GithubResponse>(json); this.Assets = obj.Assets; this.PublishedAt = obj.PublishedAt; this.ReleaseFileName = obj.ReleaseFileName; this.ReleaseTagName = obj.ReleaseTagName; this.ReleaseUrl = obj.ReleaseUrl; return(this); } catch (Exception e) { Logger.Error(e.ToString()); return(this); } finally { Sync.Release(); } }