예제 #1
0
        public static int GetVersionNumber()
        {
            var path = Updater.LauncherFolder;

            if (!Directory.Exists(path))
            {
                CreateLauncherFolder();
            }

            if (!File.Exists(path + Updater.VersionFileName))
            {
                CreateVersionFile();
            }

            return(XmlVersionReader.GetVersionFromXml(path + Updater.VersionFileName));
        }
예제 #2
0
        public static async Task <int> GetLatestVersionNumber()
        {
            Console.WriteLine("Checking version...");

            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.UserAgent.Add(
                new ProductInfoHeaderValue("DeLauncher", typeof(Updater).Assembly.GetName().Version.ToString()));

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

            var contentsUrl = $"https://api.github.com/repos/{repo}/contents";

            var contentsJson = await httpClient.GetStringAsync(contentsUrl);

            dynamic contents = new JavaScriptSerializer().DeserializeObject(contentsJson);

            foreach (var data in contents)
            {
                var parsedData = (Dictionary <string, object>)data;

                var fileName = (string)data["name"];

                if (fileName == Updater.VersionFileName)
                {
                    var downloadUrl = (string)data["download_url"];
                    var myWebClient = new WebClient();
                    var name        = tempPrefix + fileName;

                    using (WebClient client = new WebClient())
                        client.DownloadFile(downloadUrl, name);

                    var newVersionNumber = XmlVersionReader.GetVersionFromXml(name);

                    File.Delete(name);

                    return(newVersionNumber);
                }
            }
            throw new ApplicationException("version file not found!");
        }