Exemple #1
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");

            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);
            }
        }
        private async void InstallWindowsServiceOnClick(object sender, RoutedEventArgs e)
        {
            MainBusyIndicator.IsBusy = !MainBusyIndicator.IsBusy;
            var failed         = false;
            var rebootRequired = false;

            await Task.Run(() =>
            {
                try
                {
                    MainBusyIndicator.SetContentThreadSafe(Properties.Resources.ServiceSetupInstalling);

                    IDictionary state = new Hashtable();
                    var service       =
                        new AssemblyInstaller(Path.Combine(GlobalConfiguration.AppDirectory, "ScpService.exe"), null);

                    state.Clear();
                    service.UseNewContext = true;

                    service.Install(state);
                    service.Commit(state);

                    if (StartService(Settings.Default.ScpServiceName))
                    {
                        Log.InfoFormat("{0} started", Settings.Default.ScpServiceName);
                    }
                    else
                    {
                        rebootRequired = true;
                    }
                }
                catch (Win32Exception w32Ex)
                {
                    switch (w32Ex.NativeErrorCode)
                    {
                    case 1073:     // ERROR_SERVICE_EXISTS
                        Log.Info("Service already exists");
                        break;

                    default:
                        Log.ErrorFormat("Win32-Error during installation: {0}", w32Ex);
                        failed = true;
                        break;
                    }
                }
                catch (InvalidOperationException iopex)
                {
                    Log.ErrorFormat("Error during installation: {0}", iopex.Message);
                    failed = true;
                }
                catch (Exception ex)
                {
                    Log.ErrorFormat("Error during installation: {0}", ex);
                    failed = true;
                }
            });

            MainBusyIndicator.IsBusy = !MainBusyIndicator.IsBusy;

            // display error message
            if (failed)
            {
                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.ServiceSetupSuccessInstruction,
                                    Properties.Resources.ServiceSetupSuccessContent,
                                    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);
            }
        }
        private async void InstallVBusOnClick(object sender, RoutedEventArgs e)
        {
            MainBusyIndicator.IsBusy = !MainBusyIndicator.IsBusy;
            var failed         = false;
            var rebootRequired = false;

            await Task.Run(() =>
            {
                string devPath = string.Empty, instanceId = string.Empty;

                try
                {
                    var busInfPath = Path.Combine(
                        GlobalConfiguration.AppDirectory,
                        "ScpVBus",
                        Environment.Is64BitOperatingSystem ? "amd64" : "x86",
                        "ScpVBus.inf");
                    Log.DebugFormat("ScpVBus.inf path: {0}", busInfPath);

                    // check for existence of Scp VBus
                    if (!Devcon.Find(Settings.Default.VirtualBusClassGuid, ref devPath, ref instanceId))
                    {
                        MainBusyIndicator.SetContentThreadSafe(Properties.Resources.VirtualBusSetupAddingDriverStore);

                        // if not detected, install Inf-file in Windows Driver Store
                        if (Devcon.Install(busInfPath, ref rebootRequired))
                        {
                            Log.Info("Virtual Bus Driver pre-installed in Windows Driver Store successfully");

                            MainBusyIndicator.SetContentThreadSafe(Properties.Resources.VirtualBusSetupCreating);

                            // create pseudo-device so the bus driver can attach to it later
                            if (Devcon.Create("System", new Guid("{4D36E97D-E325-11CE-BFC1-08002BE10318}"),
                                              "root\\ScpVBus\0\0"))
                            {
                                Log.Info("Virtual Bus Created");
                            }
                            else
                            {
                                Log.Fatal("Virtual Bus Device creation failed");
                                failed = true;
                            }
                        }
                        else
                        {
                            Log.FatalFormat("Virtual Bus Driver pre-installation failed with Win32 error {0}",
                                            (uint)Marshal.GetLastWin32Error());
                            failed = true;
                        }
                    }

                    MainBusyIndicator.SetContentThreadSafe(Properties.Resources.VirtualBusSetupInstalling);

                    // install Virtual Bus driver
                    var result = Difx.Instance.Install(busInfPath,
                                                       DifxFlags.DRIVER_PACKAGE_ONLY_IF_DEVICE_PRESENT | DifxFlags.DRIVER_PACKAGE_FORCE,
                                                       out rebootRequired);

                    if (result != 0)
                    {
                        failed = true;
                    }
                }
                catch (Exception ex)
                {
                    Log.ErrorFormat("Error during installation: {0}", ex);
                }
            });

            MainBusyIndicator.IsBusy = !MainBusyIndicator.IsBusy;

            // display error message
            if (failed)
            {
                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.VirtualBusSetupSuccessInstruction,
                                    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);
            }
        }
        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);
            }
        }
Exemple #5
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");

            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.SetupSuccessTitle,
                                        Properties.Resources.DualShockSetupSuccessInstruction,
                                        Properties.Resources.SetupSuccessContent,
                                        string.Empty,
                                        string.Empty,
                                        TaskDialogIcon.Information);
            }

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