Update DiskInfoToolkit (#2328)

* Update DiskInfoToolkit.
Add trace to report.

* Adjust identifier to also support scsi identification.
This commit is contained in:
Blacktempel
2026-04-20 20:03:51 +02:00
committed by GitHub
parent 035a878e20
commit d7473cc8cc
3 changed files with 57 additions and 37 deletions
@@ -7,12 +7,12 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using BlackSharp.Core.Converters;
using BlackSharp.Core.Converters.Enums;
using DiskInfoToolkit;
using DiskInfoToolkit.Smart;
using Windows.Win32;
using Windows.Win32.Foundation;
@@ -49,8 +49,8 @@ public sealed class StorageDevice : Hardware, ISmart
private Sensor _usageSensor;
private Sensor _freeSpaceSensor;
public StorageDevice(StorageDeviceDIT storage, string id, ISettings settings)
: base(storage.ProductName, new Identifier(id, storage.StorageDeviceNumber.GetValueOrDefault().ToString(CultureInfo.InvariantCulture)), settings)
public StorageDevice(StorageDeviceDIT storage, ISettings settings)
: base(storage.ProductName, GetIdentifier(storage), settings)
{
_storage = storage;
@@ -202,6 +202,7 @@ public sealed class StorageDevice : Hardware, ISmart
}
r.AppendLine($"Total Size: {_storage.DiskSizeBytes}");
_storage.ProbeTrace.ForEach(line => r.AppendLine($"Probe Trace: {line}"));
return r.ToString();
}
@@ -212,6 +213,56 @@ public sealed class StorageDevice : Hardware, ISmart
sensor.Accept(visitor);
}
private static string GetID(StorageDeviceDIT disk)
{
switch (disk.TransportKind)
{
case StorageTransportKind.Ata:
return "ata";
case StorageTransportKind.Scsi:
return "scsi";
case StorageTransportKind.Nvme:
return "nvme";
case StorageTransportKind.Usb:
return "usb";
case StorageTransportKind.Sd:
return "sd";
case StorageTransportKind.Mmc:
return "mmc";
case StorageTransportKind.Raid:
return "raid";
case StorageTransportKind.Sas:
return "sas";
case StorageTransportKind.Ahci:
return "ahci";
case StorageTransportKind.Virtual:
return "virtual";
case StorageTransportKind.Unknown:
default:
return "disk";
}
}
private static Identifier GetIdentifier(StorageDeviceDIT storage)
{
string id;
if (storage.StorageDeviceNumber.HasValue)
{
id = storage.StorageDeviceNumber.Value.ToString();
}
else if (storage.Scsi.PathID.HasValue && storage.Scsi.TargetID.HasValue)
{
id = $"{storage.Scsi.PathID}::{storage.Scsi.TargetID}";
}
else
{
id = "id_error";
}
return new Identifier(GetID(storage), id);
}
private void CreateAttributes()
{
_attributes.Clear();
@@ -7,7 +7,6 @@
using System.Collections.Generic;
using System.Linq;
using DiskInfoToolkit;
using StorageDeviceDIT = DiskInfoToolkit.StorageDevice;
using StorageDIT = DiskInfoToolkit.Storage;
namespace LibreHardwareMonitor.Hardware.Storage;
@@ -41,7 +40,7 @@ internal class StorageGroup : IGroup, IHardwareChanged
var disks = StorageDIT.GetDisks();
//Transform storage device to hardware
_hardware.AddRange(disks.Select(s => new StorageDevice(s, GetID(s), settings)));
_hardware.AddRange(disks.Select(s => new StorageDevice(s, settings)));
StorageDIT.DevicesChanged += OnStoragesChanged;
}
@@ -50,7 +49,7 @@ internal class StorageGroup : IGroup, IHardwareChanged
{
foreach (var added in e.Added)
{
var storageDevice = new StorageDevice(added, GetID(added), _settings);
var storageDevice = new StorageDevice(added, _settings);
_hardware.Add(storageDevice);
HardwareAdded?.Invoke(storageDevice);
@@ -67,36 +66,6 @@ internal class StorageGroup : IGroup, IHardwareChanged
}
}
private string GetID(StorageDeviceDIT disk)
{
switch (disk.TransportKind)
{
case StorageTransportKind.Ata:
return "ata";
case StorageTransportKind.Scsi:
return "scsi";
case StorageTransportKind.Nvme:
return "nvme";
case StorageTransportKind.Usb:
return "usb";
case StorageTransportKind.Sd:
return "sd";
case StorageTransportKind.Mmc:
return "mmc";
case StorageTransportKind.Raid:
return "raid";
case StorageTransportKind.Sas:
return "sas";
case StorageTransportKind.Ahci:
return "ahci";
case StorageTransportKind.Virtual:
return "virtual";
case StorageTransportKind.Unknown:
default:
return "disk";
}
}
public void Close() { }
public string GetReport() => null;
@@ -81,7 +81,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="DiskInfoToolkit" Version="2.0.2" />
<PackageReference Include="DiskInfoToolkit" Version="2.0.3" />
<PackageReference Include="HidSharp" Version="2.6.4" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.275">
<PrivateAssets>all</PrivateAssets>