in ScpService/Ds3Service.cs [48:123]
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);
Log.DebugFormat("Setting process priority to {0}", GlobalConfiguration.Instance.ServiceProcessPriority);
Process.GetCurrentProcess().PriorityClass = GlobalConfiguration.Instance.ServiceProcessPriority;
_mControlHandler = ServiceControlHandler;
_mServiceHandle = ScpDevice.RegisterServiceCtrlHandlerEx(ServiceName, _mControlHandler, IntPtr.Zero);
var installTask = Task.Factory.StartNew(() =>
{
using (var db = new ScpDb())
{
#if FIXME
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);
#endif
}
});
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);
}