using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Xml.Linq; using Newtonsoft.Json.Linq; namespace SoraV2Utils_Agent { public class UpdateCheck { private static string GetLatestReleaseTag() { using (var client = new HttpClient()) { var url = $"https://git.jan.sx/api/v1/repos/krjan02/SoraV2Utils/releases/latest"; var response = client.GetStringAsync(url).Result; var json = JObject.Parse(response); return json["tag_name"].ToString(); } } private 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 void 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), "SoraV2 Utils Updater", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { System.Diagnostics.Process.Start("https://git.jan.sx/krjan02/SoraV2Utils/releases/latest"); ServiceIPC.Instance.Exit(); //Stop the Service and the Agent } } } } }