예제 #1
0
        /// <summary>
        /// Parses the command line arguments.
        /// </summary>
        /// <param name="args">The args.</param>
        public static void ParseArguments(string[] args, CodeGenApp app)
        {
            var showHelp = false;

            var options = new OptionSet()
            {
                "Copyright (c) 2010-2014 SharpDX - Alexandre Mutel",
                "Usage: SharpGen [options] config_file.xml",
                "Code generator from C++ to C# for .Net languages",
                "",
                { "c|castxml=", "Specify the path to castxml.exe", opt => app.CastXmlExecutablePath = opt },
                { "d|doc", "Specify to generate the documentation [default: false]", opt => app.IsGeneratingDoc = true },
                { "p|docpath=", "Specify the path to the assembly doc provider [default: null]", opt => app.DocProviderAssemblyPath = opt },
                { "v|vctools=", "Specify the path to the Visual C++ Toolset", opt => app.VcToolsPath = opt },
                { "od|outputdir=", "Specify the base output directory for the generated code", opt => app.OutputDirectory = opt },
                { "a|apptype=", "Specify what app type to generate code for (i.e. DESKTOP_APP or STORE_APP)", opt => app.AppType = opt },
                { "D:", "Define a macro that is used in the config files", m => app.Macros.Add(m) },
                { "g|global=", "Specify the namespace with the infrastructure types such as ComObject and FunctionCallback", opt => app.GlobalNamespace = new GlobalNamespaceProvider(opt) },
                "",
                { "h|help", "Show this message and exit", opt => showHelp = opt != null },
                // default
                { "<>", opt => app.ConfigRootPath = opt },
            };

            try
            {
                options.Parse(args);
            }
            catch (OptionException e)
            {
                UsageError(e.Message);
            }

            if (showHelp)
            {
                options.WriteOptionDescriptions(Console.Out);
                Environment.Exit(0);
            }

            if (app.ConfigRootPath == null)
            {
                UsageError("Missing config.xml. A config.xml must be specified");
            }
            if (app.AppType == null)
            {
                UsageError("Missing apptype argument. an App type must be specified (for example: -apptype=DESKTOP_APP");
            }
        }
예제 #2
0
        public static void Main(string[] args)
        {
            _progressForm = new ProgressForm();
            var logger = new Logger(new ConsoleLogger(), _progressForm);

            try
            {
                _codeGenApp = new CodeGenApp(logger)
                {
                    GlobalNamespace = new GlobalNamespaceProvider("SharpDX") // Fall back to SharpDX for now
                };
                ParseArguments(args, _codeGenApp);

                if (_codeGenApp.Init())
                {
                    if (Environment.GetEnvironmentVariable("SharpDXBuildNoWindow") == null)
                    {
                        Application.EnableVisualStyles();
                        Application.SetCompatibleTextRenderingDefault(false);

                        _progressForm.Show();

                        var runningThread = new Thread(() => RunAsync(logger))
                        {
                            IsBackground = true
                        };
                        runningThread.Start();

                        Application.Run(_progressForm);
                    }
                    else
                    {
                        RunAsync(logger);
                    }
                }
                else
                {
                    logger.Message("Latest code generation is up to date. No need to run code generation");
                }
            }
            catch (Exception ex)
            {
                logger.Fatal("Unexpected exception", ex);
            }
            Environment.Exit(0);
        }
예제 #3
0
        static void Main(string[] args)
        {
            var appBuilder = BuildAvaloniaApp().SetupWithoutStarting();
            var model      = new SharpGenModel();
            var logger     = new Logger(new ConsoleLogger(), new SharpGenModel.ProgressReporter(model));
            var codeGenApp = new CodeGenApp(logger)
            {
                GlobalNamespace = new GlobalNamespaceProvider("SharpGen.Runtime")
            };

            ParseArguments(args, codeGenApp);
            var window = new ProgressView(new SharpGenModel());

            window.Show();

            Task.Run(() =>
            {
                if (codeGenApp.Init())
                {
                    try
                    {
                        logger.Progress(0, "Starting code generation...");

                        codeGenApp.Run();
                    }
                    catch (Exception ex)
                    {
                        logger.Fatal("Unexpected exception", ex);
                    }
                    finally
                    {
                        Application.Current.Exit();
                    }
                }
            });

            appBuilder.Instance.Run(window);
        }