From 8273ecf0c22876f0f4e9dfa9eb29b9d491614faa Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 7 Jan 2021 23:11:24 -0800 Subject: Refactor --- grapher/Models/Devices/DeviceIDManager.cs | 90 +++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 grapher/Models/Devices/DeviceIDManager.cs (limited to 'grapher/Models/Devices/DeviceIDManager.cs') diff --git a/grapher/Models/Devices/DeviceIDManager.cs b/grapher/Models/Devices/DeviceIDManager.cs new file mode 100644 index 0000000..00e7f9d --- /dev/null +++ b/grapher/Models/Devices/DeviceIDManager.cs @@ -0,0 +1,90 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Management; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher.Models.Devices +{ + public class DeviceIDManager + { + public DeviceIDManager(ToolStripMenuItem deviceIDs) + { + DeviceIDsMenuItem = deviceIDs; + } + + public ToolStripMenuItem DeviceIDsMenuItem { get; } + + public string HWID { get => SelectedDeviceID.HWID; } + + public DeviceIDItem SelectedDeviceID { get; private set; } + + public Dictionary DeviceIDs { get; private set; } + + public static IEnumerable<(string, string)> GetDeviceHardwareIDs(string PNPClass = "Mouse") + { + ManagementObjectSearcher searcher = new ManagementObjectSearcher(new SelectQuery("Win32_PnPEntity")); + + foreach (ManagementObject obj in searcher.Get()) + { + if (obj["PNPClass"] != null && obj["PNPClass"].ToString().Equals(PNPClass) && obj["HardwareID"] != null) + { + string[] hwidArray = (string[])(obj["HardwareID"]); + if (hwidArray.Length > 0) + { + string hwid = hwidArray[0].ToString(); + string name = obj["Name"].ToString(); + yield return (name, hwid); + } + } + } + } + + public void SetActive(DeviceIDItem deviceIDItem) + { + if (SelectedDeviceID != null) + { + SelectedDeviceID.SetDeactivated(); + } + + SelectedDeviceID = deviceIDItem; + SelectedDeviceID.SetActivated(); + } + + public void OnStartup(string hwid) + { + var nonEmptyHwid = !string.IsNullOrWhiteSpace(hwid); + + DeviceIDsMenuItem.Checked = nonEmptyHwid; + DeviceIDsMenuItem.DropDownItems.Clear(); + var anyDevice = new DeviceIDItem("Any", string.Empty, this); + if (!nonEmptyHwid) + { + SetActive(anyDevice); + } + + bool found = false; + + foreach (var device in GetDeviceHardwareIDs()) + { + var deviceItem = new DeviceIDItem(device.Item1, device.Item2, this); + if (deviceItem.HWID.Equals(hwid)) + { + found = true; + deviceItem.SetActivated(); + SelectedDeviceID = deviceItem; + } + } + + if (nonEmptyHwid && !found) + { + var deviceItem = new DeviceIDItem(string.Empty, hwid, this); + deviceItem.SetDisconnected(); + } + } + + } +} -- cgit v1.2.3 From 0fc716f6529c97aa77a53762785603158dc680ac Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 7 Jan 2021 23:16:45 -0800 Subject: Small behavior improvements --- grapher/Models/Devices/DeviceIDManager.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'grapher/Models/Devices/DeviceIDManager.cs') diff --git a/grapher/Models/Devices/DeviceIDManager.cs b/grapher/Models/Devices/DeviceIDManager.cs index 00e7f9d..d0a90a2 100644 --- a/grapher/Models/Devices/DeviceIDManager.cs +++ b/grapher/Models/Devices/DeviceIDManager.cs @@ -14,6 +14,7 @@ namespace grapher.Models.Devices public DeviceIDManager(ToolStripMenuItem deviceIDs) { DeviceIDsMenuItem = deviceIDs; + DeviceIDsMenuItem.Checked = false; } public ToolStripMenuItem DeviceIDsMenuItem { get; } @@ -58,7 +59,6 @@ namespace grapher.Models.Devices { var nonEmptyHwid = !string.IsNullOrWhiteSpace(hwid); - DeviceIDsMenuItem.Checked = nonEmptyHwid; DeviceIDsMenuItem.DropDownItems.Clear(); var anyDevice = new DeviceIDItem("Any", string.Empty, this); if (!nonEmptyHwid) @@ -83,6 +83,7 @@ namespace grapher.Models.Devices { var deviceItem = new DeviceIDItem(string.Empty, hwid, this); deviceItem.SetDisconnected(); + anyDevice.SetActivated(); } } -- cgit v1.2.3 From 0e60e22b73dd0693b349cbb63cf9a390c01fd5dd Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Tue, 12 Jan 2021 17:01:18 -0500 Subject: filter raw input based on id use device id (from device instance) over first hardware id use buffered method for all ioctls update gui/DeviceIDManager to match driver behavior respond to device change events desync MouseData and PointData accessors --- grapher/Models/Devices/DeviceIDManager.cs | 45 ++++++++++++++----------------- 1 file changed, 20 insertions(+), 25 deletions(-) (limited to 'grapher/Models/Devices/DeviceIDManager.cs') diff --git a/grapher/Models/Devices/DeviceIDManager.cs b/grapher/Models/Devices/DeviceIDManager.cs index d0a90a2..c50cda8 100644 --- a/grapher/Models/Devices/DeviceIDManager.cs +++ b/grapher/Models/Devices/DeviceIDManager.cs @@ -19,27 +19,26 @@ namespace grapher.Models.Devices public ToolStripMenuItem DeviceIDsMenuItem { get; } - public string HWID { get => SelectedDeviceID.HWID; } + public string ID { get => SelectedDeviceID.ID; } public DeviceIDItem SelectedDeviceID { get; private set; } public Dictionary DeviceIDs { get; private set; } - public static IEnumerable<(string, string)> GetDeviceHardwareIDs(string PNPClass = "Mouse") + public static IEnumerable<(string, string)> GetDeviceIDs(string PNPClass = "Mouse") { ManagementObjectSearcher searcher = new ManagementObjectSearcher(new SelectQuery("Win32_PnPEntity")); foreach (ManagementObject obj in searcher.Get()) { - if (obj["PNPClass"] != null && obj["PNPClass"].ToString().Equals(PNPClass) && obj["HardwareID"] != null) + if (obj["PNPClass"] != null && obj["PNPClass"].ToString().Equals(PNPClass) && obj["DeviceID"] != null) { - string[] hwidArray = (string[])(obj["HardwareID"]); - if (hwidArray.Length > 0) - { - string hwid = hwidArray[0].ToString(); - string name = obj["Name"].ToString(); - yield return (name, hwid); - } + string name = obj["Name"].ToString(); + + string devInstanceID = obj["DeviceID"].ToString(); + string devID = devInstanceID.Remove(devInstanceID.LastIndexOf('\\')); + + yield return (name, devID); } } } @@ -55,35 +54,31 @@ namespace grapher.Models.Devices SelectedDeviceID.SetActivated(); } - public void OnStartup(string hwid) + public void Update(string devID) { - var nonEmptyHwid = !string.IsNullOrWhiteSpace(hwid); - DeviceIDsMenuItem.DropDownItems.Clear(); + + bool found = string.IsNullOrEmpty(devID); + var anyDevice = new DeviceIDItem("Any", string.Empty, this); - if (!nonEmptyHwid) - { - SetActive(anyDevice); - } - bool found = false; + if (found) SetActive(anyDevice); - foreach (var device in GetDeviceHardwareIDs()) + foreach (var device in GetDeviceIDs().Distinct()) { var deviceItem = new DeviceIDItem(device.Item1, device.Item2, this); - if (deviceItem.HWID.Equals(hwid)) + if (!found && deviceItem.ID.Equals(devID)) { + SetActive(deviceItem); found = true; - deviceItem.SetActivated(); - SelectedDeviceID = deviceItem; } } - if (nonEmptyHwid && !found) + if (!found) { - var deviceItem = new DeviceIDItem(string.Empty, hwid, this); + var deviceItem = new DeviceIDItem(string.Empty, devID, this); deviceItem.SetDisconnected(); - anyDevice.SetActivated(); + SetActive(deviceItem); } } -- cgit v1.2.3