Changeset 2085
- Timestamp:
- 5/9/2010 11:00:15 AM (3 years ago)
- Location:
- trunk/eraser
- Files:
-
- 11 edited
-
Eraser.DefaultPlugins/ErasureMethods/FirstLast16KB.cs (modified) (1 diff)
-
Eraser.DefaultPlugins/ErasureTargets/FileErasureTarget.cs (modified) (1 diff)
-
Eraser.DefaultPlugins/ErasureTargets/FileSystemObjectErasureTarget.cs (modified) (11 diffs)
-
Eraser.DefaultPlugins/ErasureTargets/FolderErasureTarget.cs (modified) (2 diffs)
-
Eraser.DefaultPlugins/ErasureTargets/RecycleBinErasureTarget.cs (modified) (2 diffs)
-
Eraser.DefaultPlugins/Strings.en.resx (modified) (3 diffs)
-
Eraser.DefaultPlugins/Strings.it.resx (modified) (3 diffs)
-
Eraser.DefaultPlugins/Strings.nl.resx (modified) (3 diffs)
-
Eraser.DefaultPlugins/Strings.pl.resx (modified) (3 diffs)
-
Eraser.DefaultPlugins/Strings.resx (modified) (3 diffs)
-
Eraser.Manager/ErasureMethod.cs (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/eraser/Eraser.DefaultPlugins/ErasureMethods/FirstLast16KB.cs
r1802 r2085 76 76 } 77 77 78 public override long CalculateEraseDataSize(ICollection< string> paths, long targetSize)78 public override long CalculateEraseDataSize(ICollection<StreamInfo> paths, long targetSize) 79 79 { 80 80 //If we have no default or we are the default then throw an exception -
trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/FileErasureTarget.cs
r2074 r2085 70 70 } 71 71 72 protected override List< string> GetPaths(out long totalSize)72 protected override List<StreamInfo> GetPaths(out long totalSize) 73 73 { 74 74 totalSize = 0; 75 List< string> result = new List<string>();75 List<StreamInfo> result = new List<StreamInfo>(); 76 76 FileInfo fileInfo = new FileInfo(Path); 77 77 78 78 if (fileInfo.Exists) 79 79 { 80 GetPathADSes(result, out totalSize, Path);80 result.AddRange(GetPathADSes(fileInfo, out totalSize)); 81 81 totalSize += fileInfo.Length; 82 82 } 83 83 84 result.Add( Path);84 result.Add(new StreamInfo(Path)); 85 85 return result; 86 86 } -
trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/FileSystemObjectErasureTarget.cs
r2084 r2085 65 65 } 66 66 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> 67 71 protected new SteppedProgressManager Progress 68 72 { … … 83 87 /// items.</param> 84 88 /// <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 } 86 116 87 117 /// <summary> 88 118 /// Adds ADSes of the given file to the list. 89 119 /// </summary> 90 /// <param name="list">The list to add the ADS paths to.</param>91 120 /// <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) 93 122 { 94 123 totalSize = 0; … … 97 126 { 98 127 //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]; 100 130 101 131 //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]); 107 135 totalSize += info.Length; 136 result[i] = info; 108 137 } 109 138 } … … 118 147 119 148 StringBuilder processStr = new StringBuilder(); 120 foreach (OpenHandle handle in OpenHandle.Close(file ))149 foreach (OpenHandle handle in OpenHandle.Close(file.FullName)) 121 150 { 122 151 try … … 135 164 136 165 if (processStr.Length == 0) 137 { 138 GetPathADSes(list, out totalSize, file); 139 return; 140 } 166 return GetPathADSes(file, out totalSize); 141 167 else 142 168 throw; … … 148 174 Logger.Log(e.Message, LogLevel.Error); 149 175 } 176 177 return new StreamInfo[0]; 150 178 } 151 179 … … 185 213 //Retrieve the list of files to erase. 186 214 long dataTotal = 0; 187 List< string> paths = GetPaths(out dataTotal);215 List<StreamInfo> paths = GetPaths(out dataTotal); 188 216 189 217 //Get the erasure method if the user specified he wants the default. … … 194 222 if (Progress == null) 195 223 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)); 197 226 198 227 //Iterate over every path, and erase the path. … … 200 229 { 201 230 //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]; 203 232 if (!info.Exists) 204 233 { … … 221 250 info.Length / (float)dataTotal, S._("Erasing files..."))); 222 251 OnProgressChanged(this, new ProgressChangedEventArgs(step, 223 new TaskProgressChangedEventArgs( paths[i], 0, method.Passes)));252 new TaskProgressChangedEventArgs(info.FullName, 0, method.Passes))); 224 253 225 254 //Remove the read-only flag, if it is set. … … 299 328 } 300 329 } 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 } 301 342 } 302 343 } -
trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/FolderErasureTarget.cs
r2081 r2085 87 87 } 88 88 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>(); 93 93 94 94 //Open the root of the search, including every file matching the pattern … … 100 100 //Then exclude each file and finalize the list and total file size 101 101 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) 103 111 { 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)); 118 132 } 119 else120 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 ADSes126 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 }134 133 135 134 //Return the filtered list. 136 135 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 IncludeMask144 /// property.</returns>145 private FileInfo[] GetFiles(DirectoryInfo info)146 {147 List<FileInfo> result = new List<FileInfo>();148 if (info.Exists)149 {150 try151 {152 foreach (DirectoryInfo dir in info.GetDirectories())153 result.AddRange(GetFiles(dir));154 155 if (IncludeMask.Length == 0)156 result.AddRange(info.GetFiles());157 else158 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();168 136 } 169 137 -
trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/RecycleBinErasureTarget.cs
r2074 r2085 64 64 } 65 65 66 protected override List< string> GetPaths(out long totalSize)66 protected override List<StreamInfo> GetPaths(out long totalSize) 67 67 { 68 68 totalSize = 0; 69 List< string> result = new List<string>();69 List<StreamInfo> result = new List<StreamInfo>(); 70 70 string[] rootDirectory = new string[] { 71 71 "$RECYCLE.BIN", 72 72 "RECYCLER" 73 73 }; 74 string userSid = System.Security.Principal.WindowsIdentity.GetCurrent(). 75 User.ToString(); 74 76 75 77 foreach (DriveInfo drive in DriveInfo.GetDrives()) … … 80 82 System.IO.Path.Combine( 81 83 System.IO.Path.Combine(drive.Name, rootDir), 82 System.Security.Principal.WindowsIdentity.GetCurrent(). 83 User.ToString())); 84 userSid)); 84 85 if (!dir.Exists) 85 86 continue; 86 87 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 } 88 102 } 89 103 } 90 104 91 105 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 try104 {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 }125 106 } 126 107 -
trunk/eraser/Eraser.DefaultPlugins/Strings.en.resx
r2078 r2085 199 199 <value>Invalid file path</value> 200 200 </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> 201 204 <data name="The file {0} was not erased as the file does not exist." xml:space="preserve"> 202 205 <value>The file {0} was not erased as the file does not exist.</value> … … 214 217 <value>Files in Folder</value> 215 218 </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>219 219 <data name="Removing folders..." xml:space="preserve"> 220 220 <value>Removing folders...</value> … … 238 238 <value>Securely move {0}</value> 239 239 </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> 240 246 <data name="Select the Source folder" xml:space="preserve"> 241 247 <value>Select the Source folder</value> -
trunk/eraser/Eraser.DefaultPlugins/Strings.it.resx
r2078 r2085 199 199 <value>(Untranslated)</value> 200 200 </data> 201 <data name="Could not erase files and subfolders in {0} because {1}" xml:space="preserve"> 202 <value>(Untranslated)</value> 203 </data> 201 204 <data name="The file {0} was not erased as the file does not exist." xml:space="preserve"> 202 205 <value>(Untranslated)</value> … … 214 217 <value>(Untranslated)</value> 215 218 </data> 216 <data name="Could not erase files and subfolders in {0} because {1}" xml:space="preserve">217 <value>(Untranslated)</value>218 </data>219 219 <data name="Removing folders..." xml:space="preserve"> 220 220 <value>(Untranslated)</value> … … 236 236 </data> 237 237 <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"> 238 244 <value>(Untranslated)</value> 239 245 </data> -
trunk/eraser/Eraser.DefaultPlugins/Strings.nl.resx
r2078 r2085 199 199 <value>(Untranslated)</value> 200 200 </data> 201 <data name="Could not erase files and subfolders in {0} because {1}" xml:space="preserve"> 202 <value>(Untranslated)</value> 203 </data> 201 204 <data name="The file {0} was not erased as the file does not exist." xml:space="preserve"> 202 205 <value>(Untranslated)</value> … … 214 217 <value>(Untranslated)</value> 215 218 </data> 216 <data name="Could not erase files and subfolders in {0} because {1}" xml:space="preserve">217 <value>(Untranslated)</value>218 </data>219 219 <data name="Removing folders..." xml:space="preserve"> 220 220 <value>(Untranslated)</value> … … 238 238 <value>(Untranslated)</value> 239 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"> 244 <value>(Untranslated)</value> 245 </data> 240 246 <data name="Select the Source folder" xml:space="preserve"> 241 247 <value>(Untranslated)</value> -
trunk/eraser/Eraser.DefaultPlugins/Strings.pl.resx
r2078 r2085 199 199 <value>(Untranslated)</value> 200 200 </data> 201 <data name="Could not erase files and subfolders in {0} because {1}" xml:space="preserve"> 202 <value>(Untranslated)</value> 203 </data> 201 204 <data name="The file {0} was not erased as the file does not exist." xml:space="preserve"> 202 205 <value>(Untranslated)</value> … … 214 217 <value>(Untranslated)</value> 215 218 </data> 216 <data name="Could not erase files and subfolders in {0} because {1}" xml:space="preserve">217 <value>(Untranslated)</value>218 </data>219 219 <data name="Removing folders..." xml:space="preserve"> 220 220 <value>(Untranslated)</value> … … 236 236 </data> 237 237 <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"> 238 244 <value>(Untranslated)</value> 239 245 </data> -
trunk/eraser/Eraser.DefaultPlugins/Strings.resx
r2078 r2085 199 199 <value>Invalid file path</value> 200 200 </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> 201 204 <data name="The file {0} was not erased as the file does not exist." xml:space="preserve"> 202 205 <value>The file {0} was not erased as the file does not exist.</value> … … 214 217 <value>Files in Folder</value> 215 218 </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>219 219 <data name="Removing folders..." xml:space="preserve"> 220 220 <value>Removing folders...</value> … … 238 238 <value>Securely move {0}</value> 239 239 </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> 240 246 <data name="Select the Source folder" xml:space="preserve"> 241 247 <value>Select the Source folder</value> -
trunk/eraser/Eraser.Manager/ErasureMethod.cs
r2035 r2085 83 83 /// are already provided. However some exceptional cases may take a 84 84 /// 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); 86 86 87 87 /// <summary> … … 285 285 } 286 286 287 public override long CalculateEraseDataSize(ICollection< string> paths, long targetSize)287 public override long CalculateEraseDataSize(ICollection<StreamInfo> paths, long targetSize) 288 288 { 289 289 //Simple. Amount of data multiplied by passes. … … 376 376 } 377 377 378 public override long CalculateEraseDataSize(ICollection< string> paths, long targetSize)378 public override long CalculateEraseDataSize(ICollection<StreamInfo> paths, long targetSize) 379 379 { 380 380 throw new InvalidOperationException("The DefaultMethod class should never " +
Note: See TracChangeset
for help on using the changeset viewer.
