source: trunk/eraser/Eraser/TaskDataSelectionForm.cs @ 2509

Revision 2509, 4.6 KB checked in by lowjoel, 3 years ago (diff)

Redesign the Eraser Plugin framework.

  • Split the plugin-dependent interfaces and related support classes out to Eraser.Plugins assembly
    • The extension interfaces are in the Eraser.Plugins.ExtensionPoints? namespace.
      • New IClientTool interface for plugins to create Eraser-hosted tools (e.g. #147)
    • The Registrars are in the Eraser.Plugins.Registrars namespace
    • Base types are now interfaces, no longer abstract base classes
    • Version the Eraser.plugins assembly differently from the rest of the project so that other plugins can target different versions of Eraser with the same assembly. Change the Eraser.Plugins assembly version only if there is an API change.
  • Plugin loading behaviour:
    • Core plugins will be loaded before the rest of the plugins, but they will be loaded only by assembly name and not by path
    • Non-core plugin loading is handled by the Manager Library and not the Plugin code
    • The PluginInstance? class is now the PluginInfo? class
    • There is no longer a need to indicate the default file and unused space erasure methods, PRNGs etc; they are now hardcoded to prevent plugins from changing defaults.
  • The separate command line for the Eraser shell extension has been removed.
    • The Erase on Restart menu item has been removed (since it is a scheduling option and should be set in the Task Properties Dialog)
  • Task Progress information is now pulled from the Eraser core instead of pushed via events.
  • New persistent store class to generalise the use of the old Settings class
  • IDragAndDropConfigurerFactory for transforming drag-and-drop operations to erasure targets. This removes the Eraser.exe assembly's dependency on Eraser.DefaultPlugins?.

Closes #363.

  • 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.Data;
26using System.Linq;
27using System.Drawing;
28using System.Text;
29using System.Windows.Forms;
30
31using System.IO;
32
33using Eraser.Manager;
34using Eraser.Util;
35using Eraser.Util.ExtensionMethods;
36using Eraser.Plugins;
37using Eraser.Plugins.ExtensionPoints;
38using Eraser.Plugins.Registrars;
39
40namespace Eraser
41{
42    public partial class TaskDataSelectionForm : Form
43    {
44        private class ErasureType
45        {
46            public ErasureType(IErasureTarget target)
47            {
48                Target = target;
49            }
50
51            public override string ToString()
52            {
53                return Target.Name;
54            }
55
56            public IErasureTarget Target;
57
58            /// <summary>
59            /// The configurer returned by the active erasure target type.
60            /// </summary>
61            public IErasureTargetConfigurer Configurer;
62        }
63
64        public TaskDataSelectionForm()
65        {
66            //Create the UI
67            InitializeComponent();
68            Theming.ApplyTheme(this);
69
70            //Insert the types of erasure targets
71            foreach (IErasureTarget target in Host.Instance.ErasureTargetFactories)
72                typeCmb.Items.Add(new ErasureType(target));
73            if (typeCmb.Items.Count != 0) 
74                typeCmb.SelectedIndex = 0;
75
76            //And the methods list
77            methodCmb.Items.Add(ErasureMethodRegistrar.Default);
78            foreach (IErasureMethod method in Host.Instance.ErasureMethods)
79                methodCmb.Items.Add(method);
80            if (methodCmb.Items.Count != 0)
81                methodCmb.SelectedIndex = 0;
82        }
83
84        /// <summary>
85        /// Retrieves the settings on the property page as the Eraser Manager API equivalent.
86        /// </summary>
87        /// <returns>An Eraser.Manager.Task.Data or Eraser.Manager.Task.UnusedSpace object
88        /// or any of its inherited classes, depending on the task selected</returns>
89        public IErasureTarget Target
90        {
91            get
92            {
93                ErasureType type = (ErasureType)typeCmb.SelectedItem;
94                IErasureTarget result = type.Target;
95                if (type.Configurer != null)
96                    type.Configurer.SaveTo(result);
97                result.Method = (IErasureMethod)methodCmb.SelectedItem;
98
99                return result;
100            }
101            set
102            {
103                //Set the erasure method.
104                foreach (object item in methodCmb.Items)
105                    if (((IErasureMethod)item).Guid == value.Method.Guid)
106                        methodCmb.SelectedItem = item;
107
108                //Set the active erasure type.
109                foreach (ErasureType type in typeCmb.Items)
110                {
111                    if (type.Target.GetType() == value.GetType())
112                    {
113                        type.Target = value;
114                        type.Configurer = value.Configurer;
115                        if (type.Configurer != null)
116                            type.Configurer.LoadFrom(value);
117
118                        typeCmb.SelectedItem = type;
119                        typeCmb_SelectedIndexChanged(typeCmb, EventArgs.Empty);
120                        break;
121                    }
122                }
123            }
124        }
125
126        private void typeCmb_SelectedIndexChanged(object sender, EventArgs e)
127        {
128            //Remove the old controls
129            while (typeSettingsPnl.Controls.Count > 0)
130                typeSettingsPnl.Controls.RemoveAt(0);
131
132            //Then add in the new configurer
133            ErasureType type = (ErasureType)typeCmb.SelectedItem;
134            if (type.Configurer == null)
135                type.Configurer = type.Target.Configurer;
136
137            if (type.Configurer == null || !(type.Configurer is Control))
138            {
139                Label label = new Label();
140                label.Text = S._("(This erasure type does not have any settings to define.)");
141                label.Dock = DockStyle.Fill;
142                typeSettingsPnl.Controls.Add(label);
143                return;
144            }
145
146            Control control = type.Configurer as Control;
147            typeSettingsPnl.Controls.Add(control);
148            control.Dock = DockStyle.Fill;
149        }
150
151        private void ok_Click(object sender, EventArgs e)
152        {
153            ErasureType type = (ErasureType)typeCmb.SelectedItem;
154            if (methodCmb.SelectedItem != ErasureMethodRegistrar.Default &&
155                !type.Target.SupportsMethod((IErasureMethod)methodCmb.SelectedItem))
156            {
157                errorProvider.SetError(methodCmb, S._("The erasure method selected does " +
158                    "not support unused disk space erasures."));
159            }
160            else if (type.Configurer == null || type.Configurer.SaveTo(type.Target))
161            {
162                errorProvider.Clear();
163                DialogResult = DialogResult.OK;
164                Close();
165            }
166        }
167    }
168}
Note: See TracBrowser for help on using the repository browser.