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