public DmdDevice() { _currentFrameFormat = new BehaviorSubject <FrameFormat>(FrameFormat.Rgb24); _vpmGray2Source = new VpmGray2Source(_currentFrameFormat); _vpmGray4Source = new VpmGray4Source(_currentFrameFormat); _vpmRgb24Source = new VpmRgb24Source(_currentFrameFormat); _vpmAlphaNumericSource = new VpmAlphaNumericSource(_currentFrameFormat); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; // setup logger var assembly = Assembly.GetCallingAssembly(); var assemblyPath = Path.GetDirectoryName(new Uri(assembly.CodeBase).LocalPath); var logConfigPath = Path.Combine(assemblyPath, "DmdDevice.log.config"); if (File.Exists(logConfigPath)) { LogManager.Configuration = new XmlLoggingConfiguration(logConfigPath, true); #if !DEBUG LogManager.Configuration.AddTarget("memory", MemLogger); LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, MemLogger)); LogManager.ReconfigExistingLoggers(); #endif } #if !DEBUG else { SimpleConfigurator.ConfigureForTargetLogging(MemLogger, LogLevel.Debug); } #endif CultureUtil.NormalizeUICulture(); _config = new Configuration(); _altcolorPath = GetColorPath(); // read versions from assembly var attr = assembly.GetCustomAttributes(typeof(AssemblyConfigurationAttribute), false); var fvi = FileVersionInfo.GetVersionInfo(assembly.Location); _version = fvi.ProductVersion; if (attr.Length > 0) { var aca = (AssemblyConfigurationAttribute)attr[0]; _sha = aca.Configuration; if (string.IsNullOrEmpty(_sha)) { _fullVersion = _version; } else { _fullVersion = $"{_version} ({_sha})"; } } else { _fullVersion = fvi.ProductVersion; _sha = ""; } Logger.Info("Starting VPinMAME API {0} through {1}.exe.", _fullVersion, Process.GetCurrentProcess().ProcessName); Logger.Info("Assembly located at {0}", assembly.Location); }
static void Main(string[] args) { var assembly = Assembly.GetExecutingAssembly(); var attr = assembly.GetCustomAttributes(typeof(AssemblyConfigurationAttribute), false); var fvi = FileVersionInfo.GetVersionInfo(assembly.Location); _version = fvi.ProductVersion; if (attr.Length > 0) { var aca = (AssemblyConfigurationAttribute)attr[0]; _sha = aca.Configuration; _fullVersion = $"{_version} ({_sha})"; } else { _fullVersion = fvi.ProductVersion; _sha = ""; } CultureUtil.NormalizeUICulture(); _commandLineArgs = args; // setup logger var assemblyPath = Path.GetDirectoryName(new Uri(assembly.CodeBase).LocalPath); var logConfigPath = Path.Combine(assemblyPath, "dmdext.log.config"); if (File.Exists(logConfigPath)) { LogManager.Configuration = new XmlLoggingConfiguration(logConfigPath, true); #if !DEBUG LogManager.Configuration.AddTarget("memory", MemLogger); LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, MemLogger)); LogManager.ReconfigExistingLoggers(); #endif } #if !DEBUG else { SimpleConfigurator.ConfigureForTargetLogging(MemLogger, LogLevel.Debug); } #endif AssertDotNetVersion(); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; // enable exit handler _handler += ExitHandler; SetConsoleCtrlHandler(_handler, true); var invokedVerb = ""; object invokedVerbInstance = null; var options = new Options(); if (!CommandLine.Parser.Default.ParseArgumentsStrict(args, options, (verb, subOptions) => { // if parsing succeeds the verb name and correct instance // will be passed to onVerbCommand delegate (string,object) invokedVerb = verb; invokedVerbInstance = subOptions; })) { Environment.Exit(CommandLine.Parser.DefaultExitCodeFail); } try { Logger.Info("Launching console tool v{0}", _fullVersion); options.Validate(); var cmdLineOptions = (BaseOptions)invokedVerbInstance; var config = cmdLineOptions.DmdDeviceIni == null ? (IConfiguration)cmdLineOptions : new Configuration(cmdLineOptions.DmdDeviceIni); //BaseOptions baseOptions; switch (invokedVerb) { case "mirror": _command = new MirrorCommand(config, (MirrorOptions)cmdLineOptions); break; case "play": _command = new PlayCommand(config, (PlayOptions)cmdLineOptions); break; case "test": _command = new TestCommand(config, (TestOptions)cmdLineOptions); break; case "server": _command = new ServerCommand(config, (ServerOptions)cmdLineOptions); break; default: throw new ArgumentOutOfRangeException(); } var renderGraphs = _command.GetRenderGraphs(); if (config.Bitmap.Enabled) { renderGraphs.AddDestination(new BitmapOutput(config.Bitmap.Path)); } if (config.PinUp.Enabled) { try { renderGraphs.AddDestination(new PinUpOutput(config.PinUp.GameName)); } catch (Exception e) { Logger.Warn("Error opening PinUP output: {0}", e.Message); } } _command.Execute(() => { if (config != null && config.Global.QuitWhenDone) { Logger.Info("Exiting."); _command?.Dispose(); Environment.Exit(0); } }, ex => { Logger.Error("Error: {0}", ex.Message); _command?.Dispose(); Environment.Exit(0); }); if (config.Global.QuitAfter > -1) { Logger.Info("Quitting in {0}ms...", config.Global.QuitAfter); Observable .Return(Unit.Default) .Delay(TimeSpan.FromMilliseconds(config.Global.QuitAfter)) .Subscribe(_ => WinApp.Dispatcher.Invoke(() => WinApp.Shutdown())); } else { Logger.Info("Press CTRL+C to close."); } WinApp.Run(); } catch (DeviceNotAvailableException e) { Logger.Error("Device {0} is not available.", e.Message); } catch (NoRenderersAvailableException) { Logger.Error("No output devices available."); } catch (InvalidOptionException e) { Logger.Error("Invalid option: {0}", e.Message); } catch (FileNotFoundException e) { Logger.Error(e.Message); Logger.Info("Try installing the Visual C++ Redistributable for Visual Studio 2015 if you haven't so already:"); Logger.Info(" https://www.microsoft.com/en-us/download/details.aspx?id=48145"); } catch (UnknownFormatException e) { Logger.Error(e.Message); } catch (WrongFormatException e) { Logger.Error(e.Message); } catch (UnsupportedResolutionException e) { Logger.Error(e.Message); } catch (InvalidFolderException e) { Logger.Error(e.Message); } catch (RenderException e) { Logger.Error(e.Message); } catch (NoRawDestinationException e) { Logger.Error(e.Message); } catch (MultipleRawSourcesException e) { Logger.Error(e.Message); } catch (ProPinballSlaveException e) { Logger.Error(e.Message); } catch (IncompatibleRenderer e) { Logger.Error(e.Message); } catch (IncompatibleSourceException e) { Logger.Error(e.Message); } catch (IniNotFoundException e) { Logger.Error(e.Message); } catch (CropRectangleOutOfRangeException e) { Logger.Error(e.Message); Logger.Error("Are you running PinballFX2 in cabinet mode with the DMD at 1040x272?"); } finally { Process.GetCurrentProcess().Kill(); } }