-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataManager.cs
60 lines (51 loc) · 1.35 KB
/
DataManager.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
using System.IO;
using System.Reflection;
namespace StreamLabs_Helper
{
public class DataManager
{
private static string defaultUrl = "https://w2g.tv/rooms/challengerandymusic-h749vkhemnt5dmld09?lang=en";
private static string prefFileName = "Preferences.txt";
private static string preferenceFilePath;
private static UserData userData;
//constructor method
static DataManager()
{
var exePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
var topLevelDir = System.IO.Directory.GetParent(exePath).FullName;
preferenceFilePath = System.IO.Path.Combine(topLevelDir, prefFileName);
if (File.Exists(preferenceFilePath))
userData = XmlHelper.FromXmlFile<UserData>(preferenceFilePath);
else
SetupNew();
}
static private void SetupNew()
{
userData = new UserData
{
Prefs = new Preferences() {
url = defaultUrl,
mode = "local"
}
};
XmlHelper.ToXmlFile(userData, preferenceFilePath);
}
public static void RefreshData()
{
userData = XmlHelper.FromXmlFile<UserData>(preferenceFilePath);
}
public static Preferences GetPreferences()
{
return userData.Prefs;
}
public static UserData GetUserData()
{
return userData;
}
public static void WriteDataToFile(UserData data)
{
userData = data;
XmlHelper.ToXmlFile(userData, preferenceFilePath);
}
}
}