private void HandleRemovalAction( IList <QuarantineFileItem> selectedItems, RemovalAction action) { const string DialogInstructionDelete = "The {0} selected file(s) will be permanently deleted."; const string DialogInstructionRestore = "The {0} selected file(s) will be placed back in their original location."; const string ErrorMessageDelete = "Unable to delete '{0}.'{1}Detail:{2}"; const string ErrorMessageRestore = "Unable to restore '{0}'.{1}Detail:{2}"; TaskDialogResult res; using (var td = new TaskDialog()) { TaskDialogStandardButtons button = TaskDialogStandardButtons.None; button |= TaskDialogStandardButtons.Yes; button |= TaskDialogStandardButtons.No; td.StandardButtons = button; td.StartupLocation = TaskDialogStartupLocation.CenterOwner; td.OwnerWindowHandle = this.Handle; td.Icon = TaskDialogStandardIcon.Information; td.InstructionText = action == RemovalAction.DELETE ? string.Format(DialogInstructionDelete, selectedItems.Count) : string.Format(DialogInstructionRestore, selectedItems.Count); td.Caption = action == RemovalAction.DELETE ? "Delete Selected Files?" : "Quarantine Selected Files?"; td.Text = "Do you want to continue?"; res = td.Show(); } if (res == TaskDialogResult.Yes) { foreach (QuarantineFileItem file in selectedItems) { try { if (action == RemovalAction.RESTORE) { logger.Debug( "Restoring file: {0} to {1}", file.AbsolutePath, file.OriginalDirectoryPath); Quarantine.QuarantineManager.RestoreFile(file); } else { logger.Debug("Deleting file: {0}", file.AbsolutePath); Quarantine.QuarantineManager.RemoveFile(file, false); } } catch (Exception err) { logger.Error( err, string.Format("File handling failed for '{0}'", file.AbsolutePath)); MessageBox.Show( string.Format( action == RemovalAction.DELETE ? ErrorMessageDelete : ErrorMessageRestore, file.AbsolutePath, Environment.NewLine, err.Message), "Quarantine Manager", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } } LoadFilesList(); } }
private void HandleRemovalAction(IList <FileItem> selectedItems, RemovalAction action) { const string DialogInstructionDelete = "The {0} selected file(s) will be permanently deleted."; const string DialogInstructionQuarantine = "The {0} selected file(s) will be moved into quarantine."; const string ErrorMessageDelete = "Unable to delete '{0}.'{1}Detail:{2}"; const string ErrorMessageQuarantine = "Unable to delete '{0}'.{1}Detail:{2}"; TaskDialogResult res; using (var td = new TaskDialog()) { TaskDialogStandardButtons button = TaskDialogStandardButtons.None; button |= TaskDialogStandardButtons.Yes; button |= TaskDialogStandardButtons.No; td.StandardButtons = button; td.StartupLocation = TaskDialogStartupLocation.CenterOwner; td.OwnerWindowHandle = this.Handle; td.Icon = TaskDialogStandardIcon.Information; td.InstructionText = action == RemovalAction.DELETE ? string.Format(DialogInstructionDelete, selectedItems.Count) : string.Format(DialogInstructionQuarantine, selectedItems.Count); td.Caption = action == RemovalAction.DELETE ? "Delete Selected Files?" : "Quarantine Selected Files?"; td.Text = "Do you want to continue?"; res = td.Show(); } if (res == TaskDialogResult.Yes) { foreach (FileItem file in selectedItems) { try { if (action == RemovalAction.QUARANTINE) { Quarantine.QuarantineManager.ImportFile(file); } else { File.Delete(file.AbsolutePath); } detections.Remove(file); } catch (Exception err) { MessageBox.Show( string.Format( action == RemovalAction.DELETE ? ErrorMessageDelete : ErrorMessageQuarantine, file.AbsolutePath, Environment.NewLine, err.Message), "Task Progress", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } } listViewResults.Freeze(); listViewResults.SetObjects(detections); listViewResults.Unfreeze(); UpdateResultsCount(); updateResultButtonStatus(); } }