static int Main(string[] args)
        {
            // We force all stderr to redirect to stdout
            // to avoid any out of order console output.
            Console.SetError(Console.Out);

            if (!Environment.Is64BitProcess && Environment.OSVersion.Platform != PlatformID.Unix)
            {
                Console.Error.WriteLine("The MonoGame content tools only work on a 64bit OS.");
                return(-1);
            }

            var content = new BuildContent();

            // Parse the command line.
            var parser = new MGBuildParser(content)
            {
                Title = "MonoGame Content Builder\n" +
                        "Builds optimized game content for MonoGame projects."
            };

            if (!parser.Parse(args))
            {
                return(-1);
            }

            // Launch debugger if requested.
            if (content.LaunchDebugger)
            {
                try {
                    System.Diagnostics.Debugger.Launch();
                } catch (NotImplementedException) {
                    // not implemented under Mono
                    Console.Error.WriteLine("The debugger is not implemented under Mono and thus is not supported on your platform.");
                }
            }

            // Print a startup message.
            var buildStarted = DateTime.Now;

            if (!content.Quiet)
            {
                Console.WriteLine("Build started {0}\n", buildStarted);
            }

            // Let the content build.
            int successCount, errorCount;

            content.Build(out successCount, out errorCount);

            // Print the finishing info.
            if (!content.Quiet)
            {
                Console.WriteLine("\nBuild {0} succeeded, {1} failed.\n", successCount, errorCount);
                Console.WriteLine("Time elapsed {0:hh\\:mm\\:ss\\.ff}.", DateTime.Now - buildStarted);
            }

            // Return the error count.
            return(errorCount);
        }
Beispiel #2
0
        static int Main(string[] args)
        {
            // We force all stderr to redirect to stdout
            // to avoid any out of order console output.
            Console.SetError(Console.Out);

            var content = new BuildContent();

            // Parse the command line.
            var parser = new MGBuildParser(content)
            {
                Title = "MonoGame Content Builder\n" +
                        "Builds optimized game content for MonoGame projects."
            };

            if (!parser.Parse(args))
            {
                return(-1);
            }

            // Do we have anything to do?
            if (!content.HasWork)
            {
                parser.ShowUsage();
                return(0);
            }

            // Launch debugger if requested.
            if (content.LaunchDebugger)
            {
                System.Diagnostics.Debugger.Launch();
            }

            // Print a startup message.
            var buildStarted = DateTime.Now;

            if (!content.Quiet)
            {
                Console.WriteLine("Build started {0}\n", buildStarted);
            }

            // Let the content build.
            int successCount, errorCount;

            content.Build(out successCount, out errorCount);

            // Print the finishing info.
            if (!content.Quiet)
            {
                Console.WriteLine("\nBuild {0} succeeded, {1} failed.\n", successCount, errorCount);
                Console.WriteLine("Time elapsed {0:hh\\:mm\\:ss\\.ff}.", DateTime.Now - buildStarted);
            }

            // Return the error count.
            return(errorCount);
        }
Beispiel #3
0
        public MGBuildParser(object optionsObject)
        {
            Instance = this;

            _optionsObject     = optionsObject;
            _requiredOptions   = new Queue <MemberInfo>();
            _optionalOptions   = new Dictionary <string, MemberInfo>();
            _requiredUsageHelp = new List <string>();

            _properties = new PreprocessorPropertyCollection();

            // Reflect to find what commandline options are available...

            // Fields
            foreach (var field in optionsObject.GetType().GetFields())
            {
                var param = GetAttribute <CommandLineParameterAttribute>(field);
                if (param == null)
                {
                    continue;
                }

                CheckReservedPrefixes(param.Name);

                if (param.Required)
                {
                    // Record a required option.
                    _requiredOptions.Enqueue(field);

                    _requiredUsageHelp.Add(string.Format("<{0}>", param.Name));
                }
                else
                {
                    // Record an optional option.
                    _optionalOptions.Add(param.Name.ToLowerInvariant(), field);
                }
            }

            // Properties
            foreach (var property in optionsObject.GetType().GetProperties())
            {
                var param = GetAttribute <CommandLineParameterAttribute>(property);
                if (param == null)
                {
                    continue;
                }

                CheckReservedPrefixes(param.Name);

                if (param.Required)
                {
                    // Record a required option.
                    _requiredOptions.Enqueue(property);

                    _requiredUsageHelp.Add(string.Format("<{0}>", param.Name));
                }
                else
                {
                    // Record an optional option.
                    _optionalOptions.Add(param.Name.ToLowerInvariant(), property);
                }
            }

            // Methods
            foreach (var method in optionsObject.GetType().GetMethods())
            {
                var param = GetAttribute <CommandLineParameterAttribute>(method);
                if (param == null)
                {
                    continue;
                }

                CheckReservedPrefixes(param.Name);

                // Only accept methods that take less than 1 parameter.
                if (method.GetParameters().Length > 1)
                {
                    throw new NotSupportedException("Methods must have one or zero parameters.");
                }

                if (param.Required)
                {
                    // Record a required option.
                    _requiredOptions.Enqueue(method);

                    _requiredUsageHelp.Add(string.Format("<{0}>", param.Name));
                }
                else
                {
                    // Record an optional option.
                    _optionalOptions.Add(param.Name.ToLowerInvariant(), method);
                }
            }

            _flags = new Dictionary <string, string>();
            foreach (var pair in _optionalOptions)
            {
                var fi = GetAttribute <CommandLineParameterAttribute>(pair.Value);
                if (!string.IsNullOrEmpty(fi.Flag))
                {
                    _flags.Add(fi.Flag, fi.Name);
                }
            }
        }