private void UpdateProgressUI() { var albumAbs = string.Format("{0:0.00} MB of {1:0.00} MB", (DownloadData.AlbumBytes / 1024.0f / 1024.0f), (CurrentAlbum.SizeInBytes / 1024.0f / 1024.0f)); var albumProgress = Math.Min(100, (int)(DownloadData.AlbumBytes * 1.0f / CurrentAlbum.SizeInBytes * 100)); ProgressOverallProgressBar.Value = albumProgress; ProgressOverallValueLabel.Text = string.Format("{0} % ({1})", albumProgress, albumAbs); var trackTotal = DownloadData.TrackTotalBytes > 0 ? DownloadData.TrackTotalBytes : DownloadData.CurrentTrack.SizeInBytes; var trackProgress = Math.Min(100, (int)(DownloadData.TrackBytes * 1.0f / trackTotal * 100)); ProgressTrackProgressBar.Value = trackProgress; ProgressTrackValueLabel.Text = string.Format("{0} % of {1}", trackProgress, DownloadData.CurrentTrack.Title); TaskbarUtils.SetProgressValue(Handle, (ulong)DownloadData.AlbumBytes, (ulong)CurrentAlbum.SizeInBytes); }
private void TracksDownloadButton_Click(object sender, EventArgs e) { try { // reset track list colors foreach (DataGridViewRow row in TracksListDataGridView.Rows) { SetDataGridRowColor(SystemColors.Control, row, null); } // determine and create target output folder var folder = DownloadLocationTextBox.Text; if (DownloadCreateSubfolderCheckBox.Checked) { var name = CurrentAlbum.Name; foreach (var c in Path.GetInvalidPathChars()) { name = name.Replace(c, '_'); } folder = Path.Combine(folder, name); } if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } // create object for holding progress relevant data during download DownloadData = new DownloadProgressData() { FolderPath = folder, RemainingTracks = new List <Track>(CurrentAlbum.Tracks) }; // deactivate form and start TaskbarUtils.SetProgressState(Handle, TaskbarUtils.ProgressState.Normal); TaskbarUtils.SetProgressValue(Handle, 0, (ulong)CurrentAlbum.SizeInBytes); SetFormEnabled(false); StartDownload(); } catch (Exception ex) { ShowEx("Failed to start download", ex); } }