Changeset 2106 for trunk/eraser


Ignore:
Timestamp:
5/15/2010 4:00:11 AM (5 years ago)
Author:
lowjoel
Message:

New API

  • the GetPaths? function no longer returns the total size of the files as an out parameter, that can be calculated from the list itself (use the Length property)
  • GetFiles? and GetPathADSes are now statis functions
Location:
trunk/eraser/Eraser.DefaultPlugins
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/FileErasureTarget.cs

    r2085 r2106  
    7070        } 
    7171 
    72         protected override List<StreamInfo> GetPaths(out long totalSize) 
     72        protected override List<StreamInfo> GetPaths() 
    7373        { 
    74             totalSize = 0; 
    7574            List<StreamInfo> result = new List<StreamInfo>(); 
    7675            FileInfo fileInfo = new FileInfo(Path); 
     
    7877            if (fileInfo.Exists) 
    7978            { 
    80                 result.AddRange(GetPathADSes(fileInfo, out totalSize)); 
    81                 totalSize += fileInfo.Length; 
     79                result.AddRange(GetPathADSes(fileInfo)); 
     80                result.Add(new StreamInfo(Path)); 
    8281            } 
    8382 
    84             result.Add(new StreamInfo(Path)); 
    8583            return result; 
    8684        } 
     
    8987        { 
    9088            Progress = new SteppedProgressManager(); 
     89 
    9190            try 
    9291            { 
  • trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/FileSystemObjectErasureTarget.cs

    r2105 r2106  
    8484        /// Retrieves the list of files/folders to erase as a list. 
    8585        /// </summary> 
    86         /// <param name="totalSize">Returns the total size in bytes of the 
    87         /// items.</param> 
    8886        /// <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(); 
    9088 
    9189        /// <summary> 
     
    9593        /// <returns>A list of files found in the directory matching the IncludeMask 
    9694        /// property.</returns> 
    97         protected FileInfo[] GetFiles(DirectoryInfo info) 
     95        protected static FileInfo[] GetFiles(DirectoryInfo info) 
    9896        { 
    9997            List<FileInfo> result = new List<FileInfo>(); 
     
    116114 
    117115        /// <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. 
    119118        /// </summary> 
    120119        /// <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        { 
    125122            try 
    126123            { 
     
    133130                { 
    134131                    StreamInfo info = new StreamInfo(file.FullName + ':' + adses[i]); 
    135                     totalSize += info.Length; 
    136132                    result[i] = info; 
    137133                } 
     
    164160 
    165161                if (processStr.Length == 0) 
    166                     return GetPathADSes(file, out totalSize); 
     162                    return GetPathADSes(file); 
    167163                else 
    168164                    throw; 
     
    207203        } 
    208204 
     205        /// <summary> 
     206        /// Erases the streams returned by the <see cref="GetPaths"/> function. 
     207        /// </summary> 
    209208        /// <remarks>The <see cref="Progress"/> property must be defined prior 
    210209        /// to the execution of this function.</remarks> 
     
    212211        { 
    213212            //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); 
    216215 
    217216            //Get the erasure method if the user specified he wants the default. 
     
    223222                throw new InvalidOperationException("The Progress property must not be null."); 
    224223            Task.Progress.Steps.Add(new SteppedProgressManagerStep(Progress, 
    225                 EraseWeight / Task.Targets.Count)); 
     224                1.0f / Task.Targets.Count)); 
    226225 
    227226            //Iterate over every path, and erase the path. 
     
    232231                    paths[i].Length / (float)dataTotal, S._("Erasing files..."))); 
    233232                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 
    239239        /// progress manager. 
    240240        /// </summary> 
     
    340340            } 
    341341        } 
    342  
    343         /// <summary> 
    344         /// The weight attached with the erase process, so that tasks can depend on 
    345         /// the erase task without it using up all the weights allocated. 
    346         /// </summary> 
    347         protected virtual float EraseWeight 
    348         { 
    349             get 
    350             { 
    351                 return 1.0f; 
    352             } 
    353         } 
    354342    } 
    355343} 
  • trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/FolderErasureTarget.cs

    r2085 r2106  
    8787        } 
    8888 
    89         protected override List<StreamInfo> GetPaths(out long totalSize) 
     89        protected override List<StreamInfo> GetPaths() 
    9090        { 
    9191            //Get a list to hold all the resulting streams. 
     
    9999 
    100100            //Then exclude each file and finalize the list and total file size 
    101             totalSize = 0; 
    102101            Regex includePattern = string.IsNullOrEmpty(IncludeMask) ? null : 
    103102                new Regex( 
     
    123122 
    124123                //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)); 
    129125 
    130126                //And the file itself 
     
    158154        { 
    159155            Progress = new SteppedProgressManager(); 
     156 
    160157            try 
    161158            { 
    162159                base.Execute(); 
    163160 
    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) 
    166202                { 
    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); 
    208204                } 
    209205            } 
    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); 
    213220            } 
    214221        } 
  • trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/RecycleBinErasureTarget.cs

    r2085 r2106  
    5959        } 
    6060 
     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 
    6172        public override IErasureTargetConfigurer Configurer 
    6273        { 
     
    6475        } 
    6576 
    66         protected override List<StreamInfo> GetPaths(out long totalSize) 
     77        protected override List<StreamInfo> GetPaths() 
    6778        { 
    68             totalSize = 0; 
    6979            List<StreamInfo> result = new List<StreamInfo>(); 
    7080            string[] rootDirectory = new string[] { 
     
    92102 
    93103                        //Add the ADSes 
    94                         long adsSize = 0; 
    95                         result.AddRange(GetPathADSes(file, out adsSize)); 
    96                         totalSize += adsSize; 
     104                        result.AddRange(GetPathADSes(file)); 
    97105 
    98106                        //Then the file itself 
    99                         totalSize += file.Length; 
    100107                        result.Add(new StreamInfo(file.FullName)); 
    101108                    } 
     
    106113        } 
    107114 
    108         /// <summary> 
    109         /// Retrieves the text to display representing this task. 
    110         /// </summary> 
    111         public override string UIText 
    112         { 
    113             get 
    114             { 
    115                 return S._("Recycle Bin"); 
    116             } 
    117         } 
    118  
    119115        public override void Execute() 
    120116        { 
    121117            Progress = new SteppedProgressManager(); 
     118 
    122119            try 
    123120            { 
    124121                base.Execute(); 
    125122 
    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(); 
    134125            } 
    135126            finally 
     
    138129            } 
    139130        } 
     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        } 
    140143    } 
    141144} 
  • trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/SecureMoveErasureTarget.cs

    r2087 r2106  
    9191        } 
    9292 
    93         protected override List<StreamInfo> GetPaths(out long totalSize) 
    94         { 
    95             totalSize = 0; 
     93        protected override List<StreamInfo> GetPaths() 
     94        { 
    9695            List<StreamInfo> result = new List<StreamInfo>(); 
    9796            if (File.Exists(Path)) 
     
    103102 
    104103                //Add the alternate data streams 
    105                 long adsesSize = 0; 
    106                 result.AddRange(GetPathADSes(info, out adsesSize)); 
    107                 totalSize += adsesSize; 
     104                result.AddRange(GetPathADSes(info)); 
    108105 
    109106                //And the file itself 
    110                 totalSize += info.Length; 
    111107                result.Add(new StreamInfo(info.FullName)); 
    112108            } 
     
    117113 
    118114            return result; 
    119         } 
    120  
    121         protected override float EraseWeight 
    122         { 
    123             get 
    124             { 
    125                 return 0.5f; 
    126             } 
    127115        } 
    128116 
  • trunk/eraser/Eraser.DefaultPlugins/Strings.en.resx

    r2094 r2106  
    202202    <value>Could not erase files and subfolders in {0} because {1}</value> 
    203203  </data> 
     204  <data name="Erasing files..." xml:space="preserve"> 
     205    <value>Erasing files...</value> 
     206  </data> 
    204207  <data name="The file {0} was not erased as the file does not exist." xml:space="preserve"> 
    205208    <value>The file {0} was not erased as the file does not exist.</value> 
    206209  </data> 
    207   <data name="Erasing files..." xml:space="preserve"> 
    208     <value>Erasing files...</value> 
    209   </data> 
    210210  <data name="The file {0} could not be erased because the file was either compressed, encrypted or a sparse file." xml:space="preserve"> 
    211211    <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  
    202202    <value>Impossibile pulire files e cartelle in {0} perchè {1}</value> 
    203203  </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> 
    207204  <data name="Erasing files..." xml:space="preserve"> 
    208205    <value>Pulizia file...</value> 
    209206  </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> 
    210210  <data name="The file {0} could not be erased because the file was either compressed, encrypted or a sparse file." xml:space="preserve"> 
    211211    <value>(Untranslated)</value> 
  • trunk/eraser/Eraser.DefaultPlugins/Strings.nl.resx

    r2094 r2106  
    202202    <value>(Untranslated)</value> 
    203203  </data> 
     204  <data name="Erasing files..." xml:space="preserve"> 
     205    <value>(Untranslated)</value> 
     206  </data> 
    204207  <data name="The file {0} was not erased as the file does not exist." xml:space="preserve"> 
    205208    <value>(Untranslated)</value> 
    206209  </data> 
    207   <data name="Erasing files..." xml:space="preserve"> 
    208     <value>(Untranslated)</value> 
    209   </data> 
    210210  <data name="The file {0} could not be erased because the file was either compressed, encrypted or a sparse file." xml:space="preserve"> 
    211211    <value>(Untranslated)</value> 
  • trunk/eraser/Eraser.DefaultPlugins/Strings.pl.resx

    r2094 r2106  
    202202    <value>(Untranslated)</value> 
    203203  </data> 
     204  <data name="Erasing files..." xml:space="preserve"> 
     205    <value>(Untranslated)</value> 
     206  </data> 
    204207  <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"> 
    208208    <value>(Untranslated)</value> 
    209209  </data> 
  • trunk/eraser/Eraser.DefaultPlugins/Strings.resx

    r2094 r2106  
    202202    <value>Could not erase files and subfolders in {0} because {1}</value> 
    203203  </data> 
     204  <data name="Erasing files..." xml:space="preserve"> 
     205    <value>Erasing files...</value> 
     206  </data> 
    204207  <data name="The file {0} was not erased as the file does not exist." xml:space="preserve"> 
    205208    <value>The file {0} was not erased as the file does not exist.</value> 
    206209  </data> 
    207   <data name="Erasing files..." xml:space="preserve"> 
    208     <value>Erasing files...</value> 
    209   </data> 
    210210  <data name="The file {0} could not be erased because the file was either compressed, encrypted or a sparse file." xml:space="preserve"> 
    211211    <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.