More cleanup
This commit is contained in:
@@ -1,18 +1,20 @@
|
||||
|
||||
// ReSharper disable BitwiseOperatorOnEnumWithoutFlags
|
||||
using Kaitai;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.CodeDom;
|
||||
using System.CodeDom.Compiler;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Reflection.Emit;
|
||||
using System.Text;
|
||||
using Kaitai;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.Text;
|
||||
using Microsoft.CSharp;
|
||||
using BlendFile = Kaitai.BlenderBlend;
|
||||
|
||||
// ReSharper disable BitwiseOperatorOnEnumWithoutFlags
|
||||
namespace CodeGenerator {
|
||||
public class Program {
|
||||
public static BlendFile blendfile;
|
||||
@@ -31,13 +33,13 @@ namespace CodeGenerator {
|
||||
ReadBlendFile();
|
||||
|
||||
Log("Generating C# code...");
|
||||
|
||||
|
||||
Log("Pass 1: Generating types");
|
||||
CodeNamespace ns = GenerateTypes();
|
||||
|
||||
|
||||
Log("Pass 2: Writing out code");
|
||||
OutputCodeFiles(ns);
|
||||
|
||||
|
||||
Log("Finished generating C# code!");
|
||||
File.AppendAllText("Log.txt", sb.ToString());
|
||||
}
|
||||
@@ -157,7 +159,7 @@ namespace CodeGenerator {
|
||||
string dims = string.Concat(dimensions.Select(d => $"[{d}]"));
|
||||
return new CodeSnippetExpression($"new {type.BaseType}{dims}");
|
||||
}
|
||||
|
||||
|
||||
private static CodeTypeConstructor GenerateStaticConstructor(CodeTypeDeclaration ctd) {
|
||||
CodeTypeConstructor ctc = new CodeTypeConstructor();
|
||||
ctc.Attributes = MemberAttributes.Static;
|
||||
@@ -206,32 +208,34 @@ namespace CodeGenerator {
|
||||
|
||||
return cc;
|
||||
}
|
||||
|
||||
private static void OutputCodeFiles(CodeNamespace ns) {
|
||||
CodeNamespace tempNs = new CodeNamespace(Namespace);
|
||||
if (!Path.Exists(OutPath)) {
|
||||
Directory.CreateDirectory(OutPath);
|
||||
}
|
||||
|
||||
CodeGeneratorOptions codeGeneratorOptions = new CodeGeneratorOptions() {
|
||||
private static void SetupCCU(out CodeGeneratorOptions codeGeneratorOptions, out CSharpCodeProvider provider,
|
||||
out CodeCompileUnit ccu) {
|
||||
codeGeneratorOptions = new CodeGeneratorOptions() {
|
||||
BlankLinesBetweenMembers = false,
|
||||
BracingStyle = "Block",
|
||||
ElseOnClosing = false,
|
||||
IndentString = " ",
|
||||
VerbatimOrder = true
|
||||
};
|
||||
var provider = new CSharpCodeProvider();
|
||||
provider = new CSharpCodeProvider();
|
||||
var date = DateTime.Now.ToString();
|
||||
|
||||
|
||||
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 = new CodeCompileUnit();
|
||||
ccu.Namespaces.Add(globalNs);
|
||||
}
|
||||
|
||||
private static void OutputCodeFiles(CodeNamespace ns) {
|
||||
if (!Path.Exists(OutPath)) Directory.CreateDirectory(OutPath);
|
||||
SetupCCU(out var codeGeneratorOptions, out var provider, out var ccu);
|
||||
CodeNamespace tempNs = new CodeNamespace(Namespace);
|
||||
ccu.Namespaces.Add(tempNs);
|
||||
foreach (var type in ns.Types.OfType<CodeTypeDeclaration>()) {
|
||||
tempNs.Types.Add(type);
|
||||
|
||||
Reference in New Issue
Block a user