| 1 | using System; |
|---|
| 2 | using System.Collections.Generic; |
|---|
| 3 | using System.ComponentModel; |
|---|
| 4 | using System.Data; |
|---|
| 5 | using System.Drawing; |
|---|
| 6 | using System.Text; |
|---|
| 7 | using System.Windows.Forms; |
|---|
| 8 | |
|---|
| 9 | using Eraser.Manager; |
|---|
| 10 | using Eraser.Util; |
|---|
| 11 | |
|---|
| 12 | namespace Eraser |
|---|
| 13 | { |
|---|
| 14 | public partial class TaskDataSelectionForm : Form |
|---|
| 15 | { |
|---|
| 16 | private class DriveItem |
|---|
| 17 | { |
|---|
| 18 | public override string ToString() |
|---|
| 19 | { |
|---|
| 20 | return Label; |
|---|
| 21 | } |
|---|
| 22 | |
|---|
| 23 | public string Drive; |
|---|
| 24 | public string Label; |
|---|
| 25 | public Icon Icon; |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | public TaskDataSelectionForm() |
|---|
| 29 | { |
|---|
| 30 | //Create the UI |
|---|
| 31 | InitializeComponent(); |
|---|
| 32 | file.Checked = true; |
|---|
| 33 | |
|---|
| 34 | //Populate the drives list |
|---|
| 35 | string[] drives = Environment.GetLogicalDrives(); |
|---|
| 36 | foreach (string drive in drives) |
|---|
| 37 | { |
|---|
| 38 | DriveTypes driveType = Drives.GetDriveType(drive); |
|---|
| 39 | if (driveType != DriveTypes.DRIVE_UNKNOWN && |
|---|
| 40 | driveType != DriveTypes.DRIVE_NO_ROOT_DIR && |
|---|
| 41 | driveType != DriveTypes.DRIVE_CDROM && |
|---|
| 42 | driveType != DriveTypes.DRIVE_REMOTE) |
|---|
| 43 | { |
|---|
| 44 | DriveItem item = new DriveItem(); |
|---|
| 45 | item.Drive = drive.Substring(0, drive.Length - 1); |
|---|
| 46 | item.Label = File.GetFileDescription(item.Drive); |
|---|
| 47 | item.Icon = File.GetFileIcon(item.Drive); |
|---|
| 48 | unusedDisk.Items.Add(item); |
|---|
| 49 | } |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | if (unusedDisk.Items.Count != 0) |
|---|
| 53 | unusedDisk.SelectedIndex = 0; |
|---|
| 54 | |
|---|
| 55 | //And the methods list |
|---|
| 56 | List<IErasureMethod> methods = ErasureMethodManager.GetMethods(); |
|---|
| 57 | foreach (IErasureMethod method in methods) |
|---|
| 58 | this.method.Items.Add(method); |
|---|
| 59 | if (this.method.Items.Count != 0) |
|---|
| 60 | this.method.SelectedIndex = 0; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | /// <summary> |
|---|
| 64 | /// Retrieves the settings on the property page as the Eraser Manager API equivalent. |
|---|
| 65 | /// </summary> |
|---|
| 66 | /// <returns>An Eraser.Manager.Task.Data or Eraser.Manager.Task.FreeSpace object |
|---|
| 67 | /// or any of its inherited classes, depending on the task selected</returns> |
|---|
| 68 | public Task.ErasureTarget GetTaskEntry() |
|---|
| 69 | { |
|---|
| 70 | Task.ErasureTarget result = null; |
|---|
| 71 | if (file.Checked) |
|---|
| 72 | { |
|---|
| 73 | Manager.Task.File fileTask = new Task.File(); |
|---|
| 74 | result = fileTask; |
|---|
| 75 | |
|---|
| 76 | fileTask.Path = filePath.Text; |
|---|
| 77 | } |
|---|
| 78 | else if (folder.Checked) |
|---|
| 79 | { |
|---|
| 80 | Manager.Task.Folder folderTask = new Task.Folder(); |
|---|
| 81 | result = folderTask; |
|---|
| 82 | |
|---|
| 83 | folderTask.Path = folderPath.Text; |
|---|
| 84 | folderTask.IncludeMask = folderInclude.Text; |
|---|
| 85 | folderTask.ExcludeMask = folderExclude.Text; |
|---|
| 86 | folderTask.DeleteIfEmpty = folderDelete.Checked; |
|---|
| 87 | } |
|---|
| 88 | else |
|---|
| 89 | { |
|---|
| 90 | Task.FreeSpace freeSpaceTask = new Task.FreeSpace(); |
|---|
| 91 | result = freeSpaceTask; |
|---|
| 92 | |
|---|
| 93 | freeSpaceTask.Drive = (unusedDisk.SelectedItem as DriveItem).Drive; |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | result.Method = this.method.SelectedItem as IErasureMethod; |
|---|
| 97 | return result; |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | private void data_CheckedChanged(object sender, EventArgs e) |
|---|
| 101 | { |
|---|
| 102 | filePath.Enabled = fileBrowse.Enabled = file.Checked; |
|---|
| 103 | folderPath.Enabled = folderBrowse.Enabled = folderIncludeLbl.Enabled = |
|---|
| 104 | folderInclude.Enabled = folderExcludeLbl.Enabled = folderExclude.Enabled = |
|---|
| 105 | folderDelete.Enabled = folder.Checked; |
|---|
| 106 | unusedDisk.Enabled = unused.Checked; |
|---|
| 107 | errorProvider.Clear(); |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | private void fileBrowse_Click(object sender, EventArgs e) |
|---|
| 111 | { |
|---|
| 112 | fileDialog.FileName = filePath.Text; |
|---|
| 113 | if (fileDialog.ShowDialog() == DialogResult.OK) |
|---|
| 114 | filePath.Text = fileDialog.FileName; |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | private void folderBrowse_Click(object sender, EventArgs e) |
|---|
| 118 | { |
|---|
| 119 | folderDialog.SelectedPath = folderPath.Text; |
|---|
| 120 | if (folderDialog.ShowDialog() == DialogResult.OK) |
|---|
| 121 | folderPath.Text = folderDialog.SelectedPath; |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | private void unusedDisk_DrawItem(object sender, DrawItemEventArgs e) |
|---|
| 125 | { |
|---|
| 126 | if (e.Index == -1) |
|---|
| 127 | return; |
|---|
| 128 | |
|---|
| 129 | Graphics g = e.Graphics; |
|---|
| 130 | DriveItem item = (DriveItem)unusedDisk.Items[e.Index]; |
|---|
| 131 | Color textColour = e.ForeColor; |
|---|
| 132 | PointF textPos = e.Bounds.Location; |
|---|
| 133 | textPos.X += item.Icon.Width + 4; |
|---|
| 134 | textPos.Y += 2; |
|---|
| 135 | |
|---|
| 136 | //Set the text colour and background colour if the control is disabled |
|---|
| 137 | if ((e.State & DrawItemState.Disabled) == 0) |
|---|
| 138 | e.DrawBackground(); |
|---|
| 139 | else |
|---|
| 140 | { |
|---|
| 141 | g.FillRectangle(new SolidBrush(SystemColors.ButtonFace), e.Bounds); |
|---|
| 142 | textColour = SystemColors.GrayText; |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | g.DrawIcon(item.Icon, e.Bounds.X + 2, e.Bounds.Y); |
|---|
| 146 | g.DrawString(item.Label, e.Font, new SolidBrush(textColour), textPos); |
|---|
| 147 | if ((e.State & DrawItemState.Focus) != 0) |
|---|
| 148 | e.DrawFocusRectangle(); |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | private void ok_Click(object sender, EventArgs e) |
|---|
| 152 | { |
|---|
| 153 | if (file.Checked && filePath.Text.Length == 0) |
|---|
| 154 | errorProvider.SetError(filePath, "Invalid file path"); |
|---|
| 155 | else if (folder.Checked && folderPath.Text.Length == 0) |
|---|
| 156 | errorProvider.SetError(folderPath, "Invalid folder path"); |
|---|
| 157 | else |
|---|
| 158 | { |
|---|
| 159 | errorProvider.Clear(); |
|---|
| 160 | DialogResult = DialogResult.OK; |
|---|
| 161 | Close(); |
|---|
| 162 | } |
|---|
| 163 | } |
|---|
| 164 | } |
|---|
| 165 | } |
|---|