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

Revision 2118, 3.7 KB checked in by lowjoel, 4 years ago (diff)

When we use File.Exists, we have to also check using Directory.Exists as File.Exists returns false if the path points to a directory.

  • 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 =
58                File.Exists(secureMove.Path) || Directory.Exists(secureMove.Path) &&
59                (File.GetAttributes(secureMove.Path) & FileAttributes.Directory) != 0;
60        }
61
62        public bool SaveTo(ErasureTarget target)
63        {
64            SecureMoveErasureTarget secureMove = target as SecureMoveErasureTarget;
65            if (secureMove == null)
66                throw new ArgumentException("The provided erasure target type is not " +
67                    "supported by this configurer.");
68
69            secureMove.Path = fromTxt.Text;
70            secureMove.Destination = toTxt.Text;
71            return true;
72        }
73
74        #endregion
75
76        #region ICliConfigurer<ErasureTarget> Members
77
78        public void Help()
79        {
80            throw new NotImplementedException();
81        }
82
83        public bool ProcessArgument(string argument)
84        {
85            throw new NotImplementedException();
86        }
87
88        #endregion
89
90        private void fromSelectButton_Click(object sender, EventArgs e)
91        {
92            if (moveFolderRadio.Checked)
93                fromTxt.Text = SelectFolder(fromTxt.Text, S._("Select the Source folder"));
94            else
95                fromTxt.Text = SelectFile(fromTxt.Text, S._("Select the Source file"));
96        }
97
98        private void toSelectButton_Click(object sender, EventArgs e)
99        {
100            if (moveFolderRadio.Checked)
101                toTxt.Text = SelectFolder(toTxt.Text, S._("Move Source folder to:"));
102            else
103                toTxt.Text = SaveFile(toTxt.Text, S._("Save Source file to"));
104        }
105
106        private string SelectFile(string currentPath, string description)
107        {
108            openFileDialog.FileName = currentPath;
109            openFileDialog.Title = description;
110            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
111            {
112                return openFileDialog.FileName;
113            }
114
115            return string.Empty;
116        }
117
118        private string SaveFile(string currentPath, string description)
119        {
120            saveFileDialog.FileName = currentPath;
121            saveFileDialog.Title = description;
122            if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
123            {
124                return saveFileDialog.FileName;
125            }
126
127            return string.Empty;
128        }
129
130        private string SelectFolder(string currentPath, string description)
131        {
132            folderDialog.SelectedPath = currentPath;
133            folderDialog.Description = description;
134            if (folderDialog.ShowDialog(this) == DialogResult.OK)
135            {
136                return folderDialog.SelectedPath;
137            }
138
139            return string.Empty;
140        }
141    }
142}
Note: See TracBrowser for help on using the repository browser.