wabbajack/Wabbajack.DTOs.ConverterGenerators/CFile.cs

39 lines
900 B
C#
Raw Normal View History

2021-09-27 12:42:46 +00:00
using System.IO;
using System.Text;
2021-10-23 16:51:17 +00:00
namespace Wabbajack.DTOs.ConverterGenerators;
public class CFile
2021-09-27 12:42:46 +00:00
{
2021-10-23 16:51:17 +00:00
private readonly StringBuilder _sb;
private int _indent;
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
public CFile()
{
_sb = new StringBuilder();
Code("// THIS FILE IS AUTOGENERATED DO NOT EDIT BY HAND");
Code("using System;");
Code("using System.Text.Json;");
Code("using System.Text.Json.Serialization;");
Code("using Wabbajack.Hashing.xxHash64;");
Code("using Microsoft.Extensions.DependencyInjection;");
Code("");
}
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
public void Write(string path)
{
File.WriteAllText(path, _sb.ToString());
}
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
public void Code(string c)
{
if (c.EndsWith("}"))
_indent--;
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
for (var i = 0; i < _indent; i++) _sb.Append(" ");
_sb.AppendLine(c);
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
if (c.EndsWith("{"))
_indent++;
2021-09-27 12:42:46 +00:00
}
}