1- using System . Collections . ObjectModel ;
21using System . IO ;
3- using System . Text . Json ;
4- using System . Text . Json . Serialization ;
5- using System . Threading . Tasks ;
6- using TabletBot . Common . Store ;
72
83namespace TabletBot . Common
94{
10- public sealed class Settings
5+ public sealed class Settings : Serializable
116 {
127 private const ulong MAIN_GUILD_ID = 615607687467761684 ;
138 private const ulong LOG_MESSAGE_CHANNEL_ID = 715344685853442198 ;
@@ -26,47 +21,6 @@ public sealed class Settings
2621
2722 public LogLevel LogLevel { set ; get ; } = LogLevel . Debug ;
2823
29- public Collection < RoleManagementMessageStore > ReactiveRoles { set ; get ; } = new Collection < RoleManagementMessageStore > ( ) ;
30- public Collection < SnippetStore > Snippets { set ; get ; } = new Collection < SnippetStore > ( ) ;
31-
32- [ JsonIgnore ]
33- public bool RunAsUnit { set ; get ; } = false ;
34-
35- private static readonly JsonSerializerOptions SerializerOptions = new JsonSerializerOptions
36- {
37- WriteIndented = true
38- } ;
39-
40- public async Task Write ( FileInfo file )
41- {
42- if ( file . Directory is { Exists : false } )
43- file . Directory . Create ( ) ;
44- await using ( var fs = file . Create ( ) )
45- await JsonSerializer . SerializeAsync ( fs , this , SerializerOptions ) ;
46- }
47-
48- public static async Task < Settings > Read ( FileInfo file )
49- {
50- await using ( var fs = file . OpenRead ( ) )
51- return await JsonSerializer . DeserializeAsync < Settings > ( fs ) ;
52- }
53-
54- public async Task < string > ExportAsync ( )
55- {
56- await using ( var ms = new MemoryStream ( ) )
57- {
58- await JsonSerializer . SerializeAsync ( ms , this , SerializerOptions ) ;
59- ms . Position = 0 ;
60- using ( var sr = new StreamReader ( ms ) )
61- return await sr . ReadToEndAsync ( ) ;
62- }
63- }
64-
65- public async Task Overwrite ( )
66- {
67- Platform . SettingsFile . Refresh ( ) ;
68- if ( Platform . SettingsFile . Exists )
69- await Write ( Platform . SettingsFile ) ;
70- }
24+ public override FileInfo File { get ; } = AppData . SettingsFile ;
7125 }
7226}
0 commit comments