Ejemplo n.º 1
0
 public void OnUpdateDownloadProgressChanged(Update update, FileDownloadProgress progress)
 {
     _menuItem.Text =
         string.Format(
             "Downloading Update: {0:P}...",
             progress.PercentComplete / 100.0);
 }
Ejemplo n.º 2
0
        public void OnBeforeDownloadUpdate(Update update)
        {
            _menuItem.Text = string.Format("Downloading Version {0}...", update.Version);
            _menuItem.Enabled = false;

            _updateMenu.Visible = false;
        }
Ejemplo n.º 3
0
        public void OnBeforeInstallUpdate(Update update)
        {
            _menuItem.Text = string.Format("Installing Version {0}...", update.Version);
            _menuItem.Enabled = false;

            if (BeforeInstallUpdate != null)
                BeforeInstallUpdate(update);
        }
Ejemplo n.º 4
0
        public void OnUpdateReadyToDownload(Update update)
        {
            _menuItem.Text = string.Format("Download Version {0}", update.Version);
            _menuItem.Enabled = true;

            _updateMenu.Visible = true;
            _downloadItem.Text = string.Format("Download v{0}...", update.Version);
            _downloadItem.Image = DefaultWebBrowser.Instance.GetIconAsBitmap(16) ?? Resources.network;
        }
Ejemplo n.º 5
0
        /// <exception cref="IOException">
        /// Thrown if a network error occurs or the SHA-1 hash of the downloaded file
        /// does not match the expected value in the update manifest.
        /// </exception>
        private void DownloadUpdateSync(Update update)
        {
            _cancellationTokenSource = new CancellationTokenSource();

            var path = Path.Combine(Path.GetTempPath(), update.FileName);
            var downloader = new FileDownloader
                {
                    Uri = update.Uri,
                    Path = path,
                    CancellationToken = _cancellationTokenSource.Token
                };

            downloader.BeforeRequest += NotifyBeforeRequest;
            downloader.ProgressChanged += DownloaderOnProgressChanged;

            downloader.DownloadSync();

            if (downloader.State != FileDownloadState.Success)
                return;

            var hash = new SHA1Algorithm().ComputeFile(path);

            if (!String.Equals(hash, update.SHA1, StringComparison.OrdinalIgnoreCase))
            {
                _logger.ErrorFormat(
                    "Unable to verify integrity of \"{0}\" via SHA-1 hash: expected {1}, but found {2}",
                    path, update.SHA1, hash);
                throw new IOException("Update file is corrupt or has been tampered with; SHA-1 hash is incorrect");
            }

            _latestInstallerPath = path;
        }
Ejemplo n.º 6
0
        private void GetLatestVersionSync()
        {
            CheckState();

            try
            {
                _state = UpdaterClientState.Checking;
                HttpRequest.BeforeRequestGlobal += NotifyBeforeRequest;
                var json = HttpRequest.Get("http://update.bdhero.org/update.json");
                var response = JsonConvert.DeserializeObject<UpdateResponse>(json);
                _latestUpdate = FromResponse(response);
                _state = UpdaterClientState.Ready;
                _hasChecked = true;
            }
            catch (Exception e)
            {
                _state = UpdaterClientState.Error;
                _logger.Error("Error occurred while checking for application update", e);
                throw;
            }
            finally
            {
                HttpRequest.BeforeRequestGlobal -= NotifyBeforeRequest;
            }
        }
Ejemplo n.º 7
0
        public bool ShouldInstallUpdate(Update update)
        {
            const string caption = "Application restart required";
            var text =
                string.Format(
                    "To install the update, you must first close the application.\n\nClose {0} and install update?",
                    AppUtils.ProductName);

            return DialogResult.Yes ==
                   MessageBox.Show(_form, text, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
        }
Ejemplo n.º 8
0
 public void OnUpdateReadyToInstall(Update update)
 {
     _menuItem.Text = string.Format("Install Version {0}", update.Version);
     _menuItem.Enabled = true;
 }