-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPluginConfig.cs
138 lines (129 loc) · 4.97 KB
/
PluginConfig.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using Advanced_Combat_Tracker;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace ACTOBSPlugin
{
public class PluginConfig
{
private bool enabled = false;
private bool autoRename = false;
private string hostPort = "ws://127.0.0.1:4455";
private string password = "";
private string[] startRecording = Array.Empty<string>();
private string[] stopRecording = Array.Empty<string>();
private readonly string settingsFilePath = Path.Combine(ActGlobals.oFormActMain.AppDataFolder.FullName, "Config\\ACTOBSPlugin.config.json");
private bool loaded = false;
public bool Enabled
{
get => enabled;
set {
var changed = enabled != value;
enabled = value;
FireEvent(EnabledChanged: changed);
}
}
public bool AutoRename
{
get => autoRename;
set {
var changed = autoRename != value;
autoRename = value;
FireEvent(AutoRenameChanged: changed);
}
}
public string IPPort
{
get => hostPort;
set {
var changed = hostPort != value;
hostPort = value;
FireEvent(HostPortChanged: changed);
}
}
public string Password
{
get => password;
set {
var changed = password != value;
password = value;
FireEvent(PasswordChanged: changed);
}
}
public string[] StartRecording
{
get => startRecording;
set {
var changed = string.Join("\n", startRecording) != string.Join("\n", value);
startRecording = value;
FireEvent(StartRecordingChanged: changed);
}
}
public string[] StopRecording
{
get => stopRecording;
set {
var changed = string.Join("\n", stopRecording) != string.Join("\n", value);
stopRecording = value;
FireEvent(StopRecordingChanged: changed);
}
}
public event EventHandler<PluginConfigEventChangedArgs> ConfigChanged;
public void Load()
{
loaded = true;
try
{
var loadedConfig = JsonConvert.DeserializeObject<PluginConfig>(File.ReadAllText(settingsFilePath));
enabled = loadedConfig.enabled;
autoRename = loadedConfig.autoRename;
hostPort = loadedConfig.hostPort;
password = loadedConfig.password;
startRecording = loadedConfig.startRecording;
stopRecording = loadedConfig.stopRecording;
}
catch (Exception ex)
{
ActGlobals.oFormActMain.WriteExceptionLog(ex, "Exception loading ACTOBSPlugin config");
}
}
public void Save()
{
var json = JsonConvert.SerializeObject(this);
File.WriteAllText(settingsFilePath, json);
}
private void FireEvent(bool EnabledChanged = false, bool AutoRenameChanged = false, bool HostPortChanged = false, bool PasswordChanged = false, bool StartRecordingChanged = false, bool StopRecordingChanged = false)
{
if (!loaded) return;
if (EnabledChanged || AutoRenameChanged || HostPortChanged || PasswordChanged || StartRecordingChanged || StopRecordingChanged)
{
Save();
ConfigChanged.Invoke(this, new PluginConfigEventChangedArgs(EnabledChanged, AutoRenameChanged, HostPortChanged, PasswordChanged, StartRecordingChanged, StopRecordingChanged));
}
}
public class PluginConfigEventChangedArgs
{
public PluginConfig Config;
public bool EnabledChanged;
public bool AutoRenameChanged;
public bool HostPortChanged;
public bool PasswordChanged;
public bool StartRecordingChanged;
public bool StopRecordingChanged;
public PluginConfigEventChangedArgs(bool enabledChanged, bool autoRenameChanged, bool hostPortChanged, bool passwordChanged, bool startRecordingChanged, bool stopRecordingChanged)
{
EnabledChanged = enabledChanged;
AutoRenameChanged = autoRenameChanged;
HostPortChanged = hostPortChanged;
PasswordChanged = passwordChanged;
StartRecordingChanged = startRecordingChanged;
StopRecordingChanged = stopRecordingChanged;
}
}
}
}