-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfiguration.cs
More file actions
223 lines (207 loc) · 8.25 KB
/
Configuration.cs
File metadata and controls
223 lines (207 loc) · 8.25 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
using Newtonsoft.Json;
using TShockAPI;
namespace AutoCompile;
internal class Configuration
{
internal static readonly string Paths = Path.Combine(TShock.SavePath, "自动编译");
public static readonly string FilePath = Path.Combine(Paths, "自动编译.json");
[JsonProperty("使用说明", Order = -10)]
public List<string> UsageTips = new List<string>();
[JsonProperty("启用", Order = 0)]
public bool Enabled = true;
[JsonProperty("包含子目录", Order = 1)]
public bool IncludeSub = true;
[JsonProperty("编译失败日志显示英文", Order = 2)]
public bool ShowErrorEnglish { get; set; } = true;
[JsonProperty("编译失败日志显示中文", Order = 3)]
public bool ShowErrorChinese { get; set; } = true;
[JsonProperty("成功后清失败日志文件", Order = 4)]
public bool ClearLogs = true;
[JsonProperty("语言版本", Order = 5)]
public string LangVer = "CSharp11";
[JsonProperty("最大文件数", Order = 6)]
public int MaxFiles = 100;
[JsonProperty("最大大小MB", Order = 7)]
public int MaxSizeMB = 50;
[JsonProperty("移除指定using语句", Order = 8)]
public List<string> RemoveUsings = new List<string>();
[JsonProperty("默认给源码添加引用", Order = 9)]
public List<string> Usings = new List<string>();
[JsonProperty("系统程序集", Order = 10)]
public List<string> SystemAsse = new List<string>();
[JsonProperty("反编译排除的程序集", Order = 11)]
public List<string> DeCompileExclude { get; set; } = new List<string>();
[JsonProperty("反编译排除的命名空间前缀", Order = 12)]
public List<string> DeCompileExcludeNamespaces { get; set; } = new List<string>();
#region 预设参数方法
public void SetDefault()
{
DeCompileExclude =
[
"TShockAPI.dll",
"linq2db.dll",
"LazyAPI.dll",
"ICSharpCode.Decompiler.dll",
"Microsoft.CodeAnalysis.CSharp.dll",
"Microsoft.CodeAnalysis.CSharp.Scripting.dll",
"Microsoft.CodeAnalysis.dll",
"Microsoft.CodeAnalysis.Scripting.dll",
"System.Collections.Immutable.dll",
"System.Reflection.Metadata.dll",
"System.Text.Encoding.CodePages.dll",
"Newtonsoft.Json.dll",
"NuGet.Packaging.dll",
"GetText.dll",
"MySql.Data.dll",
];
DeCompileExcludeNamespaces =
[
"Microsoft",
"System",
];
UsageTips = new List<string>()
{
"1. 将所有.cs文件放入[自动编译]文件夹里的[源码]文件夹",
"2. 使用命令 /cs by 进行编译",
"3. 生成的DLL在[自动编译]文件夹里的[编译输出]文件夹",
"【配置项说明】",
"启用: 开关插件功能",
"包含子目录: 是否扫描[源码]子目录中的.cs文件",
"语言版本: C#语言版本(CSharp8-CSharp14)",
"最大文件数: 单次编译最多处理文件数",
"最大大小MB: 所有.cs文件总大小限制",
"默认添加引用: 为所有cs文件添加默认引用" +
"(已存在则不添加,只需写命名空间自动添加using)",
"移除using语句:自动移除已存在的using语句",
"注意:暂时不支持内嵌资源的插件生成",
};
RemoveUsings = new List<string>()
{
"Steamworks",
"System.Numerics",
"System.Security.Policy",
"Org.BouncyCastle.Asn1.Cmp",
"Org.BouncyCastle.Asn1.X509",
"NuGet.Protocol.Plugins",
"Org.BouncyCastle.Math.EC.ECCurve",
"using static Org.BouncyCastle.Math.EC.ECCurve;",
"using static MonoMod.InlineRT.MonoModRule;",
};
Usings = new List<string>()
{
"System",
"System.Collections",
"System.Collections.Generic",
"System.Linq",
"System.Text",
"System.Threading",
"System.Threading.Tasks",
"System.IO",
"System.IO.Streams",
"System.IO.Compression",
"System.Reflection",
"System.Diagnostics",
"System.Globalization",
"System.Security",
"System.Security.Cryptography",
"System.Net",
"System.Net.Http",
"System.Runtime.CompilerServices",
"System.Runtime.InteropServices",
"Terraria",
"TShockAPI",
"Microsoft.Xna.Framework",
};
SystemAsse = new List<string>()
{
// 系统核心相关
"System.dll",
"System.Web.dll",
"System.Web.HttpUtility.dll",
"System.Net.dll",
"System.Net.Http.dll",
"System.Net.Requests.dll",
"System.Net.Primitives.dll",
"System.Private.CoreLib.dll",
"System.Private.Uri.dll",
"System.Runtime.dll",
"netstandard.dll",
"System.Core.dll",
"System.Private.Xml.Linq.dll",
"System.Diagnostics.TraceSource.dll",
// 集合相关
"System.Collections.dll",
"System.Collections.Concurrent.dll",
"System.Collections.Immutable.dll",
// LinQ相关
"System.Linq.dll",
"System.Linq.Expressions.dll",
"System.Linq.Queryable.dll",
// IO
"System.IO.dll","System.IO.FileSystem.dll","System.IO.FileSystem.Primitives.dll",
// GZip
"System.IO.Compression.dll","System.IO.Compression.ZipFile.dll",
// 文本处理
"System.Text.Json.dll",
"System.Text.RegularExpressions.dll",
"System.Text.Encoding.dll",
"System.Text.Encoding.Extensions.dll",
// 异步和多线程
"System.Threading.dll",
"System.Threading.Tasks.dll",
"System.Threading.Tasks.Extensions.dll",
"System.Threading.Thread.dll",
"System.Threading.ThreadPool.dll",
"System.Runtime.Extensions.dll",
"System.Runtime.InteropServices.dll",
"System.Runtime.CompilerServices.Unsafe.dll",
"System.Runtime.Numerics.dll",
"System.ComponentModel.dll",
"System.ComponentModel.Primitives.dll",
"System.ComponentModel.TypeConverter.dll",
"System.Xml.ReaderWriter.dll",
"System.Memory.dll",
"System.Buffers.dll",
"System.Numerics.Vectors.dll",
"System.Reflection.dll",
"System.Reflection.Primitives.dll",
"System.Reflection.Extensions.dll",
"System.Reflection.Metadata.dll",
"System.Reflection.TypeExtensions.dll",
"System.ObjectModel.dll",
"System.Globalization.dll",
"System.Diagnostics.Debug.dll",
"System.Diagnostics.Tools.dll",
"System.Diagnostics.Tracing.dll",
"System.Diagnostics.Process.dll",
"System.AppContext.dll",
"System.Console.dll",
"System.Security.Cryptography.Algorithms.dll",
"System.Security.Cryptography.Primitives.dll",
"System.Security.Principal.dll",
};
}
#endregion
#region 读取与创建配置文件方法
public void Write()
{
string json = JsonConvert.SerializeObject(this, Formatting.Indented);
File.WriteAllText(FilePath, json);
}
public static Configuration Read()
{
if (!File.Exists(FilePath))
{
var NewConfig = new Configuration();
NewConfig.SetDefault();
NewConfig.Write();
return NewConfig;
}
else
{
string jsonContent = File.ReadAllText(FilePath);
return JsonConvert.DeserializeObject<Configuration>(jsonContent)!;
}
}
#endregion
}