Example #1
0
        void bp_DownloadProgress(object sender, Tools.BackgroundPatcher.DownloadProgressEventArgs e)
        {
            if (this.InvokeRequired)
            {
                try
                {
                    this.Invoke(new MethodInvoker(
                                    delegate
                    {
                        bp_DownloadProgress(sender, e);
                    }));
                }
                catch (Exception exc)
                {
                    Util.Logging.Log(exc);
                }

                return;
            }

            bool update = false;

            if (e.downloadRate != this.downloadRate)
            {
                this.downloadRate = e.downloadRate;
                update            = true;
            }

            this.contentBytesTotal = e.contentBytesTotal;
            this.contentBytesCore  = e.contentBytesCore;

            if (e.bytesDownloaded != this.bytesDownloaded)
            {
                this.bytesDownloaded = e.bytesDownloaded;
                update = true;
            }

            if (update)
            {
                var t = Util.Text.FormatBytes(bytesDownloaded);
                if (downloadRate > 0)
                {
                    labelDownloaded.Text = t + " @ " + Util.Text.FormatBytes(downloadRate) + "/s";
                }
                else
                {
                    labelDownloaded.Text = t;
                }
            }

            if (e.estimatedBytesRemaining != this.estimatedBytesRemaining)
            {
                this.estimatedBytesRemaining = e.estimatedBytesRemaining;
                labelSize.Text = Util.Text.FormatBytes(estimatedBytesRemaining);
            }

            int files = e.filesDownloaded + e.manifestsDownloaded;
            int total = e.filesTotal + e.manifestsTotal;

            if (files != this.filesDownloaded || total != this.filesTotal)
            {
                this.filesDownloaded = files;
                this.filesTotal      = total;

                if (!manifestsComplete && e.manifestsDownloaded == e.manifestsTotal)
                {
                    manifestsComplete          = true;
                    labelSizeEstimated.Visible = true;
                    if (taskBar != null)
                    {
                        taskBar.SetState(this.Handle, Windows.Taskbar.TaskbarStates.Normal);
                    }
                }

                if (manifestsComplete)
                {
                    if (!errored)
                    {
                        labelFiles.Text = string.Format("{0:#,##0} of {1:#,##0}", files, total);
                    }

                    if (progressDownload.Maximum != e.filesTotal)
                    {
                        progressDownload.Maximum = e.filesTotal;
                    }
                    if (progressDownload.Value != e.filesDownloaded)
                    {
                        progressDownload.Value = e.filesDownloaded;
                    }

                    if (taskBar != null)
                    {
                        taskBar.SetValue(this.Handle, (ulong)e.filesDownloaded, (ulong)e.filesTotal);
                    }
                }
                else if (!errored)
                {
                    labelFiles.Text = string.Format("{0:#,##0} of ...", files);
                }
            }
        }