Пример #1
0
        /// <summary>
        /// Downloads the update from the given Github release, and returns the path to the updater program.
        /// A progress handler can be passed to react when the operation progress (in the range [0, 100]) changes.
        /// Throws an InvalidOperationException if the update is not valid.
        /// </summary>
        /// <param name="release"></param>
        /// <param name="progressHandler"></param>
        /// <returns></returns>
        public static bool UpdateProgram(GithubRelease release, ProgressChangedEventHandler progressHandler)
        {
            string fileName = Path.Combine(Settings.TempFolderPath, "SporeModManagerSetup.exe");
            var    asset    = Array.Find(release.assets, a => a.name.ToLowerInvariant() == "sporemodmanagersetup.exe");

            if (asset == null)
            {
                throw new InvalidOperationException("Invalid update: no 'SporeModManagerSetup.exe' asset");
            }
            using (var client = new WebClient())
            {
                client.DownloadProgressChanged += (s, e) =>
                {
                    if (progressHandler != null)
                    {
                        progressHandler.Invoke(null, e);
                    }
                };

                client.DownloadFile(asset.browser_download_url, fileName);
                client.DownloadFileCompleted += (sneder, args) => UpdateDownloadCompleted?.Invoke(fileName, null);
            }
            return(true);
        }
Пример #2
0
 /// <summary>
 /// Called when the update download was completed.
 /// </summary>
 /// <param name="e">The args.</param>
 protected virtual void OnUpdateDownloadCompleted(UpdateDownloadCompletedArgs e)
 {
     UpdateDownloadCompleted?.Invoke(this, e);
 }