/// <summary> /// Equipes a given device with the WinUSB driver. /// </summary> /// <param name="device">The device to perform the driver installation on.</param> /// <param name="deviceGuid">The device class GUID of the driver.</param> /// <param name="driverPath">The filesystem path to extract the driver and helper files to.</param> /// <param name="infName">The name of the *.INF file to create.</param> /// <param name="hwnd">The handle of the parent window to relate the progress dialog to.</param> /// <returns>The error code (0 if succeeded).</returns> public static WdiErrorCode InstallWinUsbDriver(WdiDeviceInfo device, Guid deviceGuid, string driverPath, string infName, IntPtr hwnd = default(IntPtr)) { // build CLI args var cliArgs = new StringBuilder(); switch (device.DeviceType) { case WdiUsbDeviceType.BluetoothHost: cliArgs.AppendFormat("--name \"Bluetooth Host (ScpToolkit)\" "); break; case WdiUsbDeviceType.DualShock3: cliArgs.AppendFormat("--name \"DualShock 3 Controller (ScpToolkit)\" "); break; case WdiUsbDeviceType.DualShock4: cliArgs.AppendFormat("--name \"DualShock 4 Controller (ScpToolkit)\" "); break; } cliArgs.AppendFormat("--inf \"{0}\" ", infName); cliArgs.AppendFormat("--manufacturer \"ScpToolkit compatible device\" "); cliArgs.AppendFormat("--vid 0x{0:X4} --pid 0x{1:X4} ", device.VendorId, device.ProductId); cliArgs.AppendFormat("--type 0 "); cliArgs.AppendFormat("--dest \"{0}\" ", driverPath); cliArgs.AppendFormat("--stealth-cert "); if (hwnd != default(IntPtr)) { cliArgs.AppendFormat("--progressbar={0:D} ", hwnd.ToInt64()); } cliArgs.AppendFormat("--timeout 120000 "); cliArgs.AppendFormat("--device-guid \"{0}\" ", deviceGuid.ToString("B")); // build path to install helper var wdiSimplePath = Path.Combine(GlobalConfiguration.AppDirectory, "libwdi", Environment.Is64BitProcess ? "amd64" : "x86", "wdi-simple.exe"); // set-up installer process var wdiProc = new Process { StartInfo = new ProcessStartInfo(wdiSimplePath, cliArgs.ToString()) { RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true } }; // start & wait wdiProc.Start(); wdiProc.WaitForExit(); // return code of application is possible error code return((WdiErrorCode)wdiProc.ExitCode); }
public static WdiErrorCode InstallBluetoothHost(WdiDeviceInfo usbDevice, IntPtr hWnd = default(IntPtr), bool force = false) { usbDevice.InfFile = string.Format("BluetoothHost_{0:X4}_{1:X4}.inf", usbDevice.VendorId, usbDevice.ProductId); usbDevice.DeviceType = WdiUsbDeviceType.BluetoothHost; var result = WdiWrapper.Instance.InstallWinUsbDriver(usbDevice.DeviceId, BthDongle.DeviceClassGuid, DriverDirectory, usbDevice.InfFile, hWnd, force); if (result != WdiErrorCode.WDI_SUCCESS) { Log.ErrorFormat("Installing Bluetooth Host ({0}) failed: {1}", usbDevice.DeviceId, result); return(result); } using (var db = new ScpDb()) { db.Engine.PutDbEntity(ScpDb.TableDevices, usbDevice.DeviceId, usbDevice); } return(result); }
public static WdiErrorCode InstallDualShock4Controller(WdiDeviceInfo usbDevice, IntPtr hWnd = default(IntPtr)) { usbDevice.InfFile = string.Format("Ds4Controller_{0:X4}_{1:X4}.inf", usbDevice.VendorId, usbDevice.ProductId); usbDevice.DeviceType = WdiUsbDeviceType.DualShock4; var result = WdiWrapper.InstallWinUsbDriver(usbDevice, UsbDs4.DeviceClassGuid, DriverDirectory, usbDevice.InfFile, hWnd); if (result != WdiErrorCode.WDI_SUCCESS) { Log.ErrorFormat("Installing DualShock 4 Controller ({0}) failed: {1}", usbDevice.DeviceId, result); return(result); } using (var db = new ScpDb()) { db.Engine.PutDbEntity(ScpDb.TableDevices, usbDevice.DeviceId, usbDevice); } return(result); }