public static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Usage: ApiParser.exe docsFolder"); Console.WriteLine(); Console.WriteLine(" docsFolder - folder that contains all versions of Unity docs"); return; } var stopwatch = Stopwatch.StartNew(); Directory.SetCurrentDirectory(args[0]); var progPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); var managedPath = Path.Combine(progPath, "Unity", "Editor", "Data", "Managed"); if (!Directory.Exists(managedPath)) { // TODO: Find the latest version rather than hardcode it // TODO: Handle this in Windows, too //managedPath = Path.Combine(progPath, "Unity", "Hub", "Editor", "2018.1.0b9", "Unity.app", "Contents", "Managed"); managedPath = Path.Combine(progPath, "Unity", "Hub", "Editor", "2017.3.1f1", "Unity.app", "Contents", "Managed"); } // Add assemblies to the type resolver so we can get the fully qualified names of types // The Unity docs only give us the short names TypeResolver.AddAssembly(Assembly.LoadFrom(Path.Combine(managedPath, @"UnityEngine.dll"))); TypeResolver.AddAssembly(Assembly.LoadFrom(Path.Combine(managedPath, @"UnityEditor.dll"))); Console.WriteLine(); var unityApi = new UnityApi(); var parser = new ApiParser(unityApi, ScriptReferenceRelativePath); parser.Progress += (s, e) => { var cursorTop = Console.CursorTop; Console.WriteLine("{0,5} / {1,5} ({2,3}%)", e.Current, e.Total, e.Percent); Console.SetCursorPosition(0, cursorTop); }; foreach (var doc in Docs) { Console.WriteLine(doc.Item1); parser.ParseFolder(doc.Item1, doc.Item2); // These are valid for all versions AddUndocumentedApis(unityApi, doc.Item2); } // THese modify existing functions AddUndocumentedOptionalParameters(unityApi); AddUndocumentedCoroutines(unityApi); FixDataFromIncorrectDocs(unityApi); using (var writer = new XmlTextWriter(@"api.xml", 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(); }
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(); }