Changeset 260 for branches/eraser6/Manager/DirectExecutor.cs
- Timestamp:
- 3/12/2008 5:34:32 AM (5 years ago)
- File:
-
- 1 edited
-
branches/eraser6/Manager/DirectExecutor.cs (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eraser6/Manager/DirectExecutor.cs
r251 r260 361 361 { 362 362 //Set the end of the stream after the wrap-round the cluster size 363 uint clusterSize = Drive s.GetDriveClusterSize(info.Directory.Root.FullName);363 uint clusterSize = Drive.GetClusterSize(info.Directory.Root.FullName); 364 364 long roundUpFileLength = strm.Length % clusterSize; 365 365 if (roundUpFileLength != 0) … … 419 419 /// </summary> 420 420 /// <param name="info">The FileInfo object representing the file.</param> 421 private void RemoveFile(FileInfo info)421 private static void RemoveFile(FileInfo info) 422 422 { 423 423 //Set the date of the file to be invalid to prevent forensic … … 431 431 for (int i = 0; i < FilenameErasePasses; ++i) 432 432 { 433 //Get a random file name434 PRNG prng = PRNGManager.GetInstance(Globals.Settings.ActivePRNG);435 byte[] newFileNameAry = new byte[info.Name.Length];436 prng.NextBytes(newFileNameAry);437 438 //Validate the name439 const string validFileNameChars = "0123456789abcdefghijklmnopqrs" +440 "tuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";441 for (int j = 0, k = newFileNameAry.Length; j < k; ++j)442 newFileNameAry[j] = (byte)validFileNameChars[443 (int)newFileNameAry[j] % validFileNameChars.Length];444 445 433 //Rename the file. 446 434 string newPath = info.DirectoryName + Path.DirectorySeparatorChar + 447 (new System.Text.UTF8Encoding()).GetString(newFileNameAry); 448 info.MoveTo(newPath); 435 GetRandomFileName(info.Name.Length); 436 437 //Try to rename the file. If it fails, it is probably due to another 438 //process locking the file. Defer, then rename again. 439 try 440 { 441 info.MoveTo(newPath); 442 } 443 catch (IOException) 444 { 445 Thread.Sleep(100); 446 --i; 447 } 449 448 } 450 449 … … 453 452 } 454 453 455 private void RemoveFolder(DirectoryInfo info)454 private static void RemoveFolder(DirectoryInfo info) 456 455 { 457 456 foreach (FileInfo file in info.GetFiles()) … … 463 462 for (int i = 0; i < FilenameErasePasses; ++i) 464 463 { 465 //Get a random file name466 PRNG prng = PRNGManager.GetInstance(Globals.Settings.ActivePRNG);467 byte[] newFileNameAry = new byte[info.Name.Length];468 prng.NextBytes(newFileNameAry);469 470 //Validate the name471 const string validFileNameChars = "0123456789abcdefghijklmnopqrs" +472 "tuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";473 for (int j = 0, k = newFileNameAry.Length; j < k; ++j)474 newFileNameAry[j] = (byte)validFileNameChars[475 (int)newFileNameAry[j] % validFileNameChars.Length];476 477 464 //Rename the folder. 478 465 string newPath = info.Parent.FullName + Path.DirectorySeparatorChar + 479 (new System.Text.UTF8Encoding()).GetString(newFileNameAry);466 GetRandomFileName(info.Name.Length); 480 467 481 468 //Try to rename the file. If it fails, it is probably due to another … … 497 484 498 485 /// <summary> 486 /// Generates a random file name with the given length. 487 /// </summary> 488 /// <param name="length">The length of the file name to generate.</param> 489 /// <returns>A random file name.</returns> 490 private static string GetRandomFileName(int length) 491 { 492 //Get a random file name 493 PRNG prng = PRNGManager.GetInstance(Globals.Settings.ActivePRNG); 494 byte[] newFileNameAry = new byte[length]; 495 prng.NextBytes(newFileNameAry); 496 497 //Validate the name 498 string validFileNameChars = "0123456789abcdefghijklmnopqrstuvwxyz" + 499 "ABCDEFGHIJKLMNOPQRSTUVWXYZ _+=-()[]{}',`~!"; 500 for (int j = 0, k = newFileNameAry.Length; j < k; ++j) 501 newFileNameAry[j] = (byte)validFileNameChars[ 502 (int)newFileNameAry[j] % validFileNameChars.Length]; 503 504 return new System.Text.UTF8Encoding().GetString(newFileNameAry); 505 } 506 507 /// <summary> 499 508 /// The thread object. 500 509 /// </summary>
Note: See TracChangeset
for help on using the changeset viewer.
