コード例 #1
0
        public static int MainInner()
        {
            TextEncoding.WritingDefault = TextEncoding.UTF8;

            var CmdLine = CommandLine.GetCmdLine();
            var argv    = CmdLine.Arguments;

            if (CmdLine.Arguments.Length != 0)
            {
                DisplayInfo();
                return(-1);
            }

            if (CmdLine.Options.Length == 0)
            {
                DisplayInfo();
                return(0);
            }

            foreach (var opt in CmdLine.Options)
            {
                var optNameLower = opt.Name.ToLower();
                if ((optNameLower == "?") || (optNameLower == "help"))
                {
                    DisplayInfo();
                    return(0);
                }
                else if (optNameLower == "load")
                {
                    var args = opt.Arguments;
                    if (args.Length == 1)
                    {
                        var CookedObjectSchemaPath = args[0];
                        InvalidateSchema();
                        osl.LoadSchema(CookedObjectSchemaPath);
                    }
                    else
                    {
                        DisplayInfo();
                        return(-1);
                    }
                }
                else if (optNameLower == "save")
                {
                    var args = opt.Arguments;
                    if (args.Length == 1)
                    {
                        var CookedObjectSchemaPath = args[0];
                        var s  = GetObjectSchema();
                        var ts = new TreeSerializer();
                        var t  = ts.Write(s);
                        TreeFile.WriteDirect(CookedObjectSchemaPath, t);
                    }
                    else
                    {
                        DisplayInfo();
                        return(-1);
                    }
                }
                else if (optNameLower == "loadtyperef")
                {
                    var args = opt.Arguments;
                    if (args.Length == 1)
                    {
                        var ObjectSchemaPath = args[0];
                        if (Directory.Exists(ObjectSchemaPath))
                        {
                            foreach (var f in Directory.GetFiles(ObjectSchemaPath, "*.tree", SearchOption.AllDirectories).OrderBy(s => s, StringComparer.OrdinalIgnoreCase))
                            {
                                InvalidateSchema();
                                osl.LoadTypeRef(f);
                            }
                        }
                        else
                        {
                            InvalidateSchema();
                            osl.LoadTypeRef(ObjectSchemaPath);
                        }
                    }
                    else
                    {
                        DisplayInfo();
                        return(-1);
                    }
                }
                else if (optNameLower == "loadtype")
                {
                    var args = opt.Arguments;
                    if (args.Length == 1)
                    {
                        var ObjectSchemaPath = args[0];
                        if (Directory.Exists(ObjectSchemaPath))
                        {
                            foreach (var f in Directory.GetFiles(ObjectSchemaPath, "*.tree", SearchOption.AllDirectories).OrderBy(s => s, StringComparer.OrdinalIgnoreCase))
                            {
                                InvalidateSchema();
                                osl.LoadType(f);
                            }
                        }
                        else
                        {
                            InvalidateSchema();
                            osl.LoadType(ObjectSchemaPath);
                        }
                    }
                    else
                    {
                        DisplayInfo();
                        return(-1);
                    }
                }
                else if (optNameLower == "import")
                {
                    var args = opt.Arguments;
                    if (args.Length == 1)
                    {
                        osl.AddImport(args[0]);
                    }
                    else
                    {
                        DisplayInfo();
                        return(-1);
                    }
                }
                else if (optNameLower == "async")
                {
                    var args = opt.Arguments;
                    if (args.Length == 1)
                    {
                        InvalidateSchema();
                        LoadAsync(args[0]);
                    }
                    else
                    {
                        DisplayInfo();
                        return(-1);
                    }
                }
                else if (optNameLower == "t2b")
                {
                    var args = opt.Arguments;
                    if (args.Length == 3)
                    {
                        TreeToBinary(args[0], args[1], args[2]);
                    }
                    else
                    {
                        DisplayInfo();
                        return(-1);
                    }
                }
                else if (optNameLower == "b2t")
                {
                    var args = opt.Arguments;
                    if (args.Length == 3)
                    {
                        BinaryToTree(args[0], args[1], args[2]);
                    }
                    else
                    {
                        DisplayInfo();
                        return(-1);
                    }
                }
                else if (optNameLower == "t2vb")
                {
                    var args = opt.Arguments;
                    if (args.Length == 1)
                    {
                        ObjectSchemaToVBCode(args[0], "", true);
                    }
                    else if (args.Length == 2)
                    {
                        ObjectSchemaToVBCode(args[0], args[1], true);
                    }
                    else if (args.Length == 3)
                    {
                        ObjectSchemaToVBCode(args[0], args[1], Boolean.Parse(args[2]));
                    }
                    else
                    {
                        DisplayInfo();
                        return(-1);
                    }
                }
                else if (optNameLower == "t2cs")
                {
                    var args = opt.Arguments;
                    if (args.Length == 1)
                    {
                        ObjectSchemaToCSharpCode(args[0], "", true);
                    }
                    else if (args.Length == 2)
                    {
                        ObjectSchemaToCSharpCode(args[0], args[1], true);
                    }
                    else if (args.Length == 3)
                    {
                        ObjectSchemaToCSharpCode(args[0], args[1], Boolean.Parse(args[2]));
                    }
                    else
                    {
                        DisplayInfo();
                        return(-1);
                    }
                }
                else if (optNameLower == "t2csb")
                {
                    var args = opt.Arguments;
                    if (args.Length == 1)
                    {
                        ObjectSchemaToCSharpBinaryCode(args[0], "", true);
                    }
                    else if (args.Length == 2)
                    {
                        ObjectSchemaToCSharpBinaryCode(args[0], args[1], true);
                    }
                    else if (args.Length == 3)
                    {
                        ObjectSchemaToCSharpBinaryCode(args[0], args[1], Boolean.Parse(args[2]));
                    }
                    else
                    {
                        DisplayInfo();
                        return(-1);
                    }
                }
                else if (optNameLower == "t2csj")
                {
                    var args = opt.Arguments;
                    if (args.Length == 1)
                    {
                        ObjectSchemaToCSharpJsonCode(args[0], "");
                    }
                    else if (args.Length == 2)
                    {
                        ObjectSchemaToCSharpJsonCode(args[0], args[1]);
                    }
                    else
                    {
                        DisplayInfo();
                        return(-1);
                    }
                }
                else if (optNameLower == "t2csc")
                {
                    var args = opt.Arguments;
                    if (args.Length == 4)
                    {
                        ObjectSchemaToCSharpCompatibleCode(args[0], args[1], args[2], args[3]);
                    }
                    else
                    {
                        DisplayInfo();
                        return(-1);
                    }
                }
                else if (optNameLower == "t2csv")
                {
                    var args = opt.Arguments;
                    if (args.Length >= 2)
                    {
                        ObjectSchemaToCSharpVersionCode(args[0], args[1], args.Skip(2).ToList());
                    }
                    else
                    {
                        DisplayInfo();
                        return(-1);
                    }
                }
                else if (optNameLower == "t2jv")
                {
                    var args = opt.Arguments;
                    if (args.Length == 2)
                    {
                        ObjectSchemaToJavaCode(args[0], args[1]);
                    }
                    else
                    {
                        DisplayInfo();
                        return(-1);
                    }
                }
                else if (optNameLower == "t2jvb")
                {
                    var args = opt.Arguments;
                    if (args.Length == 2)
                    {
                        ObjectSchemaToJavaBinaryCode(args[0], args[1]);
                    }
                    else
                    {
                        DisplayInfo();
                        return(-1);
                    }
                }
                else if (optNameLower == "t2cpp")
                {
                    var args = opt.Arguments;
                    if (args.Length == 1)
                    {
                        ObjectSchemaToCppCode(args[0], "");
                    }
                    else if (args.Length == 2)
                    {
                        ObjectSchemaToCppCode(args[0], args[1]);
                    }
                    else
                    {
                        DisplayInfo();
                        return(-1);
                    }
                }
                else if (optNameLower == "t2cppb")
                {
                    var args = opt.Arguments;
                    if (args.Length == 1)
                    {
                        ObjectSchemaToCppBinaryCode(args[0], "", true, true);
                    }
                    else if (args.Length == 2)
                    {
                        ObjectSchemaToCppBinaryCode(args[0], args[1], true, true);
                    }
                    else if (args.Length == 4)
                    {
                        ObjectSchemaToCppBinaryCode(args[0], args[1], Boolean.Parse(args[2]), Boolean.Parse(args[3]));
                    }
                    else
                    {
                        DisplayInfo();
                        return(-1);
                    }
                }
                else if (optNameLower == "t2cppc")
                {
                    var args = opt.Arguments;
                    if (args.Length == 4)
                    {
                        ObjectSchemaToCppCompatibleCode(args[0], args[1], args[2], args[3]);
                    }
                    else
                    {
                        DisplayInfo();
                        return(-1);
                    }
                }
                else if (optNameLower == "t2cppv")
                {
                    var args = opt.Arguments;
                    if (args.Length >= 2)
                    {
                        ObjectSchemaToCppVersionCode(args[0], args[1], args.Skip(2).ToList());
                    }
                    else
                    {
                        DisplayInfo();
                        return(-1);
                    }
                }
                else if (optNameLower == "t2hx")
                {
                    var args = opt.Arguments;
                    if (args.Length == 2)
                    {
                        ObjectSchemaToHaxeCode(args[0], args[1]);
                    }
                    else
                    {
                        DisplayInfo();
                        return(-1);
                    }
                }
                else if (optNameLower == "t2hxj")
                {
                    var args = opt.Arguments;
                    if (args.Length == 2)
                    {
                        ObjectSchemaToHaxeJsonCode(args[0], args[1]);
                    }
                    else
                    {
                        DisplayInfo();
                        return(-1);
                    }
                }
                else if (optNameLower == "t2py")
                {
                    var args = opt.Arguments;
                    if (args.Length == 1)
                    {
                        ObjectSchemaToPythonCode(args[0]);
                    }
                    else
                    {
                        DisplayInfo();
                        return(-1);
                    }
                }
                else if (optNameLower == "t2pyb")
                {
                    var args = opt.Arguments;
                    if (args.Length == 1)
                    {
                        ObjectSchemaToPythonBinaryCode(args[0]);
                    }
                    else
                    {
                        DisplayInfo();
                        return(-1);
                    }
                }
                else if (optNameLower == "t2xhtml")
                {
                    var args = opt.Arguments;
                    if (args.Length == 3)
                    {
                        ObjectSchemaToXhtml(args[0], args[1], args[2]);
                    }
                    else
                    {
                        DisplayInfo();
                        return(-1);
                    }
                }
                else if (optNameLower == "gentypecmpt")
                {
                    var args = opt.Arguments;
                    if (args.Length % 2 == 1)
                    {
                        var ListOfObjectSchemaDirOrCookedObjectSchemaFileAndVersion = new List <KeyValuePair <String, String> >();
                        for (int k = 0; k < args.Length - 1; k += 2)
                        {
                            ListOfObjectSchemaDirOrCookedObjectSchemaFileAndVersion.Add(new KeyValuePair <String, String>(args[k], args[k + 1]));
                        }
                        GenerateTypeCompatibilityTreeFile(ListOfObjectSchemaDirOrCookedObjectSchemaFileAndVersion, args[args.Length - 1]);
                    }
                    else
                    {
                        DisplayInfo();
                        return(-1);
                    }
                }
                else if (optNameLower == "gencomcmpt")
                {
                    var args = opt.Arguments;
                    if (args.Length % 2 == 1)
                    {
                        var ListOfObjectSchemaDirOrCookedObjectSchemaFileAndVersion = new List <KeyValuePair <String, String> >();
                        for (int k = 0; k < args.Length - 1; k += 2)
                        {
                            ListOfObjectSchemaDirOrCookedObjectSchemaFileAndVersion.Add(new KeyValuePair <String, String>(args[k], args[k + 1]));
                        }
                        GenerateTypeCompatibilityTreeFile(ListOfObjectSchemaDirOrCookedObjectSchemaFileAndVersion, args[args.Length - 1], true);
                    }
                    else
                    {
                        DisplayInfo();
                        return(-1);
                    }
                }
                else
                {
                    throw new ArgumentException(opt.Name);
                }
            }
            return(0);
        }