Ejemplo n.º 1
0
 /// <summary>
 /// Clean up any resources being used.
 /// </summary>
 /// <param name="disposing">True if managed resources should be disposed; otherwise, false.</param>
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         BaseCommand.Dispose();
     }
 }
Ejemplo n.º 2
0
 private static bool ExitHandler(CtrlType sig)
 {
     switch (sig)
     {
     case CtrlType.CTRL_C_EVENT:
     case CtrlType.CTRL_LOGOFF_EVENT:
     case CtrlType.CTRL_SHUTDOWN_EVENT:
     case CtrlType.CTRL_CLOSE_EVENT:
     default:
         _command?.Dispose();
         return(false);
     }
 }
Ejemplo n.º 3
0
        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();
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            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);
            }

            BaseOptions baseOptions;

            switch (invokedVerb)
            {
            case "mirror":
                baseOptions = (BaseOptions)invokedVerbInstance;
                _command    = new MirrorCommand((MirrorOptions)baseOptions);
                break;

            case "test":
                baseOptions = (BaseOptions)invokedVerbInstance;
                _command    = new TestCommand((TestOptions)baseOptions);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            try {
                _command.Execute(() => {
                    if (baseOptions != null && baseOptions.QuitWhenDone)
                    {
                        Logger.Info("Exiting.");
                        _command?.Dispose();
                        Environment.Exit(0);
                    }
                }, ex => {
                    Logger.Error("Error: {0}", ex.Message);
                    _command?.Dispose();
                    Environment.Exit(0);
                });
                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);
            } finally {
                Environment.Exit(CommandLine.Parser.DefaultExitCodeFail);
            }
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            _commandLineArgs = args;

            // setup logger
            var assemblyPath  = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().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.Debug, 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);
            }

            Logger.Info("Launching console tool.");
            BaseOptions baseOptions;
            switch (invokedVerb)
            {
            case "mirror":
                baseOptions = (BaseOptions)invokedVerbInstance;
                _command    = new MirrorCommand((MirrorOptions)baseOptions);
                break;

            case "play":
                baseOptions = (PlayOptions)invokedVerbInstance;
                _command    = new PlayCommand((PlayOptions)baseOptions);
                break;

            case "test":
                baseOptions = (BaseOptions)invokedVerbInstance;
                _command    = new TestCommand((TestOptions)baseOptions);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            try {
                var renderer = _command.GetRenderGraph();

                if (baseOptions.SaveToFile != null)
                {
                    (renderer as RenderGraph)?.Destinations.Add(new BitmapOutput(baseOptions.SaveToFile));
                }

                _command.Execute(() => {
                    if (baseOptions != null && baseOptions.QuitWhenDone)
                    {
                        Logger.Info("Exiting.");
                        _command?.Dispose();
                        Environment.Exit(0);
                    }
                }, ex => {
                    Logger.Error("Error: {0}", ex.Message);
                    _command?.Dispose();
                    Environment.Exit(0);
                });

                if (baseOptions.QuitAfter > -1)
                {
                    Logger.Info("Quitting in {0}ms...", baseOptions.QuitAfter);
                    Observable
                    .Return(Unit.Default)
                    .Delay(TimeSpan.FromMilliseconds(baseOptions.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 (CropRectangleOutOfRangeException e) {
                Logger.Error(e.Message);
                Logger.Error("Are you running PinballFX2 in cabinet mode with the DMD at 1040x272?");
            } finally {
                Process.GetCurrentProcess().Kill();
            }
        }