-
Notifications
You must be signed in to change notification settings - Fork 2
/
Settings.cs
135 lines (118 loc) · 3.49 KB
/
Settings.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
using HomeSeerAPI;
namespace HSPI_AKExample
{
public class Settings
{
private IHSApplication Hs { get; set; }
private string IniFile { get; set; }
public Settings(string IniFile, IHSApplication Hs)
{
this.IniFile = IniFile;
this.Hs = Hs;
Load();
}
private string _location;
public string Location
{
get => _location;
set
{
_location = value;
SaveVal("Location", _location);
}
}
private string _location2;
public string Location2
{
get => _location2;
set
{
_location2 = value;
SaveVal("Location2", _location2);
}
}
private string _selectedDeviceRef;
public string SelectedDeviceRef
{
get => _selectedDeviceRef;
set
{
_selectedDeviceRef = value;
SaveVal("SelectedDeviceRef", _selectedDeviceRef);
}
}
private bool _debugLog;
public bool DebugLog
{
get => _debugLog;
set
{
_debugLog = value;
SaveVal("DebugLog", _debugLog.ToString());
}
}
/// <summary>
/// Call UpdateConfiguration in main or new thread
/// </summary>
private bool _InitIOinThread;
public bool InitIOinThread
{
get => _InitIOinThread;
set
{
_InitIOinThread = value;
SaveVal("InitIOinThread", _InitIOinThread.ToString());
}
}
/// <summary>
/// Display tables inside SliderTab
/// </summary>
private bool _InSlider;
public bool InSlider
{
get => _InSlider;
set
{
_InSlider = value;
SaveVal("InSlider", _InSlider.ToString());
}
}
/// <summary>
/// Prevent calling SaveVal while calling Load()
/// </summary>
private bool loading = false;
public void Load()
{
loading = true;
InSlider = bool.Parse(LoadVal("InSlider", "true"));
InitIOinThread = bool.Parse(LoadVal("InitIOinThread", "true"));
DebugLog = bool.Parse(LoadVal("DebugLog", "false"));
Location = LoadVal("Location");
Location2 = LoadVal("Location2");
SelectedDeviceRef = LoadVal("SelectedDeviceRef");
loading = false;
}
public void Save()
{
SaveVal("InSlider", InSlider.ToString());
SaveVal("InitIOinThread", InitIOinThread.ToString());
SaveVal("DebugLog", DebugLog.ToString());
SaveVal("Location", Location);
SaveVal("Location2", Location2);
SaveVal("SelectedDeviceRef", SelectedDeviceRef);
}
public string LoadVal(string key, string value = "", string fName = null)
{
if(fName==null) fName = IniFile;
return Hs.GetINISetting("Settings", key, value, fName);
}
public void SaveVal(string key, string value, string fName = null)
{
if(!loading)
{
if(fName==null) fName = IniFile;
Hs.SaveINISetting("Settings", key, value, fName);
}
}
}
}