From bf3f10d0aefa11b11a1e7bbf9083bc31b376dec3 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Fri, 18 Jan 2019 15:38:13 -0600 Subject: [PATCH] Apply proposed changes for HG v.1 support --- DS4Windows/DS4Control/ControlService.cs | 12 ++++++++++++ DS4Windows/DS4Control/ScpUtil.cs | 25 +++++++++++++++++++------ DS4Windows/DS4Forms/DS4Form.cs | 2 +- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/DS4Windows/DS4Control/ControlService.cs b/DS4Windows/DS4Control/ControlService.cs index 3bb0c16..3d9c79b 100644 --- a/DS4Windows/DS4Control/ControlService.cs +++ b/DS4Windows/DS4Control/ControlService.cs @@ -155,6 +155,18 @@ namespace DS4Windows // Thread.SpinWait(500); //} + if (Global.IsHidGuardianInstalled()) + { + ProcessStartInfo startInfo = + new ProcessStartInfo(Global.exepath + "\\HidGuardHelper.exe"); + startInfo.Verb = "runas"; + startInfo.Arguments = Process.GetCurrentProcess().Id.ToString(); + startInfo.WorkingDirectory = Global.exepath; + try + { Process tempProc = Process.Start(startInfo); tempProc.Dispose(); } + catch { } + } + for (int i = 0, arlength = DS4Controllers.Length; i < arlength; i++) { processingData[i] = new X360Data(); diff --git a/DS4Windows/DS4Control/ScpUtil.cs b/DS4Windows/DS4Control/ScpUtil.cs index 6959f53..b56d4f7 100644 --- a/DS4Windows/DS4Control/ScpUtil.cs +++ b/DS4Windows/DS4Control/ScpUtil.cs @@ -227,7 +227,7 @@ namespace DS4Windows { protected static BackingStore m_Config = new BackingStore(); protected static Int32 m_IdleTimeout = 600000; - public static string exepath = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName; + public static readonly string exepath = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName; public static string appdatapath; public static bool firstRun = false; public static bool multisavespots = false; @@ -297,25 +297,28 @@ namespace DS4Windows return principal.IsInRole(WindowsBuiltInRole.Administrator); } - public static bool IsScpVBusInstalled() + private static bool CheckForSysDevice(string searchHardwareId) { 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); + 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, null, 0, 0); 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, + 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")) + if (hardwareId.Equals(searchHardwareId)) result = true; } } @@ -328,6 +331,16 @@ namespace DS4Windows return result; } + public static bool IsHidGuardianInstalled() + { + return CheckForSysDevice(@"Root\HidGuardian"); + } + + public static bool IsScpVBusInstalled() + { + return CheckForSysDevice(@"root\ScpVBus"); + } + public static void FindConfigLocation() { if (File.Exists(exepath + "\\Auto Profiles.xml") diff --git a/DS4Windows/DS4Forms/DS4Form.cs b/DS4Windows/DS4Forms/DS4Form.cs index b48dcbb..d89b20c 100644 --- a/DS4Windows/DS4Forms/DS4Form.cs +++ b/DS4Windows/DS4Forms/DS4Form.cs @@ -401,7 +401,7 @@ namespace DS4Windows if (btnStartStop.Enabled && start) { - TaskRunner.Delay(50).ContinueWith((t) => { + TaskRunner.Delay(100).ContinueWith((t) => { this.BeginInvoke((System.Action)(() => BtnStartStop_Clicked())); }); }