Apply proposed changes for HG v.1 support

This commit is contained in:
Travis Nickles 2019-01-18 15:38:13 -06:00
parent 8f25e4b630
commit bf3f10d0ae
3 changed files with 32 additions and 7 deletions

View File

@ -155,6 +155,18 @@ namespace DS4Windows
// Thread.SpinWait(500); // 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++) for (int i = 0, arlength = DS4Controllers.Length; i < arlength; i++)
{ {
processingData[i] = new X360Data(); processingData[i] = new X360Data();

View File

@ -227,7 +227,7 @@ namespace DS4Windows
{ {
protected static BackingStore m_Config = new BackingStore(); protected static BackingStore m_Config = new BackingStore();
protected static Int32 m_IdleTimeout = 600000; 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 string appdatapath;
public static bool firstRun = false; public static bool firstRun = false;
public static bool multisavespots = false; public static bool multisavespots = false;
@ -297,25 +297,28 @@ namespace DS4Windows
return principal.IsInRole(WindowsBuiltInRole.Administrator); return principal.IsInRole(WindowsBuiltInRole.Administrator);
} }
public static bool IsScpVBusInstalled() private static bool CheckForSysDevice(string searchHardwareId)
{ {
bool result = false; bool result = false;
Guid sysGuid = Guid.Parse("{4d36e97d-e325-11ce-bfc1-08002be10318}"); Guid sysGuid = Guid.Parse("{4d36e97d-e325-11ce-bfc1-08002be10318}");
NativeMethods.SP_DEVINFO_DATA deviceInfoData = new NativeMethods.SP_DEVINFO_DATA(); NativeMethods.SP_DEVINFO_DATA deviceInfoData =
deviceInfoData.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(deviceInfoData); new NativeMethods.SP_DEVINFO_DATA();
deviceInfoData.cbSize =
System.Runtime.InteropServices.Marshal.SizeOf(deviceInfoData);
var dataBuffer = new byte[4096]; var dataBuffer = new byte[4096];
ulong propertyType = 0; ulong propertyType = 0;
var requiredSize = 0; var requiredSize = 0;
IntPtr deviceInfoSet = NativeMethods.SetupDiGetClassDevs(ref sysGuid, null, 0, 0); IntPtr deviceInfoSet = NativeMethods.SetupDiGetClassDevs(ref sysGuid, null, 0, 0);
for (int i = 0; !result && NativeMethods.SetupDiEnumDeviceInfo(deviceInfoSet, i, ref deviceInfoData); i++) 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)) dataBuffer, dataBuffer.Length, ref requiredSize, 0))
{ {
string hardwareId = dataBuffer.ToUTF16String(); string hardwareId = dataBuffer.ToUTF16String();
//if (hardwareIds.Contains("Scp Virtual Bus Driver")) //if (hardwareIds.Contains("Scp Virtual Bus Driver"))
// result = true; // result = true;
if (hardwareId.Equals(@"root\ScpVBus")) if (hardwareId.Equals(searchHardwareId))
result = true; result = true;
} }
} }
@ -328,6 +331,16 @@ namespace DS4Windows
return result; return result;
} }
public static bool IsHidGuardianInstalled()
{
return CheckForSysDevice(@"Root\HidGuardian");
}
public static bool IsScpVBusInstalled()
{
return CheckForSysDevice(@"root\ScpVBus");
}
public static void FindConfigLocation() public static void FindConfigLocation()
{ {
if (File.Exists(exepath + "\\Auto Profiles.xml") if (File.Exists(exepath + "\\Auto Profiles.xml")

View File

@ -401,7 +401,7 @@ namespace DS4Windows
if (btnStartStop.Enabled && start) if (btnStartStop.Enabled && start)
{ {
TaskRunner.Delay(50).ContinueWith((t) => { TaskRunner.Delay(100).ContinueWith((t) => {
this.BeginInvoke((System.Action)(() => BtnStartStop_Clicked())); this.BeginInvoke((System.Action)(() => BtnStartStop_Clicked()));
}); });
} }