/// <summary> /// Corresponds to CLI "headers" keyword. Converts given c# assemblies to corresponding c++ files. /// Combination of extract and generate keywords. /// </summary> public void Execute() { AssemblyCache assemblies = new AssemblyCache(); // Create list of assemblies (enrolling masks when needed) foreach (string assemblyPath in Assemblies) { string assemblyName = Path.GetFileName(assemblyPath); if (!string.IsNullOrEmpty(assemblyName)) { string assemblyDirectory = string.IsNullOrEmpty(assemblyDirectory = Path.GetDirectoryName(assemblyPath)) ? Environment.CurrentDirectory : Path.GetFullPath(assemblyDirectory); assemblies.AddFiles(Directory.EnumerateFiles(assemblyDirectory, assemblyName)); } } List <IDecl> declarations = new List <IDecl>(); foreach (Assembly assembly in assemblies) { CommentNavigator.TryCreate(assembly, out CommentNavigator docNavigator); ProjectNavigator.TryCreate(ProjectPath, assembly, out ProjectNavigator projNavigator); List <Type> types = TypesExtractor.GetTypes(assembly, Types); List <Type> enums = TypesExtractor.GetEnums(assembly, Types); declarations.AddRange(types.Concat(enums) .Select(type => DeclarationConvertor.ToDecl(type, docNavigator, projNavigator))); } GeneratorSettingsProvider.PopulateFromFile(SettingsPath); var fileContentInfos = DeclConverter.ConvertSet(declarations); foreach (var hppFile in fileContentInfos) { var fullPath = Path.Combine(OutputFolder, hppFile.FolderName, hppFile.FileName); var directory = Path.GetDirectoryName(fullPath); Directory.CreateDirectory(directory); if (File.Exists(fullPath)) { Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine($"Warning! File already exists. Overwriting: {hppFile.FolderName}/{hppFile.FileName}"); Console.ResetColor(); } else { Console.WriteLine($"Generated: {hppFile.FolderName}/{hppFile.FileName}"); } File.WriteAllText(fullPath, hppFile.Content); } }
/// <summary> /// Corresponds to CLI "generate" keyword. Converts given declarations to corresponding c++ files. /// </summary> public void Execute() { var declFiles = DeclConverter.ReadDeclUnits(InputFolder); GeneratorSettingsProvider.PopulateFromFile(SettingsPath); // Check Category field. In case if type name != file name it will be empty Console.ForegroundColor = ConsoleColor.Yellow; foreach (var decl in declFiles) { if (string.IsNullOrEmpty(decl.Category)) { Console.WriteLine($"Warning! Unable to locate: {decl.Name}. Possible type<->file names mismatch."); } } Console.ResetColor(); var fileContentInfos = DeclConverter.ConvertSet(declFiles); foreach (var hppFile in fileContentInfos) { var fullPath = Path.Combine(OutputFolder, hppFile.FolderName, hppFile.FileName); var directory = Path.GetDirectoryName(fullPath); Directory.CreateDirectory(directory); if (File.Exists(fullPath)) { Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine($"Warning! File already exists. Overwriting: {hppFile.FolderName}/{hppFile.FileName}"); Console.ResetColor(); } else { Console.WriteLine($"Generated: {hppFile.FolderName}/{hppFile.FileName}"); } File.WriteAllText(fullPath, hppFile.Content); } }