source: branches/eraser6/pluginsRewrite/Eraser.DefaultPlugins/ErasureTargets/RecycleBinErasureTarget.cs @ 2486

Revision 2486, 3.2 KB checked in by lowjoel, 2 years ago (diff)

Report progress updates by pushing information to the SteppedProgressManager? instance associated with each erasure target. Furthermore, do not manipulate the state of the Task object, instead, let the Task object manage its own Progress state.

Because of this, a new property Tag is created in ProgressManagerBase?, to hold state information.

  • 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.Linq;
25using System.Text;
26
27using System.Runtime.Serialization;
28using System.Runtime.InteropServices;
29using System.IO;
30
31using Eraser.Util;
32using Eraser.Plugins;
33using Eraser.Plugins.ExtensionPoints;
34
35namespace Eraser.DefaultPlugins
36{
37    [Serializable]
38    [Guid("A1FA7354-0258-4903-88E9-0D31FC5F8D51")]
39    class RecycleBinErasureTarget : FileSystemObjectErasureTarget
40    {
41        #region Serialization code
42        protected RecycleBinErasureTarget(SerializationInfo info, StreamingContext context)
43            : base(info, context)
44        {
45        }
46        #endregion
47
48        public RecycleBinErasureTarget()
49        {
50        }
51
52        public override Guid Guid
53        {
54            get { return GetType().GUID; }
55        }
56
57        public override string Name
58        {
59            get { return S._("Recycle Bin"); }
60        }
61
62        /// <summary>
63        /// Retrieves the text to display representing this task.
64        /// </summary>
65        public override string ToString()
66        {
67            return S._("Recycle Bin");
68        }
69
70        public override IErasureTargetConfigurer Configurer
71        {
72            get { return new RecycleBinErasureTargetConfigurer(); }
73        }
74
75        protected override List<StreamInfo> GetPaths()
76        {
77            List<StreamInfo> result = new List<StreamInfo>();
78            string[] rootDirectory = new string[] {
79                    "$RECYCLE.BIN",
80                    "RECYCLER"
81                };
82            string userSid = System.Security.Principal.WindowsIdentity.GetCurrent().
83                User.ToString();
84
85            foreach (DriveInfo drive in DriveInfo.GetDrives())
86            {
87                foreach (string rootDir in rootDirectory)
88                {
89                    DirectoryInfo dir = new DirectoryInfo(
90                        System.IO.Path.Combine(
91                            System.IO.Path.Combine(drive.Name, rootDir),
92                            userSid));
93                    if (!dir.Exists)
94                        continue;
95
96                    foreach (FileInfo file in GetFiles(dir))
97                    {
98                        //Add the ADSes
99                        result.AddRange(GetPathADSes(file));
100
101                        //Then the file itself
102                        result.Add(new StreamInfo(file.FullName));
103                    }
104                }
105            }
106
107            return result;
108        }
109
110        public override void Execute()
111        {
112            Progress = new SteppedProgressManager();
113
114            try
115            {
116                base.Execute();
117
118                //Empty the contents of the Recycle Bin
119                EmptyRecycleBin();
120            }
121            finally
122            {
123                Progress = null;
124            }
125        }
126
127        private void EmptyRecycleBin()
128        {
129            ProgressManager progress = new ProgressManager();
130            Progress.Steps.Add(new SteppedProgressManagerStep(progress,
131                0.0f, S._("Emptying recycle bin...")));
132
133            RecycleBin.Empty(EmptyRecycleBinOptions.NoConfirmation |
134                EmptyRecycleBinOptions.NoProgressUI | EmptyRecycleBinOptions.NoSound);
135        }
136    }
137}
Note: See TracBrowser for help on using the repository browser.