Changed the HDD enumeration code to drop drives without smart support and without any non-zero-sized logical drives.
authormoel.mich
Sun, 30 Jun 2013 16:24:52 +0000
changeset 4092ce8da367490
parent 408 bbeb9004c491
child 410 3e69541ad89a
Changed the HDD enumeration code to drop drives without smart support and without any non-zero-sized logical drives.
Hardware/HDD/AbstractHarddrive.cs
     1.1 --- a/Hardware/HDD/AbstractHarddrive.cs	Sun Jun 30 11:41:36 2013 +0000
     1.2 +++ b/Hardware/HDD/AbstractHarddrive.cs	Sun Jun 30 16:24:52 2013 +0000
     1.3 @@ -69,9 +69,12 @@
     1.4        foreach (string logicalDrive in logicalDrives) {
     1.5          try {
     1.6            DriveInfo di = new DriveInfo(logicalDrive);
     1.7 -          if (di.TotalSize > 0) 
     1.8 +          if (di.TotalSize > 0)
     1.9              driveInfoList.Add(new DriveInfo(logicalDrive));
    1.10 -        } catch (ArgumentException) { } catch (IOException) { }
    1.11 +        } catch (ArgumentException) {
    1.12 +        } catch (IOException) {
    1.13 +        } catch (UnauthorizedAccessException) {
    1.14 +        }
    1.15        }
    1.16        driveInfos = driveInfoList.ToArray();
    1.17  
    1.18 @@ -105,6 +108,23 @@
    1.19          string[] logicalDrives = smart.GetLogicalDrives(driveIndex);
    1.20          if (logicalDrives == null || logicalDrives.Length == 0)
    1.21            return null;
    1.22 +
    1.23 +        bool hasNonZeroSizeDrive = false;
    1.24 +        foreach (string logicalDrive in logicalDrives) {
    1.25 +          try {
    1.26 +            DriveInfo di = new DriveInfo(logicalDrive);
    1.27 +            if (di.TotalSize > 0) {
    1.28 +              hasNonZeroSizeDrive = true;
    1.29 +              break;
    1.30 +            }
    1.31 +          } catch (ArgumentException) { 
    1.32 +          } catch (IOException) { 
    1.33 +          } catch (UnauthorizedAccessException) {
    1.34 +          }
    1.35 +        }
    1.36 +
    1.37 +        if (!hasNonZeroSizeDrive)
    1.38 +          return null;
    1.39        }
    1.40  
    1.41        if (string.IsNullOrEmpty(name))