mirror of
https://github.com/openhardwaremonitor/openhardwaremonitor
synced 2025-08-30 05:47:38 +00:00
Added used space load sensors for hard drives.
This commit is contained in:
parent
a53679c3ad
commit
5e87af437d
@ -13,6 +13,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using OpenHardwareMonitor.Collections;
|
using OpenHardwareMonitor.Collections;
|
||||||
|
|
||||||
@ -42,6 +43,9 @@ namespace OpenHardwareMonitor.Hardware.HDD {
|
|||||||
private IList<SmartAttribute> smartAttributes;
|
private IList<SmartAttribute> smartAttributes;
|
||||||
private IDictionary<SmartAttribute, Sensor> sensors;
|
private IDictionary<SmartAttribute, Sensor> sensors;
|
||||||
|
|
||||||
|
private DriveInfo[] driveInfos;
|
||||||
|
private Sensor usageSensor;
|
||||||
|
|
||||||
protected AbstractHarddrive(ISmart smart, string name,
|
protected AbstractHarddrive(ISmart smart, string name,
|
||||||
string firmwareRevision, int index,
|
string firmwareRevision, int index,
|
||||||
IEnumerable<SmartAttribute> smartAttributes, ISettings settings)
|
IEnumerable<SmartAttribute> smartAttributes, ISettings settings)
|
||||||
@ -59,6 +63,17 @@ namespace OpenHardwareMonitor.Hardware.HDD {
|
|||||||
|
|
||||||
this.smartAttributes = new List<SmartAttribute>(smartAttributes);
|
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();
|
CreateSensors();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,6 +176,12 @@ namespace OpenHardwareMonitor.Hardware.HDD {
|
|||||||
sensorTypeAndChannels.Add(pair);
|
sensorTypeAndChannels.Add(pair);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (driveInfos.Length > 0) {
|
||||||
|
usageSensor =
|
||||||
|
new Sensor("Used Space", 0, SensorType.Load, this, settings);
|
||||||
|
ActivateSensor(usageSensor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override HardwareType HardwareType {
|
public override HardwareType HardwareType {
|
||||||
@ -184,6 +205,16 @@ namespace OpenHardwareMonitor.Hardware.HDD {
|
|||||||
}
|
}
|
||||||
|
|
||||||
UpdateAdditionalSensors(values);
|
UpdateAdditionalSensors(values);
|
||||||
|
|
||||||
|
if (usageSensor != null) {
|
||||||
|
long totalSize = 0;
|
||||||
|
long totalFreeSpace = 0;
|
||||||
|
for (int i = 0; i < driveInfos.Length; i++) {
|
||||||
|
totalSize += driveInfos[i].TotalSize;
|
||||||
|
totalFreeSpace += driveInfos[i].TotalFreeSpace;
|
||||||
|
}
|
||||||
|
usageSensor.Value = 100.0f - (100.0f * totalFreeSpace) / totalSize;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
count++;
|
count++;
|
||||||
@ -253,6 +284,14 @@ namespace OpenHardwareMonitor.Hardware.HDD {
|
|||||||
r.AppendLine();
|
r.AppendLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (DriveInfo di in driveInfos) {
|
||||||
|
r.AppendLine("Logical drive name: " + di.Name);
|
||||||
|
r.AppendLine("Format: " + di.DriveFormat);
|
||||||
|
r.AppendLine("Total size: " + di.TotalSize);
|
||||||
|
r.AppendLine("Total free space: " + di.TotalFreeSpace);
|
||||||
|
r.AppendLine();
|
||||||
|
}
|
||||||
|
|
||||||
return r.ToString();
|
return r.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,6 +412,10 @@ namespace OpenHardwareMonitor.Hardware.HDD {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public IntPtr InvalidHandle { get { return (IntPtr)(-1); } }
|
public IntPtr InvalidHandle { get { return (IntPtr)(-1); } }
|
||||||
|
|
||||||
|
public string[] GetLogicalDrives(int driveIndex) {
|
||||||
|
return new string[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -30,5 +30,7 @@ namespace OpenHardwareMonitor.Hardware.HDD {
|
|||||||
void CloseHandle(IntPtr handle);
|
void CloseHandle(IntPtr handle);
|
||||||
|
|
||||||
IntPtr InvalidHandle { get; }
|
IntPtr InvalidHandle { get; }
|
||||||
|
|
||||||
|
string[] GetLogicalDrives(int driveIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Management;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace OpenHardwareMonitor.Hardware.HDD {
|
namespace OpenHardwareMonitor.Hardware.HDD {
|
||||||
@ -341,6 +342,23 @@ namespace OpenHardwareMonitor.Hardware.HDD {
|
|||||||
NativeMethods.CloseHandle(handle);
|
NativeMethods.CloseHandle(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string[] GetLogicalDrives(int driveIndex) {
|
||||||
|
List<string> list = new List<string>();
|
||||||
|
try {
|
||||||
|
using (ManagementObjectSearcher s = new ManagementObjectSearcher(
|
||||||
|
"root\\CIMV2",
|
||||||
|
"SELECT * FROM Win32_DiskPartition " +
|
||||||
|
"WHERE DiskIndex = " + driveIndex))
|
||||||
|
using (ManagementObjectCollection dpc = s.Get())
|
||||||
|
foreach (ManagementObject dp in dpc)
|
||||||
|
using (ManagementObjectCollection ldc =
|
||||||
|
dp.GetRelated("Win32_LogicalDisk"))
|
||||||
|
foreach (ManagementBaseObject ld in ldc)
|
||||||
|
list.Add(((string)ld["Name"]).TrimEnd(':'));
|
||||||
|
} catch { }
|
||||||
|
return list.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
protected static class NativeMethods {
|
protected static class NativeMethods {
|
||||||
private const string KERNEL = "kernel32.dll";
|
private const string KERNEL = "kernel32.dll";
|
||||||
|
|
||||||
|
@ -10,5 +10,5 @@
|
|||||||
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
[assembly: AssemblyVersion("0.4.0.20")]
|
[assembly: AssemblyVersion("0.4.0.21")]
|
||||||
[assembly: AssemblyInformationalVersion("0.4.0.20 Alpha")]
|
[assembly: AssemblyInformationalVersion("0.4.0.21 Alpha")]
|
Loading…
x
Reference in New Issue
Block a user