public static async Task UpdateCheckAsync(ParentForm parentForm) { string localAppVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); string remoteAppVersion = ""; // Update port # in the following line. client.BaseAddress = new Uri("https://api.github.com/repos/tharmes42/vCamDesk/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.UserAgent.Clear(); ProductHeaderValue header = new ProductHeaderValue("VCamDeskApp", localAppVersion); ProductInfoHeaderValue userAgent = new ProductInfoHeaderValue(header); client.DefaultRequestHeaders.UserAgent.Add(userAgent); // User-Agent: VCamDeskApp/1.0.0.0 try { GithubRelease githubRelease = null; // Get the latest release // see https://developer.github.com/v3/repos/releases/#list-releases githubRelease = await GetGithubReleaseAsync("releases/latest"); ShowGithubRelease(githubRelease); if (githubRelease != null) { remoteAppVersion = githubRelease.Tag_name.Substring(1); //omit leading "v" var localVersion = new Version(localAppVersion); var remoteVersion = new Version(remoteAppVersion); var result = localVersion.CompareTo(remoteVersion); if (result > 0) { Console.WriteLine("Local version is greater, no update available."); } else if (result < 0) { Console.WriteLine("Remote version is greater. Update available!"); //notify: update available! parentForm.Invoke(parentForm.showUpdateAvailableDelegate); } else { Console.WriteLine("Versions are equal, no update available."); } } } catch (Exception e) { Console.WriteLine(e.Message); } }
static async Task <GithubRelease> GetGithubReleaseAsync(string path) { GithubRelease githubRelease = null; HttpResponseMessage response = await client.GetAsync(path); if (response.IsSuccessStatusCode) { githubRelease = await response.Content.ReadAsAsync <GithubRelease>(); } return(githubRelease); }
static void ShowGithubRelease(GithubRelease githubRelease) { if (githubRelease != null) { Console.WriteLine($"Name: {githubRelease.Name} \nTag_name: " + $"{githubRelease.Tag_name} \nTarget_commitish: {githubRelease.Target_commitish}"); } else { Console.WriteLine("Error. Release was null"); } }