Hardware/HDD/HDDGroup.cs
changeset 205 a38b51ef489c
parent 204 59278dadc5c0
child 218 194186efdde9
     1.1 --- a/Hardware/HDD/HDDGroup.cs	Sat Oct 02 14:39:25 2010 +0000
     1.2 +++ b/Hardware/HDD/HDDGroup.cs	Sat Oct 02 15:46:12 2010 +0000
     1.3 @@ -37,6 +37,7 @@
     1.4  
     1.5  using System;
     1.6  using System.Collections.Generic;
     1.7 +using System.Globalization;
     1.8  using System.Text;
     1.9  
    1.10  namespace OpenHardwareMonitor.Hardware.HDD {
    1.11 @@ -46,8 +47,6 @@
    1.12  
    1.13      private readonly List<HDD> hardware = new List<HDD>();
    1.14  
    1.15 -    private readonly Dictionary<string, SMART.DriveAttribute[]> ignoredDrives = new Dictionary<string, SMART.DriveAttribute[]>();
    1.16 -
    1.17      public HDDGroup(ISettings settings) {
    1.18        int p = (int)Environment.OSVersion.Platform;
    1.19        if (p == 4 || p == 128) return;
    1.20 @@ -70,26 +69,39 @@
    1.21          }
    1.22  
    1.23          SMART.DriveAttribute[] attributes = SMART.ReadSmart(handle, drive);
    1.24 +        if (attributes == null) {
    1.25 +          SMART.CloseHandle(handle);
    1.26 +          continue;
    1.27 +        }
    1.28  
    1.29 -        if (attributes != null) {
    1.30 -          int attribute = -1;
    1.31 +        int attribute = -1;
    1.32  
    1.33 -          int i = 0;
    1.34 -          foreach (SMART.DriveAttribute attr in attributes) {
    1.35 -            if (attr.ID == SMART.AttributeID.Temperature
    1.36 -                || attr.ID == SMART.AttributeID.DriveTemperature
    1.37 -                || attr.ID == SMART.AttributeID.AirflowTemperature) {
    1.38 +        // search for the Temperature attribute
    1.39 +        for (int i = 0; i < attributes.Length; i++)
    1.40 +          if (attributes[i].ID == SMART.AttributeID.Temperature) {
    1.41 +            attribute = i;
    1.42 +            break;
    1.43 +          }
    1.44 +
    1.45 +        // if no temperature attribute is found, search for DriveTemperature
    1.46 +        if (attribute == -1)
    1.47 +          for (int i = 0; i < attributes.Length; i++)
    1.48 +            if (attributes[i].ID == SMART.AttributeID.DriveTemperature) {
    1.49                attribute = i;
    1.50                break;
    1.51              }
    1.52 -            i++;
    1.53 -          }
    1.54  
    1.55 -          if (attribute >= 0)
    1.56 -          {
    1.57 -            hardware.Add(new HDD(name, handle, drive, attribute, settings));
    1.58 -            continue;
    1.59 -          }
    1.60 +        // if no temperature attribute is found, search for AirflowTemperature
    1.61 +        if (attribute == -1)
    1.62 +          for (int i = 0; i < attributes.Length; i++)
    1.63 +            if (attributes[i].ID == SMART.AttributeID.AirflowTemperature) {
    1.64 +              attribute = i;
    1.65 +              break;
    1.66 +            }
    1.67 +
    1.68 +        if (attribute >= 0) {
    1.69 +          hardware.Add(new HDD(name, handle, drive, attribute, settings));
    1.70 +          continue;
    1.71          }
    1.72  
    1.73          SMART.CloseHandle(handle);
    1.74 @@ -133,25 +145,24 @@
    1.75          if (attributes != null) {
    1.76            r.AppendLine("Drive name: " + name);
    1.77            r.AppendLine();
    1.78 -          r.AppendFormat(" {0}{1}{2}{3}{4}{5}",
    1.79 -                          ("ID").PadRight(6),
    1.80 -                          ("RawValue").PadRight(20),
    1.81 -                          ("WorstValue").PadRight(12),
    1.82 -                          ("AttrValue").PadRight(12),
    1.83 -                          ("Name"),
    1.84 -                          Environment.NewLine);
    1.85 +          r.AppendFormat(CultureInfo.InvariantCulture, " {0}{1}{2}{3}{4}{5}",
    1.86 +            ("ID").PadRight(6),
    1.87 +            ("RawValue").PadRight(20),
    1.88 +            ("WorstValue").PadRight(12),
    1.89 +            ("AttrValue").PadRight(12),
    1.90 +            ("Name"),
    1.91 +            Environment.NewLine);
    1.92  
    1.93 -          foreach (SMART.DriveAttribute attr in attributes) {
    1.94 -            if (attr.ID == 0) continue;
    1.95 -            string raw = BitConverter.ToString(attr.RawValue);
    1.96 -            r.AppendFormat(" {0}{1}{2}{3}{4}{5}",
    1.97 -                           attr.ID.ToString("d").PadRight(6), 
    1.98 -                           raw.Replace("-", " ").PadRight(20),
    1.99 -                           attr.WorstValue.ToString().PadRight(12),
   1.100 -                           attr.AttrValue.ToString().PadRight(12),
   1.101 -                           attr.ID,
   1.102 -                           Environment.NewLine)
   1.103 -              ;
   1.104 +          foreach (SMART.DriveAttribute a in attributes) {
   1.105 +            if (a.ID == 0) continue;
   1.106 +            string raw = BitConverter.ToString(a.RawValue);
   1.107 +            r.AppendFormat(CultureInfo.InvariantCulture, " {0}{1}{2}{3}{4}{5}",
   1.108 +              a.ID.ToString("d").PadRight(6), 
   1.109 +              raw.Replace("-", " ").PadRight(20),
   1.110 +              a.WorstValue.ToString(CultureInfo.InvariantCulture).PadRight(12),
   1.111 +              a.AttrValue.ToString(CultureInfo.InvariantCulture).PadRight(12),
   1.112 +              a.ID,
   1.113 +              Environment.NewLine);
   1.114            }
   1.115            r.AppendLine();
   1.116          }