public HDDGroup(ISettings settings) { int p = (int)Environment.OSVersion.Platform; if (p == 4 || p == 128) { return; } for (int drive = 0; drive < MAX_DRIVES; drive++) { IntPtr handle = SMART.OpenPhysicalDrive(drive); if (handle == SMART.INVALID_HANDLE_VALUE) { continue; } if (!SMART.EnableSmart(handle, drive)) { SMART.CloseHandle(handle); continue; } string name = SMART.ReadName(handle, drive); if (name == null) { SMART.CloseHandle(handle); continue; } List <SMART.DriveAttribute> attributes = new List <SMART.DriveAttribute>(SMART.ReadSmart(handle, drive)); if (!(attributes.Count > 0)) { SMART.CloseHandle(handle); continue; } SMART.SSDLifeID ssdLifeID = GetSSDLifeID(attributes); if (ssdLifeID == SMART.SSDLifeID.None) { SMART.AttributeID temperatureID = GetTemperatureIndex(attributes); if (temperatureID != 0x00) { hardware.Add(new HDD(name, handle, drive, temperatureID, settings)); continue; } } else { hardware.Add(new HDD(name, handle, drive, ssdLifeID, settings)); continue; } SMART.CloseHandle(handle); } }
public HDDGroup() { int p = (int)System.Environment.OSVersion.Platform; if ((p != 4) && (p != 128)) { for (int drive = 0; drive < MAX_DRIVES; drive++) { IntPtr handle = SMART.OpenPhysicalDrive(drive); if (handle == SMART.INVALID_HANDLE_VALUE) { continue; } if (SMART.EnableSmart(handle, drive)) { string name = SMART.ReadName(handle, drive); if (name != null) { SMART.DriveAttribute[] attributes = SMART.ReadSmart(handle, drive); if (attributes == null) { continue; } int attribute = -1; for (int i = 0; i < attributes.Length; i++) { if (attributes[i].ID == SMART.AttributeID.Temperature) { attribute = i; break; } } if (attribute >= 0) { hardware.Add(new HDD(name, handle, drive, attribute)); continue; } } } SMART.CloseHandle(handle); } } }
public HDDGroup(ISettings settings) { int p = (int)Environment.OSVersion.Platform; if (p == 4 || p == 128) { return; } for (int drive = 0; drive < MAX_DRIVES; drive++) { IntPtr handle = SMART.OpenPhysicalDrive(drive); if (handle == SMART.INVALID_HANDLE_VALUE) { continue; } if (!SMART.EnableSmart(handle, drive)) { SMART.CloseHandle(handle); continue; } string name = SMART.ReadName(handle, drive); if (name == null) { SMART.CloseHandle(handle); continue; } SMART.DriveAttribute[] attributes = SMART.ReadSmart(handle, drive); if (attributes == null) { SMART.CloseHandle(handle); continue; } int attribute = -1; // search for the Temperature attribute for (int i = 0; i < attributes.Length; i++) { if (attributes[i].ID == SMART.AttributeID.Temperature) { attribute = i; break; } } // if no temperature attribute is found, search for DriveTemperature if (attribute == -1) { for (int i = 0; i < attributes.Length; i++) { if (attributes[i].ID == SMART.AttributeID.DriveTemperature) { attribute = i; break; } } } // if no temperature attribute is found, search for AirflowTemperature if (attribute == -1) { for (int i = 0; i < attributes.Length; i++) { if (attributes[i].ID == SMART.AttributeID.AirflowTemperature) { attribute = i; break; } } } if (attribute >= 0) { hardware.Add(new HDD(name, handle, drive, attribute, settings)); continue; } SMART.CloseHandle(handle); } }
public string GetReport() { int p = (int)Environment.OSVersion.Platform; if (p == 4 || p == 128) { return(null); } StringBuilder r = new StringBuilder(); r.AppendLine("S.M.A.R.T Data"); r.AppendLine(); for (int drive = 0; drive < MAX_DRIVES; drive++) { IntPtr handle = SMART.OpenPhysicalDrive(drive); if (handle == SMART.INVALID_HANDLE_VALUE) { continue; } if (!SMART.EnableSmart(handle, drive)) { SMART.CloseHandle(handle); continue; } string name = SMART.ReadName(handle, drive); if (name == null) { SMART.CloseHandle(handle); continue; } SMART.DriveAttribute[] attributes = SMART.ReadSmart(handle, drive); if (attributes != null) { r.AppendLine("Drive name: " + name); r.AppendLine(); r.AppendFormat(CultureInfo.InvariantCulture, " {0}{1}{2}{3}{4}{5}", ("ID").PadRight(6), ("RawValue").PadRight(20), ("WorstValue").PadRight(12), ("AttrValue").PadRight(12), ("Name"), Environment.NewLine); foreach (SMART.DriveAttribute a in attributes) { if (a.ID == 0) { continue; } string raw = BitConverter.ToString(a.RawValue); r.AppendFormat(CultureInfo.InvariantCulture, " {0}{1}{2}{3}{4}{5}", a.ID.ToString("d").PadRight(6), raw.Replace("-", " ").PadRight(20), a.WorstValue.ToString(CultureInfo.InvariantCulture).PadRight(12), a.AttrValue.ToString(CultureInfo.InvariantCulture).PadRight(12), a.ID, Environment.NewLine); } r.AppendLine(); } SMART.CloseHandle(handle); } return(r.ToString()); }