Ejemplo n.º 1
0
        private void WebClient_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            State = UpdaterState.Idle;

            File.WriteAllText(changelogFilePath, changelog);
            File.WriteAllText(versionFilePath, latestRelease.TagName.Replace("v", ""));

            List <string> updateFiles = Directory.GetFiles(updatePath).ToList();

            updateFiles.ForEach(x => File.Delete(x));

            if (ZipFile.IsZipFile(downloadFilePath) && ZipFile.CheckZip(downloadFilePath))
            {
                using (ZipFile zip = new ZipFile(downloadFilePath))
                    zip.ExtractAll(updatePath, ExtractExistingFileAction.OverwriteSilently);

                if (File.Exists(downloadFilePath))
                {
                    File.Delete(downloadFilePath);
                }
            }
            else
            {
                string newFilePath = $@"{updatePath}\{Path.GetFileName(downloadFilePath)}";
                File.Move(downloadFilePath, newFilePath);
            }

            DownloadingCompleted?.Invoke(this, new VersionEventArgs(currentVersion, latestVersion, false, changelog));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Downloads the new EXE from github.
        /// </summary>
        /// <returns>Awaitable Task</returns>
        ///  <exception cref="NullReferenceException">Thrown when the Repository is null</exception>
        ///  <exception cref="FileLoadException">Thrown when the asset file is a .zip</exception>
        public async Task DownloadUpdateAsync()
        {
            DownloadingStarted?.Invoke(this, EventArgs.Empty);
            State = UpdaterState.Downloading;

            if (client == null)
            {
                client = new WebClient();
            }
            if (repository == null)
            {
                throw new NullReferenceException("Could not retrieve Repository");
            }
            if (repository.Assets[0].Name.EndsWith(".zip"))
            {
                throw new FileLoadException("The downloaded file is a zip file, which is not supported");
            }

            string destination = Path.GetTempPath() + repository.Assets[0].Name;

            downloadedAssetPath = destination;

            client.DownloadProgressChanged += DownloadProgressChanged;
            await client.DownloadFileTaskAsync(repository.Assets[0].BrowserDownloadUrl, destination);

            State = UpdaterState.Idle;
            DownloadingCompleted?.Invoke(this, EventArgs.Empty);
        }