Esempio n. 1
0
        public static RuntimeConfig FromCommandLine(string[] args)
        {
            var config = new RuntimeConfig();

            foreach (var arg in args)
            {
                if (arg.StartsWith("-"))
                {
                    if (arg == "-v22")
                    {
                        config.Version = GmVersion.Gm22;
                        continue;
                    }
                    else if (arg == "-v23")
                    {
                        config.Version = GmVersion.Gm23;
                        continue;
                    }
                }

                if (config.InputPath == null)
                {
                    config.InputPath = arg;
                    continue;
                }
                else if (config.OutputPath == null)
                {
                    config.OutputPath = arg;
                    continue;
                }

                Console.WriteLine($"Unknown option: {arg}");
            }

            if (config.Version == GmVersion.None && config.InputPath != null)
            {
                if (config.InputPath.EndsWith(".yymps"))
                {
                    config.Version = GmVersion.Gm23;
                }
                else if (config.InputPath.EndsWith(".yymp"))
                {
                    config.Version = GmVersion.Gm22;
                }
            }

            if (config.OutputPath == null && config.InputPath != null)
            {
                if (config.InputPath.EndsWith(".yymps") || config.InputPath.EndsWith(".yymp"))
                {
                    config.OutputPath = Path.ChangeExtension(config.InputPath, "yy");
                }
                else if (config.InputPath.EndsWith(".yy"))
                {
                    if (config.Version == GmVersion.Gm22)
                    {
                        config.OutputPath = Path.ChangeExtension(config.InputPath, "yymp");
                    }
                    else if (config.Version == GmVersion.Gm23)
                    {
                        config.OutputPath = Path.ChangeExtension(config.InputPath, "yymps");
                    }
                }
            }

            if (config.Version == GmVersion.None || config.InputPath == null || config.OutputPath == null)
            {
                return(null);
            }

            return(config);
        }