Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        public void Update()
        {
            if (count == 0)
            {
                SMART.DriveAttribute[] attributes = SMART.ReadSmart(handle, drive);
                temperature.Value = attributes[attribute].RawValue[0];
            }
            else
            {
                temperature.Value = temperature.Value;
            }

            count++; count %= UPDATE_DIVIDER;
        }
Exemplo n.º 3
0
        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);
                }
            }
        }
Exemplo n.º 4
0
        public override void Update()
        {
            if (count == 0)
            {
                SMART.DriveAttribute[] attributes = SMART.ReadSmart(handle, drive);

                if (temperatureID != SMART.AttributeID.None &&
                    Array.Exists(attributes, attr => attr.ID == temperatureID))
                {
                    temperatureSensor.Value = Array
                                              .Find(attributes, attr => attr.ID == temperatureID)
                                              .RawValue[0];
                }

                if (lifeID != SMART.AttributeID.None &&
                    Array.Exists(attributes, attr => attr.ID == lifeID))
                {
                    lifeSensor.Value = Array
                                       .Find(attributes, attr => attr.ID == lifeID)
                                       .AttrValue;
                }
            }
            else
            {
                if (temperatureID != SMART.AttributeID.None)
                {
                    temperatureSensor.Value = temperatureSensor.Value;
                }

                if (lifeID != SMART.AttributeID.None)
                {
                    lifeSensor.Value = lifeSensor.Value;
                }
            }

            count++; count %= UPDATE_DIVIDER;
        }
Exemplo n.º 5
0
        public void Update()
        {
            if (count == 0)
            {
                List <SMART.DriveAttribute> attributes = SMART.ReadSmart(handle, drive);
                if (temperatureID != 0x00 &&
                    attributes.Exists(attr => (int)attr.ID == (int)temperatureID))
                {
                    temperatureSensor.Value = attributes
                                              .Find(attr => (int)attr.ID == (int)temperatureID)
                                              .RawValue[0];
                }

                if (lifeID != 0x00 &&
                    attributes.Exists(attr => (int)attr.ID == (int)lifeID))
                {
                    lifeSensor.Value = attributes
                                       .Find(attr => (int)attr.ID == (int)temperatureID)
                                       .AttrValue;
                }
            }
            else
            {
                if (temperatureID != 0x00)
                {
                    temperatureSensor.Value = temperatureSensor.Value;
                }

                if (lifeID != 0x00)
                {
                    lifeSensor.Value = lifeSensor.Value;
                }
            }

            count++; count %= UPDATE_DIVIDER;
        }
Exemplo n.º 6
0
        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);
            }
        }
Exemplo n.º 7
0
        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());
        }