Changeset 1576
- Timestamp:
- 1/18/2010 10:19:38 AM (3 years ago)
- Location:
- branches/eraser6/CodeReview
- Files:
-
- 3 edited
-
Eraser.Manager/DirectExecutor.cs (modified) (1 diff)
-
Eraser.Manager/Task.cs (modified) (1 diff)
-
Eraser.Util/Win32ErrorCodes.cs (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eraser6/CodeReview/Eraser.Manager/DirectExecutor.cs
r1570 r1576 625 625 info.FullName), LogLevel.Error)); 626 626 } 627 catch (FileLoadException) 628 { 629 if (!ManagerLibrary.Settings.ForceUnlockLockedFiles) 627 catch (IOException) 628 { 629 if (System.Runtime.InteropServices.Marshal.GetLastWin32Error() == 630 Win32ErrorCode.SharingViolation) 631 { 632 if (!ManagerLibrary.Settings.ForceUnlockLockedFiles) 633 throw; 634 635 List<System.Diagnostics.Process> processes = 636 new List<System.Diagnostics.Process>(); 637 foreach (OpenHandle handle in OpenHandle.Items) 638 if (handle.Path == paths[i]) 639 processes.Add(System.Diagnostics.Process.GetProcessById(handle.ProcessId)); 640 641 StringBuilder processStr = new StringBuilder(); 642 foreach (System.Diagnostics.Process process in processes) 643 processStr.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, 644 "{0}, ", process.MainModule.FileName); 645 646 task.Log.LastSessionEntries.Add(new LogEntry(S._( 647 "Could not force closure of file \"{0}\" (locked by {1})", 648 paths[i], processStr.ToString().Remove(processStr.Length - 2)), 649 LogLevel.Error)); 650 } 651 else 630 652 throw; 631 632 List<System.Diagnostics.Process> processes = new List<System.Diagnostics.Process>();633 foreach (OpenHandle handle in OpenHandle.Items)634 if (handle.Path == paths[i])635 processes.Add(System.Diagnostics.Process.GetProcessById(handle.ProcessId));636 637 StringBuilder processStr = new StringBuilder();638 foreach (System.Diagnostics.Process process in processes)639 processStr.AppendFormat(System.Globalization.CultureInfo.InvariantCulture,640 "{0}, ", process.MainModule.FileName);641 642 task.Log.LastSessionEntries.Add(new LogEntry(S._(643 "Could not force closure of file \"{0}\" (locked by {1})",644 paths[i], processStr.ToString().Remove(processStr.Length - 2)), LogLevel.Error));645 653 } 646 654 finally -
branches/eraser6/CodeReview/Eraser.Manager/Task.cs
r1572 r1576 459 459 } 460 460 } 461 catch (FileLoadException) 462 { 463 //The system cannot open the file, try to force the file handle to close. 464 if (!ManagerLibrary.Settings.ForceUnlockLockedFiles) 461 catch (IOException) 462 { 463 if (System.Runtime.InteropServices.Marshal.GetLastWin32Error() == 464 Win32ErrorCode.SharingViolation) 465 { 466 //The system cannot open the file, try to force the file handle to close. 467 if (!ManagerLibrary.Settings.ForceUnlockLockedFiles) 468 throw; 469 470 foreach (OpenHandle handle in OpenHandle.Items) 471 if (handle.Path == file && handle.Close()) 472 { 473 GetPathADSes(list, out totalSize, file); 474 return; 475 } 476 } 477 else 465 478 throw; 466 467 foreach (OpenHandle handle in OpenHandle.Items)468 if (handle.Path == file && handle.Close())469 {470 GetPathADSes(list, out totalSize, file);471 return;472 }473 479 } 474 480 catch (UnauthorizedAccessException e) -
branches/eraser6/CodeReview/Eraser.Util/Win32ErrorCodes.cs
r1566 r1576 24 24 using System.Text; 25 25 using System.Runtime.InteropServices; 26 using System.IO; 26 27 27 28 namespace Eraser.Util … … 34 35 /// <param name="errorCode">The error code to convert.</param> 35 36 /// <returns>A HRESULT value representing the error code.</returns> 36 internalstatic int GetHRForWin32Error(int errorCode)37 private static int GetHRForWin32Error(int errorCode) 37 38 { 38 39 const uint FACILITY_WIN32 = 7; … … 48 49 internal static Exception GetExceptionForWin32Error(int errorCode) 49 50 { 50 int HR = GetHRForWin32Error(errorCode); 51 return Marshal.GetExceptionForHR(HR); 51 switch (errorCode) 52 { 53 case NoError: return null; 54 case SharingViolation: return new IOException(); 55 56 default: 57 int HR = GetHRForWin32Error(errorCode); 58 return Marshal.GetExceptionForHR(HR); 59 } 52 60 } 53 61
Note: See TracChangeset
for help on using the changeset viewer.
