public static async void CheckForUpdateAsync()
{
try
{
await Task.Run(() =>
{
// Use WebClient to download the latest version string
using (Web = new WebClient())
{
// Simulate some headers, Github throws a fit otherwise
Web.Headers["User-Agent"] = "BF2Statistics Control Center v" + Program.Version;
Web.Headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
Web.Headers["Accept-Language"] = "en-US,en;q=0.8";
Web.Proxy = null; // Disable proxy because this can cause slowdown on some machines
// Download file
string json = Web.DownloadString(Url);
// Use our Json.Net library to convert our API string into an object
List<GitHubRelease> Releases = JsonConvert.DeserializeObject<List<GitHubRelease>>(json)
.Where(x => x.PreRelease == false && x.Draft == false && x.Assets.Count > 0)
.OrderByDescending(x => x.Published).ToList();
// Parse version
if (Releases?.Count > 0)
Version.TryParse(Releases[0].TagName, out NewVersion);
}
});
}
catch (Exception e)
{
Program.ErrorLog.Write("WARNING: Error occured while trying to fetch the new release version: " + e.Message);
NewVersion = Program.Version;
}
// Fire Check Completed Event
CheckCompleted(NewVersion, EventArgs.Empty);
}