| [2064] | 1 | /* |
|---|
| 2 | * $Id$ |
|---|
| [2516] | 3 | * Copyright 2008-2012 The Eraser Project |
|---|
| [2064] | 4 | * Original Author: Joel Low <lowjoel@users.sourceforge.net> |
|---|
| 5 | * Modified By: |
|---|
| 6 | * |
|---|
| 7 | * This file is part of Eraser. |
|---|
| 8 | * |
|---|
| 9 | * Eraser is free software: you can redistribute it and/or modify it under the |
|---|
| 10 | * terms of the GNU General Public License as published by the Free Software |
|---|
| 11 | * Foundation, either version 3 of the License, or (at your option) any later |
|---|
| 12 | * version. |
|---|
| 13 | * |
|---|
| 14 | * Eraser is distributed in the hope that it will be useful, but WITHOUT ANY |
|---|
| 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
|---|
| 16 | * A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
|---|
| 17 | * |
|---|
| 18 | * A copy of the GNU General Public License can be found at |
|---|
| 19 | * <http://www.gnu.org/licenses/>. |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | using System; |
|---|
| 23 | using System.Collections.Generic; |
|---|
| 24 | using System.ComponentModel; |
|---|
| 25 | using System.Drawing; |
|---|
| 26 | using System.Data; |
|---|
| 27 | using System.Linq; |
|---|
| 28 | using System.Text; |
|---|
| 29 | using System.Windows.Forms; |
|---|
| [2077] | 30 | using System.IO; |
|---|
| [2230] | 31 | using System.Text.RegularExpressions; |
|---|
| [2064] | 32 | |
|---|
| [2068] | 33 | using Eraser.Util; |
|---|
| [2509] | 34 | using Eraser.Plugins; |
|---|
| 35 | using Eraser.Plugins.ExtensionPoints; |
|---|
| [2064] | 36 | |
|---|
| 37 | namespace Eraser.DefaultPlugins |
|---|
| 38 | { |
|---|
| [2517] | 39 | partial class SecureMoveErasureTargetConfigurer : UserControl, IErasureTargetConfigurer |
|---|
| [2064] | 40 | { |
|---|
| 41 | public SecureMoveErasureTargetConfigurer() |
|---|
| 42 | { |
|---|
| 43 | InitializeComponent(); |
|---|
| [2068] | 44 | Theming.ApplyTheme(this); |
|---|
| [2064] | 45 | } |
|---|
| [2066] | 46 | |
|---|
| 47 | #region IConfigurer<ErasureTarget> Members |
|---|
| 48 | |
|---|
| [2509] | 49 | public void LoadFrom(IErasureTarget target) |
|---|
| [2066] | 50 | { |
|---|
| [2071] | 51 | SecureMoveErasureTarget secureMove = target as SecureMoveErasureTarget; |
|---|
| 52 | if (secureMove == null) |
|---|
| 53 | throw new ArgumentException("The provided erasure target type is not " + |
|---|
| 54 | "supported by this configurer."); |
|---|
| 55 | |
|---|
| 56 | fromTxt.Text = secureMove.Path; |
|---|
| 57 | toTxt.Text = secureMove.Destination; |
|---|
| [2077] | 58 | |
|---|
| [2118] | 59 | moveFolderRadio.Checked = |
|---|
| 60 | File.Exists(secureMove.Path) || Directory.Exists(secureMove.Path) && |
|---|
| [2077] | 61 | (File.GetAttributes(secureMove.Path) & FileAttributes.Directory) != 0; |
|---|
| [2066] | 62 | } |
|---|
| 63 | |
|---|
| [2509] | 64 | public bool SaveTo(IErasureTarget target) |
|---|
| [2066] | 65 | { |
|---|
| [2071] | 66 | SecureMoveErasureTarget secureMove = target as SecureMoveErasureTarget; |
|---|
| 67 | if (secureMove == null) |
|---|
| 68 | throw new ArgumentException("The provided erasure target type is not " + |
|---|
| 69 | "supported by this configurer."); |
|---|
| 70 | |
|---|
| 71 | secureMove.Path = fromTxt.Text; |
|---|
| 72 | secureMove.Destination = toTxt.Text; |
|---|
| [2066] | 73 | return true; |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | #endregion |
|---|
| 77 | |
|---|
| 78 | #region ICliConfigurer<ErasureTarget> Members |
|---|
| 79 | |
|---|
| [2232] | 80 | public string Help() |
|---|
| [2066] | 81 | { |
|---|
| [2232] | 82 | return S._(@"move Securely moves a file/directory to a new location |
|---|
| 83 | arguments: move=<source>|<destination>"); |
|---|
| [2066] | 84 | } |
|---|
| 85 | |
|---|
| 86 | public bool ProcessArgument(string argument) |
|---|
| 87 | { |
|---|
| [2230] | 88 | //The secure move source and target, which are separated by a pipe. |
|---|
| 89 | Regex regex = new Regex("(move=)?(?<source>.*)\\|(?<target>.*)", |
|---|
| 90 | RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.RightToLeft); |
|---|
| 91 | Match match = regex.Match(argument); |
|---|
| 92 | |
|---|
| 93 | if (match.Groups["source"].Success && match.Groups["target"].Success) |
|---|
| 94 | { |
|---|
| 95 | //Get the source and destination paths |
|---|
| 96 | fromTxt.Text = match.Groups["source"].Value; |
|---|
| 97 | toTxt.Text = match.Groups["target"].Value; |
|---|
| 98 | |
|---|
| 99 | //Check the folder radio button if the source is a folder. |
|---|
| 100 | moveFileRadio.Checked = !( |
|---|
| 101 | moveFolderRadio.Checked = Directory.Exists(fromTxt.Text)); |
|---|
| 102 | return true; |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | return false; |
|---|
| [2066] | 106 | } |
|---|
| 107 | |
|---|
| 108 | #endregion |
|---|
| [2068] | 109 | |
|---|
| 110 | private void fromSelectButton_Click(object sender, EventArgs e) |
|---|
| 111 | { |
|---|
| [2077] | 112 | if (moveFolderRadio.Checked) |
|---|
| 113 | fromTxt.Text = SelectFolder(fromTxt.Text, S._("Select the Source folder")); |
|---|
| 114 | else |
|---|
| 115 | fromTxt.Text = SelectFile(fromTxt.Text, S._("Select the Source file")); |
|---|
| [2068] | 116 | } |
|---|
| 117 | |
|---|
| [2077] | 118 | private void toSelectButton_Click(object sender, EventArgs e) |
|---|
| [2068] | 119 | { |
|---|
| [2077] | 120 | if (moveFolderRadio.Checked) |
|---|
| [2086] | 121 | toTxt.Text = SelectFolder(toTxt.Text, S._("Move Source folder to:")); |
|---|
| [2077] | 122 | else |
|---|
| [2086] | 123 | toTxt.Text = SaveFile(toTxt.Text, S._("Save Source file to")); |
|---|
| [2068] | 124 | } |
|---|
| 125 | |
|---|
| [2077] | 126 | private string SelectFile(string currentPath, string description) |
|---|
| [2068] | 127 | { |
|---|
| [2077] | 128 | openFileDialog.FileName = currentPath; |
|---|
| 129 | openFileDialog.Title = description; |
|---|
| 130 | if (openFileDialog.ShowDialog(this) == DialogResult.OK) |
|---|
| 131 | { |
|---|
| 132 | return openFileDialog.FileName; |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | return string.Empty; |
|---|
| [2068] | 136 | } |
|---|
| 137 | |
|---|
| [2077] | 138 | private string SaveFile(string currentPath, string description) |
|---|
| [2068] | 139 | { |
|---|
| [2077] | 140 | saveFileDialog.FileName = currentPath; |
|---|
| 141 | saveFileDialog.Title = description; |
|---|
| 142 | if (saveFileDialog.ShowDialog(this) == DialogResult.OK) |
|---|
| [2068] | 143 | { |
|---|
| [2077] | 144 | return saveFileDialog.FileName; |
|---|
| [2068] | 145 | } |
|---|
| 146 | |
|---|
| 147 | return string.Empty; |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | private string SelectFolder(string currentPath, string description) |
|---|
| 151 | { |
|---|
| 152 | folderDialog.SelectedPath = currentPath; |
|---|
| 153 | folderDialog.Description = description; |
|---|
| 154 | if (folderDialog.ShowDialog(this) == DialogResult.OK) |
|---|
| 155 | { |
|---|
| 156 | return folderDialog.SelectedPath; |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | return string.Empty; |
|---|
| 160 | } |
|---|
| [2064] | 161 | } |
|---|
| 162 | } |
|---|