/// <summary> /// Creates a new instance of <see cref="Driver"/> with the specified argument, /// and loads it according to the specified <see cref="DriverLoad"/> method. /// </summary> /// <param name="Config">The configuration.</param> /// <exception cref="System.ArgumentNullException">Config</exception> /// <exception cref="System.IO.FileNotFoundException">The driver file does not exist.</exception> public static Driver CreateAndLoad(DriverConfig Config) { if (Config == null) { throw new ArgumentNullException(nameof(Config)); } if (!Driver.CanConnectTo(Config.SymbolicLink)) { if (Config.DriverFile == null || !Config.DriverFile.Exists) { throw new FileNotFoundException("The driver file does not exist."); } } var DriverObject = new Driver(Config); try { DriverObject.Load(); } catch (Exception) { // .. } return(DriverObject); }
/// <summary> /// Initializes a new instance of the <see cref="Driver"/> class. /// </summary> /// <param name="Config">The configuration.</param> /// <param name="LoaderPath">The path of the driver loader.</param> public Driver(DriverConfig Config, string LoaderPath = null) { this.Setup(Config, LoaderPath); switch (Config.IoMethod) { case IoMethod.None: { this.IO = null; break; } case IoMethod.IoControl: { this.IO = new DriverIo(this); break; } case IoMethod.SharedMemory: { this.IO = new DriverIoShared(this); break; } default: { throw new ArgumentException("Invalid IoMethod specified", nameof(Config.IoMethod)); } } }
/// <summary> /// Setups the specified driver. /// </summary> /// <param name="Config">The driver configuration.</param> /// <param name="LoaderPath">The path of the driver loader.</param> /// <exception cref="ArgumentException">Invalid LoadType specified.</exception> public void Setup(DriverConfig Config, string LoaderPath = null) { if (Config == null) { throw new ArgumentNullException(nameof(Config)); } this.Config = Config; if (string.IsNullOrEmpty(Config.ServiceName)) { throw new Exception("Config->ServiceName is null or empty"); } if (Config.IoMethod == IoMethod.IoControl) { if (string.IsNullOrEmpty(Config.SymbolicLink)) { throw new Exception("Config->SymbolicLink is null or empty"); } } if (!string.IsNullOrEmpty(LoaderPath)) { this.SetLoaderPath(LoaderPath); } switch (this.Config.LoadMethod) { case DriverLoad.Normal: { this.Loader = new ServiceLoad(); break; } case DriverLoad.Dse: { this.Loader = new DseLoad(); break; } case DriverLoad.Tdl: { this.Loader = new TurlaLoad(); break; } case DriverLoad.Capcom: { this.Loader = new CapcomLoad(); break; } case DriverLoad.IntelMapp90er: { this.Loader = new IntelMapperLoad(); break; } default: { throw new ArgumentException("Invalid LoadMethod specified", nameof(Config.LoadMethod)); } } }
/// <summary> /// Initializes a new instance of the <see cref="Driver"/> class. /// </summary> /// <param name="Config">The configuration.</param> /// <param name="LoaderPath">The path of the driver loader.</param> public Driver(DriverConfig Config, string LoaderPath = null) : this() { this.Setup(Config, LoaderPath); }