using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Xml.Linq; namespace Click_to_Call_Tray { public class UpdateCheck { private static string GetLatestReleaseTag() { try { using (var client = new HttpClient()) { var url = $"https://git.jan.sx/api/v1/repos/krjan02/Click-to-Call-Tray/releases/latest"; var response = client.GetStringAsync(url).Result; var json = JObject.Parse(response); return json["tag_name"].ToString(); } } catch(Exception p) { return "0.0"; } } public static string GetCurrentVersion() { System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); System.Diagnostics.FileVersionInfo fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location); return fvi.FileVersion; } private static bool IsVersionLower(string currentVersion, string releaseVersion) { Version current = Version.Parse(currentVersion); Version release = Version.Parse(releaseVersion); return current.CompareTo(release) < 0; } public static bool CheckUpdate() { var CurrentVersion = GetCurrentVersion(); var LatestVersion = GetLatestReleaseTag(); if (IsVersionLower(CurrentVersion, LatestVersion)) { DialogResult dialogResult = MessageBox.Show("" + String.Format("Version {0} is available. You are running {1}" + "\nDo you want to Update now?", LatestVersion, CurrentVersion), "Click-to-Call-Tray Updater", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { System.Diagnostics.Process.Start("https://git.jan.sx/krjan02/Click-to-Call-Tray/releases/latest"); } return true; } return false; } } }