예제 #1
0
        public void DownloadLatestVersion()
        {
            lock (LatestDetails)
            {
                if (LatestDetails.CanUpdate && !LatestDetails.UpdateDownloaded)
                {
                    var downloadUri = new Uri(LatestDetails.InstallUrl);
                    string filename = System.IO.Path.GetFileName(downloadUri.LocalPath);
                    var filePath = Path.Combine(Directory.GetCurrentDirectory(), filename);
                    var fd = new FileDownloader(downloadUri, filePath);
                    var dtask = fd.Download();
                    dtask.Start();
                    dtask.Wait();

                }
            }
        }
예제 #2
0
        private void DownloadUpdate(UpdateDetails details)
        {
            _realCloseWindow = true;
            Log.Info("Not up to date.");
            IsClosingDown = true;

            var downloadUri = new Uri(details.InstallUrl);
            string filename = System.IO.Path.GetFileName(downloadUri.LocalPath);

            if (details.UpdateDownloaded)
            {
                UpdateStatus("Launching Updater");
                Log.Info("Launching updater");
                Close();
                return;
            }

            UpdateStatus("Downloading new version.");

            var fd = new FileDownloader(downloadUri, Path.Combine(Directory.GetCurrentDirectory(), filename));

            progressBar1.Maximum = 100;
            progressBar1.IsIndeterminate = false;
            progressBar1.Value = 0;

            var myBinding = new Binding("Progress");
            myBinding.Source = fd;
            progressBar1.SetBinding(ProgressBar.ValueProperty, myBinding);

            var downloadTask = fd.Download();
            downloadTask.ContinueWith((t) =>
            {
                Log.Info("Download Complete");

                if (fd.DownloadFailed || !fd.DownloadComplete)
                {
                    Log.Info("Download Failed");
                    UpdateStatus("Downloading the new version failed. Please manually download.");
                    Program.LaunchUrl(details.InstallUrl);
                }
                else
                {
                    Log.Info("Launching updater");
                    UpdateStatus("Launching Updater");
                }
                Dispatcher.Invoke(new Action(() =>
                {
                    progressBar1.IsIndeterminate = true;
                    Close();
                }));
            });
            downloadTask.Start();
        }