private void CreateZip_AddProgress(object sender, AddProgressEventArgs e) { if (e.EventType == ZipProgressEventType.Adding_Started) { var progress = new ZipperBackgroundWorkerProgressState { Type = ZipperBackgroundWorkerProgressType.Add, Text = "Adding files to Zip...", AddEntryAction = ZipperBackgroundWorkerProgressEntryAction.Reset }; CreateZip_BackgroundWorker.ReportProgress(0, progress); } else if (e.EventType == ZipProgressEventType.Adding_AfterAddEntry) { var progress = new ZipperBackgroundWorkerProgressState { Type = ZipperBackgroundWorkerProgressType.Add, AddEntryAction = ZipperBackgroundWorkerProgressEntryAction.Add }; CreateZip_BackgroundWorker.ReportProgress(e.EntriesTotal, progress); } else if (e.EventType == ZipProgressEventType.Adding_Completed) { var progress = new ZipperBackgroundWorkerProgressState { Type = ZipperBackgroundWorkerProgressType.Add }; CreateZip_BackgroundWorker.ReportProgress(100, progress); } }
private void CreateZip_SaveProgress(object sender, SaveProgressEventArgs e) { if (e.EventType == ZipProgressEventType.Saving_Started) { var progress = new ZipperBackgroundWorkerProgressState { Type = ZipperBackgroundWorkerProgressType.Save, Text = "Saving Zip...." }; CreateZip_BackgroundWorker.ReportProgress(0, progress); } else if (e.EventType == ZipProgressEventType.Saving_AfterWriteEntry) { var progress = new ZipperBackgroundWorkerProgressState { Type = ZipperBackgroundWorkerProgressType.Save }; CreateZip_BackgroundWorker.ReportProgress(e.EntriesSaved * 100 / e.EntriesTotal, progress); } else if (e.EventType == ZipProgressEventType.Saving_Completed) { var progress = new ZipperBackgroundWorkerProgressState { Type = ZipperBackgroundWorkerProgressType.Save, Text = "Finished" }; CreateZip_BackgroundWorker.ReportProgress(100, progress); } else if (e.EventType == ZipProgressEventType.Error_Saving) { var progress = new ZipperBackgroundWorkerProgressState { Type = ZipperBackgroundWorkerProgressType.Save, Text = "Failed", Error = "An error occurred saving the Zip file." }; CreateZip_BackgroundWorker.ReportProgress(0, progress); } }
private void CreateZip_BackgroundWorker_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e) { if (CreateZip_BackgroundWorker.CancellationPending) { return; } var state = (ZipperBackgroundWorkerProgressState)e.UserState; if (!string.IsNullOrEmpty(state.Text)) { ZipStatus_Label.Text = state.Text; } if (state.Type == ZipperBackgroundWorkerProgressType.Add) { if (state.AddEntryAction == ZipperBackgroundWorkerProgressEntryAction.Reset) { _entriesAdded = 0; Zip_ProgressBar.Value = 0; } else if (state.AddEntryAction == ZipperBackgroundWorkerProgressEntryAction.Add) { _entriesAdded++; Zip_ProgressBar.Value = _entriesAdded * 100 / e.ProgressPercentage; } } else { Zip_ProgressBar.Value = e.ProgressPercentage; } if (!string.IsNullOrEmpty(state.Error)) { MessageBox.Show(state.Error, "Zipper Error", MessageBoxButtons.OK, MessageBoxIcon.Error); CreateZip_BackgroundWorker.CancelAsync(); } }
private void Zip_Button_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(OutputPath_TextBox.Text)) { MessageBox.Show("You must enter an output path location for the Zip file.", "Zipper Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (File.Exists(OutputPath_TextBox.Text)) { MessageBox.Show("A file already exists at the specified output path location.", "Zipper Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var selectedBranch = Branch_ComboBox.SelectedItem.ToString(); if (_originalBranch != selectedBranch) { var result = _gitCommands.RunGitCmdResult("checkout " + selectedBranch); if (!result.ExitedSuccessfully) { MessageBox.Show("An error occurred checking out the selected branch: " + result.StdError, "Zipper Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } Zip_Button.Enabled = false; CreateZip_BackgroundWorker.RunWorkerAsync(new ZipperBackgroundWorkerArg { OutputPath = OutputPath_TextBox.Text, SourcePath = _gitCommands.WorkingDir, CompressionLevel = _plugin.GetCompressionLevelSetting(), CompressionMethod = _plugin.GetCompressionMethodSetting() }); }