Ignore:
Timestamp:
2/3/2010 3:37:13 AM (2 years ago)
Author:
lowjoel
Message:

Forward ported changes from trunk to r1743

Location:
branches/eraser6/CodeReview
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eraser6/CodeReview

  • branches/eraser6/CodeReview/Eraser.Util/VolumeInfo.cs

    r1711 r1745  
    5858                fileSystemName = new StringBuilder(NativeMethods.MaxPath * sizeof(char)); 
    5959            uint serialNumber, maxComponentLength, filesystemFlags; 
    60             if (!NativeMethods.GetVolumeInformation(volumeId, volumeName, NativeMethods.MaxPath, 
     60            if (NativeMethods.GetVolumeInformation(volumeId, volumeName, NativeMethods.MaxPath, 
    6161                out serialNumber, out maxComponentLength, out filesystemFlags, fileSystemName, 
    6262                NativeMethods.MaxPath)) 
    6363            { 
    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 Win32ErrorCode.GetExceptionForWin32Error(lastError); 
    75                 } 
    76             } 
    77             else 
    78             { 
    7964                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                     } 
     65            } 
     66 
     67            //If GetVolumeInformation returns zero some of the information may 
     68            //have been stored, so we just try to extract it. 
     69            VolumeLabel = volumeName.Length == 0 ? null : volumeName.ToString(); 
     70            VolumeFormat = fileSystemName.Length == 0 ? null : fileSystemName.ToString(); 
     71 
     72            //Determine whether it is FAT12 or FAT16 
     73            if (VolumeFormat == "FAT") 
     74            { 
     75                uint clusterSize, sectorSize, freeClusters, totalClusters; 
     76                if (NativeMethods.GetDiskFreeSpace(VolumeId, out clusterSize, 
     77                    out sectorSize, out freeClusters, out totalClusters)) 
     78                { 
     79                    if (totalClusters <= 0xFF0) 
     80                        VolumeFormat += "12"; 
     81                    else 
     82                        VolumeFormat += "16"; 
    9583                } 
    9684            } 
Note: See TracChangeset for help on using the changeset viewer.