// Occurs every time of block of data has been downloaded, and can be used to display the progress with // Note that you can also create a timer, and display the progress every certain interval // Also note that the progress properties return a size in bytes, which is not really user friendly to display // The FileDownloader class provides static functions to format these byte amounts to a more readible format, either in binary or decimal notation private void downloader_ProgressChanged(object sender, EventArgs e) { if (downloader.SupportsProgress) { this.Text = downloader.CurrentFilePercentage().ToString("###.0") + "% - Downloading \"" + downloader.CurrentFile.Name + "\"..."; speedTextBox.Text = FileDownloader.FormatSizeBinary(downloader.DownloadSpeed); downloadBar.Value = Convert.ToInt32(downloader.TotalPercentage()); } }
/// <summary> /// Tries to open the pgf manual. If it is not present, downloads it. /// </summary> public void OpenPgfManual() { String pgfmanualurl = Consts.PGFManualDownloadPath; //open file if it exists and downloader is not busy downloading it (then file is not complete) string PgfManualPath = Path.Combine(Helper.GetAppdataPath(), "pgfmanual.pdf"); if (File.Exists(PgfManualPath) && (downloader == null || (downloader != null && !downloader.IsBusy && downloader.CurrentFile.Path == pgfmanualurl))) { System.Diagnostics.Process.Start(PgfManualPath); } else { // Creating a new instance of a FileDownloader if (downloader == null) { downloader = new FileDownloader(); downloader.LocalDirectory = Helper.GetAppdataPath(); downloader.FileDownloadStarted += ((s, args) => GlobalUI.UI.AddStatusLine(this, "Download of Tikz/Pgf manual started. Please be patient.")); downloader.FileDownloadSucceeded += ((s, args) => GlobalUI.UI.AddStatusLine(this, "Download of Tikz/Pgf manual succeeded.")); downloader.FileDownloadFailed += ((s, args) => GlobalUI.UI.AddStatusLine(this, "Download of Tikz/Pgf manual failed.", true)); } //if downloader is downloading file show status. if (downloader.IsBusy) { String msg = String.Format("Downloaded {0} of {1} ({2}%)", FileDownloader.FormatSizeBinary(downloader.CurrentFileProgress), FileDownloader.FormatSizeBinary(downloader.CurrentFileSize), downloader.CurrentFilePercentage()) + String.Format(" - {0}/s", FileDownloader.FormatSizeBinary(downloader.DownloadSpeed)); if (DialogResult.Cancel == GlobalUI.UI.ShowMessageBox(msg + Environment.NewLine + "Press cancel to abort download.", "Download in progress", MessageBoxButtons.OKCancel, MessageBoxIcon.Information)) { downloader.Stop(); } } //else ask user to download file else { FileDownloader.FileInfo loadfile = new FileDownloader.FileInfo(pgfmanualurl); String msg = "Tikz/Pgf manual not found. Do you want to download it now?"; if (DialogResult.Yes == GlobalUI.UI.ShowMessageBox(msg, "Start download?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { if (!downloader.Files.Contains(loadfile)) { downloader.Files.Add(loadfile); } GlobalUI.UI.AddStatusLine(this, "Starting download of Pgf manual from " + pgfmanualurl + " ... (F2 for status)"); downloader.Start(); } } } }
// Occurs every time of block of data has been downloaded, and can be used to display the progress with // Note that you can also create a timer, and display the progress every certain interval // Also note that the progress properties return a size in bytes, which is not really user friendly to display // The FileDownloader class provides static functions to format these byte amounts to a more readible format, either in binary or decimal notatio private void downloader_ProgressChanged(object sender, EventArgs e) { // Current File Information label7.Text = String.Format("Downloaded {0} of {1} ({2}%)", FileDownloader.FormatSizeDecimal(_downloader.CurrentFileProgress), FileDownloader.FormatSizeDecimal(_downloader.CurrentFileSize), _downloader.CurrentFilePercentage()) + String.Format(" @ {0}/s", FileDownloader.FormatSizeDecimal(_downloader.DownloadSpeed)); int percent = (int)_downloader.CurrentFilePercentage(); if (percent > 0 && percent <= 100) { progressBar1.Value = percent; } // Overall Information label16.Text = String.Format("Downloaded {0} of {1} ({2}%)", FileDownloader.FormatSizeDecimal(_downloader.TotalProgress), FileDownloader.FormatSizeDecimal(_downloader.TotalSize), _downloader.TotalPercentage()); progressBar2.Value = (int)_downloader.TotalPercentage(); }