1.1 --- a/Hardware/HDD/AbstractHarddrive.cs Wed Jul 18 22:47:30 2012 +0000
1.2 +++ b/Hardware/HDD/AbstractHarddrive.cs Sun Jul 22 18:07:11 2012 +0000
1.3 @@ -13,6 +13,7 @@
1.4 using System;
1.5 using System.Collections.Generic;
1.6 using System.Globalization;
1.7 +using System.IO;
1.8 using System.Text;
1.9 using OpenHardwareMonitor.Collections;
1.10
1.11 @@ -42,6 +43,9 @@
1.12 private IList<SmartAttribute> smartAttributes;
1.13 private IDictionary<SmartAttribute, Sensor> sensors;
1.14
1.15 + private DriveInfo[] driveInfos;
1.16 + private Sensor usageSensor;
1.17 +
1.18 protected AbstractHarddrive(ISmart smart, string name,
1.19 string firmwareRevision, int index,
1.20 IEnumerable<SmartAttribute> smartAttributes, ISettings settings)
1.21 @@ -59,6 +63,17 @@
1.22
1.23 this.smartAttributes = new List<SmartAttribute>(smartAttributes);
1.24
1.25 + string[] logicalDrives = smart.GetLogicalDrives(index);
1.26 + List<DriveInfo> driveInfoList = new List<DriveInfo>(logicalDrives.Length);
1.27 + foreach (string logicalDrive in logicalDrives) {
1.28 + try {
1.29 + DriveInfo di = new DriveInfo(logicalDrive);
1.30 + if (di.TotalSize > 0)
1.31 + driveInfoList.Add(new DriveInfo(logicalDrive));
1.32 + } catch (ArgumentException) { } catch (IOException) { }
1.33 + }
1.34 + driveInfos = driveInfoList.ToArray();
1.35 +
1.36 CreateSensors();
1.37 }
1.38
1.39 @@ -83,7 +98,7 @@
1.40 smart.CloseHandle(deviceHandle);
1.41
1.42 if (!nameValid || string.IsNullOrEmpty(name))
1.43 - return null;
1.44 + return null;
1.45
1.46 foreach (Type type in hddTypes) {
1.47 // get the array of name prefixes for the current type
1.48 @@ -161,6 +176,12 @@
1.49 sensorTypeAndChannels.Add(pair);
1.50 }
1.51 }
1.52 +
1.53 + if (driveInfos.Length > 0) {
1.54 + usageSensor =
1.55 + new Sensor("Used Space", 0, SensorType.Load, this, settings);
1.56 + ActivateSensor(usageSensor);
1.57 + }
1.58 }
1.59
1.60 public override HardwareType HardwareType {
1.61 @@ -184,6 +205,16 @@
1.62 }
1.63
1.64 UpdateAdditionalSensors(values);
1.65 +
1.66 + if (usageSensor != null) {
1.67 + long totalSize = 0;
1.68 + long totalFreeSpace = 0;
1.69 + for (int i = 0; i < driveInfos.Length; i++) {
1.70 + totalSize += driveInfos[i].TotalSize;
1.71 + totalFreeSpace += driveInfos[i].TotalFreeSpace;
1.72 + }
1.73 + usageSensor.Value = 100.0f - (100.0f * totalFreeSpace) / totalSize;
1.74 + }
1.75 }
1.76
1.77 count++;
1.78 @@ -201,7 +232,7 @@
1.79 r.AppendLine();
1.80 r.AppendLine("Drive name: " + name);
1.81 r.AppendLine("Firmware version: " + firmwareRevision);
1.82 - r.AppendLine();
1.83 + r.AppendLine();
1.84 r.AppendFormat(CultureInfo.InvariantCulture,
1.85 " {0}{1}{2}{3}{4}{5}{6}{7}",
1.86 ("ID").PadRight(3),
1.87 @@ -253,6 +284,14 @@
1.88 r.AppendLine();
1.89 }
1.90
1.91 + foreach (DriveInfo di in driveInfos) {
1.92 + r.AppendLine("Logical drive name: " + di.Name);
1.93 + r.AppendLine("Format: " + di.DriveFormat);
1.94 + r.AppendLine("Total size: " + di.TotalSize);
1.95 + r.AppendLine("Total free space: " + di.TotalFreeSpace);
1.96 + r.AppendLine();
1.97 + }
1.98 +
1.99 return r.ToString();
1.100 }
1.101