Exemplo n.º 1
0
        protected void InstallWorker_DoWork(object sender, DoWorkEventArgs e) 
        {
            String InfPath = (String) e.Argument;
            String DevPath = String.Empty, InstanceId = String.Empty;

            try
            {
                UInt32  Result = 0;
                Boolean RebootRequired = false;

                DifxFlags Flags = DifxFlags.DRIVER_PACKAGE_ONLY_IF_DEVICE_PRESENT;

                if (cbForce.Checked) Flags |= DifxFlags.DRIVER_PACKAGE_FORCE;

                if (cbBus.Checked)
                {
                    if (!Devcon.Find(new Guid(DS3_BUS_CLASS_GUID), 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");
                            Bus_Device_Configured = true;
                        }
                    }

                    Result = Installer.Install(InfPath + @"ScpVBus.inf", Flags, out RebootRequired); Reboot |= RebootRequired;
                    if (Result == 0) Bus_Driver_Configured = true;
                }

                if (cbBluetooth.Checked)
                {
                    Result = Installer.Install(InfPath + @"BthWinUsb.inf", Flags, out RebootRequired); Reboot |= RebootRequired;
                    if (Result == 0) BTH_Driver_Configured = true;
                }


                if (cbDS3.Checked)
                {
                    Result = Installer.Install(InfPath + @"Ds3WinUsb.inf", Flags, out RebootRequired); Reboot |= RebootRequired;
                    if (Result == 0) DS3_Driver_Configured = true;
                }

                if (cbService.Checked)
                {
                    IDictionary       State = new Hashtable();
                    AssemblyInstaller Service = new AssemblyInstaller(Directory.GetCurrentDirectory() + @"\ScpService.exe", null);

                    State.Clear(); Service.UseNewContext = true;

                    Service.Install(State);
                    Service.Commit (State);

                    if (Start(ScpService)) Logger(DifxLog.DIFXAPI_INFO, 0, ScpService + " Started.");
                    else Reboot = true;

                    Scp_Service_Configured = true;
                }
            }
            catch { }
        }
Exemplo n.º 2
0
        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;

            #endregion

            #region Installation

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

                try
                {
                    uint result = 0;
                    bool rebootRequired;

                    var flags = DifxFlags.DRIVER_PACKAGE_ONLY_IF_DEVICE_PRESENT;

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

                    if (cbBus.Checked)
                    {
                        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;
                            }
                        }

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

                    if (cbBluetooth.Checked)
                    {
                        result = DriverInstaller.InstallBluetoothDongles(Handle);
                        if (result > 0)
                        {
                            _bthDriverConfigured = true;
                        }
                    }

                    if (cbDS3.Checked)
                    {
                        result = DriverInstaller.InstallDualShock3Controllers(Handle);
                        if (result > 0)
                        {
                            _ds3DriverConfigured = true;
                        }
                    }

                    if (cbDs4.Checked)
                    {
                        result = DriverInstaller.InstallDualShock4Controllers(Handle);
                        if (result > 0)
                        {
                            _ds4DriverConfigured = true;
                        }
                    }

                    if (cbService.Checked)
                    {
                        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
        }