- Timestamp:
- 5/4/2010 3:04:18 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/FolderErasureTarget.cs
r2044 r2045 182 182 public override void Execute() 183 183 { 184 base.Execute(); 185 186 //If the user requested a folder removal, do it. 187 if (Directory.Exists(Path)) 188 { 189 ProgressManager step = new ProgressManager(); 190 Progress.Steps.Add(new SteppedProgressManagerStep(step, 191 0.0f, S._("Removing folders..."))); 192 193 //Remove all subfolders which are empty. 194 FileSystem fsManager = ManagerLibrary.Instance.FileSystemRegistrar[ 195 VolumeInfo.FromMountPoint(Path)]; 196 Action<DirectoryInfo> eraseEmptySubFolders = null; 197 eraseEmptySubFolders = delegate(DirectoryInfo info) 198 { 199 foreach (DirectoryInfo subDir in info.GetDirectories()) 184 Progress = new SteppedProgressManager(); 185 try 186 { 187 base.Execute(); 188 189 //If the user requested a folder removal, do it. 190 if (Directory.Exists(Path)) 191 { 192 ProgressManager step = new ProgressManager(); 193 Progress.Steps.Add(new SteppedProgressManagerStep(step, 194 0.0f, S._("Removing folders..."))); 195 196 //Remove all subfolders which are empty. 197 FileSystem fsManager = ManagerLibrary.Instance.FileSystemRegistrar[ 198 VolumeInfo.FromMountPoint(Path)]; 199 Action<DirectoryInfo> eraseEmptySubFolders = null; 200 eraseEmptySubFolders = delegate(DirectoryInfo info) 201 { 202 foreach (DirectoryInfo subDir in info.GetDirectories()) 203 eraseEmptySubFolders(subDir); 204 OnProgressChanged(this, new ProgressChangedEventArgs(step, 205 new TaskProgressChangedEventArgs(info.FullName, 0, 0))); 206 207 FileSystemInfo[] files = info.GetFileSystemInfos(); 208 if (files.Length == 0) 209 fsManager.DeleteFolder(info); 210 }; 211 212 DirectoryInfo directory = new DirectoryInfo(Path); 213 foreach (DirectoryInfo subDir in directory.GetDirectories()) 200 214 eraseEmptySubFolders(subDir); 201 OnProgressChanged(this, new ProgressChangedEventArgs(step, 202 new TaskProgressChangedEventArgs(info.FullName, 0, 0))); 203 204 FileSystemInfo[] files = info.GetFileSystemInfos(); 205 if (files.Length == 0) 206 fsManager.DeleteFolder(info); 207 }; 208 209 DirectoryInfo directory = new DirectoryInfo(Path); 210 foreach (DirectoryInfo subDir in directory.GetDirectories()) 211 eraseEmptySubFolders(subDir); 212 213 if (DeleteIfEmpty) 214 { 215 //See if this is the root of a volume. 216 bool isVolumeRoot = directory.Parent == null; 217 foreach (VolumeInfo volume in VolumeInfo.Volumes) 218 foreach (string mountPoint in volume.MountPoints) 219 if (directory.FullName == mountPoint) 220 isVolumeRoot = true; 221 222 //If the folder is a mount point, then don't delete it. If it isn't, 223 //search for files under the folder to see if it is empty. 224 if (!isVolumeRoot && directory.Exists && 225 directory.GetFiles("*", SearchOption.AllDirectories).Length == 0) 215 216 if (DeleteIfEmpty) 226 217 { 227 fsManager.DeleteFolder(directory); 218 //See if this is the root of a volume. 219 bool isVolumeRoot = directory.Parent == null; 220 foreach (VolumeInfo volume in VolumeInfo.Volumes) 221 foreach (string mountPoint in volume.MountPoints) 222 if (directory.FullName == mountPoint) 223 isVolumeRoot = true; 224 225 //If the folder is a mount point, then don't delete it. If it isn't, 226 //search for files under the folder to see if it is empty. 227 if (!isVolumeRoot && directory.Exists && 228 directory.GetFiles("*", SearchOption.AllDirectories).Length == 0) 229 { 230 fsManager.DeleteFolder(directory); 231 } 228 232 } 229 233 } 234 } 235 finally 236 { 237 Progress = null; 230 238 } 231 239 }
Note: See TracChangeset
for help on using the changeset viewer.
