- Timestamp:
- 3/1/2010 8:54:11 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/eraser6/Eraser.DefaultPlugins/FileSystems/Windows.cs
r1866 r1870 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq; 24 25 using System.Text; 25 26 … … 120 121 //definitely using the file; throw an exception. 121 122 if (tries > FileNameEraseTries) 122 throw new IOException(S._("The file {0} is currently in use and " + 123 "cannot be removed.", info.FullName), e); 123 { 124 //Try to force the handle closed. 125 if (tries > FileNameEraseTries + 1 || 126 !ManagerLibrary.Settings.ForceUnlockLockedFiles) 127 { 128 throw new IOException(S._("The file {0} is currently in use " + 129 "and cannot be removed.", info.FullName), e); 130 } 131 132 IEnumerable<OpenHandle> handles = OpenHandle.Items.Where( 133 handle => handle.Path == info.FullName); 134 List<System.Diagnostics.Process> processes = 135 new List<System.Diagnostics.Process>(); 136 foreach (OpenHandle handle in handles) 137 if (!handle.Close()) 138 processes.Add(System.Diagnostics.Process.GetProcessById(handle.ProcessId)); 139 140 if (processes.Count > 0) 141 { 142 StringBuilder processStr = new StringBuilder(); 143 foreach (System.Diagnostics.Process process in processes) 144 { 145 try 146 { 147 processStr.AppendFormat( 148 System.Globalization.CultureInfo.InvariantCulture, 149 "{0}, ", process.MainModule.FileName); 150 } 151 catch (System.ComponentModel.Win32Exception) 152 { 153 } 154 } 155 156 Logger.Log(S._("Could not force closure of file \"{0}\" {1}", 157 info.FullName, S._("(locked by {0})", 158 processStr.ToString().Remove(processStr.Length - 2)).Trim()), 159 LogLevel.Error); 160 } 161 } 124 162 125 163 //Let the process locking the file release the lock
Note: See TracChangeset
for help on using the changeset viewer.
