コード例 #1
0
ファイル: App.xaml.cs プロジェクト: David-DFT/DS4Windows
        private void CheckOptions(ArgumentParser parser)
        {
            if (parser.HasErrors)
            {
                runShutdown = false;
                exitApp     = true;
                Current.Shutdown(1);
            }
            else if (parser.Driverinstall)
            {
                CreateBaseThread();
                WelcomeDialog dialog = new WelcomeDialog(true);
                dialog.ShowDialog();
                runShutdown = false;
                exitApp     = true;
                Current.Shutdown();
            }
            else if (parser.ReenableDevice)
            {
                DS4Devices.ReEnableDevice(parser.DeviceInstanceId);
                runShutdown = false;
                exitApp     = true;
                Current.Shutdown();
            }
            else if (parser.Runtask)
            {
                StartupMethods.LaunchOldTask();
                runShutdown = false;
                exitApp     = true;
                Current.Shutdown();
            }
            else if (parser.Command)
            {
                IntPtr hWndDS4WindowsForm = FindWindow(ReadIPCClassNameMMF(), "DS4Windows");
                if (hWndDS4WindowsForm != IntPtr.Zero)
                {
                    COPYDATASTRUCT cds;
                    cds.lpData = IntPtr.Zero;

                    try
                    {
                        cds.dwData = IntPtr.Zero;
                        cds.cbData = parser.CommandArgs.Length;
                        cds.lpData = Marshal.StringToHGlobalAnsi(parser.CommandArgs);
                        SendMessage(hWndDS4WindowsForm, DS4Forms.MainWindow.WM_COPYDATA, IntPtr.Zero, ref cds);
                    }
                    finally
                    {
                        if (cds.lpData != IntPtr.Zero)
                        {
                            Marshal.FreeHGlobal(cds.lpData);
                        }
                    }
                }

                runShutdown = false;
                exitApp     = true;
                Current.Shutdown();
            }
        }
コード例 #2
0
ファイル: InputManager.cs プロジェクト: DinossourGames/BREATH
        private void FindController()
        {
            new Thread(() =>
            {
                var canRun   = true;
                _game.OnEnd += () => canRun = false;
                while (canRun)
                {
                    if (device == null)
                    {
                        DS4Devices.findControllers();
                        device          = DS4Devices.getDS4Controllers().First();
                        device.Removal += (sender, args) =>
                        {
                            device = null;
                            DS4Devices.stopControllers();
                        };
                        device.Report += DeviceOnReport;
                        device.StartUpdate();
                        device.LightBarColor = new DS4Color(Color.DeepPink);
                        PrintInfo();
                    }

                    if (device != null && !_isAlive)
                    {
                        device = null;
                    }

                    Thread.Sleep(16);
                }
            }).Start();
        }
コード例 #3
0
        private void GetDS4()
        {
            DS4Devices.findControllers();              //Finds all DS4 using directInput --> look for xInput and directInput for more info
            var list = DS4Devices.getDS4Controllers(); // Get an enumerable with all devices encountered.

            ds4 = list.First();
            ds4.StartUpdate(); // Starts the updating process on selected device --> this will start another thread to process all the inputs recieved from controller.
        }
コード例 #4
0
 public void RefreshDevices()
 {
     DS4Devices.findControllers();
     DS4Device[] devs = DS4Devices.getDS4Controllers().ToArray();
     for (int i = 0; i < devs.Length; i++)
     {
         connectedControllers[i] = new DS4ControllerHandler(i, devs[i]);
     }
 }
コード例 #5
0
ファイル: DS4Input.cs プロジェクト: Akilliez/WoWmapper
        public DS4Input(string MAC)
        {
            var control = DS4Devices.getDS4Controller(MAC);

            if (control == null)
            {
                return;
            }
            _controller = control;
        }
コード例 #6
0
ファイル: Core_DS4WindowsApi.cs プロジェクト: t-l-k/IOWrapper
        public void RefreshDevices()
        {
            DS4Devices.findControllers();
            var devs = DS4Devices.getDS4Controllers().ToArray();

            for (var i = 0; i < devs.Length; i++)
            {
                var dev = new DS4ControllerHandler(i, devs[i]);
                connectedControllers.Add(dev);
            }
        }
コード例 #7
0
        public void Shutdown()
        {
            Log.WriteLine
                ("Shutting down DS4 controllers...");

            DS4Devices.stopControllers();

            foreach (var c in Controllers)
            {
                c.Stop();
            }
        }
コード例 #8
0
        void DetectAttachedJoystickDevice(int unityJoystickId, string unityJoystickName)
        {
            if (unityJoystickName != "Wireless Controller") //This is the joystick name for ps4 controller on windows
            {
                return;
            }

            var matchedDeviceProfile = deviceProfiles.Find(config => config.HasJoystickName(unityJoystickName));

            if (matchedDeviceProfile == null)
            {
                matchedDeviceProfile = deviceProfiles.Find(config => config.HasLastResortRegex(unityJoystickName));
            }

            UnityInputDeviceProfile deviceProfile = null;

            if (matchedDeviceProfile == null)
            {
                return;
            }
            else
            {
                deviceProfile = matchedDeviceProfile;
            }

            int deviceCount = devices.Count;

            for (int i = 0; i < deviceCount; i++)
            {
                var device      = devices[i];
                var unityDevice = device as UnityInputDevice;
                if (unityDevice != null && unityDevice.IsConfiguredWith(deviceProfile, unityJoystickId))
                {
                    Logger.LogInfo("Device \"" + unityJoystickName + "\" is already configured with " + deviceProfile.Name);
                    return;
                }
            }

            var joystickDevice = new PS4WinDevice(deviceProfile, unityJoystickId);

            joystickDevice.Device = DS4Devices.getNextDS4Controller(); //TODO: wrong, nothing ensures that order is the same so we could end rumbling the other player controller
            AttachDevice(joystickDevice);

            if (matchedDeviceProfile == null)
            {
                Logger.LogWarning("Device " + unityJoystickId + " with name \"" + unityJoystickName + "\" does not match any known profiles.");
            }
            else
            {
                Logger.LogInfo("Device " + unityJoystickId + " matched profile " + deviceProfile.GetType().Name + " (" + deviceProfile.Name + ")");
            }
        }
コード例 #9
0
        private void CheckDeviceState()
        {
            DS4Devices.findControllers();
            IEnumerable <DS4Device> devices = DS4Devices.getDS4Controllers();

            Device = devices.FirstOrDefault();

            IsConnected = Device != null;

            if (!IsConnected)
            {
                return;
            }
        }
コード例 #10
0
 public bool Stop(bool showlog = true)
 {
     if (running)
     {
         running = false;
         if (showlog)
         {
             LogDebug(Properties.Resources.StoppingX360);
         }
         bool anyUnplugged = false;
         for (int i = 0; i < DS4Controllers.Length; i++)
         {
             if (DS4Controllers[i] != null)
             {
                 if (Global.getDCBTatStop() && !DS4Controllers[i].Charging && showlog)
                 {
                     DS4Controllers[i].DisconnectBT();
                 }
                 else
                 {
                     DS4LightBar.defualtLight = true;
                     DS4LightBar.updateLightBar(DS4Controllers[i], i, CurrentState[i], ExposedState[i], touchPad[i]);
                     System.Threading.Thread.Sleep(50);
                 }
                 CurrentState[i].Battery = PreviousState[i].Battery = 0; // Reset for the next connection's initial status change.
                 x360Bus.Unplug(i);
                 anyUnplugged      = true;
                 DS4Controllers[i] = null;
                 touchPad[i]       = null;
             }
         }
         if (anyUnplugged)
         {
             System.Threading.Thread.Sleep(XINPUT_UNPLUG_SETTLE_TIME);
         }
         x360Bus.UnplugAll();
         x360Bus.Stop();
         if (showlog)
         {
             LogDebug(Properties.Resources.StoppingDS4);
         }
         DS4Devices.stopControllers();
         if (showlog)
         {
             LogDebug(Properties.Resources.StoppedDS4Windows);
         }
         Global.ControllerStatusChanged(this);
     }
     return(true);
 }
コード例 #11
0
        public void Initialize()
        {
            InitializeLayout();

            try
            {
                DS4Devices.findControllers();
                IEnumerable <DS4Device> devices = DS4Devices.getDS4Controllers();
                device = devices.ElementAt(0);
                device.StartUpdate();
            }
            catch (System.Exception)
            {
                throw;
            }
        }
コード例 #12
0
        public override void Shutdown()
        {
            if (!isInitialized)
            {
                return;
            }

            foreach (var dev in Devices)
            {
                dev.Disconnect(GlobalVarRegistry.GetVariable <bool>($"{DeviceName}_disconnect_when_stop"));
            }

            DS4Devices.stopControllers();
            Devices.Clear();
            isInitialized = false;
        }
コード例 #13
0
        public bool Initialize()
        {
            newkey          = Global.Configuration.VarRegistry.GetVariable <DeviceKeys>($"{devicename}_devicekey");
            setRestoreColor = Color.Transparent;
            DS4Devices.findControllers();
            IEnumerable <DS4Device> devices = DS4Devices.getDS4Controllers();

            if (!devices.Any())
            {
                return(false);
            }

            device    = devices.ElementAt(0);
            initColor = device.LightBarColor;

            if (!isInitialized)
            {
                try
                {
                    device.Report += SendColor;
                    device.Report += UpdateProperties;
                    device.StartUpdate();
                    Global.logger.Info("Initialized Dualshock");
                }
                catch (Exception e)
                {
                    Global.logger.Error("Could not initialize Dualshock" + e);
                    isInitialized = false;
                }
                if (device != null)
                {
                    isInitialized = true;
                    if (Global.Configuration.dualshock_first_time)
                    {
                        App.Current.Dispatcher.Invoke(() =>
                        {
                            DualshockInstallInstructions instructions = new DualshockInstallInstructions();
                            instructions.ShowDialog();
                        });
                        Global.Configuration.dualshock_first_time = false;
                        Settings.ConfigManager.Save(Global.Configuration);
                    }
                }
            }

            return(isInitialized);
        }
コード例 #14
0
 public static void Stop()
 {
     if (_watcherThread == null)
     {
         return;
     }
     Logger.Write("Stopping controller manager");
     _watcherThread.Abort();
     _watcherThread = null;
     foreach (var controller in _allControllers)
     {
         controller?.Stop();
     }
     _allControllers.Clear();
     XboxController.StopPolling();
     DS4Devices.stopControllers();
 }
コード例 #15
0
        public override void Shutdown()
        {
            if (!IsInitialized)
            {
                return;
            }

            isDisconnecting = true;
            foreach (var dev in devices)
            {
                dev.Disconnect(Global.Configuration.VarRegistry.GetVariable <bool>($"{DeviceName}_disconnect_when_stop"));
            }

            DS4Devices.stopControllers();
            devices.Clear();
            IsInitialized   = false;
            isDisconnecting = false;
        }
コード例 #16
0
        public override bool Initialize()
        {
            if (isInitialized)
            {
                return(true);
            }

            key = GlobalVarRegistry.GetVariable <DeviceKeys>($"{DeviceName}_devicekey");
            DS4Devices.findControllers();
            var controllers = DS4Devices.getDS4Controllers();

            foreach (var controller in controllers)
            {
                Devices.Add(new DS4Container(controller));
            }

            return(isInitialized = Devices.Any());
        }
コード例 #17
0
        public override bool Initialize()
        {
            if (IsInitialized)
            {
                return(true);
            }

            key = Global.Configuration.VarRegistry.GetVariable <DeviceKeys>($"{DeviceName}_devicekey");
            DS4Devices.findControllers();

            var restore = Global.Configuration.VarRegistry.GetVariable <RealColor>($"{DeviceName}_restore_dualshock").GetDrawingColor();

            foreach (var controller in DS4Devices.getDS4Controllers())
            {
                devices.Add(new DS4Container(controller, restore));
            }

            return(IsInitialized = devices.Count > 0);
        }
コード例 #18
0
        public void Scan()
        {
            //Log.WriteLine("Searching for DS4 controllers...");
            // Update controller list
            DS4Devices.findControllers();

            // Check validity of connected controllers
            var deadControllers = new List <IController>();

            foreach (var controller in Controllers)
            {
                if (controller.IsAlive())
                {
                    continue;
                }

                Log.WriteLine($"DS4 device {controller.Name} was disconnected.");
                controller.Stop();
                deadControllers.Add(controller);
            }

            // Remove disconnected devices
            if (deadControllers.Count > 0)
            {
                Controllers.RemoveAll(c => deadControllers.Contains(c));
            }


            var ds4Devices = DS4Devices.getDS4Controllers().ToArray();

            for (var i = 0; i < ds4Devices.Length; i++)
            {
                if (ds4Devices[i] != null &&
                    Controllers.Count(controller => controller.UnderlyingController == ds4Devices[i]) == 0)
                {
                    var controller = new DS4Controller(ds4Devices[i]);
                    Controllers.Add(controller);
                    Log.WriteLine($"DS4 device {ds4Devices[i].MacAddress} was connected.");
                }
            }
        }
コード例 #19
0
 public static void Start()
 {
     if (_watcherThread != null)
     {
         return;
     }
     Logger.Write("Starting controller manager");
     _watcherThread = new Thread(ControllerWatcher)
     {
         IsBackground = true
     };
     _watcherThread.Start();
     if (Settings.Default.EnableXbox)
     {
         XboxController.StartPolling();
     }
     if (Settings.Default.EnableDS4)
     {
         DS4Devices.findControllers();
     }
 }
コード例 #20
0
        private void DeviceListChanged(object sender, HidSharp.DeviceListChangedEventArgs e)
        {
            if ((Global.Configuration?.DevicesDisabled?.Contains(typeof(DualshockDevice)) ?? false) ||
                (!Global.Configuration?.VarRegistry?.GetVariable <bool>($"{DeviceName}_auto_init") ?? false))
            {
                return;
            }


            if (isDisconnecting)
            {
                return;
            }

            LogInfo("Detected device list changed, rescanning for controllers...");
            DS4Devices.findControllers();
            if (DS4Devices.getDS4Controllers().Count() != devices.Count)
            {
                Reset();
            }
        }
コード例 #21
0
        public Form1()
        {
            InitializeComponent();

            // The array of picture boxes will make easier to manage them
            pbx[0] = b;
            pbx[1] = c;
            pbx[2] = d;
            pbx[3] = e;


            cor[0] = Color.Green;
            cor[1] = Color.Blue;
            cor[2] = Color.Purple;
            cor[3] = Color.Yellow;
            DS4Devices.findControllers();
            ds4 = DS4Devices.getDS4Controllers().FirstOrDefault();
            if (ds4 != null)
            {
                ds4.StartUpdate();
            }
        }
コード例 #22
0
 public void Shutdown()
 {
     try
     {
         if (isInitialized)
         {
             if (Global.Configuration.VarRegistry.GetVariable <bool>($"{devicename}_disconnect_when_stop"))
             {
                 device.DisconnectBT();
                 device.DisconnectDongle();
             }
             RestoreColor();
             device.StopUpdate();
             DS4Devices.stopControllers();
             isInitialized = false;
         }
     }
     catch (Exception e)
     {
         Global.logger.Error("There was an error shutting down DualShock: " + e);
         isInitialized = true;
     }
 }
コード例 #23
0
        public bool HotPlug()
        {
            if (running)
            {
                DS4Devices.findControllers();
                IEnumerable <DS4Device> devices = DS4Devices.getDS4Controllers();
                foreach (DS4Device device in devices)
                {
                    if (device.IsDisconnecting)
                    {
                        continue;
                    }
                    if (((Func <bool>) delegate
                    {
                        for (Int32 Index = 0; Index < DS4Controllers.Length; Index++)
                        {
                            if (DS4Controllers[Index] != null && DS4Controllers[Index].MacAddress == device.MacAddress)
                            {
                                return(true);
                            }
                        }
                        return(false);
                    })())
                    {
                        continue;
                    }
                    for (Int32 Index = 0; Index < DS4Controllers.Length; Index++)
                    {
                        if (DS4Controllers[Index] == null)
                        {
                            LogDebug(Properties.Resources.FoundController + device.MacAddress + " (" + device.ConnectionType + ")");
                            WarnExclusiveModeFailure(device);
                            DS4Controllers[Index] = device;
                            device.Removal       -= DS4Devices.On_Removal;
                            device.Removal       += this.On_DS4Removal;
                            device.Removal       += DS4Devices.On_Removal;
                            touchPad[Index]       = new Mouse(Index, device);
                            //device.LightBarColor = MainColor[Index];
                            //device.Report += this.On_Report;
                            //if (!DinputOnly[Index])
                            //    x360Bus.Plugin(Index);
                            TouchPadOn(Index, device);
                            //string filename = Path.GetFileName(ProfilePath[Index]);
                            //if (System.IO.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);
        }
コード例 #24
0
 public PS4WinDeviceManager()
 {
     DS4Devices.findControllers();
     AutoDiscoverDeviceProfiles();
     RefreshDevices();
 }
コード例 #25
0
 public bool Start(bool showlog = true)
 {
     if (x360Bus.Open() && x360Bus.Start())
     {
         if (showlog)
         {
             LogDebug(Properties.Resources.Starting);
         }
         DS4Devices.isExclusiveMode = Global.getUseExclusiveMode();
         if (showlog)
         {
             LogDebug(Properties.Resources.SearchingController);
             LogDebug(DS4Devices.isExclusiveMode ?  Properties.Resources.UsingExclusive: Properties.Resources.UsingShared);
         }
         try
         {
             DS4Devices.findControllers();
             IEnumerable <DS4Device> devices = DS4Devices.getDS4Controllers();
             int ind = 0;
             DS4LightBar.defualtLight = false;
             foreach (DS4Device device in devices)
             {
                 if (showlog)
                 {
                     LogDebug(Properties.Resources.FoundController + device.MacAddress + " (" + device.ConnectionType + ")");
                 }
                 WarnExclusiveModeFailure(device);
                 DS4Controllers[ind] = device;
                 device.Removal     -= DS4Devices.On_Removal;
                 device.Removal     += this.On_DS4Removal;
                 device.Removal     += DS4Devices.On_Removal;
                 touchPad[ind]       = new Mouse(ind, device);
                 DS4Color color = Global.loadColor(ind);
                 device.LightBarColor = color;
                 if (!Global.getDinputOnly(ind))
                 {
                     x360Bus.Plugin(ind);
                 }
                 device.Report += this.On_Report;
                 TouchPadOn(ind, device);
                 string filename = Path.GetFileName(Global.getAProfile(ind));
                 ind++;
                 if (showlog)
                 {
                     if (System.IO.File.Exists(Global.appdatapath + "\\Profiles\\" + filename))
                     {
                         string prolog = Properties.Resources.UsingProfile.Replace("*number*", ind.ToString()).Replace("*Profile name*", filename.Substring(0, filename.Length - 4));
                         LogDebug(prolog);
                         Log.LogToTray(prolog);
                     }
                     else
                     {
                         LogDebug("Controller " + ind + " is not using a profile");
                         Log.LogToTray("Controller " + ind + " is not using a profile");
                     }
                 }
                 if (ind >= 4) // out of Xinput devices!
                 {
                     break;
                 }
             }
         }
         catch (Exception e)
         {
             LogDebug(e.Message);
             Log.LogToTray(e.Message);
         }
         running = true;
     }
     return(true);
 }
コード例 #26
0
        public bool HotPlug()
        {
            if (running)
            {
                DS4Devices.findControllers();
                IEnumerable <DS4Device> devices = DS4Devices.getDS4Controllers();
                foreach (DS4Device device in devices)
                {
                    if (device.IsDisconnecting)
                    {
                        continue;
                    }
                    if (((Func <bool>) delegate
                    {
                        for (Int32 Index = 0; Index < DS4Controllers.Length; Index++)
                        {
                            if (DS4Controllers[Index] != null && DS4Controllers[Index].MacAddress == device.MacAddress)
                            {
                                return(true);
                            }
                        }
                        return(false);
                    })())
                    {
                        continue;
                    }
                    for (Int32 Index = 0; Index < DS4Controllers.Length; Index++)
                    {
                        if (DS4Controllers[Index] == null)
                        {
                            LogDebug(Properties.Resources.FoundController + device.MacAddress + " (" + device.ConnectionType + ")");
                            WarnExclusiveModeFailure(device);
                            DS4Controllers[Index] = device;
                            device.Removal       -= DS4Devices.On_Removal;
                            device.Removal       += this.On_DS4Removal;
                            device.Removal       += DS4Devices.On_Removal;
                            touchPad[Index]       = new Mouse(Index, device);
                            device.LightBarColor  = Global.loadColor(Index);
                            device.Report        += this.On_Report;
                            if (!Global.getDinputOnly(Index))
                            {
                                x360Bus.Plugin(Index);
                            }
                            TouchPadOn(Index, device);
                            string filename = Path.GetFileName(Global.getAProfile(Index));
                            if (System.IO.File.Exists(Global.appdatapath + "\\Profiles\\" + filename))
                            {
                                string prolog = Properties.Resources.UsingProfile.Replace("*number*", (Index + 1).ToString()).Replace("*Profile name*", filename.Substring(0, filename.Length - 4));
                                LogDebug(prolog);
                                Log.LogToTray(prolog);
                            }
                            else
                            {
                                LogDebug("Controller " + (Index + 1) + " is not using a profile");
                                Log.LogToTray("Controller " + (Index + 1) + " is not using a profile");
                            }

                            break;
                        }
                    }
                }
            }
            return(true);
        }
コード例 #27
0
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     DS4Devices.stopControllers(); // Kill all connections with ds4 devices connected. leting the control to host os.
 }
コード例 #28
0
        public static void ScanDevices()
        {
            // Scan for devices
            lock (_allControllers)
            {
                if (Settings.Default.EnableDS4)
                {
                    try
                    {
                        DS4Devices.findControllers();

                        var listDS4 = DS4Devices.getDS4Controllers();

                        foreach (var controller in listDS4)
                        {
                            if (_allControllers.Count(c => c.UnderlyingDevice == controller.HidDevice) == 0)
                            {
                                Logger.Write("Found new DS4 device: {0}", controller.MacAddress);
                                _allControllers.Add(new DS4Input(controller.MacAddress));
                                ControllersUpdated?.Invoke();
                            }
                        }
                    }
                    catch (ThreadAbortException ex)
                    { }
                    catch (Exception ex)
                    {
                        Logger.Write("DS4 driver error: ", ex);
                        MessageBox.Show(string.Format(Resources.ErrorDriverDs4Disabled, ex.Message), Resources.ErrorDriverDisabledTitle, MessageBoxButton.OK, MessageBoxImage.Error);
                        Settings.Default.EnableDS4 = false;
                        Settings.Default.Save();
                    }
                }

                if (Settings.Default.EnableXbox)
                {
                    // Scan for Xbox controllers
                    try
                    {
                        for (int i = XboxController.FIRST_CONTROLLER_INDEX; i < XboxController.MAX_CONTROLLER_COUNT; i++)
                        {
                            XInputState stateController = new XInputState();
                            int         result          = XInput.XInputGetState(i, ref stateController);
                            if (result == 0) // Controller found
                            {
                                var controller = XboxController.RetrieveController(i);
                                if (_allControllers.Count(c => c.UnderlyingDevice == controller) == 0)
                                {
                                    Logger.Write("Found new XInput device: {0}", i);
                                    _allControllers.Add(new XboxInput(i));
                                    ControllersUpdated?.Invoke();
                                }
                            }
                        }
                    }
                    catch (ThreadAbortException ex)
                    { }
                    catch (Exception ex)
                    {
                        Logger.Write("XInput driver error: ", ex);
                        MessageBox.Show(string.Format(Resources.ErrorDriverXboxDisabled, ex.Message), Resources.ErrorDriverDisabledTitle, MessageBoxButton.OK, MessageBoxImage.Error);
                        Settings.Default.EnableXbox = false;
                        Settings.Default.Save();
                    }
                }
            }
        }
コード例 #29
0
 public bool Start(bool showlog = true)
 {
     if (x360Bus.Open() && x360Bus.Start())
     {
         if (showlog)
         {
             //LogDebug(Properties.Resources.Starting);
             //DS4Devices.isExclusiveMode = UseExclusiveMode;
             if (showlog)
             {
                 //LogDebug(Properties.Resources.SearchingController);
                 //LogDebug(DS4Devices.isExclusiveMode ?  Properties.Resources.UsingExclusive: Properties.Resources.UsingShared);
             }
         }
         try
         {
             DS4Devices.findControllers();
             IEnumerable <DS4Device> devices = DS4Devices.getDS4Controllers();
             int ind = 0;
             //DS4LightBar.defualtLight = false;
             foreach (DS4Device device in devices)
             {
                 if (showlog)
                 {
                     LogDebug(Properties.Resources.FoundController + device.MacAddress + " (" + device.ConnectionType + ")");
                 }
                 WarnExclusiveModeFailure(device);
                 DS4Controllers[ind] = device;
                 device.Removal     -= DS4Devices.On_Removal;
                 device.Removal     += this.On_DS4Removal;
                 device.Removal     += DS4Devices.On_Removal;
                 touchPad[ind]       = new Mouse(ind, device);
                 //device.LightBarColor = MainColor[ind];
                 //if (!DinputOnly[ind])
                 //    x360Bus.Plugin(ind);
                 //device.Report += this.On_Report;
                 TouchPadOn(ind, device);
                 //string filename = ProfilePath[ind];
                 ind++;
                 //if (showlog)
                 //    if (System.IO.File.Exists(appdatapath + "\\Profiles\\" + ProfilePath[ind-1] + ".xml"))
                 //    {
                 //        string prolog = Properties.Resources.UsingProfile.Replace("*number*", ind.ToString()).Replace("*Profile name*", ProfilePath[ind-1]);
                 //        LogDebug(prolog);
                 //        Log.LogToTray(prolog);
                 //    }
                 //    else
                 //    {
                 //        string prolog = Properties.Resources.NotUsingProfile.Replace("*number*", (ind).ToString());
                 //        LogDebug(prolog);
                 //        Log.LogToTray(prolog);
                 //    }
                 if (ind >= 4) // out of Xinput devices!
                 {
                     break;
                 }
             }
         }
         catch (Exception e)
         {
             LogDebug(e.Message);
             Log.LogToTray(e.Message);
         }
         running = true;
     }
     return(true);
 }