Exemplo n.º 1
0
        /// <inheritdoc/>
        public override bool Execute(bool previousTaskState)
        {
            Version         localVersion   = GetSetting <Version>("LocalVersion");
            Version         remoteVersion  = GetSetting <Version>("RemoteVersion");
            string          downloadTarget = Path.GetTempPath() + "SIVLauncherUpdate.zip";
            ArtifactRelease latestArtifact = GetSetting <ArtifactRelease>("LatestArtifact");

            if (latestArtifact == null || latestArtifact.Artifacts.Count == 0 || localVersion >= remoteVersion)
            {
                return(false);
            }
            if (File.Exists(downloadTarget))
            {
                File.Delete(downloadTarget);
            }
            using (WebClient client = new WebClient())
            {
                Artifact artifactToDownload = latestArtifact.Artifacts.Find(
                    artifact => artifact.Name.ToLower().EndsWith("communitypatchlauncher.zip") && artifact.Name.Contains(remoteVersion.ToString())
                    );
                if (artifactToDownload == null)
                {
                    return(false);
                }
                client.DownloadFile(artifactToDownload.DownloadUri, downloadTarget);
            }
            AddSetting("LauncherUpdate", downloadTarget);
            return(true);
        }
Exemplo n.º 2
0
        /// <inheritdoc/>
        public override bool Execute(bool previousTaskState)
        {
            GitHubClient client = new GitHubClient(new ProductHeaderValue(repositoryOwner));
            Task <IReadOnlyList <Release> > releaseTask;

            try
            {
                releaseTask = client.Repository.Release.GetAll(repositoryOwner, RepositoryName);
                releaseTask.Wait(4000);
            }
            catch (Exception ex)
            {
                warningPopup?.Execute(Properties.Resources.Dialog_GetRemoteVersionError.Replace("{exception}", ex.Message));
                return(false);
            }

            if (!releaseTask.IsCompleted && filter != null)
            {
                warningPopup?.Execute(Properties.Resources.Dialog_GetRemoteTimeout);
                return(false);
            }
            IReadOnlyList <Release> releases = releaseTask.Result;

            releases = releases.Where(obj =>
            {
                return(filter.IsMatch(obj.TagName));
            }).ToList();

            if (releases.Count == 0)
            {
                warningPopup?.Execute(Properties.Resources.Dialog_GetRemoteNoBuildsFound);
                return(false);
            }

            List <ArtifactRelease> artifactReleases = new List <ArtifactRelease>();

            foreach (Release release in releases)
            {
                artifactReleases.Add(new ArtifactRelease(release, filter));
            }
            artifactReleases.Sort((release1, release2) => release2.Version.CompareTo(release1.Version));
            ArtifactRelease newestArtifact = artifactReleases.First();

            AddSetting("RemoteVersion", newestArtifact.Version);
            AddSetting("LatestArtifact", newestArtifact);

            return(true);
        }