Changeset 2085


Ignore:
Timestamp:
5/9/2010 11:00:15 AM (4 years ago)
Author:
lowjoel
Message:
Location:
trunk/eraser
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/eraser/Eraser.DefaultPlugins/ErasureMethods/FirstLast16KB.cs

    r1802 r2085  
    7676        } 
    7777 
    78         public override long CalculateEraseDataSize(ICollection<string> paths, long targetSize) 
     78        public override long CalculateEraseDataSize(ICollection<StreamInfo> paths, long targetSize) 
    7979        { 
    8080            //If we have no default or we are the default then throw an exception 
  • trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/FileErasureTarget.cs

    r2074 r2085  
    7070        } 
    7171 
    72         protected override List<string> GetPaths(out long totalSize) 
     72        protected override List<StreamInfo> GetPaths(out long totalSize) 
    7373        { 
    7474            totalSize = 0; 
    75             List<string> result = new List<string>(); 
     75            List<StreamInfo> result = new List<StreamInfo>(); 
    7676            FileInfo fileInfo = new FileInfo(Path); 
    7777 
    7878            if (fileInfo.Exists) 
    7979            { 
    80                 GetPathADSes(result, out totalSize, Path); 
     80                result.AddRange(GetPathADSes(fileInfo, out totalSize)); 
    8181                totalSize += fileInfo.Length; 
    8282            } 
    8383 
    84             result.Add(Path); 
     84            result.Add(new StreamInfo(Path)); 
    8585            return result; 
    8686        } 
  • trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/FileSystemObjectErasureTarget.cs

    r2084 r2085  
    6565        } 
    6666 
     67        /// <summary> 
     68        /// The Progress of this target's erasure. This property must be set 
     69        /// before <see cref="FileSystemObjectErasureTarget.Execute"/> is called. 
     70        /// </summary> 
    6771        protected new SteppedProgressManager Progress 
    6872        { 
     
    8387        /// items.</param> 
    8488        /// <returns>A list containing the paths to all the files to be erased.</returns> 
    85         protected abstract List<string> GetPaths(out long totalSize); 
     89        protected abstract List<StreamInfo> GetPaths(out long totalSize); 
     90 
     91        /// <summary> 
     92        /// Gets all files in the provided directory. 
     93        /// </summary> 
     94        /// <param name="info">The directory to look files in.</param> 
     95        /// <returns>A list of files found in the directory matching the IncludeMask 
     96        /// property.</returns> 
     97        protected FileInfo[] GetFiles(DirectoryInfo info) 
     98        { 
     99            List<FileInfo> result = new List<FileInfo>(); 
     100            if (info.Exists) 
     101            { 
     102                try 
     103                { 
     104                    foreach (DirectoryInfo dir in info.GetDirectories()) 
     105                        result.AddRange(GetFiles(dir)); 
     106                } 
     107                catch (UnauthorizedAccessException e) 
     108                { 
     109                    Logger.Log(S._("Could not erase files and subfolders in {0} because {1}", 
     110                        info.FullName, e.Message), LogLevel.Error); 
     111                } 
     112            } 
     113 
     114            return result.ToArray(); 
     115        } 
    86116 
    87117        /// <summary> 
    88118        /// Adds ADSes of the given file to the list. 
    89119        /// </summary> 
    90         /// <param name="list">The list to add the ADS paths to.</param> 
    91120        /// <param name="file">The file to look for ADSes</param> 
    92         protected void GetPathADSes(ICollection<string> list, out long totalSize, string file) 
     121        protected StreamInfo[] GetPathADSes(FileInfo file, out long totalSize) 
    93122        { 
    94123            totalSize = 0; 
     
    97126            { 
    98127                //Get the ADS names 
    99                 IList<string> adses = new FileInfo(file).GetADSes(); 
     128                IList<string> adses = file.GetADSes(); 
     129                StreamInfo[] result = new StreamInfo[adses.Count]; 
    100130 
    101131                //Then prepend the path. 
    102                 foreach (string adsName in adses) 
    103                 { 
    104                     string adsPath = file + ':' + adsName; 
    105                     list.Add(adsPath); 
    106                     StreamInfo info = new StreamInfo(adsPath); 
     132                for (int i = 0; i < adses.Count; ++i) 
     133                { 
     134                    StreamInfo info = new StreamInfo(file.FullName + ':' + adses[i]); 
    107135                    totalSize += info.Length; 
     136                    result[i] = info; 
    108137                } 
    109138            } 
     
    118147 
    119148                StringBuilder processStr = new StringBuilder(); 
    120                 foreach (OpenHandle handle in OpenHandle.Close(file)) 
     149                foreach (OpenHandle handle in OpenHandle.Close(file.FullName)) 
    121150                { 
    122151                    try 
     
    135164 
    136165                if (processStr.Length == 0) 
    137                 { 
    138                     GetPathADSes(list, out totalSize, file); 
    139                     return; 
    140                 } 
     166                    return GetPathADSes(file, out totalSize); 
    141167                else 
    142168                    throw; 
     
    148174                Logger.Log(e.Message, LogLevel.Error); 
    149175            } 
     176 
     177            return new StreamInfo[0]; 
    150178        } 
    151179 
     
    185213            //Retrieve the list of files to erase. 
    186214            long dataTotal = 0; 
    187             List<string> paths = GetPaths(out dataTotal); 
     215            List<StreamInfo> paths = GetPaths(out dataTotal); 
    188216 
    189217            //Get the erasure method if the user specified he wants the default. 
     
    194222            if (Progress == null) 
    195223                throw new InvalidOperationException("The Progress property must not be null."); 
    196             Task.Progress.Steps.Add(new SteppedProgressManagerStep(Progress, 1.0f / Task.Targets.Count)); 
     224            Task.Progress.Steps.Add(new SteppedProgressManagerStep(Progress, 
     225                EraseWeight / Task.Targets.Count)); 
    197226 
    198227            //Iterate over every path, and erase the path. 
     
    200229            { 
    201230                //Check that the file exists - we do not want to bother erasing nonexistant files 
    202                 StreamInfo info = new StreamInfo(paths[i]); 
     231                StreamInfo info = paths[i]; 
    203232                if (!info.Exists) 
    204233                { 
     
    221250                        info.Length / (float)dataTotal, S._("Erasing files..."))); 
    222251                    OnProgressChanged(this, new ProgressChangedEventArgs(step, 
    223                         new TaskProgressChangedEventArgs(paths[i], 0, method.Passes))); 
     252                        new TaskProgressChangedEventArgs(info.FullName, 0, method.Passes))); 
    224253 
    225254                    //Remove the read-only flag, if it is set. 
     
    299328            } 
    300329        } 
     330 
     331        /// <summary> 
     332        /// The weight attached with the erase process, so that tasks can depend on 
     333        /// the erase task without it using up all the weights allocated. 
     334        /// </summary> 
     335        protected virtual float EraseWeight 
     336        { 
     337            get 
     338            { 
     339                return 1.0f; 
     340            } 
     341        } 
    301342    } 
    302343} 
  • trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/FolderErasureTarget.cs

    r2081 r2085  
    8787        } 
    8888 
    89         protected override List<string> GetPaths(out long totalSize) 
    90         { 
    91             //Get a list to hold all the resulting paths. 
    92             List<string> result = new List<string>(); 
     89        protected override List<StreamInfo> GetPaths(out long totalSize) 
     90        { 
     91            //Get a list to hold all the resulting streams. 
     92            List<StreamInfo> result = new List<StreamInfo>(); 
    9393 
    9494            //Open the root of the search, including every file matching the pattern 
     
    100100            //Then exclude each file and finalize the list and total file size 
    101101            totalSize = 0; 
    102             if (ExcludeMask.Length != 0) 
     102            Regex includePattern = string.IsNullOrEmpty(IncludeMask) ? null : 
     103                new Regex( 
     104                    Regex.Escape(ExcludeMask).Replace("\\*", ".*").Replace("\\?", "."), 
     105                    RegexOptions.IgnoreCase | RegexOptions.Compiled); 
     106            Regex excludePattern = string.IsNullOrEmpty(ExcludeMask) ? null : 
     107                new Regex( 
     108                    Regex.Escape(ExcludeMask).Replace("\\*", ".*").Replace("\\?", "."), 
     109                    RegexOptions.IgnoreCase | RegexOptions.Compiled); 
     110            foreach (FileInfo file in files) 
    103111            { 
    104                 string regex = Regex.Escape(ExcludeMask).Replace("\\*", ".*"). 
    105                     Replace("\\?", "."); 
    106                 Regex excludePattern = new Regex(regex, RegexOptions.IgnoreCase); 
    107                 foreach (FileInfo file in files) 
    108                     if (file.Exists && 
    109                         (file.Attributes & FileAttributes.ReparsePoint) == 0 && 
    110                         excludePattern.Matches(file.FullName).Count == 0) 
    111                     { 
    112                         totalSize += file.Length; 
    113                         long adsesSize = 0; 
    114                         GetPathADSes(result, out adsesSize, file.FullName); 
    115                         totalSize += adsesSize; 
    116                         result.Add(file.FullName); 
    117                     } 
     112                //Check that the file exists and is not a reparse point. 
     113                if (!file.Exists || (file.Attributes & FileAttributes.ReparsePoint) == 0) 
     114                    continue; 
     115 
     116                //Check that the file is included 
     117                if (includePattern != null && !includePattern.Match(file.FullName).Success) 
     118                    continue; 
     119 
     120                //Check that the file is not excluded 
     121                if (excludePattern != null && excludePattern.Match(file.FullName).Success) 
     122                    continue; 
     123 
     124                //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; 
     129 
     130                //And the file itself 
     131                result.Add(new StreamInfo(file.FullName)); 
    118132            } 
    119             else 
    120                 foreach (FileInfo file in files) 
    121                 { 
    122                     if (!file.Exists || (file.Attributes & FileAttributes.ReparsePoint) != 0) 
    123                         continue; 
    124  
    125                     //Get the size of the file and its ADSes 
    126                     totalSize += file.Length; 
    127                     long adsesSize = 0; 
    128                     GetPathADSes(result, out adsesSize, file.FullName); 
    129                     totalSize += adsesSize; 
    130  
    131                     //Append this file to the list of files to erase. 
    132                     result.Add(file.FullName); 
    133                 } 
    134133 
    135134            //Return the filtered list. 
    136135            return result; 
    137         } 
    138  
    139         /// <summary> 
    140         /// Gets all files in the provided directory. 
    141         /// </summary> 
    142         /// <param name="info">The directory to look files in.</param> 
    143         /// <returns>A list of files found in the directory matching the IncludeMask 
    144         /// property.</returns> 
    145         private FileInfo[] GetFiles(DirectoryInfo info) 
    146         { 
    147             List<FileInfo> result = new List<FileInfo>(); 
    148             if (info.Exists) 
    149             { 
    150                 try 
    151                 { 
    152                     foreach (DirectoryInfo dir in info.GetDirectories()) 
    153                         result.AddRange(GetFiles(dir)); 
    154  
    155                     if (IncludeMask.Length == 0) 
    156                         result.AddRange(info.GetFiles()); 
    157                     else 
    158                         result.AddRange(info.GetFiles(IncludeMask, SearchOption.TopDirectoryOnly)); 
    159                 } 
    160                 catch (UnauthorizedAccessException e) 
    161                 { 
    162                     Logger.Log(S._("Could not erase files and subfolders in {0} because {1}", 
    163                         info.FullName, e.Message), LogLevel.Error); 
    164                 } 
    165             } 
    166  
    167             return result.ToArray(); 
    168136        } 
    169137 
  • trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/RecycleBinErasureTarget.cs

    r2074 r2085  
    6464        } 
    6565 
    66         protected override List<string> GetPaths(out long totalSize) 
     66        protected override List<StreamInfo> GetPaths(out long totalSize) 
    6767        { 
    6868            totalSize = 0; 
    69             List<string> result = new List<string>(); 
     69            List<StreamInfo> result = new List<StreamInfo>(); 
    7070            string[] rootDirectory = new string[] { 
    7171                    "$RECYCLE.BIN", 
    7272                    "RECYCLER" 
    7373                }; 
     74            string userSid = System.Security.Principal.WindowsIdentity.GetCurrent(). 
     75                User.ToString(); 
    7476 
    7577            foreach (DriveInfo drive in DriveInfo.GetDrives()) 
     
    8082                        System.IO.Path.Combine( 
    8183                            System.IO.Path.Combine(drive.Name, rootDir), 
    82                             System.Security.Principal.WindowsIdentity.GetCurrent(). 
    83                                 User.ToString())); 
     84                            userSid)); 
    8485                    if (!dir.Exists) 
    8586                        continue; 
    8687 
    87                     GetRecyclerFiles(dir, result, ref totalSize); 
     88                    foreach (FileInfo file in GetFiles(dir)) 
     89                    { 
     90                        if (!file.Exists || (file.Attributes & FileAttributes.ReparsePoint) != 0) 
     91                            continue; 
     92 
     93                        //Add the ADSes 
     94                        long adsSize = 0; 
     95                        result.AddRange(GetPathADSes(file, out adsSize)); 
     96                        totalSize += adsSize; 
     97 
     98                        //Then the file itself 
     99                        totalSize += file.Length; 
     100                        result.Add(new StreamInfo(file.FullName)); 
     101                    } 
    88102                } 
    89103            } 
    90104 
    91105            return result; 
    92         } 
    93  
    94         /// <summary> 
    95         /// Retrieves all files within this folder, without exclusions. 
    96         /// </summary> 
    97         /// <param name="info">The DirectoryInfo object representing the folder to traverse.</param> 
    98         /// <param name="paths">The list of files to store path information in.</param> 
    99         /// <param name="totalSize">Receives the total size of the files.</param> 
    100         private void GetRecyclerFiles(DirectoryInfo info, List<string> paths, 
    101             ref long totalSize) 
    102         { 
    103             try 
    104             { 
    105                 foreach (FileInfo fileInfo in info.GetFiles()) 
    106                 { 
    107                     if (!fileInfo.Exists || (fileInfo.Attributes & FileAttributes.ReparsePoint) != 0) 
    108                         continue; 
    109  
    110                     long adsSize = 0; 
    111                     GetPathADSes(paths, out adsSize, fileInfo.FullName); 
    112                     totalSize += adsSize; 
    113                     totalSize += fileInfo.Length; 
    114                     paths.Add(fileInfo.FullName); 
    115                 } 
    116  
    117                 foreach (DirectoryInfo directoryInfo in info.GetDirectories()) 
    118                     if ((directoryInfo.Attributes & FileAttributes.ReparsePoint) == 0) 
    119                         GetRecyclerFiles(directoryInfo, paths, ref totalSize); 
    120             } 
    121             catch (UnauthorizedAccessException e) 
    122             { 
    123                 Logger.Log(e.Message, LogLevel.Error); 
    124             } 
    125106        } 
    126107 
  • trunk/eraser/Eraser.DefaultPlugins/Strings.en.resx

    r2078 r2085  
    199199    <value>Invalid file path</value> 
    200200  </data> 
     201  <data name="Could not erase files and subfolders in {0} because {1}" xml:space="preserve"> 
     202    <value>Could not erase files and subfolders in {0} because {1}</value> 
     203  </data> 
    201204  <data name="The file {0} was not erased as the file does not exist." xml:space="preserve"> 
    202205    <value>The file {0} was not erased as the file does not exist.</value> 
     
    214217    <value>Files in Folder</value> 
    215218  </data> 
    216   <data name="Could not erase files and subfolders in {0} because {1}" xml:space="preserve"> 
    217     <value>Could not erase files and subfolders in {0} because {1}</value> 
    218   </data> 
    219219  <data name="Removing folders..." xml:space="preserve"> 
    220220    <value>Removing folders...</value> 
     
    238238    <value>Securely move {0}</value> 
    239239  </data> 
     240  <data name="Copying source file to destination" xml:space="preserve"> 
     241    <value>Copying source file to destination</value> 
     242  </data> 
     243  <data name="Erasing incomplete destination file" xml:space="preserve"> 
     244    <value>Erasing incomplete destination file</value> 
     245  </data> 
    240246  <data name="Select the Source folder" xml:space="preserve"> 
    241247    <value>Select the Source folder</value> 
  • trunk/eraser/Eraser.DefaultPlugins/Strings.it.resx

    r2078 r2085  
    199199    <value>(Untranslated)</value> 
    200200  </data> 
     201  <data name="Could not erase files and subfolders in {0} because {1}" xml:space="preserve"> 
     202    <value>(Untranslated)</value> 
     203  </data> 
    201204  <data name="The file {0} was not erased as the file does not exist." xml:space="preserve"> 
    202205    <value>(Untranslated)</value> 
     
    214217    <value>(Untranslated)</value> 
    215218  </data> 
    216   <data name="Could not erase files and subfolders in {0} because {1}" xml:space="preserve"> 
    217     <value>(Untranslated)</value> 
    218   </data> 
    219219  <data name="Removing folders..." xml:space="preserve"> 
    220220    <value>(Untranslated)</value> 
     
    236236  </data> 
    237237  <data name="Securely move {0}" xml:space="preserve"> 
     238    <value>(Untranslated)</value> 
     239  </data> 
     240  <data name="Copying source file to destination" xml:space="preserve"> 
     241    <value>(Untranslated)</value> 
     242  </data> 
     243  <data name="Erasing incomplete destination file" xml:space="preserve"> 
    238244    <value>(Untranslated)</value> 
    239245  </data> 
  • trunk/eraser/Eraser.DefaultPlugins/Strings.nl.resx

    r2078 r2085  
    199199    <value>(Untranslated)</value> 
    200200  </data> 
     201  <data name="Could not erase files and subfolders in {0} because {1}" xml:space="preserve"> 
     202    <value>(Untranslated)</value> 
     203  </data> 
    201204  <data name="The file {0} was not erased as the file does not exist." xml:space="preserve"> 
    202205    <value>(Untranslated)</value> 
     
    214217    <value>(Untranslated)</value> 
    215218  </data> 
    216   <data name="Could not erase files and subfolders in {0} because {1}" xml:space="preserve"> 
    217     <value>(Untranslated)</value> 
    218   </data> 
    219219  <data name="Removing folders..." xml:space="preserve"> 
    220220    <value>(Untranslated)</value> 
     
    238238    <value>(Untranslated)</value> 
    239239  </data> 
     240  <data name="Copying source file to destination" xml:space="preserve"> 
     241    <value>(Untranslated)</value> 
     242  </data> 
     243  <data name="Erasing incomplete destination file" xml:space="preserve"> 
     244    <value>(Untranslated)</value> 
     245  </data> 
    240246  <data name="Select the Source folder" xml:space="preserve"> 
    241247    <value>(Untranslated)</value> 
  • trunk/eraser/Eraser.DefaultPlugins/Strings.pl.resx

    r2078 r2085  
    199199    <value>(Untranslated)</value> 
    200200  </data> 
     201  <data name="Could not erase files and subfolders in {0} because {1}" xml:space="preserve"> 
     202    <value>(Untranslated)</value> 
     203  </data> 
    201204  <data name="The file {0} was not erased as the file does not exist." xml:space="preserve"> 
    202205    <value>(Untranslated)</value> 
     
    214217    <value>(Untranslated)</value> 
    215218  </data> 
    216   <data name="Could not erase files and subfolders in {0} because {1}" xml:space="preserve"> 
    217     <value>(Untranslated)</value> 
    218   </data> 
    219219  <data name="Removing folders..." xml:space="preserve"> 
    220220    <value>(Untranslated)</value> 
     
    236236  </data> 
    237237  <data name="Securely move {0}" xml:space="preserve"> 
     238    <value>(Untranslated)</value> 
     239  </data> 
     240  <data name="Copying source file to destination" xml:space="preserve"> 
     241    <value>(Untranslated)</value> 
     242  </data> 
     243  <data name="Erasing incomplete destination file" xml:space="preserve"> 
    238244    <value>(Untranslated)</value> 
    239245  </data> 
  • trunk/eraser/Eraser.DefaultPlugins/Strings.resx

    r2078 r2085  
    199199    <value>Invalid file path</value> 
    200200  </data> 
     201  <data name="Could not erase files and subfolders in {0} because {1}" xml:space="preserve"> 
     202    <value>Could not erase files and subfolders in {0} because {1}</value> 
     203  </data> 
    201204  <data name="The file {0} was not erased as the file does not exist." xml:space="preserve"> 
    202205    <value>The file {0} was not erased as the file does not exist.</value> 
     
    214217    <value>Files in Folder</value> 
    215218  </data> 
    216   <data name="Could not erase files and subfolders in {0} because {1}" xml:space="preserve"> 
    217     <value>Could not erase files and subfolders in {0} because {1}</value> 
    218   </data> 
    219219  <data name="Removing folders..." xml:space="preserve"> 
    220220    <value>Removing folders...</value> 
     
    238238    <value>Securely move {0}</value> 
    239239  </data> 
     240  <data name="Copying source file to destination" xml:space="preserve"> 
     241    <value>Copying source file to destination</value> 
     242  </data> 
     243  <data name="Erasing incomplete destination file" xml:space="preserve"> 
     244    <value>Erasing incomplete destination file</value> 
     245  </data> 
    240246  <data name="Select the Source folder" xml:space="preserve"> 
    241247    <value>Select the Source folder</value> 
  • trunk/eraser/Eraser.Manager/ErasureMethod.cs

    r2035 r2085  
    8383        /// are already provided. However some exceptional cases may take a 
    8484        /// long time if the data set is large.</remarks> 
    85         public abstract long CalculateEraseDataSize(ICollection<string> paths, long targetSize); 
     85        public abstract long CalculateEraseDataSize(ICollection<StreamInfo> paths, long targetSize); 
    8686 
    8787        /// <summary> 
     
    285285        } 
    286286 
    287         public override long CalculateEraseDataSize(ICollection<string> paths, long targetSize) 
     287        public override long CalculateEraseDataSize(ICollection<StreamInfo> paths, long targetSize) 
    288288        { 
    289289            //Simple. Amount of data multiplied by passes. 
     
    376376            } 
    377377 
    378             public override long CalculateEraseDataSize(ICollection<string> paths, long targetSize) 
     378            public override long CalculateEraseDataSize(ICollection<StreamInfo> paths, long targetSize) 
    379379            { 
    380380                throw new InvalidOperationException("The DefaultMethod class should never " + 
Note: See TracChangeset for help on using the changeset viewer.