public static void Shutdown() { var drivers = DriverConfiguration.Drivers; DriverConfiguration.Drivers = new DriverConfiguration(); DriverConfiguration.Shutdown(drivers); }
public static DriverConfiguration Initialise(params string[] assemblyNames) { foreach (var asmName in assemblyNames) { AppDomain.CurrentDomain.Load(asmName); } IMonitorDriver monitorDriver = null; IWindowDriver windowDriver = null; IImageDriver imageDriver = null; IFontDriver fontDriver = null; IGraphicsDriver graphicsDriver = null; IAudioDriver audioDriver = null; foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { var jwdriver = assembly.GetCustomAttribute <JankWorksDriver>(); if (jwdriver != null) { var driverInstance = Activator.CreateInstance(jwdriver.DriverType); SetDriverApi(ref monitorDriver, driverInstance); SetDriverApi(ref windowDriver, driverInstance); SetDriverApi(ref imageDriver, driverInstance); SetDriverApi(ref fontDriver, driverInstance); SetDriverApi(ref graphicsDriver, driverInstance); SetDriverApi(ref audioDriver, driverInstance); } } var config = new DriverConfiguration ( monitorDriver, windowDriver, imageDriver, fontDriver, graphicsDriver, audioDriver ); DriverConfiguration.Drivers = config; return(config); void SetDriverApi <T>(ref T api, object driver) { if (api == null && driver is T driverApi) { api = driverApi; } } }
private static void Shutdown(DriverConfiguration drivers) { MaybeDispose(drivers.monitorApi); MaybeDispose(drivers.windowApi); MaybeDispose(drivers.graphicsApi); MaybeDispose(drivers.imageApi); MaybeDispose(drivers.fontApi); MaybeDispose(drivers.audioApi); void MaybeDispose(IDriver driver) { if (driver is IDisposable disposable) { disposable.Dispose(); } } }
public static IDisposable Initialise(DriverConfiguration configuration) { DriverConfiguration.Drivers = configuration; return(new ScopedConfiguration(configuration)); }
public void Dispose() => DriverConfiguration.Shutdown(config);
public ScopedConfiguration(DriverConfiguration config) { this.config = config; }