Пример #1
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            MainButton.IsEnabled = !MainButton.IsEnabled;

            await Task.Run(() =>
            {
                #region Service tasks

                Log.InfoFormat("Stopping \"SCP DS3 Service\"...");
                StopService("SCP DS3 Service");

                Log.InfoFormat("Stopping \"SCP DSx Service\"...");
                StopService("SCP DSx Service");

                Log.InfoFormat("Searching for running processes...");
                foreach (var proc in Process.GetProcessesByName("Ds3Service"))
                {
                    Log.InfoFormat("Killing process: {0}", proc.ProcessName);
                    proc.Kill();
                }

                foreach (var proc in Process.GetProcessesByName("DsxService"))
                {
                    Log.InfoFormat("Killing process: {0}", proc.ProcessName);
                    proc.Kill();
                }

                Log.InfoFormat("Removing service...");
                Process.Start("sc", "delete Ds3Service").WaitForExit();

                Process.Start("sc", "delete DsxService").WaitForExit();

                #endregion

                #region Driver store clean-up

                Log.InfoFormat("Searching the driver store...");
                var storeEntries = DrvStore.EnumeratePackages();

                foreach (var entry in storeEntries.Where(dse => dse.DriverPkgProvider.Equals("Scarlet.Crush Productions")))
                {
                    Log.InfoFormat("Removing package from driver store: {0} by {1}", entry.DriverPublishedName, entry.DriverPkgProvider);
                    DrvStore.DeletePackage(entry, true);
                }

                foreach (var entry in storeEntries.Where(dse => dse.DriverSignerName.Contains("libwdi autogenerated") &&
                                                         dse.DriverPkgProvider.Equals("libusbK")))
                {
                    Log.InfoFormat("Removing package from driver store: {0} by {1}", entry.DriverPublishedName, entry.DriverPkgProvider);
                    DrvStore.DeletePackage(entry, true);
                }

                foreach (var entry in storeEntries.Where(dse => dse.DriverPkgProvider.Contains("MotioninJoy")))
                {
                    Log.InfoFormat("Removing package from driver store: {0} by {1}", entry.DriverPublishedName, entry.DriverPkgProvider);
                    DrvStore.DeletePackage(entry, true);
                }

                #endregion

                #region Driver uninstallation

                string devPath      = string.Empty;
                string instanceId   = string.Empty;
                bool rebootRequired = false;

                DriverInstaller.UninstallBluetoothDongles(ref rebootRequired);

                DriverInstaller.UninstallDualShock3Controllers(ref rebootRequired);

                DriverInstaller.UninstallDualShock4Controllers(ref rebootRequired);

                if (Devcon.Find(Guid.Parse("f679f562-3164-42ce-a4db-e7ddbe723909"), ref devPath, ref instanceId))
                {
                    if (Devcon.Remove(Guid.Parse("f679f562-3164-42ce-a4db-e7ddbe723909"), devPath, instanceId))
                    {
                        Difx.Instance.Uninstall(Path.Combine(@".\System\", @"ScpVBus.inf"),
                                                DifxFlags.DRIVER_PACKAGE_DELETE_FILES,
                                                out rebootRequired);
                    }
                }

                while (Devcon.Find(Guid.Parse("2F87C733-60E0-4355-8515-95D6978418B2"), ref devPath, ref instanceId))
                {
                    Devcon.Remove(Guid.Parse("2F87C733-60E0-4355-8515-95D6978418B2"), devPath, instanceId);
                }

                while (Devcon.Find(Guid.Parse("E2824A09-DBAA-4407-85CA-C8E8FF5F6FFA"), ref devPath, ref instanceId))
                {
                    Devcon.Remove(Guid.Parse("E2824A09-DBAA-4407-85CA-C8E8FF5F6FFA"), devPath, instanceId);
                }

                while (Devcon.Find(Guid.Parse("2ED90CE1-376F-4982-8F7F-E056CBC3CA71"), ref devPath, ref instanceId))
                {
                    Devcon.Remove(Guid.Parse("2ED90CE1-376F-4982-8F7F-E056CBC3CA71"), devPath, instanceId);
                }

                Devcon.Refresh();

                #endregion

                #region Cert store clean-up

                CertStore.Open(OpenFlags.MaxAllowed);

                foreach (var cert in CertStore.Certificates.Cast <X509Certificate2>().Where(c => c.FriendlyName.Contains("libwdi")))
                {
                    Log.InfoFormat("Removing certificate from root certificate store: {0}", cert.SubjectName.Name);
                    CertStore.Remove(cert);
                }

                //Close the store.
                CertStore.Close();

                #endregion
            });

            MainButton.IsEnabled = !MainButton.IsEnabled;

            MessageBox.Show("All steps finished, now try ScpDriverInstaller again! Good luck :)", "Finished",
                            MessageBoxButton.OK, MessageBoxImage.Information);

            Close();
        }
Пример #2
0
        private async void btnUninstall_Click(object sender, EventArgs e)
        {
            #region Pre-Uninstallation

            _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 Uninstallation

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

                try
                {
                    uint result         = 0;
                    bool rebootRequired = false;

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

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

                        if (Stop(Settings.Default.ScpServiceName))
                        {
                            Logger(DifxLog.DIFXAPI_INFO, 0, Settings.Default.ScpServiceName + " Stopped.");
                        }

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

                    if (cbBluetooth.Checked)
                    {
                        DriverInstaller.UninstallBluetoothDongles(ref rebootRequired);
                        _reboot |= rebootRequired;
                    }

                    if (cbDS3.Checked)
                    {
                        DriverInstaller.UninstallDualShock3Controllers(ref rebootRequired);
                        _reboot |= rebootRequired;
                    }

                    if (cbDs4.Checked)
                    {
                        DriverInstaller.UninstallDualShock4Controllers(ref rebootRequired);
                        _reboot |= rebootRequired;
                    }

                    if (cbBus.Checked && Devcon.Find(Settings.Default.Ds3BusClassGuid, ref devPath, ref instanceId))
                    {
                        if (Devcon.Remove(Settings.Default.Ds3BusClassGuid, devPath, instanceId))
                        {
                            Logger(DifxLog.DIFXAPI_SUCCESS, 0, "Virtual Bus Removed");
                            _busDeviceConfigured = true;

                            _installer.Uninstall(Path.Combine(Settings.Default.InfFilePath, @"ScpVBus.inf"),
                                                 DifxFlags.DRIVER_PACKAGE_DELETE_FILES,
                                                 out rebootRequired);
                            _reboot |= rebootRequired;
                        }
                        else
                        {
                            Logger(DifxLog.DIFXAPI_ERROR, 0, "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

            pbRunning.Style = ProgressBarStyle.Continuous;

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

            Cursor = _saved;

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

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

            if (_scpServiceConfigured)
            {
                Log.Info("SCP DS3 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
        }