Repository navigation
Expand file tree
/
Copy pathgeneric.vb
More file actions
397 lines (267 loc) · 11.9 KB
/
Copy pathgeneric.vb
File metadata and controls
397 lines (267 loc) · 11.9 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
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
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 SetControlByRegKeyAnt(ByRef chklstAny As CheckedListBox)
Using key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(sRegKey & "\Ants")
If key Is Nothing Then
My.Computer.Registry.CurrentUser.CreateSubKey(sRegKey & "\Ants")
End If
End Using
Using key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(sRegKey & "\Ants")
Dim sTemp As String
For Each sTemp In key.GetSubKeyNames
chklstAny.Items.Add(sTemp)
Next
End Using
End Sub
Public Sub SetControlByRegKey(ByRef trackAny As TrackBar, Optional iValue As Integer = 4)
Using key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(sRegKey)
Call SetControlByRegKey(key, trackAny, iValue)
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 trackAny As TrackBar, Optional iValue As Integer = 4)
Dim sKey As String
Dim sTemp As String
If dictRegkeyNames.TryGetValue(trackAny.Name, sKey) = True Then
sTemp = regKey.GetValue(sKey)
If sTemp.IsNullOrEmpty = True Then
trackAny.Value = iValue
Else
trackAny.Value = Val(sTemp)
End If
Else
Throw New Exception("Internal error: " & trackAny.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 trackAny As TrackBar)
_SetRegKeyByControl(trackAny)
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
Private Sub _SetRegKeyByControl(ByRef ctlAny As TrackBar)
Dim sKeyname As String
If dictRegkeyNames.TryGetValue(ctlAny.Name, sKeyname) = True Then
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\" & sRegKey, sKeyname, ctlAny.Value, 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
Dim p() As String
Using key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(sRegKey & "\" & chkLstAny.Name, True)
If key IsNot Nothing Then
For Each sTemp In key.GetValueNames
key.DeleteValue(sTemp)
Next
End If
End Using
For Each sValue In chkLstAny.Items
p = sValue.Split(":")
sValue = p(0) & ":" & p(1)
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
''' <summary>
''' Returns the string located at the In String Reverse position
''' </summary>
''' <param name="sString"></param>
''' <param name="sSearch">String to search for</param>
''' <param name="iStart">Where to start searching</param>
''' <returns></returns>
''' <remarks></remarks>
<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
''' <summary>
''' Returns the leftmost part of the string minus the value passed
''' </summary>
''' <param name="sString"></param>
''' <param name="iMinusValue">How many chars from the end to omit</param>
''' <returns></returns>
''' <remarks></remarks>
<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
Public Class enListbox
Inherits ListBox
Private dictTags As System.Collections.Generic.Dictionary(Of Integer, Object)
Public Function AddItem(ByRef o As Object, ByRef t As Object) As Integer
Dim i As Integer
i = MyBase.Items.Add(o)
dictTags.Add(i, t)
Return i
End Function
Public Sub RemoveSelectedItem()
Dim x As Integer
Dim b As Boolean
Dim o As Object
'when an item is removed from the list collection, the list indexes for every item after it are renumbered!
'this compensates for that in the dictionary of tags by renumbering them there as well
For x = MyBase.SelectedIndex To Me.dictTags.Count - 1
If b = False Then
dictTags.Remove(x)
MyBase.Items.RemoveAt(x)
b = True
Else
o = (Me.dictTags(x))
Me.dictTags.Remove(x)
Me.dictTags.Add(x - 1, o)
End If
Next
End Sub
Public Property ItemTag(ByVal iIndex As Integer) As Object
Get
Dim o As Object
If dictTags.TryGetValue(iIndex, o) = True Then
Return o
Else
Return Nothing
End If
End Get
Set(value)
Dim o As Object
If dictTags.TryGetValue(iIndex, o) = True Then
dictTags(iIndex) = value
Else
dictTags.Add(iIndex, value)
End If
End Set
End Property
Public Sub New()
MyBase.New()
Me.dictTags = New Dictionary(Of Integer, Object)
End Sub
End Class