public bool HotPlug(SynchronizationContext uiContext) { if (running) { DS4Devices.findControllers(); IEnumerable <DS4Device> devices = DS4Devices.getDS4Controllers(); //foreach (DS4Device device in devices) for (int i = 0, devlen = devices.Count(); i < devlen; i++) { DS4Device device = devices.ElementAt(i); if (device.isDisconnectingStatus()) { continue; } if (((Func <bool>) delegate { for (Int32 Index = 0, arlength = DS4Controllers.Length; Index < arlength; Index++) { if (DS4Controllers[Index] != null && DS4Controllers[Index].getMacAddress() == device.getMacAddress()) { return(true); } } return(false); })()) { continue; } for (Int32 Index = 0, arlength = DS4Controllers.Length; Index < arlength; Index++) { if (DS4Controllers[Index] == null) { LogDebug(Properties.Resources.FoundController + device.getMacAddress() + " (" + device.getConnectionType() + ")"); Task task = new Task(() => { Thread.Sleep(5); WarnExclusiveModeFailure(device); }); task.Start(); DS4Controllers[Index] = device; device.setUiContext(uiContext); device.Removal += this.On_DS4Removal; device.Removal += DS4Devices.On_Removal; device.SyncChange += this.On_SyncChange; device.SyncChange += DS4Devices.UpdateSerial; device.SerialChange += this.On_SerialChange; touchPad[Index] = new Mouse(Index, device); device.LightBarColor = getMainColor(Index); device.Report += this.On_Report; if (!getDInputOnly(Index) && device.isSynced()) { int xinputIndex = x360Bus.FirstController + Index; LogDebug("Plugging in X360 Controller #" + xinputIndex); bool xinputResult = x360Bus.Plugin(Index); if (xinputResult) { LogDebug("X360 Controller # " + xinputIndex + " connected"); useDInputOnly[Index] = false; } else { LogDebug("X360 Controller # " + xinputIndex + " failed. Using DInput only mode"); useDInputOnly[Index] = true; } } TouchPadOn(Index, device); CheckProfileOptions(Index, device); device.StartUpdate(); //string filename = Path.GetFileName(ProfilePath[Index]); if (File.Exists(appdatapath + "\\Profiles\\" + ProfilePath[Index] + ".xml")) { string prolog = Properties.Resources.UsingProfile.Replace("*number*", (Index + 1).ToString()).Replace("*Profile name*", ProfilePath[Index]); LogDebug(prolog); Log.LogToTray(prolog); } else { string prolog = Properties.Resources.NotUsingProfile.Replace("*number*", (Index + 1).ToString()); LogDebug(prolog); Log.LogToTray(prolog); } break; } } } } return(true); }