コード例 #1
0
ファイル: Program.cs プロジェクト: wbars/resharper-unity
        public static void Main(string[] args)
        {
            if (args.Length != 1 && args.Length != 2)
            {
                Console.WriteLine("Usage: ApiParser.exe docsFolder");
                Console.WriteLine("       ApiParser.exe apiXmlPath version");
                Console.WriteLine();
                Console.WriteLine("ApiParser.exe docsFolder");
                Console.WriteLine("  Parse all documentation installed by Unity Hub, as well as everything in the docsFolder and create a new api.xml");
                Console.WriteLine();
                Console.WriteLine("  docsFolder - folder that contains multiple versions of Unity docs");
                Console.WriteLine("               Contents should be in the format Documentation-X.Y.ZfA/Documentation/en/ScriptReference");
                Console.WriteLine();
                Console.WriteLine("ApiParser.exe apiXmlPath version");
                Console.WriteLine("  Parse the installed documentation corresponding to version and merge into an existing api.xml file");
                Console.WriteLine();
                Console.WriteLine("  apiXmlPath - location of api.xml to read and merge into");
                Console.WriteLine("  version - version of Unity to read docs from. Must be installed in standard Unity Hub location");
                Console.WriteLine();
                Console.WriteLine("Note that the output file is written to the current directory");
                return;
            }

            var stopwatch = Stopwatch.StartNew();
            var apiXml    = FileSystemPath.Parse("api.xml");

            var docVersions = new List <(string, Version)>();

            if (args.Length == 1)
            {
                Directory.SetCurrentDirectory(args[0]);
                foreach (var directory in Directory.EnumerateDirectories(Directory.GetCurrentDirectory()))
                {
                    var docFolder = Path.Combine(Directory.GetCurrentDirectory(), directory);
                    var version   = Regex.Match(directory, @"Documentation-(\d+.\d+)").Groups[1].Value;
                    docVersions.Add((docFolder, Version.Parse(version)));
                }

                foreach (var directory in Directory.EnumerateDirectories(Path.Combine(
                                                                             Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Unity", "Hub", "Editor")))
                {
                    var docFolder = GetDocumentationRoot(directory).FullPath;
                    var version   = Regex.Match(directory, @"(\d+.\d+)").Groups[1].Value;
                    docVersions.Add((docFolder, Version.Parse(version)));
                }

                docVersions = docVersions.OrderBy(v => v.Item2).ToList();
            }
            else
            {
                apiXml = FileSystemPath.ParseRelativelyTo(args[0], FileSystemPath.Parse(Directory.GetCurrentDirectory()));
                if (!apiXml.ExistsFile)
                {
                    throw new InvalidOperationException("api.xml path does not exist");
                }

                var requiredVersion = args[1];
                var docRoot         = GetDocumentationRoot(requiredVersion);
                if (!docRoot.ExistsDirectory)
                {
                    throw new InvalidOperationException($"Cannot find locally installed docs: {docRoot}");
                }
                var parseableVersion = Regex.Match(requiredVersion, @"^(\d+\.\d+)").Groups[1].Value;
                docVersions.Add((docRoot.FullPath, Version.Parse(parseableVersion)));
            }

            var unityApi = new UnityApi();

            if (apiXml.ExistsFile)
            {
                unityApi = UnityApi.ImportFrom(apiXml);
            }
            var typeResolver = new TypeResolver();
            var parser       = new ApiParser(unityApi, typeResolver);

            foreach (var(name, version) in docVersions)
            {
                Console.WriteLine($"{name} ({version})");
                parser.ParseFolder(name, version);

                AddUndocumentedApis(unityApi, version);
            }

            // These modify existing functions
            AddUndocumentedOptionalParameters(unityApi);
            AddUndocumentedCoroutines(unityApi);
            FixDataFromIncorrectDocs(unityApi, typeResolver);

            using (var writer = new XmlTextWriter(apiXml.FullPath, Encoding.UTF8)
            {
                Formatting = Formatting.Indented
            })
            {
                parser.ExportTo(writer);
            }

            Console.WriteLine("Done. Elapsed time: {0}", stopwatch.Elapsed);

            // Console.WriteLine( "Press <Enter> key to continue..." );
            // Console.ReadLine();
        }