From 215a21f9b62aa50d9ca4037ca0a22f5b0920f373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Pazdiora?= Date: Thu, 7 Jan 2021 23:21:33 +0100 Subject: rough GUI integration of "Device Hardware ID" --- devicelist/App.config | 6 --- devicelist/Program.cs | 37 -------------- devicelist/Properties/AssemblyInfo.cs | 36 -------------- devicelist/devicelist.csproj | 73 ---------------------------- grapher/Form1.Designer.cs | 31 +++++++----- grapher/Form1.cs | 1 + grapher/Models/AccelGUIFactory.cs | 2 + grapher/Models/Devices/DeviceList.cs | 33 +++++++++++++ grapher/Models/Serialized/SettingsManager.cs | 66 +++++++++++++++++++++++++ grapher/grapher.csproj | 2 + rawaccel.sln | 6 --- 11 files changed, 124 insertions(+), 169 deletions(-) delete mode 100644 devicelist/App.config delete mode 100644 devicelist/Program.cs delete mode 100644 devicelist/Properties/AssemblyInfo.cs delete mode 100644 devicelist/devicelist.csproj create mode 100644 grapher/Models/Devices/DeviceList.cs diff --git a/devicelist/App.config b/devicelist/App.config deleted file mode 100644 index 56efbc7..0000000 --- a/devicelist/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/devicelist/Program.cs b/devicelist/Program.cs deleted file mode 100644 index 9323fd4..0000000 --- a/devicelist/Program.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using System.Text; -using System.Management; -using System.Windows.Forms; - -namespace devicelist -{ - class Program - { - static void Main(string[] args) - { - Console.WriteLine("To use Raw Accel driver for a specific device, " - + "replace '\"Device Hardware ID\": null' in 'settings.json' by following:"); - Console.WriteLine(""); - - ManagementObjectSearcher searcher = new ManagementObjectSearcher(new SelectQuery("Win32_PnPEntity")); - - foreach (ManagementObject obj in searcher.Get()) - { - bool is_mouse = obj["PNPClass"] != null && obj["PNPClass"].ToString() == "Mouse"; // == "HIDClass" ??? - - if (is_mouse && obj["HardwareID"] != null) { - String[] hwidArray = (String[])(obj["HardwareID"]); - if (hwidArray.Length > 0) { - String hwid = hwidArray[0].ToString().Replace(@"\", @"\\"); - String name = obj["Name"].ToString(); - Console.WriteLine(name + ":"); - Console.WriteLine("\"Device Hardware ID\": \"" + hwid + "\""); - Console.WriteLine(""); - } - } - } - - Console.ReadKey(); - } - } -} diff --git a/devicelist/Properties/AssemblyInfo.cs b/devicelist/Properties/AssemblyInfo.cs deleted file mode 100644 index 36f0015..0000000 --- a/devicelist/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Raw Accel devicelist")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Raw Accel")] -[assembly: AssemblyCopyright("")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("3666b731-7406-41b1-bcfc-c65073fd09a1")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion(RawAccelVersion.value)] -[assembly: AssemblyFileVersion(RawAccelVersion.value)] diff --git a/devicelist/devicelist.csproj b/devicelist/devicelist.csproj deleted file mode 100644 index 154d0d0..0000000 --- a/devicelist/devicelist.csproj +++ /dev/null @@ -1,73 +0,0 @@ - - - - - Debug - AnyCPU - {3666B731-7406-41B1-BCFC-C65073FD09A1} - Exe - devicelist - devicelist - v4.7.2 - 512 - true - true - - - true - $(SolutionDir)$(Platform)\$(Configuration)\ - DEBUG;TRACE - full - x64 - 7.3 - prompt - MinimumRecommendedRules.ruleset - true - - - $(SolutionDir)$(Platform)\$(Configuration)\ - TRACE - true - pdbonly - x64 - 7.3 - prompt - MinimumRecommendedRules.ruleset - true - - - - - - - - - - - - - - - - - - - - - - - - - - - {28a3656f-a1de-405c-b547-191c32ec555f} - wrapper - - - - - IF ($(ConfigurationName)) == (Debug) GOTO END -copy /Y "$(TargetPath)" "$(SolutionDir)signed\$(TargetFileName)" -:END - - \ No newline at end of file diff --git a/grapher/Form1.Designer.cs b/grapher/Form1.Designer.cs index 6fd9478..c388d79 100644 --- a/grapher/Form1.Designer.cs +++ b/grapher/Form1.Designer.cs @@ -161,6 +161,8 @@ namespace grapher this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.wholeVectorToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.byVectorComponentToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.AutoWriteMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.UseSpecificDeviceMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.chartsPanel = new System.Windows.Forms.Panel(); this.GainChartY = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.VelocityChartY = new System.Windows.Forms.DataVisualization.Charting.Chart(); @@ -168,7 +170,6 @@ namespace grapher this.GainChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.VelocityChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.AccelerationChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); - this.AutoWriteMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.optionsPanel.SuspendLayout(); this.menuStrip1.SuspendLayout(); this.chartsPanel.SuspendLayout(); @@ -956,7 +957,8 @@ namespace grapher this.capStyleToolStripMenuItem, this.offsetStyleToolStripMenuItem, this.toolStripMenuItem1, - this.AutoWriteMenuItem}); + this.AutoWriteMenuItem, + this.UseSpecificDeviceMenuItem}); this.advancedToolStripMenuItem.Name = "advancedToolStripMenuItem"; this.advancedToolStripMenuItem.Size = new System.Drawing.Size(72, 20); this.advancedToolStripMenuItem.Text = "Advanced"; @@ -1029,6 +1031,21 @@ namespace grapher this.byVectorComponentToolStripMenuItem.Size = new System.Drawing.Size(154, 22); this.byVectorComponentToolStripMenuItem.Text = "By Component"; // + // AutoWriteMenuItem + // + this.AutoWriteMenuItem.Checked = true; + this.AutoWriteMenuItem.CheckOnClick = true; + this.AutoWriteMenuItem.CheckState = System.Windows.Forms.CheckState.Checked; + this.AutoWriteMenuItem.Name = "AutoWriteMenuItem"; + this.AutoWriteMenuItem.Size = new System.Drawing.Size(210, 22); + this.AutoWriteMenuItem.Text = "Apply Settings On Startup"; + // + // UseSpecificDeviceMenuItem + // + this.UseSpecificDeviceMenuItem.Name = "UseSpecificDeviceMenuItem"; + this.UseSpecificDeviceMenuItem.Size = new System.Drawing.Size(210, 22); + this.UseSpecificDeviceMenuItem.Text = "Use Specific Device"; + // // chartsPanel // this.chartsPanel.AutoScroll = true; @@ -1281,15 +1298,6 @@ namespace grapher title6.Text = "Sensitivity"; this.AccelerationChart.Titles.Add(title6); // - // AutoWriteMenuItem - // - this.AutoWriteMenuItem.Checked = true; - this.AutoWriteMenuItem.CheckOnClick = true; - this.AutoWriteMenuItem.CheckState = System.Windows.Forms.CheckState.Checked; - this.AutoWriteMenuItem.Name = "AutoWriteMenuItem"; - this.AutoWriteMenuItem.Size = new System.Drawing.Size(210, 22); - this.AutoWriteMenuItem.Text = "Apply Settings On Startup"; - // // RawAcceleration // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -1418,6 +1426,7 @@ namespace grapher private System.Windows.Forms.DataVisualization.Charting.Chart VelocityChart; private System.Windows.Forms.DataVisualization.Charting.Chart AccelerationChart; private System.Windows.Forms.ToolStripMenuItem AutoWriteMenuItem; + private System.Windows.Forms.ToolStripMenuItem UseSpecificDeviceMenuItem; } } diff --git a/grapher/Form1.cs b/grapher/Form1.cs index 0c12b86..e149163 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -71,6 +71,7 @@ namespace grapher gainOffsetToolStripMenuItem, legacyOffsetToolStripMenuItem, AutoWriteMenuItem, + UseSpecificDeviceMenuItem, ScaleMenuItem, DPITextBox, PollRateTextBox, diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index 901a1b5..0e3646d 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -34,6 +34,7 @@ namespace grapher.Models ToolStripMenuItem gainOffsetToolStripMenuItem, ToolStripMenuItem legacyOffsetToolStripMenuItem, ToolStripMenuItem autoWriteMenuItem, + ToolStripMenuItem useSpecificDeviceMenuItem, ToolStripMenuItem scaleMenuItem, ToolStripTextBox dpiTextBox, ToolStripTextBox pollRateTextBox, @@ -329,6 +330,7 @@ namespace grapher.Models accelCalculator.DPI, accelCalculator.PollRate, autoWriteMenuItem, + useSpecificDeviceMenuItem, showLastMouseMoveMenuItem, showVelocityGainToolStripMenuItem); diff --git a/grapher/Models/Devices/DeviceList.cs b/grapher/Models/Devices/DeviceList.cs new file mode 100644 index 0000000..9f2b81d --- /dev/null +++ b/grapher/Models/Devices/DeviceList.cs @@ -0,0 +1,33 @@ +using System; +using System.Management; +using System.Collections.Generic; + +namespace grapher.Models.Devices +{ + class DeviceList + { + public static List> GetDeviceHardwareIDs(string PNPClass = "Mouse") + { + var results = new List>(); + + ManagementObjectSearcher searcher = new ManagementObjectSearcher(new SelectQuery("Win32_PnPEntity")); + + foreach (ManagementObject obj in searcher.Get()) + { + if (obj["PNPClass"] != null && obj["PNPClass"].ToString() == PNPClass && obj["HardwareID"] != null) + { + String[] hwidArray = (String[])(obj["HardwareID"]); + if (hwidArray.Length > 0) + { + String hwid = hwidArray[0].ToString(); + String name = obj["Name"].ToString(); + results.Add(Tuple.Create(name, hwid)); + } + } + } + + return results; + } + + } +} diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index 41ebcb5..3adbc8b 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -3,6 +3,7 @@ using System; using System.Windows.Forms; using System.Threading; using System.Text; +using System.Drawing; namespace grapher.Models.Serialized { @@ -15,6 +16,7 @@ namespace grapher.Models.Serialized Field dpiField, Field pollRateField, ToolStripMenuItem autoWrite, + ToolStripMenuItem useSpecificDevice, ToolStripMenuItem showLastMouseMove, ToolStripMenuItem showVelocityAndGain) { @@ -22,6 +24,7 @@ namespace grapher.Models.Serialized DpiField = dpiField; PollRateField = pollRateField; AutoWriteMenuItem = autoWrite; + UseSpecificDeviceMenuItem = useSpecificDevice; ShowLastMouseMoveMenuItem = showLastMouseMove; ShowVelocityAndGainMoveMenuItem = showVelocityAndGain; } @@ -40,6 +43,8 @@ namespace grapher.Models.Serialized private ToolStripMenuItem AutoWriteMenuItem { get; set; } + private ToolStripMenuItem UseSpecificDeviceMenuItem { get; set; } + private ToolStripMenuItem ShowLastMouseMoveMenuItem { get; set; } private ToolStripMenuItem ShowVelocityAndGainMoveMenuItem { get; set; } @@ -61,6 +66,66 @@ namespace grapher.Models.Serialized return errors; } + private void SpecificDeviceClickHnadler(Object o, EventArgs a, string hwid) + { + var item = (ToolStripMenuItem)o; + foreach (ToolStripMenuItem i in UseSpecificDeviceMenuItem.DropDownItems) + { + i.Checked = false; + } + item.Checked = true; + if (hwid == null || hwid == "") + { + UseSpecificDeviceMenuItem.Checked = false; + } else + { + UseSpecificDeviceMenuItem.Checked = true; + } + RawAccelSettings.AccelerationSettings.deviceHardwareID = hwid; + + TryUpdateActiveSettings(RawAccelSettings.AccelerationSettings); + + } + private void UpdateUseSpecificDeviceMenu() + { + var hwid = RawAccelSettings.AccelerationSettings.deviceHardwareID; + if (hwid == null) { hwid = ""; } + + UseSpecificDeviceMenuItem.Checked = hwid.Length > 0; + UseSpecificDeviceMenuItem.DropDownItems.Clear(); + + var any_device = new ToolStripMenuItem(); + any_device.Text = ""; + any_device.Checked = hwid.Length == 0; + any_device.Click += new EventHandler(delegate(Object o, EventArgs a) { SpecificDeviceClickHnadler(o, a, ""); }); + UseSpecificDeviceMenuItem.DropDownItems.Add(any_device); + + var hwid_not_found = true; + + foreach (Tuple device in Models.Devices.DeviceList.GetDeviceHardwareIDs()) + { + if (hwid == device.Item2) + { + hwid_not_found = false; + } + var dev = new ToolStripMenuItem(); + dev.Text = device.Item1; + dev.Checked = device.Item2 == RawAccelSettings.AccelerationSettings.deviceHardwareID; + dev.Click += new EventHandler(delegate (Object o, EventArgs a) { SpecificDeviceClickHnadler(o, a, device.Item2); }); + UseSpecificDeviceMenuItem.DropDownItems.Add(dev); + } + + if (hwid.Length > 0 && hwid_not_found) + { + var current_hwid = new ToolStripMenuItem(); + current_hwid.Text = "Disconnected (" + hwid + ")"; + current_hwid.ForeColor = Color.DarkGray; + current_hwid.Checked = true; + current_hwid.Click += new EventHandler(delegate (Object o, EventArgs a) { SpecificDeviceClickHnadler(o, a, hwid); }); + UseSpecificDeviceMenuItem.DropDownItems.Add(current_hwid); + } + } + public void UpdateFieldsFromGUISettings() { DpiField.SetToEntered(RawAccelSettings.GUISettings.DPI); @@ -110,6 +175,7 @@ namespace grapher.Models.Serialized { RawAccelSettings = RawAccelSettings.Load(() => MakeGUISettingsFromFields()); UpdateFieldsFromGUISettings(); + UpdateUseSpecificDeviceMenu(); if (RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup) { TryUpdateAccel(RawAccelSettings.AccelerationSettings); diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj index f6bdcb9..8adfa75 100644 --- a/grapher/grapher.csproj +++ b/grapher/grapher.csproj @@ -59,6 +59,7 @@ + @@ -92,6 +93,7 @@ + diff --git a/rawaccel.sln b/rawaccel.sln index fc3d256..9b3978c 100644 --- a/rawaccel.sln +++ b/rawaccel.sln @@ -27,8 +27,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "converter", "converter\conv {28A3656F-A1DE-405C-B547-191C32EC555F} = {28A3656F-A1DE-405C-B547-191C32EC555F} EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "devicelist", "devicelist\devicelist.csproj", "{3666B731-7406-41B1-BCFC-C65073FD09A1}" -EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution common\common.vcxitems*{24b4226f-1461-408f-a1a4-1371c97153ea}*SharedItemsImports = 9 @@ -75,10 +73,6 @@ Global {4C421992-9A27-4860-A40C-ADD76FBACE55}.Debug|x64.Build.0 = Debug|x64 {4C421992-9A27-4860-A40C-ADD76FBACE55}.Release|x64.ActiveCfg = Release|x64 {4C421992-9A27-4860-A40C-ADD76FBACE55}.Release|x64.Build.0 = Release|x64 - {3666B731-7406-41B1-BCFC-C65073FD09A1}.Debug|x64.ActiveCfg = Debug|x64 - {3666B731-7406-41B1-BCFC-C65073FD09A1}.Debug|x64.Build.0 = Debug|x64 - {3666B731-7406-41B1-BCFC-C65073FD09A1}.Release|x64.ActiveCfg = Release|x64 - {3666B731-7406-41B1-BCFC-C65073FD09A1}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE -- cgit v1.2.3