Changeset 2179 for trunk/eraser/Eraser.Util/VolumeInfo.cs
- Timestamp:
- 6/18/2010 6:53:20 AM (2 years ago)
- File:
-
- 1 edited
-
trunk/eraser/Eraser.Util/VolumeInfo.cs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/eraser/Eraser.Util/VolumeInfo.cs
r2178 r2179 92 92 private List<string> GetLocalVolumeMountPoints() 93 93 { 94 List<string> result = new List<string>(); 95 96 //Get the paths of the said volume 97 string pathNames; 98 { 99 uint returnLength = 0; 100 char[] pathNamesBuffer = new char[NativeMethods.MaxPath]; 101 while (!NativeMethods.GetVolumePathNamesForVolumeName(VolumeId, 102 pathNamesBuffer, (uint)pathNamesBuffer.Length, out returnLength)) 103 { 104 int errorCode = Marshal.GetLastWin32Error(); 105 switch (errorCode) 106 { 107 case Win32ErrorCode.NotReady: 108 //The drive isn't ready yet: just return an empty list. 109 return result; 110 case Win32ErrorCode.MoreData: 111 pathNamesBuffer = new char[pathNamesBuffer.Length * 2]; 112 break; 113 default: 114 throw Win32ErrorCode.GetExceptionForWin32Error(errorCode); 115 } 116 } 117 118 pathNames = new string(pathNamesBuffer, 0, (int)returnLength); 119 } 120 121 //OK, the marshalling is complete. Convert the pathNames string into a list 122 //of strings containing all of the volumes mountpoints; because the 123 //GetVolumePathNamesForVolumeName function returns a convoluted structure 124 //containing the path names. 125 for (int lastIndex = 0, i = 0; i != pathNames.Length; ++i) 126 { 127 if (pathNames[i] == '\0') 128 { 129 //If there are no mount points for this volume, the string will only 130 //have one NULL 131 if (i - lastIndex == 0) 132 break; 133 134 result.Add(pathNames.Substring(lastIndex, i - lastIndex)); 135 136 lastIndex = i + 1; 137 if (pathNames[lastIndex] == '\0') 138 break; 139 } 140 } 141 142 return result; 94 return new List<string>(NativeMethods.GetVolumePathNamesForVolumeName(VolumeId)); 143 95 } 144 96
Note: See TracChangeset
for help on using the changeset viewer.
