source: trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/SecureMoveErasureTargetConfigurer.cs @ 2077

Revision 2077, 3.7 KB checked in by lowjoel, 5 years ago (diff)

Don't use the split button to pick the file or folder to move to; ask the user what he wants moved, then present the appropriate dialogs. Addresses #60: Eraser Secure Cut.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1/*
2 * $Id$
3 * Copyright 2008-2010 The Eraser Project
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
22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
25using System.Drawing;
26using System.Data;
27using System.Linq;
28using System.Text;
29using System.Windows.Forms;
30using System.IO;
31
32using Eraser.Manager;
33using Eraser.Util;
34
35namespace Eraser.DefaultPlugins
36{
37    public partial class SecureMoveErasureTargetConfigurer : UserControl, IErasureTargetConfigurer
38    {
39        public SecureMoveErasureTargetConfigurer()
40        {
41            InitializeComponent();
42            Theming.ApplyTheme(this);
43        }
44
45        #region IConfigurer<ErasureTarget> Members
46
47        public void LoadFrom(ErasureTarget target)
48        {
49            SecureMoveErasureTarget secureMove = target as SecureMoveErasureTarget;
50            if (secureMove == null)
51                throw new ArgumentException("The provided erasure target type is not " +
52                    "supported by this configurer.");
53
54            fromTxt.Text = secureMove.Path;
55            toTxt.Text = secureMove.Destination;
56
57            moveFolderRadio.Checked = File.Exists(secureMove.Path) &&
58                (File.GetAttributes(secureMove.Path) & FileAttributes.Directory) != 0;
59        }
60
61        public bool SaveTo(ErasureTarget target)
62        {
63            SecureMoveErasureTarget secureMove = target as SecureMoveErasureTarget;
64            if (secureMove == null)
65                throw new ArgumentException("The provided erasure target type is not " +
66                    "supported by this configurer.");
67
68            secureMove.Path = fromTxt.Text;
69            secureMove.Destination = toTxt.Text;
70            return true;
71        }
72
73        #endregion
74
75        #region ICliConfigurer<ErasureTarget> Members
76
77        public void Help()
78        {
79            throw new NotImplementedException();
80        }
81
82        public bool ProcessArgument(string argument)
83        {
84            throw new NotImplementedException();
85        }
86
87        #endregion
88
89        private void fromSelectButton_Click(object sender, EventArgs e)
90        {
91            if (moveFolderRadio.Checked)
92                fromTxt.Text = SelectFolder(fromTxt.Text, S._("Select the Source folder"));
93            else
94                fromTxt.Text = SelectFile(fromTxt.Text, S._("Select the Source file"));
95        }
96
97        private void toSelectButton_Click(object sender, EventArgs e)
98        {
99            if (moveFolderRadio.Checked)
100                toTxt.Text = SelectFolder(toTxt.Text, S._("Save moved file as"));
101            else
102                toTxt.Text = SaveFile(toTxt.Text, S._("Move Source folder to:"));
103        }
104
105        private string SelectFile(string currentPath, string description)
106        {
107            openFileDialog.FileName = currentPath;
108            openFileDialog.Title = description;
109            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
110            {
111                return openFileDialog.FileName;
112            }
113
114            return string.Empty;
115        }
116
117        private string SaveFile(string currentPath, string description)
118        {
119            saveFileDialog.FileName = currentPath;
120            saveFileDialog.Title = description;
121            if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
122            {
123                return saveFileDialog.FileName;
124            }
125
126            return string.Empty;
127        }
128
129        private string SelectFolder(string currentPath, string description)
130        {
131            folderDialog.SelectedPath = currentPath;
132            folderDialog.Description = description;
133            if (folderDialog.ShowDialog(this) == DialogResult.OK)
134            {
135                return folderDialog.SelectedPath;
136            }
137
138            return string.Empty;
139        }
140    }
141}
Note: See TracBrowser for help on using the repository browser.