Changeset 1701
- Timestamp:
- 1/27/2010 5:08:03 AM (3 years ago)
- Location:
- branches/eraser6/CodeReview
- Files:
-
- 1 added
- 15 edited
-
. (modified) (1 prop)
-
Eraser.DefaultPlugins/FileSystems/Windows.cs (modified) (1 diff)
-
Eraser.Manager/DirectExecutor.cs (modified) (10 diffs)
-
Eraser.Manager/Strings.en.resx (modified) (2 diffs)
-
Eraser.Manager/Strings.it.resx (modified) (1 diff)
-
Eraser.Manager/Strings.nl.resx (modified) (1 diff)
-
Eraser.Manager/Strings.resx (modified) (1 diff)
-
Eraser.Manager/Task.cs (modified) (1 diff)
-
Eraser.Util/Eraser.Util.csproj (modified) (1 diff)
-
Eraser.Util/NativeMethods/Mpr.cs (added)
-
Eraser.Util/StreamInfo.cs (modified) (1 diff)
-
Eraser.Util/VolumeInfo.cs (modified) (7 diffs)
-
Eraser.Util/Win32ErrorCodes.cs (modified) (1 diff)
-
Eraser/SchedulerPanel.Designer.cs (modified) (1 diff)
-
Eraser/SchedulerPanel.cs (modified) (1 diff)
-
Eraser/UpdateForm.cs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eraser6/CodeReview
- Property svn:mergeinfo changed
/branches/eraser6/6.0 merged: 1695,1699 /trunk/eraser6 merged: 1688-1700
- Property svn:mergeinfo changed
-
branches/eraser6/CodeReview/Eraser.DefaultPlugins/FileSystems/Windows.cs
r1681 r1701 115 115 } 116 116 } 117 } 118 119 //If the user wants plausible deniability, find a random file on the same 120 //volume and write it over. 121 if (Manager.ManagerLibrary.Settings.PlausibleDeniability) 122 { 123 using (FileStream fileStream = info.OpenWrite()) 124 CopyPlausibleDeniabilityFile(fileStream); 117 125 } 118 126 -
branches/eraser6/CodeReview/Eraser.Manager/DirectExecutor.cs
r1681 r1701 402 402 delegate(int currentFile, int totalFiles, string currentFilePath) 403 403 { 404 tipSearch. Completed = tipSearch.Total;404 tipSearch.MarkComplete(); 405 405 tipProgress.Total = totalFiles; 406 406 tipProgress.Completed = currentFile; … … 482 482 483 483 //Mark the main bulk of the progress as complete 484 mainProgress. Completed = mainProgress.Total;484 mainProgress.MarkComplete(); 485 485 486 486 //Erase old resident file system table files … … 502 502 ); 503 503 504 residentProgress. Completed = residentProgress.Total = 1;504 residentProgress.MarkComplete(); 505 505 } 506 506 finally … … 513 513 new TaskProgressChangedEventArgs(string.Empty, 0, 0))); 514 514 fsManager.DeleteFolder(info); 515 tempFiles.Completed = tempFiles.Total = 1;515 tempFiles.Completed = tempFiles.Total; 516 516 } 517 517 … … 537 537 ); 538 538 539 structureProgress. Completed = structureProgress.Total;539 structureProgress.MarkComplete(); 540 540 target.Progress = null; 541 541 } … … 583 583 //Get the filesystem provider to handle the secure file erasures 584 584 FileSystem fsManager = FileSystemManager.Get( 585 VolumeInfo.FromMount point(info.DirectoryName));585 VolumeInfo.FromMountPoint(info.DirectoryName)); 586 586 587 587 bool isReadOnly = false; … … 611 611 throw new OperationCanceledException(S._("The task was cancelled.")); 612 612 613 step.Total = totalData; 613 614 step.Completed += lastWritten; 614 step.Total = totalData;615 615 task.OnProgressChanged(target, 616 616 new ProgressChangedEventArgs(step, … … 622 622 if (fileInfo != null) 623 623 fsManager.DeleteFile(fileInfo); 624 step. Completed = step.Total = 1;624 step.MarkComplete(); 625 625 } 626 626 catch (UnauthorizedAccessException) … … 644 644 processes.Add(System.Diagnostics.Process.GetProcessById(handle.ProcessId)); 645 645 646 string lockedBy = null; 647 if (processes.Count > 0) 648 { 649 StringBuilder processStr = new StringBuilder(); 650 foreach (System.Diagnostics.Process process in processes) 651 processStr.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, 652 "{0}, ", process.MainModule.FileName); 653 654 lockedBy = S._("(locked by {0})", processStr.ToString().Remove(processStr.Length - 2)); 655 } 656 657 task.Log.LastSessionEntries.Add(new LogEntry(S._( 658 "Could not force closure of file \"{0}\" (locked by {1})", 659 paths[i], processStr.ToString().Remove(processStr.Length - 2)), 660 LogLevel.Error)); 646 string lockedBy = null; 647 if (processes.Count > 0) 648 { 649 StringBuilder processStr = new StringBuilder(); 650 foreach (System.Diagnostics.Process process in processes) 651 { 652 try 653 { 654 processStr.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, 655 "{0}, ", process.MainModule.FileName); 656 } 657 catch (System.ComponentModel.Win32Exception) 658 { 659 } 660 } 661 662 lockedBy = S._("(locked by {0})", processStr.ToString().Remove(processStr.Length - 2)); 663 } 664 665 task.Log.LastSessionEntries.Add(new LogEntry(S._( 666 "Could not force closure of file \"{0}\" {1}", paths[i], 667 lockedBy == null ? string.Empty : lockedBy).Trim(), LogLevel.Error)); 661 668 } 662 669 else … … 702 709 new ProgressChangedEventArgs(step, 703 710 new TaskProgressChangedEventArgs(info.FullName, 0, 0))); 704 705 //See if this is the root of a volume. 706 bool isVolumeRoot = info.Parent == null; 707 foreach (VolumeInfo volume in VolumeInfo.Volumes) 708 foreach (string mountPoint in volume.MountPoints) 709 if (info.FullName == mountPoint) 710 isVolumeRoot = true; 711 712 //If the folder is a mount point, then don't delete it. If it isn't, 713 //search for files under the folder to see if it is empty. 714 if (!isVolumeRoot && info.Exists && info.GetFiles("*", SearchOption.AllDirectories).Length == 0) 715 fsManager.DeleteFolder(info); 711 fsManager.DeleteFolder(info); 716 712 } 717 713 } -
branches/eraser6/CodeReview/Eraser.Manager/Strings.en.resx
r1681 r1701 170 170 </data> 171 171 <data name="Could not force closure of file \"{0}\" {1}" xml:space="preserve"> 172 <value> Could not force closure of file \"{0}\" {1}</value>172 <value>(Untranslated)</value> 173 173 </data> 174 174 <data name="Removing folders..." xml:space="preserve"> … … 295 295 <value>Unused disk space ({0})</value> 296 296 </data> 297 <data name="Could not erase {0} because {1}" xml:space="preserve">298 <value>Could not erase {0} because {1}</value>297 <data name="Could not erase files and subfolders in {0} because {1}" xml:space="preserve"> 298 <value>Could not erase files and subfolders in {0} because {1}</value> 299 299 </data> 300 300 <data name="Recycle Bin" xml:space="preserve"> -
branches/eraser6/CodeReview/Eraser.Manager/Strings.it.resx
r1681 r1701 295 295 <value>Spazio disco inutilizzato ({0})</value> 296 296 </data> 297 <data name="Could not erase {0} because {1}" xml:space="preserve">298 <value> Impossibile pulire {0} a causa di {1}</value>297 <data name="Could not erase files and subfolders in {0} because {1}" xml:space="preserve"> 298 <value>(Untranslated)</value> 299 299 </data> 300 300 <data name="Recycle Bin" xml:space="preserve"> -
branches/eraser6/CodeReview/Eraser.Manager/Strings.nl.resx
r1681 r1701 295 295 <value>(Untranslated)</value> 296 296 </data> 297 <data name="Could not erase {0} because {1}" xml:space="preserve">297 <data name="Could not erase files and subfolders in {0} because {1}" xml:space="preserve"> 298 298 <value>(Untranslated)</value> 299 299 </data> -
branches/eraser6/CodeReview/Eraser.Manager/Strings.resx
r1681 r1701 295 295 <value>Unused disk space ({0})</value> 296 296 </data> 297 <data name="Could not erase {0} because {1}" xml:space="preserve">298 <value>Could not erase {0} because {1}</value>297 <data name="Could not erase files and subfolders in {0} because {1}" xml:space="preserve"> 298 <value>Could not erase files and subfolders in {0} because {1}</value> 299 299 </data> 300 300 <data name="Recycle Bin" xml:space="preserve"> -
branches/eraser6/CodeReview/Eraser.Manager/Task.cs
r1681 r1701 508 508 public override string UIText 509 509 { 510 get { return System.IO.Path.GetFileName(Path); } 510 get 511 { 512 string fileName = System.IO.Path.GetFileName(Path); 513 string directoryName = System.IO.Path.GetDirectoryName(Path); 514 return string.IsNullOrEmpty(fileName) ? 515 (string.IsNullOrEmpty(directoryName) ? Path : directoryName) 516 : fileName; 517 } 511 518 } 512 519 -
branches/eraser6/CodeReview/Eraser.Util/Eraser.Util.csproj
r1618 r1701 104 104 <Compile Include="ConsoleWindow.cs" /> 105 105 <Compile Include="NativeMethods\DbgHelp.cs" /> 106 <Compile Include="NativeMethods\Mpr.cs" /> 106 107 <Compile Include="PostDataBuilder.cs" /> 107 108 <Compile Include="Power.cs" /> -
branches/eraser6/CodeReview/Eraser.Util/StreamInfo.cs
r1681 r1701 138 138 { 139 139 case Win32ErrorCode.FileNotFound: 140 case Win32ErrorCode.PathNotFound 140 case Win32ErrorCode.PathNotFound: 141 141 return false; 142 case Win32ErrorCode.AccessDenied: 142 143 case Win32ErrorCode.SharingViolation: 143 144 return true; -
branches/eraser6/CodeReview/Eraser.Util/VolumeInfo.cs
r1681 r1701 37 37 /// Constructor. 38 38 /// </summary> 39 /// <param name="volumeId">The ID of the volume, in the form "\\?\Volume{GUID}\"</param> 39 /// <param name="volumeId">The ID of the volume, either in the form 40 /// "\\?\Volume{GUID}\" or as a valid UNC path.</param> 40 41 public VolumeInfo(string volumeId) 41 42 { 42 //Set the volume Id 43 //We only accept UNC paths as well as volume identifiers. 44 if (!(volumeId.StartsWith("\\\\?\\") || volumeId.StartsWith("\\\\"))) 45 throw new ArgumentException("The volumeId parameter only accepts volume GUID " + 46 "and UNC paths", "volumeId"); 47 48 //Verify that the path ends with a trailing backslash 49 if (!volumeId.EndsWith("\\")) 50 throw new ArgumentException("The volumeId parameter must end with a trailing " + 51 "backslash.", "volumeId"); 52 53 //Set the volume ID 43 54 VolumeId = volumeId; 55 56 //Fill up the remaining members of the structure: file system, label, etc. 57 StringBuilder volumeName = new StringBuilder(NativeMethods.MaxPath * sizeof(char)), 58 fileSystemName = new StringBuilder(NativeMethods.MaxPath * sizeof(char)); 59 uint serialNumber, maxComponentLength, filesystemFlags; 60 if (!NativeMethods.GetVolumeInformation(volumeId, volumeName, NativeMethods.MaxPath, 61 out serialNumber, out maxComponentLength, out filesystemFlags, fileSystemName, 62 NativeMethods.MaxPath)) 63 { 64 int lastError = Marshal.GetLastWin32Error(); 65 switch (lastError) 66 { 67 case Win32ErrorCode.Success: 68 case Win32ErrorCode.NotReady: 69 case Win32ErrorCode.InvalidParameter: //when the volume given is not mounted. 70 case Win32ErrorCode.UnrecognizedVolume: 71 break; 72 73 default: 74 throw Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error()); 75 } 76 } 77 else 78 { 79 IsReady = true; 80 VolumeLabel = volumeName.ToString(); 81 VolumeFormat = fileSystemName.ToString(); 82 83 //Determine whether it is FAT12 or FAT16 84 if (VolumeFormat == "FAT") 85 { 86 uint clusterSize, sectorSize, freeClusters, totalClusters; 87 if (NativeMethods.GetDiskFreeSpace(VolumeId, out clusterSize, 88 out sectorSize, out freeClusters, out totalClusters)) 89 { 90 if (totalClusters <= 0xFF0) 91 VolumeFormat += "12"; 92 else 93 VolumeFormat += "16"; 94 } 95 } 96 } 97 } 98 99 /// <summary> 100 /// Gets the mountpoints associated with the current volume. 101 /// </summary> 102 /// <returns>A list of volume mount points for the current volume.</returns> 103 private List<string> GetLocalVolumeMountPoints() 104 { 105 List<string> result = new List<string>(); 44 106 45 107 //Get the paths of the said volume … … 81 143 break; 82 144 83 mountPoints.Add(pathNames.Substring(lastIndex, i - lastIndex));145 result.Add(pathNames.Substring(lastIndex, i - lastIndex)); 84 146 85 147 lastIndex = i + 1; … … 89 151 } 90 152 91 //Fill up the remaining members of the structure: file system, label, etc. 92 StringBuilder volumeName = new StringBuilder(NativeMethods.MaxPath * sizeof(char)), 93 fileSystemName = new StringBuilder(NativeMethods.MaxPath * sizeof(char)); 94 uint serialNumber, maxComponentLength, filesystemFlags; 95 if (!NativeMethods.GetVolumeInformation(volumeId, volumeName, NativeMethods.MaxPath, 96 out serialNumber, out maxComponentLength, out filesystemFlags, fileSystemName, 97 NativeMethods.MaxPath)) 98 { 99 int lastError = Marshal.GetLastWin32Error(); 100 switch (lastError) 101 { 102 case Win32ErrorCode.Success: 103 case Win32ErrorCode.NotReady: 104 case Win32ErrorCode.InvalidParameter: //when the volume given is not mounted. 105 case Win32ErrorCode.UnrecognizedVolume: 106 break; 107 108 default: 109 throw Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error()); 110 } 111 } 112 else 113 { 114 IsReady = true; 115 VolumeLabel = volumeName.ToString(); 116 VolumeFormat = fileSystemName.ToString(); 117 118 //Determine whether it is FAT12 or FAT16 119 if (VolumeFormat == "FAT") 120 { 121 uint clusterSize, sectorSize, freeClusters, totalClusters; 122 if (NativeMethods.GetDiskFreeSpace(VolumeId, out clusterSize, 123 out sectorSize, out freeClusters, out totalClusters)) 153 return result; 154 } 155 156 /// <summary> 157 /// Gets the mountpoints associated with the network share. 158 /// </summary> 159 /// <returns>A list of network mount points for the given network share.</returns> 160 private List<string> GetNetworkMountPoints() 161 { 162 List<string> result = new List<string>(); 163 164 //Open an enumeration handle to list mount points. 165 IntPtr enumHandle; 166 uint errorCode = NativeMethods.WNetOpenEnum(NativeMethods.RESOURCE_CONNECTED, 167 NativeMethods.RESOURCETYPE_DISK, 0, IntPtr.Zero, out enumHandle); 168 if (errorCode != Win32ErrorCode.Success) 169 throw new Win32Exception((int)errorCode); 170 171 try 172 { 173 int resultBufferCount = 32; 174 int resultBufferSize = resultBufferCount * 175 Marshal.SizeOf(typeof(NativeMethods.NETRESOURCE)); 176 IntPtr resultBuffer = Marshal.AllocHGlobal(resultBufferSize); 177 178 try 179 { 180 for ( ; ; ) 124 181 { 125 if (totalClusters <= 0xFF0) 126 VolumeFormat += "12"; 127 else 128 VolumeFormat += "16"; 182 uint resultBufferStored = (uint)resultBufferCount; 183 uint resultBufferRequiredSize = (uint)resultBufferSize; 184 errorCode = NativeMethods.WNetEnumResource(enumHandle, 185 ref resultBufferStored, resultBuffer, 186 ref resultBufferRequiredSize); 187 188 if (errorCode == Win32ErrorCode.NoMoreItems) 189 break; 190 else if (errorCode != Win32ErrorCode.Success) 191 throw new Win32Exception((int)errorCode); 192 193 unsafe 194 { 195 //Marshal the memory block to managed structures. 196 byte* pointer = (byte*)resultBuffer.ToPointer(); 197 198 for (uint i = 0; i < resultBufferStored; 199 ++i, pointer += Marshal.SizeOf(typeof(NativeMethods.NETRESOURCE))) 200 { 201 NativeMethods.NETRESOURCE resource = 202 (NativeMethods.NETRESOURCE)Marshal.PtrToStructure( 203 (IntPtr)pointer, typeof(NativeMethods.NETRESOURCE)); 204 205 //Ensure that the path in the resource structure ends with a trailing 206 //backslash as out volume ID ends with one. 207 if (string.IsNullOrEmpty(resource.lpRemoteName)) 208 continue; 209 if (resource.lpRemoteName[resource.lpRemoteName.Length - 1] != '\\') 210 resource.lpRemoteName += '\\'; 211 212 if (resource.lpRemoteName == VolumeId) 213 result.Add(resource.lpLocalName); 214 } 215 } 129 216 } 130 217 } 131 } 218 finally 219 { 220 Marshal.FreeHGlobal(resultBuffer); 221 } 222 } 223 finally 224 { 225 NativeMethods.WNetCloseEnum(enumHandle); 226 } 227 228 return result; 132 229 } 133 230 … … 172 269 public static VolumeInfo FromMountPoint(string mountPoint) 173 270 { 271 //Verify that the mountpoint given exists; if it doesn't we'll raise 272 //a DirectoryNotFound exception. 174 273 DirectoryInfo mountpointDir = new DirectoryInfo(mountPoint); 175 StringBuilder volumeID = new StringBuilder(50 * sizeof(char));176 177 //Verify that the mountpoint given exists; if it doesn't we'll raise178 //a PathNotFound exception.179 274 if (!mountpointDir.Exists) 180 275 throw new DirectoryNotFoundException(); … … 182 277 do 183 278 { 279 //Ensure that the current path has a trailing backslash 184 280 string currentDir = mountpointDir.FullName; 185 281 if (currentDir.Length > 0 && currentDir[currentDir.Length - 1] != '\\') 186 282 currentDir += '\\'; 187 if (!NativeMethods.GetVolumeNameForVolumeMountPoint(currentDir, volumeID, 50)) 188 { 189 int errorCode = Marshal.GetLastWin32Error(); 283 284 //The path cannot be empty. 285 if (string.IsNullOrEmpty(currentDir)) 286 throw new DirectoryNotFoundException(); 287 288 //Get the type of the drive 289 DriveType driveType = (DriveType)NativeMethods.GetDriveType(currentDir); 290 291 //We do different things for different kinds of drives. Network drives 292 //will need us to resolve the drive to a UNC path. Local drives will 293 //be resolved to a volume GUID 294 StringBuilder volumeID = new StringBuilder(NativeMethods.MaxPath); 295 if (driveType == DriveType.Network) 296 { 297 //Resolve the mountpoint to a UNC path 298 uint bufferCapacity = (uint)volumeID.Capacity; 299 uint errorCode = NativeMethods.WNetGetConnection( 300 currentDir.Substring(0, currentDir.Length - 1), 301 volumeID, ref bufferCapacity); 190 302 191 303 switch (errorCode) 192 304 { 193 case Win32ErrorCode. InvalidFunction:194 case Win32ErrorCode.FileNotFound:195 case Win32ErrorCode.PathNotFound: 196 case Win32ErrorCode. NotAReparsePoint:305 case Win32ErrorCode.Success: 306 return new VolumeInfo(volumeID.ToString() + '\\'); 307 308 case Win32ErrorCode.BadDevice: //Path is not a network share 197 309 break; 310 198 311 default: 199 throw Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error());312 throw new Win32Exception((int)errorCode); 200 313 } 201 314 } 202 315 else 203 316 { 204 return new VolumeInfo(volumeID.ToString()); 317 if (!NativeMethods.GetVolumeNameForVolumeMountPoint(currentDir, volumeID, 50)) 318 { 319 int errorCode = Marshal.GetLastWin32Error(); 320 switch (errorCode) 321 { 322 case Win32ErrorCode.InvalidFunction: 323 case Win32ErrorCode.FileNotFound: 324 case Win32ErrorCode.PathNotFound: 325 case Win32ErrorCode.NotAReparsePoint: 326 break; 327 default: 328 throw Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error()); 329 } 330 } 331 else 332 { 333 return new VolumeInfo(volumeID.ToString()); 334 } 205 335 } 206 336 … … 397 527 get 398 528 { 399 return mountPoints.AsReadOnly(); 529 return (VolumeType == DriveType.Network ? 530 GetNetworkMountPoints() : GetLocalVolumeMountPoints()).AsReadOnly(); 400 531 } 401 532 } … … 538 669 return new VolumeLock(stream); 539 670 } 540 541 private List<string> mountPoints = new List<string>();542 671 } 543 672 -
branches/eraser6/CodeReview/Eraser.Util/Win32ErrorCodes.cs
r1576 r1701 71 71 public const int InvalidParameter = 87; 72 72 public const int MoreData = 234; 73 public const int NoMoreItems = 259; 73 74 public const int UnrecognizedVolume = 1005; 75 public const int BadDevice = 1200; 74 76 public const int NotAReparsePoint = 4390; 75 77 } -
branches/eraser6/CodeReview/Eraser/SchedulerPanel.Designer.cs
r1681 r1701 78 78 this.titleLabel.AccessibleName = null; 79 79 resources.ApplyResources(this.titleLabel, "titleLabel"); 80 this.titleLabel.Font = null;81 80 // 82 81 // titleIcon -
branches/eraser6/CodeReview/Eraser/SchedulerPanel.cs
r1681 r1701 652 652 653 653 Rectangle rect = ((ListViewItem)schedulerProgress.Tag).SubItems[2].Bounds; 654 rect.Offset(2, 2); 654 655 schedulerProgress.Location = rect.Location; 655 656 schedulerProgress.Size = rect.Size; -
branches/eraser6/CodeReview/Eraser/UpdateForm.cs
r1681 r1701 733 733 734 734 //Let the event handler know the download is complete. 735 step. Completed = step.Total;735 step.MarkComplete(); 736 736 OnProgress(new ProgressEventArgs(step.Progress, progress.Progress, 737 737 update, S._("Downloaded: {0}", update.Name)));
Note: See TracChangeset
for help on using the changeset viewer.
