private async void btnInstall_Click()

in ScpInstaller/ScpForm.cs [178:336]


        private async void btnInstall_Click(object sender, EventArgs e)
        {
            #region Pre-Installation

            _saved = Cursor;
            Cursor = Cursors.WaitCursor;

            btnInstall.Enabled = false;
            btnUninstall.Enabled = false;
            btnExit.Enabled = false;

            _busDeviceConfigured = false;
            _busDriverConfigured = false;
            _ds3DriverConfigured = false;
            _bthDriverConfigured = false;
            _scpServiceConfigured = false;

            pbRunning.Style = ProgressBarStyle.Marquee;

            var forceInstall = cbForce.Checked;
            var installBus = cbBus.Checked;
            var installBth = cbBluetooth.Checked;
            var installDs3 = cbDS3.Checked;
            var installDs4 = cbDs4.Checked;
            var installService = cbService.Checked;

            #endregion

            #region Installation

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

                try
                {
                    uint result = 0;

                    var flags = DifxFlags.DRIVER_PACKAGE_ONLY_IF_DEVICE_PRESENT;

                    if (forceInstall)
                        flags |= DifxFlags.DRIVER_PACKAGE_FORCE;

                    if (installBus)
                    {
                        if (!Devcon.Find(Settings.Default.Ds3BusClassGuid, ref devPath, ref instanceId))
                        {
                            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;
                            }
                        }

                        bool rebootRequired;
                        result = _installer.Install(Path.Combine(Settings.Default.InfFilePath, @"ScpVBus.inf"), flags,
                            out rebootRequired);
                        _reboot |= rebootRequired;
                        if (result == 0) _busDriverConfigured = true;
                    }

                    if (installBth)
                    {
                        Invoke(
                            (MethodInvoker) delegate { result = DriverInstaller.InstallBluetoothDongles(Handle, forceInstall); });
                        if (result > 0) _bthDriverConfigured = true;
                    }

                    if (installDs3)
                    {
                        Invoke(
                            (MethodInvoker)
                                delegate { result = DriverInstaller.InstallDualShock3Controllers(Handle, forceInstall); });
                        if (result > 0) _ds3DriverConfigured = true;
                    }

                    if (installDs4)
                    {
                        Invoke(
                            (MethodInvoker)
                                delegate { result = DriverInstaller.InstallDualShock4Controllers(Handle, forceInstall); });
                        if (result > 0) _ds4DriverConfigured = true;
                    }

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

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

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

                        if (Start(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.WarnFormat("Service already exists, skipping installation...");
                            break;
                        default:
                            Log.ErrorFormat("Win32-Error during installation: {0}", w32Ex);
                            break;
                    }
                }
                catch (Exception ex)
                {
                    Log.ErrorFormat("Error during installation: {0}", ex);
                }
            });

            #endregion

            #region Post-Installation

            pbRunning.Style = ProgressBarStyle.Continuous;

            btnInstall.Enabled = true;
            btnUninstall.Enabled = true;
            btnExit.Enabled = true;

            Cursor = _saved;

            Log.Info("Install Succeeded.");
            if (_reboot)
                Log.InfoFormat("[Reboot Required]");

            Log.Info("-- Install Summary --");
            if (_scpServiceConfigured)
                Log.Info("SCP DS3 Service installed");

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

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

            if (_ds3DriverConfigured)
                Log.Info("DS3 USB Driver installed");

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

            if (_ds4DriverConfigured)
                Log.Info("DS4 USB Driver installed");

            #endregion
        }