/
ApplicationSettings.cs
121 lines (91 loc) · 4.26 KB
/
ApplicationSettings.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
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
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
namespace PlenBotLogUploader.AppSettings
{
[JsonObject(MemberSerialization.OptIn)]
internal sealed class ApplicationSettings
{
#region application version
internal static int Version => 88;
#endregion
#region load & save functionality
internal static ApplicationSettings Current { get; private set; }
internal static string FileName => "app_settings.json";
internal static string LocalDir { get; set; }
internal event EventHandler<EventArgs> SettingsSaved;
internal ApplicationSettings()
{
Current = this;
}
private void SerialiseToFile(string saveLocation)
{
SettingsSaved?.Invoke(this, EventArgs.Empty);
File.WriteAllText(saveLocation, JsonConvert.SerializeObject(this, Formatting.Indented));
}
private static ApplicationSettings DeserialiseFromFile(string loadLocation)
{
if (File.Exists(loadLocation))
{
var json = File.ReadAllText(loadLocation);
var settings = JsonConvert.DeserializeObject<ApplicationSettings>(json);
if (settings is not null)
{
return settings;
}
}
var sett = new ApplicationSettings();
sett.Save();
return sett;
}
internal static bool Exists() => File.Exists(LocalDir + FileName);
internal static ApplicationSettings Load() => DeserialiseFromFile(LocalDir + FileName);
internal void Save() => SerialiseToFile(LocalDir + FileName);
#endregion
#region internal properties
[JsonProperty("aleeva")]
internal ApplicationSettingsAleeva Aleeva { get; set; } = new ApplicationSettingsAleeva();
[JsonProperty("arcUpdate")]
internal ApplicationSettingsArcUpdate ArcUpdate { get; set; } = new ApplicationSettingsArcUpdate();
[JsonProperty("autoUpdate")]
internal bool AutoUpdate { get; set; } = false;
[JsonProperty("bossTemplate")]
internal ApplicationSettingsBossTemplate BossTemplate { get; set; } = new ApplicationSettingsBossTemplate();
[JsonProperty("buildCodes")]
internal ApplicationSettingsBuildCodes BuildCodes { get; set; } = new();
[JsonProperty("firstApplicationRun")]
internal bool FirstApplicationRun { get; set; } = true;
[JsonProperty("firstTimeMinimised")]
internal bool FirstTimeMinimised { get; set; } = false;
[JsonProperty("gw2APIKeys")]
internal List<ApplicationSettingsGw2Api> Gw2Apis { get; set; } = [];
[JsonProperty("gw2Bot")]
internal ApplicationSettingsGw2Bot Gw2Bot { get; set; } = new ApplicationSettingsGw2Bot();
[JsonProperty("gw2Location")]
internal string Gw2Location { get; set; } = "";
[JsonProperty("logsLocation")]
internal string LogsLocation { get; set; } = "";
[JsonProperty("usePollingForLogs")]
internal bool UsePollingForLogs { get; set; } = false;
[JsonProperty("mainFormSize")]
internal System.Drawing.Size MainFormSize { get; set; } = new System.Drawing.Size(649, 784);
[JsonProperty("mainFormState")]
internal System.Windows.Forms.FormWindowState MainFormState { get; set; } = System.Windows.Forms.FormWindowState.Normal;
[JsonProperty("maxConcurrentUploads")]
internal int MaxConcurrentUploads { get; set; } = 4;
[JsonProperty("minimiseToTry")]
internal bool MinimiseToTray { get; set; } = true;
[JsonProperty("closeToTry")]
internal bool CloseToTray { get; set; } = false;
[JsonProperty("session")]
internal ApplicationSettingsSession Session { get; set; } = new ApplicationSettingsSession();
[JsonProperty("shortenThousands")]
internal bool ShortenThousands { get; set; } = false;
[JsonProperty("twitch")]
internal ApplicationSettingsTwitch Twitch { get; set; } = new ApplicationSettingsTwitch();
[JsonProperty("upload")]
internal ApplicationSettingsUpload Upload { get; set; } = new ApplicationSettingsUpload();
#endregion
}
}