source: trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/FileErasureTargetConfigurer.cs @ 2228

Revision 2228, 2.8 KB checked in by lowjoel, 4 years ago (diff)

Based on r2226, allow the file and folder erasure target configurers to detect a path (of their own type) and then accept it as their own. This allows the specification of paths on the command line without explicit handler requirements, so things like these work:

eraser addtask D:\test.txt D:\testing

And a file target and a directory target will be made, respectively, using default settings.

Also fixed an implementation error where the return code of the ProcessArgument? function was not properly set.

  • 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;
30
31using System.Text.RegularExpressions;
32
33using Eraser.Manager;
34using Eraser.Util;
35using System.IO;
36
37namespace Eraser.DefaultPlugins
38{
39    public partial class FileErasureTargetConfigurer : UserControl, IErasureTargetConfigurer
40    {
41        public FileErasureTargetConfigurer()
42        {
43            InitializeComponent();
44            Theming.ApplyTheme(this);
45        }
46
47        #region IConfigurer<ErasureTarget> Members
48
49        public void LoadFrom(ErasureTarget target)
50        {
51            FileErasureTarget file = target as FileErasureTarget;
52            if (file == null)
53                throw new ArgumentException("The provided erasure target type is not " +
54                    "supported by this configurer.");
55
56            filePath.Text = file.Path;
57        }
58
59        public bool SaveTo(ErasureTarget target)
60        {
61            FileErasureTarget file = target as FileErasureTarget;
62            if (file == null)
63                throw new ArgumentException("The provided erasure target type is not " +
64                    "supported by this configurer.");
65
66            if (filePath.Text.Length == 0)
67            {
68                errorProvider.SetError(filePath, S._("Invalid file path"));
69                return false;
70            }
71
72            file.Path = filePath.Text;
73            return true;
74        }
75
76        #endregion
77
78        #region ICliConfigurer<ErasureTarget> Members
79
80        public void Help()
81        {
82            throw new NotImplementedException();
83        }
84
85        public bool ProcessArgument(string argument)
86        {
87            Regex regex = new Regex("file=(?<fileName>.*)",
88                RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.RightToLeft);
89            Match match = regex.Match(argument);
90
91            if (match.Groups["fileName"].Success)
92            {
93                filePath.Text = match.Groups["fileName"].Value;
94                return true;
95            }
96            else if (File.Exists(argument))
97            {
98                filePath.Text = argument;
99                return true;
100            }
101
102            return false;
103        }
104
105        #endregion
106
107        private void fileBrowse_Click(object sender, EventArgs e)
108        {
109            fileDialog.FileName = filePath.Text;
110            if (fileDialog.ShowDialog() == DialogResult.OK)
111                filePath.Text = fileDialog.FileName;
112        }
113    }
114}
Note: See TracBrowser for help on using the repository browser.