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; 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 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); } }