forked from mdude77/MMinerMonitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneric.vb
254 lines (167 loc) · 8.14 KB
/
generic.vb
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
Imports System.Runtime.CompilerServices
Public Class ControlsByRegistry
Private dictRegkeyNames As Dictionary(Of String, String)
Private sRegKey As String
Public Sub AddControl(ByRef ctlAny As Control, ByVal sName As String)
Me.dictRegkeyNames.Add(ctlAny.Name, sName)
End Sub
Public Sub SetControlByRegKey(ByRef chklstAny As CheckedListBox)
Using key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(sRegKey & "\" & chklstAny.Name)
If key Is Nothing Then
My.Computer.Registry.CurrentUser.CreateSubKey(sRegKey & "\" & chklstAny.Name)
End If
End Using
Using key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(sRegKey & "\" & chklstAny.Name)
Dim sTemp As String
For Each sTemp In key.GetValueNames
chklstAny.Items.Add(key.GetValue(sTemp))
Next
End Using
End Sub
Public Sub SetControlByRegKey(ByRef chkAny As CheckBox, Optional bDefault As Boolean = False)
Using key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(sRegKey)
Call SetControlByRegKey(key, chkAny, bDefault)
End Using
End Sub
Public Sub SetControlByRegKey(ByRef optAny As RadioButton, Optional bDefault As Boolean = False)
Using key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(sRegKey)
Call SetControlByRegKey(key, optAny, bDefault)
End Using
End Sub
Public Sub SetControlByRegKey(ByRef regKey As Microsoft.Win32.RegistryKey, ByRef chkAny As CheckBox, Optional bDefault As Boolean = False)
Dim sKey As String
Dim sTemp As String
If dictRegkeyNames.TryGetValue(chkAny.Name, sKey) = True Then
sTemp = regKey.GetValue(sKey)
If sTemp = "Y" Then
chkAny.Checked = True
Else
If String.IsNullOrEmpty(sTemp) = True Then
chkAny.Checked = bDefault
Else
chkAny.Checked = False
End If
End If
Else
Throw New Exception("Internal error: " & chkAny.Name & " not found in regKey dictionary.")
End If
End Sub
Public Sub SetControlByRegKey(ByRef regKey As Microsoft.Win32.RegistryKey, ByRef optAny As RadioButton, Optional bDefault As Boolean = False)
Dim sKey As String
Dim sTemp As String
If dictRegkeyNames.TryGetValue(optAny.Name, sKey) = True Then
sTemp = regKey.GetValue(sKey)
If sTemp = "Y" Then
optAny.Checked = True
Else
If String.IsNullOrEmpty(sTemp) = True Then
optAny.Checked = bDefault
Else
optAny.Checked = False
End If
End If
Else
Throw New Exception("Internal error: " & optAny.Name & " not found in regKey dictionary.")
End If
End Sub
Public Sub SetControlByRegKey(ByRef cmbAny As ComboBox, Optional ByVal sDefault As String = "")
Using key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(sRegKey)
Call SetControlByRegKey(key, cmbAny, sDefault)
End Using
End Sub
Public Sub SetControlByRegKey(ByRef txtAny As TextBox, Optional ByVal sDefault As String = "")
Using key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(sRegKey)
Call SetControlByRegKey(key, txtAny, sDefault)
End Using
End Sub
Public Sub SetControlByRegKey(ByRef regKey As Microsoft.Win32.RegistryKey, ByRef txtAny As TextBox, Optional ByVal sDefault As String = "")
Call _SetControlByRegKey(regKey, txtAny, sDefault)
End Sub
Public Sub SetControlByRegKey(ByRef regKey As Microsoft.Win32.RegistryKey, ByRef cmbAny As ComboBox, Optional ByVal sDefault As String = "")
Call _SetControlByRegKey(regKey, cmbAny, sDefault)
End Sub
Private Sub _SetControlByRegKey(ByRef regKey As Microsoft.Win32.RegistryKey, ByRef ctlAny As Control, Optional ByVal sDefault As String = "")
Dim sKey As String
Dim sReturn As String
If dictRegkeyNames.TryGetValue(ctlAny.Name, sKey) = True Then
sReturn = regKey.GetValue(sKey)
If String.IsNullOrEmpty(sReturn) = True Then
ctlAny.Text = sDefault
Else
ctlAny.Text = sReturn
End If
Else
Throw New Exception("Internal error: " & ctlAny.Name & " not found in regKey dictionary.")
End If
End Sub
Public Sub SetRegKeyByControl(ByRef txtAny As TextBox)
_SetRegKeyByControl(txtAny)
End Sub
Public Sub SetRegKeyByControl(ByRef optAny As RadioButton)
_SetRegKeyByControl(optAny)
End Sub
Public Sub SetRegKeyByControl(ByRef txtAny As TextBox, ByVal sOverRide As String)
_SetRegKeyByControl(txtAny, sOverRide)
End Sub
Public Sub SetRegKeyByControl(ByRef cmbAny As ComboBox)
_SetRegKeyByControl(cmbAny)
End Sub
Private Sub _SetRegKeyByControl(ByRef ctlAny As Control, ByVal sOverRide As String)
Dim sKeyname As String
If dictRegkeyNames.TryGetValue(ctlAny.Name, sKeyname) = True Then
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\" & sRegKey, sKeyname, sOverRide, Microsoft.Win32.RegistryValueKind.String)
Else
Throw New Exception("Internal error: " & ctlAny.Name & " not found in regKey dictionary.")
End If
End Sub
Private Sub _SetRegKeyByControl(ByRef ctlAny As Control)
Dim sKeyname As String
If dictRegkeyNames.TryGetValue(ctlAny.Name, sKeyname) = True Then
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\" & sRegKey, sKeyname, ctlAny.Text, Microsoft.Win32.RegistryValueKind.String)
Else
Throw New Exception("Internal error: " & ctlAny.Name & " not found in regKey dictionary.")
End If
End Sub
Public Sub SetRegKeyByControl(ByRef chkLstAny As CheckedListBox)
Dim sValue As String
Using key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(sRegKey & "\" & chkLstAny.Name, True)
For Each sTemp In key.GetValueNames
key.DeleteValue(sTemp)
Next
End Using
For Each sValue In chkLstAny.Items
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\" & sRegKey & "\" & chkLstAny.Name, sValue, sValue, Microsoft.Win32.RegistryValueKind.String)
Next
End Sub
Public Sub SetRegKeyByControl(ByRef chkAny As CheckBox)
Dim sKeyname As String
If dictRegkeyNames.TryGetValue(chkAny.Name, sKeyname) = True Then
If chkAny.Checked = True Then
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\" & sRegKey, sKeyname, "Y", Microsoft.Win32.RegistryValueKind.String)
Else
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\" & sRegKey, sKeyname, "N", Microsoft.Win32.RegistryValueKind.String)
End If
Else
Throw New Exception("Internal error: " & chkAny.Name & " not found in regKey dictionary.")
End If
End Sub
Public Sub New(ByVal csRegKey As String)
dictRegkeyNames = New Dictionary(Of String, String)
Me.sRegKey = csRegKey
End Sub
End Class
Public Module Extensions
<Extension()> Public Function IsNullOrEmpty(ByVal sString As String) As Boolean
Return String.IsNullOrEmpty(sString)
End Function
<Extension()> Public Function InstrRev(ByVal sString As String, ByVal sSearch As String, Optional ByVal iStart As Integer = -1) As String
Return sString.Substring(Microsoft.VisualBasic.InStrRev(sString, sSearch, iStart))
End Function
<Extension()> Public Function LeftMost(ByVal sString As String, ByVal iMinusValue As Integer) As String
If sString.Length < iMinusValue Then
Return sString
Else
Return sString.Substring(0, sString.Length - iMinusValue)
End If
End Function
End Module