protected void UninstallWorker_DoWork(object sender, DoWorkEventArgs e) { String InfPath = (String)e.Argument; String DevPath = String.Empty, InstanceId = String.Empty; try { UInt32 Result = 0; Boolean RebootRequired = false; if (cbService.Checked) { IDictionary State = new Hashtable(); AssemblyInstaller Service = new AssemblyInstaller(Directory.GetCurrentDirectory() + @"\ScpService.exe", null); State.Clear(); Service.UseNewContext = true; if (Stop(ScpService)) { Logger(DifxLog.DIFXAPI_INFO, 0, ScpService + " Stopped."); } try { Service.Uninstall(State); Scp_Service_Configured = true; } catch { } } if (cbBluetooth.Checked) { Result = Installer.Uninstall(InfPath + @"BthWinUsb.inf", DifxFlags.DRIVER_PACKAGE_DELETE_FILES, out RebootRequired); Reboot |= RebootRequired; if (Result == 0) { BTH_Driver_Configured = true; } } Result = Installer.Uninstall(InfPath + @"Ds3WinUsb.inf", DifxFlags.DRIVER_PACKAGE_DELETE_FILES, out RebootRequired); Reboot |= RebootRequired; if (Result == 0) { DS3_Driver_Configured = true; } if (cbService.Checked && Devcon.Find(new Guid(DS3_BUS_CLASS_GUID), ref DevPath, ref InstanceId)) { if (Devcon.Remove(new Guid(DS3_BUS_CLASS_GUID), DevPath, InstanceId)) { Logger(DifxLog.DIFXAPI_SUCCESS, 0, "Virtual Bus Removed"); Bus_Device_Configured = true; } else { Logger(DifxLog.DIFXAPI_ERROR, 0, "Virtual Bus Removal Failure"); } } } catch { } }
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 }