Example #1
0
        internal void TurnOnPs4Service()
        {
            if (IsPs4SupportChecked)
            {
                if (!DS4ControllerService.IsScpDriverInstalled())
                {
                    // user must install the driver first before using ds4. prompt user driver will silently install then turn on
                    var messageResult = MessageDialogWindow.Show("The SCP Virtual Bus Driver is not installed. It is required to enable PS4 controller support.\n\nDo you want to install the driver?", "Missing Required Driver", MessageBoxButton.YesNo, MessageBoxImage.Question);

                    if (messageResult.Result == MessageBoxResult.No)
                    {
                        IsPs4SupportChecked = false; // uncheck this since user does not have driver installed so it can't be supported
                        return;
                    }

                    InstallDriverAsync().ContinueWith((result) =>
                    {
                        if (IsPs4SupportChecked && DS4ControllerService.IsScpDriverInstalled())
                        {
                            DS4ControllerService.Instance.StartService();
                        }
                    });
                    return;
                }

                // just turn on service if driver installed
                DS4ControllerService.Instance.StartService();
            }
        }
Example #2
0
        /// <summary>
        /// Run ScpDriver.exe on background task to install driver. Shows message and turns off ps4 controller support if fails.
        /// </summary>
        /// <returns></returns>
        private Task InstallDriverAsync()
        {
            IsInstallingDriver = true;
            return(Task.Factory.StartNew(() =>
            {
                ProcessStartInfo startInfo = new ProcessStartInfo(Sys.PathToScpDriverExe, "si")
                {
                    Verb = "runas",
                    WorkingDirectory = Sys.PathToVBusDriver // ensure the working directory is where the .exe is located
                };
                Process.Start(startInfo);

                // wait for the .exe driver install to finish
                while (Process.GetProcessesByName("ScpDriver").Length > 0)
                {
                    Thread.Sleep(100);
                }

                // check for installation by looking at log file
                bool installSuccess = false;

                if (File.Exists(Path.Combine(Sys.PathToVBusDriver, "ScpDriver.log")))
                {
                    string logContents = File.ReadAllText(Path.Combine(Sys.PathToVBusDriver, "ScpDriver.log"));
                    installSuccess = logContents.Contains("Install Succeeded");
                }

                // show message to user if issues with install or detecting
                if (installSuccess && !DS4ControllerService.IsScpDriverInstalled())
                {
                    MessageDialogWindow.Show("The SCP driver finished installing but could not be detected yet. Wait 5-10 seconds and try again (you may need to reboot for Windows to notice the driver.)", "Driver Installed", MessageBoxButton.OK, MessageBoxImage.Warning);
                    IsPs4SupportChecked = false; // uncheck so user can toggle back on in a few seconds
                }
                else if (!installSuccess)
                {
                    MessageDialogWindow.Show("The SCP driver failed to install.", "Install Failed", MessageBoxButton.OK, MessageBoxImage.Warning);
                    IsPs4SupportChecked = false; // uncheck so user can toggle back on in a few seconds to try again
                }

                IsInstallingDriver = false;
            }));
        }