static int Main(string[] args)
        {
            ParseArgs(args);
            if (_install || _uninstall || _quiet)
            {
                return(DriverInstaller.doInstaller(_uninstall, _quiet));
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new DriverInstaller());
            return(0);
        }
Exemple #2
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);
            }
        }
Exemple #3
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);
                }
            }
        }
Exemple #4
0
        private async void ViewModelOnUninstallButtonClicked(object sender, EventArgs eventArgs)
        {
            #region Pre-Installation

            _saved = Cursor;
            Cursor = Cursors.Wait;
            InstallGrid.IsEnabled           = !InstallGrid.IsEnabled;
            MainProgressBar.IsIndeterminate = !MainProgressBar.IsIndeterminate;

            #endregion

            #region Uninstallation

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

                try
                {
                    var rebootRequired   = false;
                    _bthDriverConfigured = false;
                    _ds3DriverConfigured = false;
                    _ds4DriverConfigured = false;
                    _busDriverConfigured = false;
                    _busDeviceConfigured = false;

                    if (_viewModel.InstallWindowsService)
                    {
                        IDictionary state = new Hashtable();
                        var service       =
                            new AssemblyInstaller(Directory.GetCurrentDirectory() + @"\ScpService.exe", null);

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

                        if (StopService(Settings.Default.ScpServiceName))
                        {
                            Log.InfoFormat("{0} stopped", Settings.Default.ScpServiceName);
                        }

                        service.Uninstall(state);
                        _scpServiceConfigured = true;
                    }

                    uint result = 0;

                    if (_viewModel.InstallBluetoothDriver)
                    {
                        result = DriverInstaller.UninstallBluetoothDongles(ref rebootRequired);

                        if (result > 0)
                        {
                            _bthDriverConfigured = true;
                        }
                        _reboot |= rebootRequired;
                    }

                    if (_viewModel.InstallDualShock3Driver)
                    {
                        result = DriverInstaller.UninstallDualShock3Controllers(ref rebootRequired);

                        if (result > 0)
                        {
                            _ds3DriverConfigured = true;
                        }
                        _reboot |= rebootRequired;
                    }

                    if (_viewModel.InstallDualShock4Driver)
                    {
                        result = DriverInstaller.UninstallDualShock4Controllers(ref rebootRequired);

                        if (result > 0)
                        {
                            _ds4DriverConfigured = true;
                        }
                        _reboot |= rebootRequired;
                    }

                    if (Devcon.Find(Settings.Default.VirtualBusClassGuid, ref devPath, ref instanceId))
                    {
                        if (Devcon.Remove(Settings.Default.VirtualBusClassGuid, devPath, instanceId))
                        {
                            Log.Info("Virtual Bus Removed");
                            _busDeviceConfigured = true;

                            Difx.Instance.Uninstall(Path.Combine(Settings.Default.InfFilePath, @"ScpVBus.inf"),
                                                    DifxFlags.DRIVER_PACKAGE_DELETE_FILES,
                                                    out rebootRequired);
                            _reboot |= rebootRequired;

                            _busDriverConfigured = true;
                            _busDeviceConfigured = true;
                        }
                        else
                        {
                            Log.Error("Virtual Bus Removal Failure");
                        }
                    }
                }
                catch (InstallException instex)
                {
                    if (!(instex.InnerException is Win32Exception))
                    {
                        Log.ErrorFormat("Error during uninstallation: {0}", instex);
                        return;
                    }

                    switch (((Win32Exception)instex.InnerException).NativeErrorCode)
                    {
                    case 1060:     // ERROR_SERVICE_DOES_NOT_EXIST
                        Log.Warn("Service doesn't exist, maybe it was uninstalled before");
                        break;

                    default:
                        Log.ErrorFormat("Win32-Error during uninstallation: {0}",
                                        (Win32Exception)instex.InnerException);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Log.ErrorFormat("Error during uninstallation: {0}", ex);
                }
            });

            #endregion

            #region Post-Uninstallation

            MainProgressBar.IsIndeterminate = !MainProgressBar.IsIndeterminate;
            InstallGrid.IsEnabled           = !InstallGrid.IsEnabled;
            Cursor = _saved;


            if (_reboot)
            {
                Log.Info("[Reboot Required]");
            }

            Log.Info("-- Uninstall Summary --");

            if (_scpServiceConfigured)
            {
                Log.Info("SCP DSx Service uninstalled");
            }

            if (_busDeviceConfigured)
            {
                Log.Info("Bus Device uninstalled");
            }

            if (_busDriverConfigured)
            {
                Log.Info("Bus Driver uninstalled");
            }

            if (_ds3DriverConfigured)
            {
                Log.Info("DS3 USB Driver uninstalled");
            }

            if (_bthDriverConfigured)
            {
                Log.Info("Bluetooth Driver uninstalled");
            }

            #endregion
        }
        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 #6
0
        private async void ViewModelOnInstallButtonClicked(object sender, EventArgs eventArgs)
        {
            #region Preparation

            // get selected Bluetooth devices
            var donglesToInstall =
                BluetoothStackPanel.Children.Cast <CheckBox>()
                .Where(c => c.IsChecked == true)
                .Select(c => c.Content)
                .Cast <WdiUsbDevice>()
                .ToList();

            if (_viewModel.InstallBluetoothDriver && !donglesToInstall.Any())
            {
                ShowPopup(Properties.Resources.BthListEmpty_Title,
                          Properties.Resources.BthListEmpty_Text,
                          NotificationType.Warning);
            }

            // get selected DualShock 3 devices
            var ds3SToInstall =
                DualShock3StackPanel.Children.Cast <CheckBox>()
                .Where(c => c.IsChecked == true)
                .Select(c => c.Content)
                .Cast <WdiUsbDevice>()
                .ToList();

            if (_viewModel.InstallDualShock3Driver && !ds3SToInstall.Any())
            {
                ShowPopup(Properties.Resources.Ds3ListEmpty_Title,
                          Properties.Resources.Ds3ListEmpty_Text,
                          NotificationType.Warning);
            }

            // get selected DualShock 4 devices
            var ds4SToInstall =
                DualShock4StackPanel.Children.Cast <CheckBox>()
                .Where(c => c.IsChecked == true)
                .Select(c => c.Content)
                .Cast <WdiUsbDevice>()
                .ToList();

            if (_viewModel.InstallDualShock4Driver && !ds4SToInstall.Any())
            {
                ShowPopup(Properties.Resources.Ds4ListEmpty_Title,
                          Properties.Resources.Ds4ListEmpty_Text,
                          NotificationType.Warning);
            }

            #endregion

            #region Pre-Installation

            _saved = Cursor;
            Cursor = Cursors.Wait;
            InstallGrid.IsEnabled           = !InstallGrid.IsEnabled;
            MainProgressBar.IsIndeterminate = !MainProgressBar.IsIndeterminate;

            #endregion

            #region Driver Installation

            await Task.Run(() =>
            {
                string devPath   = string.Empty, instanceId = string.Empty;
                var forceInstall = _viewModel.ForceDriverInstallation;

                try
                {
                    uint result = 0;

                    var flags = DifxFlags.DRIVER_PACKAGE_ONLY_IF_DEVICE_PRESENT;

                    if (forceInstall)
                    {
                        flags |= DifxFlags.DRIVER_PACKAGE_FORCE;
                    }

                    var rebootRequired = false;
                    var busInfPath     = Path.Combine(GlobalConfiguration.AppDirectory,
                                                      "System", "ScpVBus.inf");
                    Log.DebugFormat("ScpVBus.inf path: {0}", busInfPath);

                    // check for existance of Scp VBus
                    if (!Devcon.Find(Settings.Default.VirtualBusClassGuid, ref devPath, ref instanceId))
                    {
                        // 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");

                            if (Devcon.Create("System", new Guid("{4D36E97D-E325-11CE-BFC1-08002BE10318}"),
                                              "root\\ScpVBus\0\0"))
                            {
                                Logger(DifxLog.DIFXAPI_SUCCESS, 0, "Virtual Bus Created");
                                _busDeviceConfigured = true;
                            }
                            else
                            {
                                Log.Fatal("Virtual Bus Device creation failed");
                                return;
                            }
                        }
                        else
                        {
                            Log.FatalFormat("Virtual Bus Driver pre-installation failed with Win32 error {0}",
                                            (uint)Marshal.GetLastWin32Error());
                            return;
                        }
                    }

                    // install Virtual Bus driver
                    result = _installer.Install(busInfPath, flags,
                                                out rebootRequired);

                    _reboot |= rebootRequired;
                    if (result == 0)
                    {
                        _busDriverConfigured = true;
                    }

                    // install Xbox 360 driver if requested (Vista/7 only)
                    if (_viewModel.IsXbox360DriverNeeded && _viewModel.InstallXbox360Driver)
                    {
                        string driverPath = string.Empty, os = OsInfoHelper.OsInfo;

                        switch (OsInfoHelper.OsParse(os))
                        {
                        case OsType.Vista:
                            driverPath = Path.Combine(GlobalConfiguration.AppDirectory,
                                                      @"Xbox360\driver\vista_xp\xusb21.inf");
                            break;

                        case OsType.Win7:
                            driverPath = Path.Combine(GlobalConfiguration.AppDirectory,
                                                      @"Xbox360\driver\win7\xusb21.inf");
                            break;

                        default:
                            Log.WarnFormat("Microsoft Xbox 360 controller driver installation for unknown OS requested, won't install driver");
                            break;
                        }

                        if (driverPath != string.Empty)
                        {
                            Log.DebugFormat("{0} detected, {1} driver selected", os, driverPath);
                            Log.InfoFormat("Installing Microsoft Xbox 360 controller driver in Windows Driver Store");

                            if (Devcon.Install(driverPath, ref rebootRequired))
                            {
                                Log.Info("Successfully installed Microsoft Xbox 360 controller driver");
                            }
                            else
                            {
                                Log.ErrorFormat("Couldn't install Microsoft Xbox 360 controller drivers [{0}]", driverPath);
                            }
                        }
                    }

                    if (_viewModel.InstallBluetoothDriver)
                    {
                        result = DriverInstaller.InstallBluetoothDongles(donglesToInstall, force: forceInstall);

                        if (result > 0)
                        {
                            _bthDriverConfigured = true;
                        }
                    }

                    if (_viewModel.InstallDualShock3Driver)
                    {
                        result = DriverInstaller.InstallDualShock3Controllers(ds3SToInstall, force: forceInstall);

                        if (result > 0)
                        {
                            _ds3DriverConfigured = true;
                        }
                    }

                    if (_viewModel.InstallDualShock4Driver)
                    {
                        result = DriverInstaller.InstallDualShock4Controllers(ds4SToInstall, force: forceInstall);

                        if (result > 0)
                        {
                            _ds4DriverConfigured = true;
                        }
                    }

                    if (_viewModel.InstallWindowsService)
                    {
                        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))
                        {
                            Logger(DifxLog.DIFXAPI_INFO, 0, Settings.Default.ScpServiceName + " Started.");
                        }
                        else
                        {
                            _reboot = true;
                        }

                        _scpServiceConfigured = true;
                    }
                }
                catch (Win32Exception w32Ex)
                {
                    switch (w32Ex.NativeErrorCode)
                    {
                    case 1073:     // ERROR_SERVICE_EXISTS
                        Log.Info("Service already exists, attempting to restart...");

                        StopService(Settings.Default.ScpServiceName);
                        Log.Info("Service stopped successfully");

                        StartService(Settings.Default.ScpServiceName);
                        Log.Info("Service started successfully");
                        break;

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

            #endregion

            #region Post-Installation

            MainProgressBar.IsIndeterminate = !MainProgressBar.IsIndeterminate;
            InstallGrid.IsEnabled           = !InstallGrid.IsEnabled;
            Cursor = _saved;

            if (_reboot)
            {
                Log.InfoFormat("[Reboot Required]");
            }

            if (_scpServiceConfigured)
            {
                Log.Info("SCP DSx Service installed");
            }

            if (_busDeviceConfigured)
            {
                Log.Info("Bus Device installed");
            }

            if (_busDriverConfigured)
            {
                Log.Info("Bus Driver installed");
            }

            if (_ds3DriverConfigured)
            {
                Log.Info("DualShock 3 USB Driver installed");
            }

            if (_bthDriverConfigured)
            {
                Log.Info("Bluetooth Driver installed");
            }

            if (_ds4DriverConfigured)
            {
                Log.Info("DualShock 4 USB Driver installed");
            }

            #endregion
        }