예제 #1
0
        private void InstallDsOnClick(object sender, RoutedEventArgs routedEventArgs)
        {
            WdiErrorCode ds3Result = WdiErrorCode.WDI_SUCCESS, ds4Result = WdiErrorCode.WDI_SUCCESS;

            var ds3SToInstall =
                DualShockStackPanelHidUsb.Children.Cast <TextBlock>()
                .Select(c => c.Tag)
                .Cast <WdiDeviceInfo>()
                .Where(d => d.VendorId == _hidUsbDs3.VendorId && d.ProductId == _hidUsbDs3.ProductId)
                .ToList();

            if (ds3SToInstall.Any())
            {
                ds3Result = DriverInstaller.InstallDualShock3Controller(ds3SToInstall.First(), _hWnd);
            }

            var ds4SToInstall =
                DualShockStackPanelHidUsb.Children.Cast <TextBlock>()
                .Select(c => c.Tag)
                .Cast <WdiDeviceInfo>()
                .Where(d => d.VendorId == _hidUsbDs4.VendorId && d.ProductId == _hidUsbDs4.ProductId)
                .ToList();

            if (ds4SToInstall.Any())
            {
                ds4Result = DriverInstaller.InstallDualShock4Controller(ds4SToInstall.First(), _hWnd);
            }

            // display success or failure message
            if (ds3Result == WdiErrorCode.WDI_SUCCESS && ds4Result == WdiErrorCode.WDI_SUCCESS)
            {
                ExtendedMessageBox.Show(this,
                                        Properties.Resources.DsInstOk_Title,
                                        Properties.Resources.DsInstOk_Instruction,
                                        Properties.Resources.DsInstOk_Content,
                                        Properties.Resources.DsInstOk_Verbose,
                                        Properties.Resources.DsInstOk_Footer,
                                        TaskDialogIcon.Information);
            }
            else
            {
                if (ds3Result != WdiErrorCode.WDI_SUCCESS)
                {
                    ExtendedMessageBox.Show(this,
                                            Properties.Resources.DsInstError_Title,
                                            Properties.Resources.DsInstError_Instruction,
                                            Properties.Resources.DsInstError_Content,
                                            string.Format(Properties.Resources.DsInstError_Verbose,
                                                          WdiWrapper.Instance.GetErrorMessage(ds3Result), ds3Result),
                                            Properties.Resources.DsInstError_Footer,
                                            TaskDialogIcon.Error);
                    return;
                }

                if (ds4Result != WdiErrorCode.WDI_SUCCESS)
                {
                    ExtendedMessageBox.Show(this,
                                            Properties.Resources.DsInstError_Title,
                                            Properties.Resources.DsInstError_Instruction,
                                            Properties.Resources.DsInstError_Content,
                                            string.Format(Properties.Resources.DsInstError_Verbose,
                                                          WdiWrapper.Instance.GetErrorMessage(ds4Result), ds4Result),
                                            Properties.Resources.DsInstError_Footer,
                                            TaskDialogIcon.Error);
                }
            }
        }
예제 #2
0
        private async void InstallDsOnClick(object sender, RoutedEventArgs routedEventArgs)
        {
            MainBusyIndicator.IsBusy = !MainBusyIndicator.IsBusy;

            var  rebootRequired = false;
            var  failed         = false;
            uint result         = 0;

            var ds3InfPath = Path.Combine(GlobalConfiguration.AppDirectory, "WinUSB", "Ds3Controller.inf");
            var ds4InfPath = Path.Combine(GlobalConfiguration.AppDirectory, "WinUSB", "Ds4Controller.inf");

            var supportedDualShockDevices = IniConfig.Instance.Ds3Driver.HardwareIds.Union(IniConfig.Instance.Ds4Driver.HardwareIds);
            var regex = new Regex("VID_([0-9A-Z]{4})&PID_([0-9A-Z]{4})", RegexOptions.IgnoreCase);

            // Use Self-Signed Drivers?
            if (_viewModel.SelfSignedDriversEnabled)
            {
                var usbDevices = WdiWrapper.Instance.UsbDeviceList.ToList();

                await Task.Run(() => {
                    foreach (
                        var usbDevice in
                        usbDevices.Where(
                            d => supportedDualShockDevices.Any(s => s.Contains(regex.Match(d.HardwareId).Value)) &&
                            !string.IsNullOrEmpty(d.CurrentDriver) && d.CurrentDriver.Equals("HidUsb"))
                        )
                    {
                        if (IniConfig.Instance.Ds4Driver.HardwareIds.Any(s => s.Contains(regex.Match(usbDevice.HardwareId).Value)))
                        {
                            MainBusyIndicator.SetContentThreadSafe(Properties.Resources.DualShockSetupInstalling4);
                            DriverInstaller.InstallDualShock4Controller(usbDevice, force: _viewModel.ForceInstallEnabled);
                        }
                        else
                        {
                            MainBusyIndicator.SetContentThreadSafe(Properties.Resources.DualShockSetupInstalling3);
                            DriverInstaller.InstallDualShock3Controller(usbDevice, force: _viewModel.ForceInstallEnabled);
                        }
                    }
                });
            }
            else
            {
                MainBusyIndicator.SetContentThreadSafe(Properties.Resources.DualShockSetupInstalling3);

                await Task.Run(() => result = Difx.Instance.Install(ds3InfPath,
                                                                    DifxFlags.DRIVER_PACKAGE_ONLY_IF_DEVICE_PRESENT | DifxFlags.DRIVER_PACKAGE_FORCE, out rebootRequired));

                // ERROR_NO_SUCH_DEVINST = 0xE000020B
                if (result != 0 && result != 0xE000020B)
                {
                    failed = true;

                    ExtendedMessageBox.Show(this,
                                            Properties.Resources.SetupFailedTitle,
                                            Properties.Resources.SetupFailedInstructions,
                                            Properties.Resources.SetupFailedContent,
                                            string.Format(Properties.Resources.SetupFailedVerbose,
                                                          new Win32Exception(Marshal.GetLastWin32Error()), Marshal.GetLastWin32Error()),
                                            Properties.Resources.SetupFailedFooter,
                                            TaskDialogIcon.Error);
                }

                MainBusyIndicator.SetContentThreadSafe(Properties.Resources.DualShockSetupInstalling4);

                await Task.Run(() => result = Difx.Instance.Install(ds4InfPath,
                                                                    DifxFlags.DRIVER_PACKAGE_ONLY_IF_DEVICE_PRESENT | DifxFlags.DRIVER_PACKAGE_FORCE, out rebootRequired));

                // ERROR_NO_SUCH_DEVINST = 0xE000020B
                if (result != 0 && result != 0xE000020B)
                {
                    failed = true;

                    ExtendedMessageBox.Show(this,
                                            Properties.Resources.SetupFailedTitle,
                                            Properties.Resources.SetupFailedInstructions,
                                            Properties.Resources.SetupFailedContent,
                                            string.Format(Properties.Resources.SetupFailedVerbose,
                                                          new Win32Exception(Marshal.GetLastWin32Error()), Marshal.GetLastWin32Error()),
                                            Properties.Resources.SetupFailedFooter,
                                            TaskDialogIcon.Error);
                }
            }

            MainBusyIndicator.IsBusy = !MainBusyIndicator.IsBusy;

            if (!failed)
            {
                ExtendedMessageBox.Show(this,
                                        Properties.Resources.DualShockSetupSuccessTitle,
                                        Properties.Resources.DualShockSetupSuccessInstruction,
                                        Properties.Resources.DualShockSetupSuccessContent,
                                        string.Empty,
                                        string.Empty,
                                        TaskDialogIcon.Information);
            }

            if (rebootRequired)
            {
                MessageBox.Show(this,
                                Properties.Resources.RebootRequiredContent,
                                Properties.Resources.RebootRequiredTitle,
                                MessageBoxButton.OK,
                                MessageBoxImage.Warning);
            }
        }