- Timestamp:
- 6/13/2010 12:39:53 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/eraser/Eraser.DefaultPlugins/FileSystems/Windows.cs
r2155 r2156 223 223 try 224 224 { 225 //Reset the file attributes. 226 FileAttributes fileAttr = streamInfo.Attributes; 227 streamInfo.Attributes = FileAttributes.Normal; 228 229 try 230 { 231 EraseFileClusterTips(files[i], method); 232 } 233 finally 234 { 235 streamInfo.Attributes = fileAttr; 236 } 225 EraseFileClusterTips(streamInfo, method); 237 226 } 238 227 catch (UnauthorizedAccessException) … … 325 314 /// Erases the cluster tips of the given file. 326 315 /// </summary> 327 /// <param name=" file">The fileto erase.</param>316 /// <param name="stream">The stream to erase.</param> 328 317 /// <param name="method">The erasure method to use.</param> 329 private void EraseFileClusterTips( string file, ErasureMethod method)318 private void EraseFileClusterTips(StreamInfo streamInfo, ErasureMethod method) 330 319 { 331 320 //Get the file access times 332 StreamInfo streamInfo = new StreamInfo(file);333 321 DateTime lastAccess = streamInfo.LastAccessTime; 334 322 DateTime lastWrite = streamInfo.LastWriteTime; 335 323 DateTime created = streamInfo.CreationTime; 336 324 325 //Get the file attributes 326 FileAttributes attributes = streamInfo.Attributes; 327 337 328 //And get the file lengths to know how much to overwrite 338 long fileArea = GetFileArea( file);329 long fileArea = GetFileArea(streamInfo); 339 330 long fileLength = streamInfo.Length; 340 331 … … 343 334 return; 344 335 345 //Otherwise, create the stream, lengthen the file, then tell the erasure346 // method to erase the cluster tips.336 //Otherwise, unset any read-only flags, create the stream, lengthen the 337 //file, then tell the erasure method to erase the cluster tips. 347 338 try 348 339 { 349 using (FileStream stream = streamInfo.Open(FileMode.Open, FileAccess.Write, 350 FileShare.None, FileOptions.WriteThrough)) 351 { 352 try 353 { 354 stream.SetLength(fileArea); 355 stream.Seek(fileLength, SeekOrigin.Begin); 356 357 //Erase the file 358 method.Erase(stream, long.MaxValue, 359 ManagerLibrary.Instance.PrngRegistrar[ 360 ManagerLibrary.Settings.ActivePrng], 361 null); 362 } 363 finally 364 { 365 //Make sure the file length is restored! 366 stream.SetLength(fileLength); 367 } 368 } 340 streamInfo.Attributes = FileAttributes.Normal; 341 FileStream stream = streamInfo.Open(FileMode.Open, FileAccess.Write, 342 FileShare.None, FileOptions.WriteThrough); 343 344 try 345 { 346 stream.SetLength(fileArea); 347 stream.Seek(fileLength, SeekOrigin.Begin); 348 349 //Erase the file 350 method.Erase(stream, long.MaxValue, ManagerLibrary.Instance.PrngRegistrar[ 351 ManagerLibrary.Settings.ActivePrng], null); 352 } 353 finally 354 { 355 //Make sure the file length is restored! 356 stream.SetLength(fileLength); 357 358 //Then destroy the stream 359 stream.Close(); 360 } 361 } 362 catch (ArgumentException e) 363 { 364 //This is an undocumented exception: when the path we are setting 365 //cannot be accessed (ERROR_ACCESS_DENIED is returned) an 366 //ArgumentException is raised (no idea why!) 367 throw new UnauthorizedAccessException(e.Message, e); 369 368 } 370 369 finally 371 370 { 371 //Reset the file attributes 372 streamInfo.Attributes = attributes; 373 372 374 //Reset the file times 373 375 streamInfo.SetTimes(MinTimestamp, created, lastWrite, lastAccess); … … 375 377 } 376 378 377 public override long GetFileArea(string filePath) 378 { 379 StreamInfo info = new StreamInfo(filePath); 379 public override long GetFileArea(StreamInfo info) 380 { 380 381 VolumeInfo volume = VolumeInfo.FromMountPoint(info.Directory.FullName); 381 382 long clusterSize = volume.ClusterSize;
Note: See TracChangeset
for help on using the changeset viewer.
