Added AutoGenerated header, switched to CodeCompileUnit, added global usings

This commit is contained in:
Samuele Lorefice
2025-01-22 02:35:20 +01:00
parent fa78292a67
commit 98f66f196e
937 changed files with 13118 additions and 942 deletions

View File

@@ -1,4 +1,6 @@
using Kaitai;

// ReSharper disable BitwiseOperatorOnEnumWithoutFlags
using Kaitai;
using System;
using System.IO;
using System.CodeDom;
@@ -11,8 +13,6 @@ using System.Text;
using Microsoft.CSharp;
using BlendFile = Kaitai.BlenderBlend;
// ReSharper disable BitwiseOperatorOnEnumWithoutFlags
namespace CodeGenerator {
public class Program {
public static BlendFile blendfile;
@@ -222,14 +222,22 @@ namespace CodeGenerator {
};
var provider = new CSharpCodeProvider();
var date = DateTime.Now.ToString();
CodeComment comment = new CodeComment("Automatically generated by BlenderSharp at " + date, false);
tempNs.Comments.Add(new(comment));
CodeNamespace globalNs = new CodeNamespace();
CodeComment comment = new CodeComment("Automatically generated by BlenderSharp at " + date, false);
globalNs.Comments.Add(new(comment));
globalNs.Imports.Add(new("System"));
globalNs.Imports.Add(new("BlendFile.CompatTypes"));
CodeCompileUnit ccu = new CodeCompileUnit();
ccu.Namespaces.Add(globalNs);
ccu.Namespaces.Add(tempNs);
foreach (var type in ns.Types.OfType<CodeTypeDeclaration>()) {
tempNs.Types.Add(type);
Log($"Writing out {(type.IsStruct ? "struct" : "class")} {type.Name}");
using var sw = new StreamWriter($"{OutPath}\\{type.Name}.cs");
provider.GenerateCodeFromNamespace(tempNs, sw, codeGeneratorOptions);
provider.GenerateCodeFromCompileUnit(ccu, sw, codeGeneratorOptions);
tempNs.Types.Remove(type);
}
}