Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Improve USB device hardware ID triplet collection #476

Merged
merged 2 commits into from
May 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[Windows] Improve USB device hardware ID triplet collection
fauxpark committed May 12, 2024
commit ea74214b017cc91dc21020275cc31eca79eb55ab
15 changes: 11 additions & 4 deletions windows/QMK Toolbox/Usb/UsbDevice.cs
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ public UsbDevice(ManagementBaseObject d)
ManufacturerString = (string)WmiDevice.GetPropertyValue("Manufacturer");
ProductString = (string)WmiDevice.GetPropertyValue("Name");

var hardwareIdTriplet = HardwareIdTripletRegex.Match(GetHardwareId(WmiDevice));
var hardwareIdTriplet = GetHardwareId(WmiDevice);
VendorId = Convert.ToUInt16(hardwareIdTriplet.Groups[1].ToString(), 16);
ProductId = Convert.ToUInt16(hardwareIdTriplet.Groups[2].ToString(), 16);
RevisionBcd = Convert.ToUInt16(hardwareIdTriplet.Groups[3].ToString(), 16);
@@ -42,12 +42,19 @@ public override string ToString()
return $"{ManufacturerString} {ProductString} ({VendorId:X4}:{ProductId:X4}:{RevisionBcd:X4})";
}

private static string GetHardwareId(ManagementBaseObject d)
private static Match GetHardwareId(ManagementBaseObject d)
{
var hardwareIds = (string[])d.GetPropertyValue("HardwareID");
if (hardwareIds != null && hardwareIds.Length > 0)
if (hardwareIds != null)
{
return hardwareIds[0];
foreach (string hardwareId in hardwareIds)
{
Match match = HardwareIdTripletRegex.Match(hardwareId);
if (match.Success)
{
return match;
}
}
}

return null;