/// <summary>Uninstall the ScpVBus driver.</summary>
        /// <remarks>Throws ScpDriverUninstallException upon known errors.</remarks>
        /// <returns>false if a reboot is still required to complete uninstallation, else true to indicate completion.</returns>
        public static bool Uninstall()
        {
            return(UsingExtractedDriverAndInstaller((inf, installer) =>
            {
                var devPath = "";
                var instanceId = "";

                if (Devcon.Find(new Guid(SCP_BUS_CLASS_GUID), ref devPath, ref instanceId))
                {
                    if (!Devcon.Remove(new Guid(SCP_BUS_CLASS_GUID), devPath, instanceId))
                    {
                        throw new ScpDriverUninstallException("Unable to remove SCP Virtual Bus, cannot continue with uninstallation.");
                    }
                }

                try
                {
                    return installer.DriverPackageUninstall(inf, DriverPackageFlags.DELETE_FILES);
                }
                catch (DriverPackageException ex)
                {
                    var msg = ex.ErrorCode == 0xe0000302 ? "Driver not found. Are you sure it is installed?" : "Driver uninstall failed: " + ex.Message;
                    throw new ScpDriverUninstallException(msg);
                }
                catch (Exception ex)
                {
                    throw new ScpDriverUninstallException("Driver uninstall failed: " + ex.Message);
                }
            }));
        }
        /// <summary>Uninstall the ScpVBus driver.</summary>
        /// <remarks>Throws exceptions upon errors.</remarks>
        /// <returns>false if a reboot is still required to complete installation, else true to indicate completion.</returns>
        public static bool Uninstall()
        {
            string infPath    = @".\Driver\";
            string devPath    = "";
            string instanceId = "";

            uint result         = 0;
            bool rebootRequired = false;
            var  installer      = Difx.Factory();

            if (Devcon.Find(new Guid(SCP_BUS_CLASS_GUID), ref devPath, ref instanceId))
            {
                if (!Devcon.Remove(new Guid(SCP_BUS_CLASS_GUID), devPath, instanceId))
                {
                    throw new ScpDriverInstallException("Unable to remove SCP Virtual Bus, cannot continue with uninstallation.");
                }
            }

            result = installer.Uninstall(infPath + @"ScpVBus.inf", DifxFlags.DRIVER_PACKAGE_DELETE_FILES, out rebootRequired);
            if (result == 0xe0000302)
            {
                throw new ScpDriverInstallException("Driver not found, please ensure it is installed.");
            }
            else if (result != 0)
            {
                throw new ScpDriverInstallException("Driver uninstall failed with DIFxAPI error 0x" + result.ToString("X8"));
            }

            return(rebootRequired);
        }
        private void uninstall_Click(object sender, EventArgs e)
        {
            Color  oldColor = uninstall.ForeColor;
            string oldText  = uninstall.Text;

            uninstall.ForeColor = Color.LightGray;
            uninstall.Text      = "Uninstalling...";
            Update();

            string infPath    = @".\Driver\";
            string devPath    = "";
            string instanceId = "";

            uint result         = 0;
            bool rebootRequired = false;

            if (Devcon.Find(new Guid(SCP_BUS_CLASS_GUID), ref devPath, ref instanceId))
            {
                if (!Devcon.Remove(new Guid(SCP_BUS_CLASS_GUID), devPath, instanceId))
                {
                    MessageBox.Show("Unable to remove SCP Virtual Bus, cannot continue with uninstallation.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    uninstall.Text      = oldText;
                    uninstall.ForeColor = oldColor;
                    return;
                }
            }

            result = installer.Uninstall(infPath + @"ScpVBus.inf", DifxFlags.DRIVER_PACKAGE_DELETE_FILES, out rebootRequired);
            if (result == 0)
            {
                if (rebootRequired)
                {
                    MessageBox.Show("Driver successfully uninstalled, but a reboot may be required to complete uninstallation.", "Uninstall Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Driver successfully uninstalled!", "Uninstall Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else if (result == 0xe0000302)
            {
                MessageBox.Show("Driver not found, are you sure it's installed?", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                MessageBox.Show("Driver uninstall failed with DIFxAPI error 0x" + result.ToString("X8"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            uninstall.Text      = oldText;
            uninstall.ForeColor = oldColor;
        }
Beispiel #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
        }