| 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 | |
|---|
| 22 | using System; |
|---|
| 23 | using System.Collections.Generic; |
|---|
| 24 | using System.Linq; |
|---|
| 25 | using System.Text; |
|---|
| 26 | |
|---|
| 27 | using System.Runtime.Serialization; |
|---|
| 28 | using System.Runtime.InteropServices; |
|---|
| 29 | using System.IO; |
|---|
| 30 | |
|---|
| 31 | using Eraser.Util; |
|---|
| 32 | using Eraser.Plugins; |
|---|
| 33 | using Eraser.Plugins.ExtensionPoints; |
|---|
| 34 | |
|---|
| 35 | namespace 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 | } |
|---|