public static uint InstallDualShock3Controllers(IEnumerable<WdiDeviceInfo> usbDevices, IntPtr hWnd = default(IntPtr), bool force = false) { // install compatible bluetooth dongles var ds3Drivers = IniConfig.Instance.Ds3Driver; uint installed = 0; foreach (var usbDevice in from usbDevice in usbDevices let result = WdiWrapper.Instance.InstallLibusbKDriver(usbDevice.DeviceId, ds3Drivers.DeviceGuid, DriverDirectory, string.Format("Ds3Controller_{0}.inf", Guid.NewGuid()), hWnd, force) where result == WdiErrorCode.WDI_SUCCESS select usbDevice) { usbDevice.DeviceType = WdiUsbDeviceType.DualShock3; using (var db = new ScpDb()) { db.Engine.PutDbEntity(ScpDb.TableDevices, usbDevice.DeviceId, usbDevice); } installed++; Log.InfoFormat("Installed driver for DualShock 3 controller {0}", usbDevice); } return installed; }
public static WdiErrorCode InstallBluetoothHost(WdiDeviceInfo usbDevice, IntPtr hWnd = default(IntPtr)) { usbDevice.InfFile = string.Format("BluetoothHost_{0:X4}_{1:X4}.inf", usbDevice.VendorId, usbDevice.ProductId); usbDevice.DeviceType = WdiUsbDeviceType.BluetoothHost; var result = WdiWrapper.InstallWinUsbDriver(usbDevice, BthDongle.DeviceClassGuid, DriverDirectory, usbDevice.InfFile, hWnd); 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; }
protected override void OnStart(string[] args) { var sw = Stopwatch.StartNew(); Log.Info("Scarlet.Crush Productions DSx Service Started"); Log.DebugFormat("++ {0} {1}", Assembly.GetExecutingAssembly().Location, Assembly.GetExecutingAssembly().GetName().Version); Log.DebugFormat("Setting working directory to {0}", GlobalConfiguration.AppDirectory); Directory.SetCurrentDirectory(GlobalConfiguration.AppDirectory); _mControlHandler = ServiceControlHandler; _mServiceHandle = ScpDevice.RegisterServiceCtrlHandlerEx(ServiceName, _mControlHandler, IntPtr.Zero); var installTask = Task.Factory.StartNew(() => { using (var db = new ScpDb()) { var bthDevices = db.Engine.GetAllDbEntities<WdiDeviceInfo>(ScpDb.TableDevices) .Where(d => d.Value.DeviceType == WdiUsbDeviceType.BluetoothHost) .Select(d => d.Value); if (GlobalConfiguration.Instance.ForceBluetoothDriverReinstallation) DriverInstaller.InstallBluetoothDongles(bthDevices); var ds3Devices = db.Engine.GetAllDbEntities<WdiDeviceInfo>(ScpDb.TableDevices) .Where(d => d.Value.DeviceType == WdiUsbDeviceType.DualShock3) .Select(d => d.Value); if (GlobalConfiguration.Instance.ForceDs3DriverReinstallation) DriverInstaller.InstallDualShock3Controllers(ds3Devices); var ds4Devices = db.Engine.GetAllDbEntities<WdiDeviceInfo>(ScpDb.TableDevices) .Where(d => d.Value.DeviceType == WdiUsbDeviceType.DualSHock4) .Select(d => d.Value); if (GlobalConfiguration.Instance.ForceDs4DriverReinstallation) DriverInstaller.InstallDualShock4Controllers(ds4Devices); } }); installTask.ContinueWith(task => { Log.FatalFormat("Error during driver installation: {0}", task.Exception); Stop(); }, TaskContinuationOptions.OnlyOnFaulted); Log.DebugFormat("Time spent 'till Root Hub start: {0}", sw.Elapsed); var hubStartTask = Task.Factory.StartNew(() => { rootHub.Open(); rootHub.Start(); }); hubStartTask.ContinueWith(task => { Log.FatalFormat("Couldn't start the root hub: {0}", task.Exception); Stop(); }, TaskContinuationOptions.OnlyOnFaulted); Log.DebugFormat("Time spent 'till registering notifications: {0}", sw.Elapsed); ScpDevice.RegisterNotify(_mServiceHandle, UsbDs3.DeviceClassGuid, ref _ds3Notify, false); ScpDevice.RegisterNotify(_mServiceHandle, UsbDs4.DeviceClassGuid, ref _ds4Notify, false); ScpDevice.RegisterNotify(_mServiceHandle, BthDongle.DeviceClassGuid, ref _bthNotify, false); ScpDevice.RegisterNotify(_mServiceHandle, UsbGenericGamepad.DeviceClassGuid, ref _genericNotify, false); Log.DebugFormat("Total Time spent in Service Start method: {0}", sw.Elapsed); }
public static bool InstallDualShock3Controller(WdiDeviceInfo usbDevice, IntPtr hWnd = default(IntPtr), bool force = false) { var result = WdiWrapper.Instance.InstallWinUsbDriver(usbDevice.DeviceId, UsbDs3.DeviceClassGuid, DriverDirectory, string.Format("Ds3Controller_{0}.inf", Guid.NewGuid()), hWnd, force); if (result != WdiErrorCode.WDI_SUCCESS) { Log.ErrorFormat("Installing DualShock 3 Controller ({0}) failed: {1}", usbDevice.DeviceId, result); return false; } usbDevice.DeviceType = WdiUsbDeviceType.DualShock3; using (var db = new ScpDb()) { db.Engine.PutDbEntity(ScpDb.TableDevices, usbDevice.DeviceId, usbDevice); } return true; }