protected AbstractHarddrive(ISmart smart, string name, string firmwareRevision, int index, IEnumerable<SmartAttribute> smartAttributes, ISettings settings) : base(name, new Identifier("hdd", index.ToString(CultureInfo.InvariantCulture)), settings) { this.firmwareRevision = firmwareRevision; this.smart = smart; handle = smart.OpenDrive(index); if (handle != smart.InvalidHandle) smart.EnableSmart(handle, index); this.index = index; this.count = 0; this.smartAttributes = new List<SmartAttribute>(smartAttributes); string[] logicalDrives = smart.GetLogicalDrives(index); List<DriveInfo> driveInfoList = new List<DriveInfo>(logicalDrives.Length); foreach (string logicalDrive in logicalDrives) { try { DriveInfo di = new DriveInfo(logicalDrive); if (di.TotalSize > 0) driveInfoList.Add(new DriveInfo(logicalDrive)); } catch (ArgumentException) { } catch (IOException) { } } driveInfos = driveInfoList.ToArray(); CreateSensors(); }
protected AbstractHarddrive(ISmart smart, string name, string firmwareRevision, int index, IEnumerable<SmartAttribute> smartAttributes, ISettings settings) : base(name, new Identifier("hdd", index.ToString(CultureInfo.InvariantCulture)), settings) { this.firmwareRevision = firmwareRevision; this.smart = smart; handle = smart.OpenDrive(index); smart.EnableSmart(handle, index); this.index = index; this.count = 0; this.smartAttributes = new List<SmartAttribute>(smartAttributes); CreateSensors(); }
protected AbstractHarddrive(ISmart smart, string name, string firmwareRevision, int index, IEnumerable <SmartAttribute> smartAttributes, ISettings settings) : base(name, new Identifier("hdd", index.ToString(CultureInfo.InvariantCulture)), settings) { this.firmwareRevision = firmwareRevision; this.smart = smart; handle = smart.OpenDrive(index); if (handle != smart.InvalidHandle) { smart.EnableSmart(handle, index); } this.index = index; this.count = 0; this.smartAttributes = new List <SmartAttribute>(smartAttributes); string[] logicalDrives = smart.GetLogicalDrives(index); List <DriveInfo> driveInfoList = new List <DriveInfo>(logicalDrives.Length); foreach (string logicalDrive in logicalDrives) { try { DriveInfo di = new DriveInfo(logicalDrive); if (di.TotalSize > 0) { driveInfoList.Add(new DriveInfo(logicalDrive)); } } catch (ArgumentException) { } catch (IOException) { } catch (UnauthorizedAccessException) { } } driveInfos = driveInfoList.ToArray(); CreateSensors(); }
internal HardDrive(ISmart smart, string name, string firmwareRevision, int index, IEnumerable <SmartAttribute> smartAttributes) : base(name, $"hdd/{index}") { this.FirmwareRevision = firmwareRevision; this.smart = smart; handle = smart.OpenDrive(index); if (handle != smart.InvalidHandle) { smart.EnableSmart(handle, index); } this.index = index; count = 0; this.SmartAttributes = new List <SmartAttribute>(smartAttributes); var logicalDrives = smart.GetLogicalDrives(index); var driveInfoList = new List <DriveInfo>(logicalDrives.Length); foreach (var logicalDrive in logicalDrives) { try { var di = new DriveInfo(logicalDrive); if (di.TotalSize > 0) { driveInfoList.Add(new DriveInfo(logicalDrive)); } } catch (ArgumentException) { } }
public static AbstractHarddrive CreateInstance(ISmart smart, int driveIndex, ISettings settings) { IntPtr deviceHandle = smart.OpenDrive(driveIndex); string name = null; string firmwareRevision = null; DriveAttributeValue[] values = { }; if (deviceHandle != smart.InvalidHandle) { bool nameValid = smart.ReadNameAndFirmwareRevision(deviceHandle, driveIndex, out name, out firmwareRevision); bool smartEnabled = smart.EnableSmart(deviceHandle, driveIndex); if (smartEnabled) values = smart.ReadSmartData(deviceHandle, driveIndex); smart.CloseHandle(deviceHandle); if (!nameValid) { name = null; firmwareRevision = null; } } else { string[] logicalDrives = smart.GetLogicalDrives(driveIndex); if (logicalDrives == null || logicalDrives.Length == 0) return null; } if (string.IsNullOrEmpty(name)) name = "Generic Hard Disk"; if (string.IsNullOrEmpty(firmwareRevision)) firmwareRevision = "Unknown"; foreach (Type type in hddTypes) { // get the array of name prefixes for the current type NamePrefixAttribute[] namePrefixes = type.GetCustomAttributes( typeof(NamePrefixAttribute), true) as NamePrefixAttribute[]; // get the array of the required SMART attributes for the current type RequireSmartAttribute[] requiredAttributes = type.GetCustomAttributes( typeof(RequireSmartAttribute), true) as RequireSmartAttribute[]; // check if all required attributes are present bool allRequiredAttributesFound = true; foreach (var requireAttribute in requiredAttributes) { bool adttributeFound = false; foreach (DriveAttributeValue value in values) { if (value.Identifier == requireAttribute.AttributeId) { adttributeFound = true; break; } } if (!adttributeFound) { allRequiredAttributesFound = false; break; } } // if an attribute is missing, then try the next type if (!allRequiredAttributesFound) continue; // check if there is a matching name prefix for this type foreach (NamePrefixAttribute prefix in namePrefixes) { if (name.StartsWith(prefix.Prefix, StringComparison.InvariantCulture)) return Activator.CreateInstance(type, smart, name, firmwareRevision, driveIndex, settings) as AbstractHarddrive; } } // no matching type has been found return null; }
public static AbstractHarddrive CreateInstance(ISmart smart, int driveIndex, ISettings settings) { IntPtr deviceHandle = smart.OpenDrive(driveIndex); string name = null; string firmwareRevision = null; DriveAttributeValue[] values = { }; if (deviceHandle != smart.InvalidHandle) { bool nameValid = smart.ReadNameAndFirmwareRevision(deviceHandle, driveIndex, out name, out firmwareRevision); bool smartEnabled = smart.EnableSmart(deviceHandle, driveIndex); if (smartEnabled) { values = smart.ReadSmartData(deviceHandle, driveIndex); } smart.CloseHandle(deviceHandle); if (!nameValid) { name = null; firmwareRevision = null; } } else { string[] logicalDrives = smart.GetLogicalDrives(driveIndex); if (logicalDrives == null || logicalDrives.Length == 0) { return(null); } } if (string.IsNullOrEmpty(name)) { name = "Generic Hard Disk"; } if (string.IsNullOrEmpty(firmwareRevision)) { firmwareRevision = "Unknown"; } foreach (Type type in hddTypes) { // get the array of name prefixes for the current type NamePrefixAttribute[] namePrefixes = type.GetCustomAttributes( typeof(NamePrefixAttribute), true) as NamePrefixAttribute[]; // get the array of the required SMART attributes for the current type RequireSmartAttribute[] requiredAttributes = type.GetCustomAttributes( typeof(RequireSmartAttribute), true) as RequireSmartAttribute[]; // check if all required attributes are present bool allRequiredAttributesFound = true; foreach (var requireAttribute in requiredAttributes) { bool adttributeFound = false; foreach (DriveAttributeValue value in values) { if (value.Identifier == requireAttribute.AttributeId) { adttributeFound = true; break; } } if (!adttributeFound) { allRequiredAttributesFound = false; break; } } // if an attribute is missing, then try the next type if (!allRequiredAttributesFound) { continue; } // check if there is a matching name prefix for this type foreach (NamePrefixAttribute prefix in namePrefixes) { if (name.StartsWith(prefix.Prefix, StringComparison.InvariantCulture)) { return(Activator.CreateInstance(type, smart, name, firmwareRevision, driveIndex, settings) as AbstractHarddrive); } } } // no matching type has been found return(null); }