/// <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); }
/// <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>Install 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 Install() { var infPath = @".\Driver\"; var devPath = ""; var instanceId = ""; var installer = Difx.Factory(); uint result = 0; bool rebootRequired = false; DifxFlags flags = DifxFlags.DRIVER_PACKAGE_ONLY_IF_DEVICE_PRESENT | DifxFlags.DRIVER_PACKAGE_FORCE; if (!Devcon.Find(new Guid(SCP_BUS_CLASS_GUID), ref devPath, ref instanceId)) { if (!Devcon.Create("System", new Guid("{4D36E97D-E325-11CE-BFC1-08002BE10318}"), "root\\ScpVBus\0\0")) { throw new ScpDriverInstallException("Unable to create SCP Virtual Bus. Cannot continue with installation."); } } result = installer.Install(infPath + @"ScpVBus.inf", flags, out rebootRequired); if (result != 0) { throw new ScpDriverInstallException("Driver installation failed with DIFxAPI error 0x" + result.ToString("X8")); } return(!rebootRequired); }
/// <summary>Install the ScpVBus driver.</summary> /// <remarks>Throws ScpDriverInstallException upon known errors.</remarks> /// <returns>false if a reboot is still required to complete installation, else true to indicate completion.</returns> public static bool Install() { return(UsingExtractedDriverAndInstaller((inf, installer) => { var devPath = ""; var instanceId = ""; var flags = DriverPackageFlags.ONLY_IF_DEVICE_PRESENT | DriverPackageFlags.FORCE; if (!Devcon.Find(new Guid(SCP_BUS_CLASS_GUID), ref devPath, ref instanceId)) { if (!Devcon.Create("System", new Guid("{4D36E97D-E325-11CE-BFC1-08002BE10318}"), "root\\ScpVBus\0\0")) { throw new ScpDriverInstallException("Unable to create SCP Virtual Bus. Cannot continue with installation."); } } try { return installer.DriverPackageInstall(inf, flags); } catch (Exception ex) { throw new ScpDriverInstallException("Driver installation failed: " + ex.Message); } })); }
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; }
private void install_Click(object sender, EventArgs e) { Color oldColor = install.ForeColor; string oldText = install.Text; install.ForeColor = Color.LightGray; install.Text = "Installing..."; Update(); string infPath = @".\Driver\"; string devPath = ""; string instanceId = ""; uint result = 0; bool rebootRequired = false; DifxFlags flags = DifxFlags.DRIVER_PACKAGE_ONLY_IF_DEVICE_PRESENT | DifxFlags.DRIVER_PACKAGE_FORCE; if (!Devcon.Find(new Guid(SCP_BUS_CLASS_GUID), ref devPath, ref instanceId)) { if (!Devcon.Create("System", new Guid("{4D36E97D-E325-11CE-BFC1-08002BE10318}"), "root\\ScpVBus\0\0")) { MessageBox.Show("Unable to create SCP Virtual Bus, cannot continue with installation.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); install.Text = oldText; install.ForeColor = oldColor; return; } } result = installer.Install(infPath + @"ScpVBus.inf", flags, out rebootRequired); if (result == 0) { if (rebootRequired) { MessageBox.Show("Driver successfully installed, but a reboot may be required for it to work properly.", "Installation Successful", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Driver successfully installed!", "Installation Successful", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("Driver installation failed with DIFxAPI error 0x" + result.ToString("X8"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } install.Text = oldText; install.ForeColor = oldColor; }
private async void InstallVBusOnClick(object sender, RoutedEventArgs e) { MainBusyIndicator.IsBusy = !MainBusyIndicator.IsBusy; await Task.Run(() => { string devPath = string.Empty, instanceId = string.Empty; try { var rebootRequired = false; var busInfPath = Path.Combine( GlobalConfiguration.AppDirectory, "ScpVBus", Environment.Is64BitOperatingSystem ? "amd64" : "x86", "ScpVBus.inf"); Log.DebugFormat("ScpVBus.inf path: {0}", busInfPath); // check for existance of Scp VBus if (!Devcon.Find(Settings.Default.VirtualBusClassGuid, ref devPath, ref instanceId)) { UiContext.InvokeOnUiThread( () => { MainBusyIndicator.BusyContent = "Installing Virtual Bus Driver in Windows Driver Store"; }); // if not detected, install Inf-file in Windows Driver Store if (Devcon.Install(busInfPath, ref rebootRequired)) { Log.Info("Virtual Bus Driver pre-installed in Windows Driver Store successfully"); UiContext.InvokeOnUiThread( () => { MainBusyIndicator.BusyContent = "Creating Hardware ID for Virtual Bus"; }); // create pseudo-device so the bus driver can attach to it later if (Devcon.Create("System", new Guid("{4D36E97D-E325-11CE-BFC1-08002BE10318}"), "root\\ScpVBus\0\0")) { Log.Info("Virtual Bus Created"); _busDeviceConfigured = true; } else { Log.Fatal("Virtual Bus Device creation failed"); return; } } else { Log.FatalFormat("Virtual Bus Driver pre-installation failed with Win32 error {0}", (uint)Marshal.GetLastWin32Error()); return; } } UiContext.InvokeOnUiThread( () => { MainBusyIndicator.BusyContent = "Installing driver on Virtual Bus"; }); // install Virtual Bus driver var result = Difx.Instance.Install(busInfPath, DifxFlags.DRIVER_PACKAGE_ONLY_IF_DEVICE_PRESENT | DifxFlags.DRIVER_PACKAGE_FORCE, out rebootRequired); _reboot |= rebootRequired; if (result == 0) { _busDriverConfigured = true; } } catch (Exception ex) { Log.ErrorFormat("Error during installation: {0}", ex); } }); MainBusyIndicator.IsBusy = !MainBusyIndicator.IsBusy; }
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 }
private async void ViewModelOnInstallButtonClicked(object sender, EventArgs eventArgs) { #region Pre-Installation _saved = Cursor; Cursor = Cursors.Wait; InstallGrid.IsEnabled = !InstallGrid.IsEnabled; MainProgressBar.IsIndeterminate = !MainProgressBar.IsIndeterminate; #endregion #region Driver Installation await Task.Run(() => { string devPath = string.Empty, instanceId = string.Empty; var forceInstall = _viewModel.ForceDriverInstallation; try { uint result = 0; var flags = DifxFlags.DRIVER_PACKAGE_ONLY_IF_DEVICE_PRESENT; if (forceInstall) { flags |= DifxFlags.DRIVER_PACKAGE_FORCE; } var rebootRequired = false; var busInfPath = Path.Combine(GlobalConfiguration.AppDirectory, "System", "ScpVBus.inf"); Log.DebugFormat("ScpVBus.inf path: {0}", busInfPath); // check for existance of Scp VBus if (!Devcon.Find(Settings.Default.VirtualBusClassGuid, ref devPath, ref instanceId)) { // if not detected, install Inf-file in Windows Driver Store if (Devcon.Install(busInfPath, ref rebootRequired)) { Log.Info("Virtual Bus Driver pre-installed in Windows Driver Store successfully"); 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; } else { Log.Fatal("Virtual Bus Device creation failed"); return; } } else { Log.FatalFormat("Virtual Bus Driver pre-installation failed with Win32 error {0}", (uint)Marshal.GetLastWin32Error()); return; } } // install Virtual Bus driver result = _installer.Install(busInfPath, flags, out rebootRequired); _reboot |= rebootRequired; if (result == 0) { _busDriverConfigured = true; } // install Xbox 360 driver if requested (Vista/7 only) if (_viewModel.IsXbox360DriverNeeded && _viewModel.InstallXbox360Driver) { string driverPath = string.Empty, os = OsInfoHelper.OsInfo; switch (OsInfoHelper.OsParse(os)) { case OsType.Vista: driverPath = Path.Combine(GlobalConfiguration.AppDirectory, @"Xbox360\driver\vista_xp\xusb21.inf"); break; case OsType.Win7: driverPath = Path.Combine(GlobalConfiguration.AppDirectory, @"Xbox360\driver\win7\xusb21.inf"); break; default: Log.WarnFormat( "Microsoft Xbox 360 controller driver installation for unknown OS requested, won't install driver"); break; } if (driverPath != string.Empty) { Log.DebugFormat("{0} detected, {1} driver selected", os, driverPath); Log.InfoFormat("Installing Microsoft Xbox 360 controller driver in Windows Driver Store"); if (Devcon.Install(driverPath, ref rebootRequired)) { Log.Info("Successfully installed Microsoft Xbox 360 controller driver"); } else { Log.ErrorFormat("Couldn't install Microsoft Xbox 360 controller drivers [{0}]", driverPath); } } } if (_viewModel.InstallWindowsService) { IDictionary state = new Hashtable(); var service = new AssemblyInstaller(Path.Combine(GlobalConfiguration.AppDirectory, "ScpService.exe"), null); state.Clear(); service.UseNewContext = true; service.Install(state); service.Commit(state); if (StartService(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.Info("Service already exists, attempting to restart..."); StopService(Settings.Default.ScpServiceName); Log.Info("Service stopped successfully"); StartService(Settings.Default.ScpServiceName); Log.Info("Service started successfully"); break; default: Log.ErrorFormat("Win32-Error during installation: {0}", w32Ex); break; } } catch (InvalidOperationException iopex) { Log.ErrorFormat("Error during installation: {0}", iopex.Message); } catch (Exception ex) { Log.ErrorFormat("Error during installation: {0}", ex); } }); #endregion #region Post-Installation MainProgressBar.IsIndeterminate = !MainProgressBar.IsIndeterminate; InstallGrid.IsEnabled = !InstallGrid.IsEnabled; Cursor = _saved; if (_reboot) { Log.InfoFormat("[Reboot Required]"); } if (_scpServiceConfigured) { Log.Info("SCP DSx Service installed"); } if (_busDeviceConfigured) { Log.Info("Bus Device installed"); } if (_busDriverConfigured) { Log.Info("Bus Driver installed"); } if (_ds3DriverConfigured) { Log.Info("DualShock 3 USB Driver installed"); } if (_bthDriverConfigured) { Log.Info("Bluetooth Driver installed"); } if (_ds4DriverConfigured) { Log.Info("DualShock 4 USB Driver installed"); } #endregion }
private async void InstallVBusOnClick(object sender, RoutedEventArgs e) { MainBusyIndicator.IsBusy = !MainBusyIndicator.IsBusy; var failed = false; var rebootRequired = false; await Task.Run(() => { string devPath = string.Empty, instanceId = string.Empty; try { var busInfPath = Path.Combine( GlobalConfiguration.AppDirectory, "ScpVBus", Environment.Is64BitOperatingSystem ? "amd64" : "x86", "ScpVBus.inf"); Log.DebugFormat("ScpVBus.inf path: {0}", busInfPath); // check for existence of Scp VBus if (!Devcon.Find(Settings.Default.VirtualBusClassGuid, ref devPath, ref instanceId)) { MainBusyIndicator.SetContentThreadSafe(Properties.Resources.VirtualBusSetupAddingDriverStore); // if not detected, install Inf-file in Windows Driver Store if (Devcon.Install(busInfPath, ref rebootRequired)) { Log.Info("Virtual Bus Driver pre-installed in Windows Driver Store successfully"); MainBusyIndicator.SetContentThreadSafe(Properties.Resources.VirtualBusSetupCreating); // create pseudo-device so the bus driver can attach to it later if (Devcon.Create("System", new Guid("{4D36E97D-E325-11CE-BFC1-08002BE10318}"), "root\\ScpVBus\0\0")) { Log.Info("Virtual Bus Created"); } else { Log.Fatal("Virtual Bus Device creation failed"); failed = true; } } else { Log.FatalFormat("Virtual Bus Driver pre-installation failed with Win32 error {0}", (uint)Marshal.GetLastWin32Error()); failed = true; } } MainBusyIndicator.SetContentThreadSafe(Properties.Resources.VirtualBusSetupInstalling); // install Virtual Bus driver var result = Difx.Instance.Install(busInfPath, DifxFlags.DRIVER_PACKAGE_ONLY_IF_DEVICE_PRESENT | DifxFlags.DRIVER_PACKAGE_FORCE, out rebootRequired); if (result != 0) { failed = true; } } catch (Exception ex) { Log.ErrorFormat("Error during installation: {0}", ex); } }); MainBusyIndicator.IsBusy = !MainBusyIndicator.IsBusy; // display error message if (failed) { ExtendedMessageBox.Show(this, Properties.Resources.SetupFailedTitle, Properties.Resources.SetupFailedInstructions, Properties.Resources.SetupFailedContent, string.Format(Properties.Resources.SetupFailedVerbose, new Win32Exception(Marshal.GetLastWin32Error()), Marshal.GetLastWin32Error()), Properties.Resources.SetupFailedFooter, TaskDialogIcon.Error); return; } // display success message ExtendedMessageBox.Show(this, Properties.Resources.SetupSuccessTitle, Properties.Resources.VirtualBusSetupSuccessInstruction, Properties.Resources.SetupSuccessContent, string.Empty, string.Empty, TaskDialogIcon.Information); // display reboot required message if (rebootRequired) { MessageBox.Show(this, Properties.Resources.RebootRequiredContent, Properties.Resources.RebootRequiredTitle, MessageBoxButton.OK, MessageBoxImage.Warning); } }