Changeset 2106 for trunk/eraser
- Timestamp:
- 5/15/2010 4:00:11 AM (3 years ago)
- Location:
- trunk/eraser/Eraser.DefaultPlugins
- Files:
-
- 10 edited
-
ErasureTargets/FileErasureTarget.cs (modified) (3 diffs)
-
ErasureTargets/FileSystemObjectErasureTarget.cs (modified) (10 diffs)
-
ErasureTargets/FolderErasureTarget.cs (modified) (4 diffs)
-
ErasureTargets/RecycleBinErasureTarget.cs (modified) (5 diffs)
-
ErasureTargets/SecureMoveErasureTarget.cs (modified) (3 diffs)
-
Strings.en.resx (modified) (1 diff)
-
Strings.it.resx (modified) (1 diff)
-
Strings.nl.resx (modified) (1 diff)
-
Strings.pl.resx (modified) (1 diff)
-
Strings.resx (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/FileErasureTarget.cs
r2085 r2106 70 70 } 71 71 72 protected override List<StreamInfo> GetPaths( out long totalSize)72 protected override List<StreamInfo> GetPaths() 73 73 { 74 totalSize = 0;75 74 List<StreamInfo> result = new List<StreamInfo>(); 76 75 FileInfo fileInfo = new FileInfo(Path); … … 78 77 if (fileInfo.Exists) 79 78 { 80 result.AddRange(GetPathADSes(fileInfo , out totalSize));81 totalSize += fileInfo.Length;79 result.AddRange(GetPathADSes(fileInfo)); 80 result.Add(new StreamInfo(Path)); 82 81 } 83 82 84 result.Add(new StreamInfo(Path));85 83 return result; 86 84 } … … 89 87 { 90 88 Progress = new SteppedProgressManager(); 89 91 90 try 92 91 { -
trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/FileSystemObjectErasureTarget.cs
r2105 r2106 84 84 /// Retrieves the list of files/folders to erase as a list. 85 85 /// </summary> 86 /// <param name="totalSize">Returns the total size in bytes of the87 /// items.</param>88 86 /// <returns>A list containing the paths to all the files to be erased.</returns> 89 protected abstract List<StreamInfo> GetPaths( out long totalSize);87 protected abstract List<StreamInfo> GetPaths(); 90 88 91 89 /// <summary> … … 95 93 /// <returns>A list of files found in the directory matching the IncludeMask 96 94 /// property.</returns> 97 protected FileInfo[] GetFiles(DirectoryInfo info)95 protected static FileInfo[] GetFiles(DirectoryInfo info) 98 96 { 99 97 List<FileInfo> result = new List<FileInfo>(); … … 116 114 117 115 /// <summary> 118 /// Adds ADSes of the given file to the list. 116 /// Adds ADSes of the given file to the list, forcing the open handles to the 117 /// files closed if necessary. 119 118 /// </summary> 120 119 /// <param name="file">The file to look for ADSes</param> 121 protected StreamInfo[] GetPathADSes(FileInfo file, out long totalSize) 122 { 123 totalSize = 0; 124 120 protected static StreamInfo[] GetPathADSes(FileInfo file) 121 { 125 122 try 126 123 { … … 133 130 { 134 131 StreamInfo info = new StreamInfo(file.FullName + ':' + adses[i]); 135 totalSize += info.Length;136 132 result[i] = info; 137 133 } … … 164 160 165 161 if (processStr.Length == 0) 166 return GetPathADSes(file , out totalSize);162 return GetPathADSes(file); 167 163 else 168 164 throw; … … 207 203 } 208 204 205 /// <summary> 206 /// Erases the streams returned by the <see cref="GetPaths"/> function. 207 /// </summary> 209 208 /// <remarks>The <see cref="Progress"/> property must be defined prior 210 209 /// to the execution of this function.</remarks> … … 212 211 { 213 212 //Retrieve the list of files to erase. 214 long dataTotal = 0;215 List<StreamInfo> paths = GetPaths(out dataTotal);213 List<StreamInfo> paths = GetPaths(); 214 long dataTotal = paths.Sum(x => x.Length); 216 215 217 216 //Get the erasure method if the user specified he wants the default. … … 223 222 throw new InvalidOperationException("The Progress property must not be null."); 224 223 Task.Progress.Steps.Add(new SteppedProgressManagerStep(Progress, 225 EraseWeight/ Task.Targets.Count));224 1.0f / Task.Targets.Count)); 226 225 227 226 //Iterate over every path, and erase the path. … … 232 231 paths[i].Length / (float)dataTotal, S._("Erasing files..."))); 233 232 EraseStream(paths[i], step); 234 } 235 } 236 237 /// <summary> 238 /// Erases the provided stream, and updates progress using tyhe provided 233 step.MarkComplete(); 234 } 235 } 236 237 /// <summary> 238 /// Erases the provided stream, and updates progress using the provided 239 239 /// progress manager. 240 240 /// </summary> … … 340 340 } 341 341 } 342 343 /// <summary>344 /// The weight attached with the erase process, so that tasks can depend on345 /// the erase task without it using up all the weights allocated.346 /// </summary>347 protected virtual float EraseWeight348 {349 get350 {351 return 1.0f;352 }353 }354 342 } 355 343 } -
trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/FolderErasureTarget.cs
r2085 r2106 87 87 } 88 88 89 protected override List<StreamInfo> GetPaths( out long totalSize)89 protected override List<StreamInfo> GetPaths() 90 90 { 91 91 //Get a list to hold all the resulting streams. … … 99 99 100 100 //Then exclude each file and finalize the list and total file size 101 totalSize = 0;102 101 Regex includePattern = string.IsNullOrEmpty(IncludeMask) ? null : 103 102 new Regex( … … 123 122 124 123 //Add the size of the file and its alternate data streams 125 totalSize += file.Length; 126 long adsesSize = 0; 127 result.AddRange(GetPathADSes(file, out adsesSize)); 128 totalSize += adsesSize; 124 result.AddRange(GetPathADSes(file)); 129 125 130 126 //And the file itself … … 158 154 { 159 155 Progress = new SteppedProgressManager(); 156 160 157 try 161 158 { 162 159 base.Execute(); 163 160 164 //If the user requested a folder removal, do it. 165 if (Directory.Exists(Path)) 161 //Remove the contents of the folder, deleting the folder if it is empty 162 //at the end of it. 163 EraseFolder(); 164 } 165 finally 166 { 167 Progress = null; 168 } 169 } 170 171 /// <summary> 172 /// Erases the folder after all files have been deleted. This folder does not 173 /// delete folders which have files within it. 174 /// </summary> 175 private void EraseFolder() 176 { 177 //Update the progress to show that folders are being removed. 178 ProgressManager step = new ProgressManager(); 179 Progress.Steps.Add(new SteppedProgressManagerStep(step, 180 0.0f, S._("Removing folders..."))); 181 182 //Remove all subfolders which are empty. 183 FileSystem fsManager = ManagerLibrary.Instance.FileSystemRegistrar[ 184 VolumeInfo.FromMountPoint(Path)]; 185 DirectoryInfo directory = new DirectoryInfo(Path); 186 foreach (DirectoryInfo subDir in directory.GetDirectories()) 187 EraseFolder(subDir, step); 188 189 if (DeleteIfEmpty) 190 { 191 //See if this is the root of a volume. 192 bool isVolumeRoot = directory.Parent == null; 193 foreach (VolumeInfo volume in VolumeInfo.Volumes) 194 foreach (string mountPoint in volume.MountPoints) 195 if (directory.FullName == mountPoint) 196 isVolumeRoot = true; 197 198 //If the folder is a mount point, then don't delete it. If it isn't, 199 //search for files under the folder to see if it is empty. 200 if (!isVolumeRoot && directory.Exists && 201 directory.GetFiles("*", SearchOption.AllDirectories).Length == 0) 166 202 { 167 ProgressManager step = new ProgressManager(); 168 Progress.Steps.Add(new SteppedProgressManagerStep(step, 169 0.0f, S._("Removing folders..."))); 170 171 //Remove all subfolders which are empty. 172 FileSystem fsManager = ManagerLibrary.Instance.FileSystemRegistrar[ 173 VolumeInfo.FromMountPoint(Path)]; 174 Action<DirectoryInfo> eraseEmptySubFolders = null; 175 eraseEmptySubFolders = delegate(DirectoryInfo info) 176 { 177 foreach (DirectoryInfo subDir in info.GetDirectories()) 178 eraseEmptySubFolders(subDir); 179 OnProgressChanged(this, new ProgressChangedEventArgs(step, 180 new TaskProgressChangedEventArgs(info.FullName, 0, 0))); 181 182 FileSystemInfo[] files = info.GetFileSystemInfos(); 183 if (files.Length == 0) 184 fsManager.DeleteFolder(info); 185 }; 186 187 DirectoryInfo directory = new DirectoryInfo(Path); 188 foreach (DirectoryInfo subDir in directory.GetDirectories()) 189 eraseEmptySubFolders(subDir); 190 191 if (DeleteIfEmpty) 192 { 193 //See if this is the root of a volume. 194 bool isVolumeRoot = directory.Parent == null; 195 foreach (VolumeInfo volume in VolumeInfo.Volumes) 196 foreach (string mountPoint in volume.MountPoints) 197 if (directory.FullName == mountPoint) 198 isVolumeRoot = true; 199 200 //If the folder is a mount point, then don't delete it. If it isn't, 201 //search for files under the folder to see if it is empty. 202 if (!isVolumeRoot && directory.Exists && 203 directory.GetFiles("*", SearchOption.AllDirectories).Length == 0) 204 { 205 fsManager.DeleteFolder(directory); 206 } 207 } 203 fsManager.DeleteFolder(directory); 208 204 } 209 205 } 210 finally 211 { 212 Progress = null; 206 } 207 208 private void EraseFolder(DirectoryInfo info, ProgressManager progress) 209 { 210 foreach (DirectoryInfo subDir in info.GetDirectories()) 211 EraseFolder(subDir, progress); 212 OnProgressChanged(this, new ProgressChangedEventArgs(progress, 213 new TaskProgressChangedEventArgs(info.FullName, 0, 0))); 214 215 FileSystemInfo[] files = info.GetFileSystemInfos(); 216 if (files.Length == 0) 217 { 218 ManagerLibrary.Instance.FileSystemRegistrar[ 219 VolumeInfo.FromMountPoint(Path)].DeleteFolder(info); 213 220 } 214 221 } -
trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/RecycleBinErasureTarget.cs
r2085 r2106 59 59 } 60 60 61 /// <summary> 62 /// Retrieves the text to display representing this task. 63 /// </summary> 64 public override string UIText 65 { 66 get 67 { 68 return S._("Recycle Bin"); 69 } 70 } 71 61 72 public override IErasureTargetConfigurer Configurer 62 73 { … … 64 75 } 65 76 66 protected override List<StreamInfo> GetPaths( out long totalSize)77 protected override List<StreamInfo> GetPaths() 67 78 { 68 totalSize = 0;69 79 List<StreamInfo> result = new List<StreamInfo>(); 70 80 string[] rootDirectory = new string[] { … … 92 102 93 103 //Add the ADSes 94 long adsSize = 0; 95 result.AddRange(GetPathADSes(file, out adsSize)); 96 totalSize += adsSize; 104 result.AddRange(GetPathADSes(file)); 97 105 98 106 //Then the file itself 99 totalSize += file.Length;100 107 result.Add(new StreamInfo(file.FullName)); 101 108 } … … 106 113 } 107 114 108 /// <summary>109 /// Retrieves the text to display representing this task.110 /// </summary>111 public override string UIText112 {113 get114 {115 return S._("Recycle Bin");116 }117 }118 119 115 public override void Execute() 120 116 { 121 117 Progress = new SteppedProgressManager(); 118 122 119 try 123 120 { 124 121 base.Execute(); 125 122 126 ProgressManager step = new ProgressManager(); 127 Progress.Steps.Add(new SteppedProgressManagerStep(step, 128 0.0f, S._("Emptying recycle bin..."))); 129 OnProgressChanged(this, new ProgressChangedEventArgs(step, 130 new TaskProgressChangedEventArgs(string.Empty, 0, 0))); 131 132 RecycleBin.Empty(EmptyRecycleBinOptions.NoConfirmation | 133 EmptyRecycleBinOptions.NoProgressUI | EmptyRecycleBinOptions.NoSound); 123 //Empty the contents of the Recycle Bin 124 EmptyRecycleBin(); 134 125 } 135 126 finally … … 138 129 } 139 130 } 131 132 private void EmptyRecycleBin() 133 { 134 ProgressManager progress = new ProgressManager(); 135 Progress.Steps.Add(new SteppedProgressManagerStep(progress, 136 0.0f, S._("Emptying recycle bin..."))); 137 OnProgressChanged(this, new ProgressChangedEventArgs(progress, 138 new TaskProgressChangedEventArgs(string.Empty, 0, 0))); 139 140 RecycleBin.Empty(EmptyRecycleBinOptions.NoConfirmation | 141 EmptyRecycleBinOptions.NoProgressUI | EmptyRecycleBinOptions.NoSound); 142 } 140 143 } 141 144 } -
trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/SecureMoveErasureTarget.cs
r2087 r2106 91 91 } 92 92 93 protected override List<StreamInfo> GetPaths(out long totalSize) 94 { 95 totalSize = 0; 93 protected override List<StreamInfo> GetPaths() 94 { 96 95 List<StreamInfo> result = new List<StreamInfo>(); 97 96 if (File.Exists(Path)) … … 103 102 104 103 //Add the alternate data streams 105 long adsesSize = 0; 106 result.AddRange(GetPathADSes(info, out adsesSize)); 107 totalSize += adsesSize; 104 result.AddRange(GetPathADSes(info)); 108 105 109 106 //And the file itself 110 totalSize += info.Length;111 107 result.Add(new StreamInfo(info.FullName)); 112 108 } … … 117 113 118 114 return result; 119 }120 121 protected override float EraseWeight122 {123 get124 {125 return 0.5f;126 }127 115 } 128 116 -
trunk/eraser/Eraser.DefaultPlugins/Strings.en.resx
r2094 r2106 202 202 <value>Could not erase files and subfolders in {0} because {1}</value> 203 203 </data> 204 <data name="Erasing files..." xml:space="preserve"> 205 <value>Erasing files...</value> 206 </data> 204 207 <data name="The file {0} was not erased as the file does not exist." xml:space="preserve"> 205 208 <value>The file {0} was not erased as the file does not exist.</value> 206 209 </data> 207 <data name="Erasing files..." xml:space="preserve">208 <value>Erasing files...</value>209 </data>210 210 <data name="The file {0} could not be erased because the file was either compressed, encrypted or a sparse file." xml:space="preserve"> 211 211 <value>The file {0} could not be erased because the file was either compressed, encrypted or a sparse file.</value> -
trunk/eraser/Eraser.DefaultPlugins/Strings.it.resx
r2097 r2106 202 202 <value>Impossibile pulire files e cartelle in {0} perchè {1}</value> 203 203 </data> 204 <data name="The file {0} was not erased as the file does not exist." xml:space="preserve">205 <value>(Untranslated)</value>206 </data>207 204 <data name="Erasing files..." xml:space="preserve"> 208 205 <value>Pulizia file...</value> 209 206 </data> 207 <data name="The file {0} was not erased as the file does not exist." xml:space="preserve"> 208 <value>(Untranslated)</value> 209 </data> 210 210 <data name="The file {0} could not be erased because the file was either compressed, encrypted or a sparse file." xml:space="preserve"> 211 211 <value>(Untranslated)</value> -
trunk/eraser/Eraser.DefaultPlugins/Strings.nl.resx
r2094 r2106 202 202 <value>(Untranslated)</value> 203 203 </data> 204 <data name="Erasing files..." xml:space="preserve"> 205 <value>(Untranslated)</value> 206 </data> 204 207 <data name="The file {0} was not erased as the file does not exist." xml:space="preserve"> 205 208 <value>(Untranslated)</value> 206 209 </data> 207 <data name="Erasing files..." xml:space="preserve">208 <value>(Untranslated)</value>209 </data>210 210 <data name="The file {0} could not be erased because the file was either compressed, encrypted or a sparse file." xml:space="preserve"> 211 211 <value>(Untranslated)</value> -
trunk/eraser/Eraser.DefaultPlugins/Strings.pl.resx
r2094 r2106 202 202 <value>(Untranslated)</value> 203 203 </data> 204 <data name="Erasing files..." xml:space="preserve"> 205 <value>(Untranslated)</value> 206 </data> 204 207 <data name="The file {0} was not erased as the file does not exist." xml:space="preserve"> 205 <value>(Untranslated)</value>206 </data>207 <data name="Erasing files..." xml:space="preserve">208 208 <value>(Untranslated)</value> 209 209 </data> -
trunk/eraser/Eraser.DefaultPlugins/Strings.resx
r2094 r2106 202 202 <value>Could not erase files and subfolders in {0} because {1}</value> 203 203 </data> 204 <data name="Erasing files..." xml:space="preserve"> 205 <value>Erasing files...</value> 206 </data> 204 207 <data name="The file {0} was not erased as the file does not exist." xml:space="preserve"> 205 208 <value>The file {0} was not erased as the file does not exist.</value> 206 209 </data> 207 <data name="Erasing files..." xml:space="preserve">208 <value>Erasing files...</value>209 </data>210 210 <data name="The file {0} could not be erased because the file was either compressed, encrypted or a sparse file." xml:space="preserve"> 211 211 <value>The file {0} could not be erased because the file was either compressed, encrypted or a sparse file.</value>
Note: See TracChangeset
for help on using the changeset viewer.
