Пример #1
0
        private void InstallBthHostOnClick(object sender, RoutedEventArgs e)
        {
            var bthResult = WdiErrorCode.WDI_SUCCESS;

            var bthToInstall =
                BluetoothStackPanelDefault.Children.Cast <TextBlock>()
                .Select(c => c.Tag)
                .Cast <WdiDeviceInfo>()
                .ToList();

            if (bthToInstall.Any())
            {
                bthResult = DriverInstaller.InstallBluetoothHost(bthToInstall.First(), _hWnd);
            }

            // display success or failure message
            if (bthResult == WdiErrorCode.WDI_SUCCESS)
            {
                ExtendedMessageBox.Show(this,
                                        Properties.Resources.BthInstOk_Title,
                                        Properties.Resources.BthInstOk_Instruction,
                                        Properties.Resources.BthInstOk_Content,
                                        Properties.Resources.BthInstOk_Verbose,
                                        Properties.Resources.BthInstOk_Footer,
                                        TaskDialogIcon.Information);
            }
            else
            {
                ExtendedMessageBox.Show(this,
                                        Properties.Resources.DsInstError_Title,
                                        Properties.Resources.DsInstError_Instruction,
                                        Properties.Resources.DsInstError_Content,
                                        string.Format(Properties.Resources.DsInstError_Verbose,
                                                      WdiWrapper.Instance.GetErrorMessage(bthResult), bthResult),
                                        Properties.Resources.DsInstError_Footer,
                                        TaskDialogIcon.Error);
            }
        }
Пример #2
0
        private async void InstallBthHostOnClick(object sender, RoutedEventArgs e)
        {
            MainBusyIndicator.IsBusy = !MainBusyIndicator.IsBusy;

            var  rebootRequired = false;
            uint result         = 0;

            var bhInfPath = Path.Combine(GlobalConfiguration.AppDirectory, "WinUSB", "BluetoothHost.inf");

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

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

                await Task.Run(() => {
                    foreach (
                        var usbDevice in
                        usbDevices.Where(
                            d => supportedBluetoothDevices.Any(s => s.Contains(regex.Match(d.HardwareId).Value)) &&
                            !string.IsNullOrEmpty(d.CurrentDriver) && d.CurrentDriver.Equals("BTHUSB"))
                        )
                    {
                        MainBusyIndicator.SetContentThreadSafe(Properties.Resources.BluetoothSetupInstalling);
                        DriverInstaller.InstallBluetoothHost(usbDevice, force: _viewModel.ForceInstallBthEnabled);
                    }
                });
            }
            else
            {
                MainBusyIndicator.SetContentThreadSafe(Properties.Resources.BluetoothSetupInstalling);

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

            MainBusyIndicator.IsBusy = !MainBusyIndicator.IsBusy;

            // ERROR_NO_SUCH_DEVINST = 0xE000020B
            if (result != 0 && result != 0xE000020B)
            {
                // display error message
                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);
                return;
            }

            // display success message
            ExtendedMessageBox.Show(this,
                                    Properties.Resources.SetupSuccessTitle,
                                    Properties.Resources.BluetoothSetupSuccessInstruction,
                                    Properties.Resources.SetupSuccessContent,
                                    string.Empty,
                                    string.Empty,
                                    TaskDialogIcon.Information);

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