-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGeneratorBase.cs
39 lines (38 loc) · 1.44 KB
/
GeneratorBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UmamusumeDeserializeDB5
{
internal class GeneratorBase
{
public void Save(string filename, object content, bool typename = false)
{
Directory.CreateDirectory("./output");
Directory.CreateDirectory("./output/json/");
filename = filename.Replace("\\", "/");
if (filename.Contains("/"))
{
foreach (var i in filename.Split("/")[..1])
{
Directory.CreateDirectory(@$"./output/{i}/");
Directory.CreateDirectory(@$"./output/json/{i}/");
}
}
string text;
if (typename)
{
text = JsonConvert.SerializeObject(content, typename ? new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All } : null);
text = text.Replace("UmamusumeDeserializeDB5", "UmamusumeResponseAnalyzer");
}
else
{
text = JsonConvert.SerializeObject(content);
}
File.WriteAllBytes(@$"./output/{filename}.br", Brotli.Compress(Encoding.UTF8.GetBytes(text)));
File.WriteAllText(@$"./output/json/{filename}.json", JsonConvert.SerializeObject(JsonConvert.DeserializeObject(text), Formatting.Indented));
}
}
}