Exemplo n.º 1
0
        public GitHubReleaseInfoReader()
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            _restClient = new RestClient("https://api.github.com/");

            _latestReleaseInfo = ReadGitHubLatestReleaseInfo();
        }
Exemplo n.º 2
0
 void CheckForNewerVersion(GitHubReleaseInfo release)
 {
     UpdateFound = CurrentVersion.ToString() != release.tag_name;
     if (UpdateFound)
     {
         _releasePageUrl = release.html_url;
         const string downloadUrlFormat = "https://github.com/EbenZhang/gitextensions/releases/download/{0}/GitExtensions.msi";
         UpdateUrl  = string.Format(downloadUrlFormat, release.tag_name);
         NewVersion = release.tag_name;
         Done();
     }
     else
     {
         _releasePageUrl = "";
         UpdateUrl       = "";
         Done();
     }
 }
Exemplo n.º 3
0
        void CheckForNewerVersion(GitHubReleaseInfo release)
        {
            Version newVersion = null;

            try
            {
                newVersion = new Version(release.tag_name);
            }
            catch { }
            if (newVersion == null)
            {
                UpdateFound = false;
            }
            else
            {
                UpdateFound = CurrentVersion < new Version(release.tag_name);
            }
            if (UpdateFound)
            {
                _releasePageUrl = release.html_url;
                InstallerPath   = string.Format("GitExtensions-{0}-Setup.msi", release.tag_name);
                if (!File.Exists(InstallerPath))
                {
                    DeleteOldSetups();
                    const string downloadUrlFormat =
                        "https://github.com/EbenZhang/gitextensions/releases/download/{0}/{1}";
                    var url = string.Format(downloadUrlFormat, release.tag_name, InstallerPath);
                    using (var client = new WebClient())
                    {
                        client.DownloadFile(url, InstallerPath);
                    }
                }
                NewVersion = release.tag_name;
                Done();
            }
            else
            {
                _releasePageUrl = "";
                InstallerPath   = "";
                Done();
            }
        }
Exemplo n.º 4
0
        public GitHubReleaseInfoReader()
        {
            _restClient = new RestClient("https://api.github.com/");

            _latestReleaseInfo = ReadGitHubLatestReleaseInfo();
        }
Exemplo n.º 5
0
        private async Task DownloadUpdateAsync(GitHubReleaseInfo gitHubReleaseInfo)
        {
            var uri = gitHubReleaseInfo.assets.FirstOrDefault(a => a.browser_download_url.EndsWith(".zip"))
                      ?.browser_download_url;

            if (string.IsNullOrEmpty(uri))
            {
                return;
            }
            try
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(uri);
                    client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue(AppName, CurrentVersion));
                    client.DefaultRequestHeaders.Accept.Clear();

                    using (var response = await client.GetAsync(uri))
                    {
                        if (response.IsSuccessStatusCode)
                        {
                            string tempArchiveDirectory    = Path.Combine(TempBaseDirectory, gitHubReleaseInfo.tag_name);
                            string relativeArchiveFilePath = Path.Combine(gitHubReleaseInfo.tag_name, client.BaseAddress.Segments.Last());
                            string tempArchiveFileName     = Path.Combine(TempBaseDirectory, relativeArchiveFilePath);

                            Directory.CreateDirectory(tempArchiveDirectory);
                            using (var fileStream = File.Open(tempArchiveFileName, FileMode.OpenOrCreate))
                            {
                                fileStream.SetLength(0);
                                await response.Content.CopyToAsync(fileStream);
                            }
                            using (ZipArchive zipArchive = ZipFile.OpenRead(tempArchiveFileName))
                            {
                                var zipArchiveEntry = zipArchive.Entries.FirstOrDefault(
                                    entry => entry.FullName.EndsWith("ArmaBrowserUpdater.exe",
                                                                     StringComparison.OrdinalIgnoreCase));
                                if (zipArchiveEntry?.FullName != null)
                                {
                                    // ReSharper disable once AssignNullToNotNullAttribute
                                    using (var entryStream = zipArchiveEntry.Open())
                                        using (var fileStream = File.OpenWrite(Path.Combine(tempArchiveDirectory,
                                                                                            Path.GetFileName(zipArchiveEntry.FullName))))
                                        {
                                            fileStream.SetLength(0);
                                            await entryStream.CopyToAsync(fileStream);
                                        }
                                }
                                else
                                {
                                    if (AppInstallDirectoryPath != null && File.Exists(Path.Combine(AppInstallDirectoryPath, "ArmaBrowserUpdater.exe")))
                                    {
                                        File.Copy(Path.Combine(AppInstallDirectoryPath, "ArmaBrowserUpdater.exe"),
                                                  Path.Combine(tempArchiveDirectory, "ArmaBrowserUpdater.exe"), true);
                                    }
                                }

                                UpdateInfo updateInfo = new UpdateInfo
                                {
                                    updaterFilepath = Path.Combine(tempArchiveDirectory, "ArmaBrowserUpdater.exe"),
                                    version         = gitHubReleaseInfo.tag_name,
                                    draft           = gitHubReleaseInfo.draft,
                                    packageFilepath = relativeArchiveFilePath
                                };
                                File.WriteAllText(Path.Combine(TempBaseDirectory, "updateinfo.json"), JsonConvert.SerializeObject(updateInfo));
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                // ignore
            }
        }
Exemplo n.º 6
0
 void CheckForNewerVersion(GitHubReleaseInfo release)
 {
     Version newVersion = null;
     try
     {
         newVersion = new Version(release.tag_name);
     }
     catch { }
     if (newVersion == null)
     {
         UpdateFound = false;
     }
     else
     {
         UpdateFound = CurrentVersion < new Version(release.tag_name);
     }
     if (UpdateFound)
     {
         _releasePageUrl = release.html_url;
         const string downloadUrlFormat = "https://github.com/EbenZhang/gitextensions/releases/download/{0}/GitExtensions-{0}-Setup.msi";
         UpdateUrl = string.Format(downloadUrlFormat, release.tag_name);
         NewVersion = release.tag_name;
         Done();
     }
     else
     {
         _releasePageUrl = "";
         UpdateUrl = "";
         Done();
     }
 }