From 618c139607184d03e937677a2590db6c4908af01 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Sun, 28 Jan 2018 02:00:29 -0600 Subject: [PATCH] First step to change how ScpVBus installation is checked Related to issue #147. --- DS4Windows/DS4Control/ScpUtil.cs | 31 ++++++++++++++++++++++++++ DS4Windows/DS4Forms/DS4Form.cs | 4 +++- DS4Windows/HidLibrary/NativeMethods.cs | 5 ++++- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/DS4Windows/DS4Control/ScpUtil.cs b/DS4Windows/DS4Control/ScpUtil.cs index d8b1f37..7277d1c 100644 --- a/DS4Windows/DS4Control/ScpUtil.cs +++ b/DS4Windows/DS4Control/ScpUtil.cs @@ -293,6 +293,37 @@ namespace DS4Windows return principal.IsInRole(WindowsBuiltInRole.Administrator); } + public static bool IsScpVBusInstalled() + { + bool result = false; + Guid sysGuid = Guid.Parse("{4d36e97d-e325-11ce-bfc1-08002be10318}"); + NativeMethods.SP_DEVINFO_DATA deviceInfoData = new NativeMethods.SP_DEVINFO_DATA(); + deviceInfoData.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(deviceInfoData); + var dataBuffer = new byte[4096]; + ulong propertyType = 0; + var requiredSize = 0; + IntPtr deviceInfoSet = NativeMethods.SetupDiGetClassDevs(ref sysGuid, "", 0, NativeMethods.DIGCF_PRESENT | NativeMethods.DIGCF_DEVICEINTERFACE | NativeMethods.DIGCF_ALLCLASSES); + for (int i = 0; !result && NativeMethods.SetupDiEnumDeviceInfo(deviceInfoSet, i, ref deviceInfoData); i++) + { + if (NativeMethods.SetupDiGetDeviceProperty(deviceInfoSet, ref deviceInfoData, ref NativeMethods.DEVPKEY_Device_HardwareIds, ref propertyType, + dataBuffer, dataBuffer.Length, ref requiredSize, 0)) + { + string hardwareId = dataBuffer.ToUTF16String(); + //if (hardwareIds.Contains("Scp Virtual Bus Driver")) + // result = true; + if (hardwareId.Equals(@"root\ScpVBus")) + result = true; + } + } + + if (deviceInfoSet.ToInt64() != NativeMethods.INVALID_HANDLE_VALUE) + { + NativeMethods.SetupDiDestroyDeviceInfoList(deviceInfoSet); + } + + return result; + } + public static event EventHandler ControllerStatusChange; // called when a controller is added/removed/battery or touchpad mode changes/etc. public static void ControllerStatusChanged(object sender) { diff --git a/DS4Windows/DS4Forms/DS4Form.cs b/DS4Windows/DS4Forms/DS4Form.cs index 00f3efc..d9ebaa4 100644 --- a/DS4Windows/DS4Forms/DS4Form.cs +++ b/DS4Windows/DS4Forms/DS4Form.cs @@ -709,7 +709,8 @@ namespace DS4Windows bool deriverinstalled = false; try { - ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PnPSignedDriver"); + deriverinstalled = Global.IsScpVBusInstalled(); + /*ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PnPSignedDriver"); foreach (ManagementObject obj in searcher.Get()) { @@ -723,6 +724,7 @@ namespace DS4Windows } catch { } } + */ if (!deriverinstalled) { diff --git a/DS4Windows/HidLibrary/NativeMethods.cs b/DS4Windows/HidLibrary/NativeMethods.cs index 35d656a..647cdd1 100644 --- a/DS4Windows/HidLibrary/NativeMethods.cs +++ b/DS4Windows/HidLibrary/NativeMethods.cs @@ -229,7 +229,10 @@ namespace DS4Windows internal static DEVPROPKEY DEVPKEY_Device_BusReportedDeviceDesc = new DEVPROPKEY { fmtid = new Guid(0x540b947e, 0x8b40, 0x45bc, 0xa8, 0xa2, 0x6a, 0x0b, 0x89, 0x4c, 0xbd, 0xa2), pid = 4 }; - [DllImport("setupapi.dll", EntryPoint = "SetupDiGetDeviceRegistryProperty")] + internal static DEVPROPKEY DEVPKEY_Device_HardwareIds = + new DEVPROPKEY { fmtid = new Guid(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0), pid = 3 }; + + [DllImport("setupapi.dll", EntryPoint = "SetupDiGetDeviceRegistryProperty")] public static extern bool SetupDiGetDeviceRegistryProperty(IntPtr deviceInfoSet, ref SP_DEVINFO_DATA deviceInfoData, int propertyVal, ref int propertyRegDataType, byte[] propertyBuffer, int propertyBufferSize, ref int requiredSize); [DllImport("setupapi.dll", EntryPoint = "SetupDiGetDevicePropertyW", SetLastError = true)]