Enforce Launch Program with Profile during a hotplug event

This commit is contained in:
Travis Nickles 2017-05-13 16:47:54 -07:00
parent d02317b5a4
commit b1c640eaa1

View File

@ -1,8 +1,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Media; using System.Media;
using System.Threading.Tasks;
using static DS4Windows.Global; using static DS4Windows.Global;
namespace DS4Windows namespace DS4Windows
@ -228,7 +230,8 @@ namespace DS4Windows
DS4LightBar.forcelight[i] = false; DS4LightBar.forcelight[i] = false;
DS4LightBar.forcedFlash[i] = 0; DS4LightBar.forcedFlash[i] = 0;
DS4LightBar.defaultLight = true; DS4LightBar.defaultLight = true;
DS4LightBar.updateLightBar(DS4Controllers[i], i, CurrentState[i], ExposedState[i], touchPad[i]); DS4LightBar.updateLightBar(DS4Controllers[i], i, CurrentState[i],
ExposedState[i], touchPad[i]);
tempDevice.IsRemoved = true; tempDevice.IsRemoved = true;
System.Threading.Thread.Sleep(50); System.Threading.Thread.Sleep(50);
} }
@ -339,6 +342,7 @@ namespace DS4Windows
} }
TouchPadOn(Index, device); TouchPadOn(Index, device);
CheckProfileOptions(Index, device);
device.StartUpdate(); device.StartUpdate();
//string filename = Path.GetFileName(ProfilePath[Index]); //string filename = Path.GetFileName(ProfilePath[Index]);
@ -364,6 +368,45 @@ namespace DS4Windows
return true; return true;
} }
private void CheckProfileOptions(int ind, DS4Device device)
{
string programPath = LaunchProgram[ind];
if (programPath != string.Empty)
{
System.Diagnostics.Process[] localAll = System.Diagnostics.Process.GetProcesses();
bool procFound = false;
for (int procInd = 0, procsLen = localAll.Length; !procFound && procInd < procsLen; procInd++)
{
try
{
string temp = localAll[procInd].MainModule.FileName;
if (temp == programPath)
{
procFound = true;
}
}
// Ignore any process for which this information
// is not exposed
catch { }
}
if (!procFound)
{
Task processTask = new Task(() =>
{
System.Diagnostics.Process tempProcess = new System.Diagnostics.Process();
tempProcess.StartInfo.FileName = programPath;
tempProcess.StartInfo.WorkingDirectory = new FileInfo(programPath).Directory.ToString();
//tempProcess.StartInfo.UseShellExecute = false;
try { tempProcess.Start(); }
catch { }
});
processTask.Start();
}
}
}
public void TouchPadOn(int ind, DS4Device device) public void TouchPadOn(int ind, DS4Device device)
{ {
ITouchpadBehaviour tPad = touchPad[ind]; ITouchpadBehaviour tPad = touchPad[ind];