-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSharedSettings.cs
More file actions
202 lines (181 loc) · 5.2 KB
/
Copy pathSharedSettings.cs
File metadata and controls
202 lines (181 loc) · 5.2 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
using SSC.Extensions;
using SSC.Interfaces;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
namespace SSC
{
[Serializable]
public class PrivateSettings
{
private static string GetConfigPath() => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "SSC", "Config.xml");
private static PrivateSettings m_Instance;
public static PrivateSettings GetInstance()
{
if (m_Instance == null)
m_Instance = LoadSettings();
return m_Instance;
}
#region Properties
[XmlElement] public bool Debug_mode { get; set; }
[XmlElement] public bool Autostart { get; set; }
[XmlElement] public float Volume { get; set; }
[XmlElement] public int Delay { get; set; }
[XmlElement] public Guid OutputDevice { get; set; }
[XmlElement] public EncryptedString UserAuth { get; set; }
[XmlElement] public EncryptedString BotAuth { get; set; }
[XmlElement] public bool RunWebSocketsServer { get; set; }
[XmlElement] public int WebSocketsServerPort { get; set; }
[XmlElement] public string UniversalSoundRewardID { get; set; }
[XmlElement] public string LastNotesFile { get; set; }
[XmlElement] public string OBS_Address { get; set; }
[XmlElement] public EncryptedString OBS_Password { get; set; }
#endregion
public PrivateSettings()
{
//NOTE: Make sure everything is initialized first!
Debug_mode = false;
Autostart = false;
Volume = 0.5f;
Delay = 15;
UserAuth = "";
BotAuth = "";
RunWebSocketsServer = false;
WebSocketsServerPort = 8005;
UniversalSoundRewardID = "";
LastNotesFile = "";
OBS_Address = "ws://127.0.0.1:4455";
OBS_Password = "";
}
#region Load/Save
private static PrivateSettings LoadSettings()
{
var path = GetConfigPath();
if (File.Exists(path))
{
PrivateSettings obj;
XmlSerializer serializer = new XmlSerializer(typeof(PrivateSettings));
FileStream fs = new FileStream(path, FileMode.Open);
obj = (PrivateSettings)serializer.Deserialize(fs);
fs.Close();
return obj;
}
else
return new PrivateSettings();
}
public void SaveSettings() => XML_Utils.Save(GetConfigPath(), this);
#endregion
}
[Serializable]
public class VoiceModConfig
{
private static string GetConfigPath() => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "SSC", "VoiceModConfig.xml");
private static VoiceModConfig m_Instance;
public static VoiceModConfig GetInstance()
{
if (m_Instance == null)
m_Instance = LoadSettings();
return m_Instance;
}
private static VoiceModConfig LoadSettings()
{
if (File.Exists(GetConfigPath()))
{
VoiceModConfig obj;
XmlSerializer serializer = new XmlSerializer(typeof(VoiceModConfig));
FileStream fs = new FileStream(GetConfigPath(), FileMode.Open);
obj = (VoiceModConfig)serializer.Deserialize(fs);
fs.Close();
return obj;
}
else
return new VoiceModConfig();
}
public void Save()
{
XmlSerializer serializer = new XmlSerializer(typeof(VoiceModConfig));
StreamWriter fw = new StreamWriter(GetConfigPath());
serializer.Serialize(fw, this);
fw.Close();
}
public string APIKey { get; set; }
public string AdressPort { get; set; }
public List<VoiceModReward> Rewards { get; set; } = new List<VoiceModReward>();
private Dictionary<string, VoiceModReward> IDToReward;
public VoiceModReward GetReward(string rewardID)
{
if (IDToReward == null)
{
IDToReward = new Dictionary<string, VoiceModReward>();
foreach (var reward in Rewards)
{
if (string.IsNullOrEmpty(reward.RewardID))
continue;
if (IDToReward.ContainsKey(reward.RewardID))
continue;
IDToReward.Add(reward.RewardID, reward);
}
}
if (IDToReward.TryGetValue(rewardID, out var foundReward))
return foundReward;
else
return null;
}
public VoiceModConfig()
{
APIKey = "";
AdressPort = "ws://localhost:59129/v1";
}
[Serializable]
public class VoiceModReward : IVoiceModeRewardBindingInterface
{
[XmlAttribute]
public string VoiceModFriendlyName { get; set; }
[XmlAttribute]
public string RewardTitle { get; set; }
[XmlAttribute]
public string RewardID { get; set; }
[XmlAttribute]
public int RewardCost { get; set; }
[XmlAttribute]
public int RewardCooldown { get; set; }
[XmlAttribute]
public int RewardDuration { get; set; }
[XmlAttribute]
public bool Enabled { get; set; }
[XmlText]
public string RewardDescription { get; set; }
[XmlIgnore]
public bool IsSetup = false;
public VoiceModReward()
{
VoiceModFriendlyName = "";
RewardTitle = "";
RewardID = "";
RewardCost = 240;
RewardDuration = 30;
RewardCooldown = 1;
Enabled = true;
RewardDescription = "";
}
public object Clone()
{
return new VoiceModReward()
{
VoiceModFriendlyName = this.VoiceModFriendlyName,
RewardTitle = this.RewardTitle,
RewardID = this.RewardID,
RewardCost = this.RewardCost,
RewardCooldown = this.RewardCooldown,
RewardDuration = this.RewardDuration,
Enabled = this.Enabled,
RewardDescription = this.RewardDescription
};
}
}
}
}