| 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 | } |