This repository has been archived by the owner on May 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
QA-Settings-Configuration-Tool.ps1
3280 lines (2932 loc) · 208 KB
/
QA-Settings-Configuration-Tool.ps1
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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<#
###############################################################################################
SERVER QA SCRIPTS
CONFIGURATION TOOL Developed and written by Mike Blackett @ My Random Thoughts
v4 https://github.com/my-random-thoughts/qa-checks-v4
###############################################################################################
###############################################################################################
# #
# Aids in the configuration of customer or environment specific settings for the QA Scripts #
# #
# CONTACT ME IF YOU REQUIRE HELP - READ ALL THE DOCUMENTATION FIRST #
# #
###############################################################################################
#>
Param ([string]$Language)
Remove-Variable -Name * -Exclude 'Language' -ErrorAction SilentlyContinue
#Requires -Version 4
Set-StrictMode -Version 2
Clear-Host
# IMG_MAINFORM Icon List
# 0: Gear : (green) - default-settings
# 1: Gear : (blue) - enabled item / custom settings
# 2: Gear : (grey) - disabled item
# 3: Flag : '?' - for languages with no flag
# 4: Flag : 'en-GB' - default english language
# 5: Clock : timeout - extra settings window
# 6: Gears : concurrent - extra settings window
# 7: Cross : (red) - clear search field
# 8: Cloud : 'MRT' logo - github link on about screen
# 9: All : tab 2 button - select all visible checks
# 10: Invert : tab 2 button - invert visible selected checks
# 11: None : tab 2 button - unselect all visible checks
# 12: Reset : tab 2 button - reset all checks back to setting defaults
# 13: Help/Info : tab 2 image - search help
[void][Reflection.Assembly]::LoadWithPartialName('System.Data')
[void][Reflection.Assembly]::LoadWithPartialName('System.Drawing')
[void][Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
[System.Drawing.Font]$sysFont = [System.Drawing.SystemFonts]::MessageBoxFont
[System.Drawing.Font]$sysFontBold = (New-Object -TypeName 'System.Drawing.Font' ($sysFont.Name, ($sysFont.SizeInPoints + 1), [System.Drawing.FontStyle]::Bold ))
[System.Drawing.Font]$sysFontItalic = (New-Object -TypeName 'System.Drawing.Font' ($sysFont.Name, $sysFont.SizeInPoints , [System.Drawing.FontStyle]::Italic))
[System.Windows.Forms.Application]::EnableVisualStyles()
[hashtable]$script:languageINI = @{}
[hashtable]$script:ToolLangINI = @{}
[object] $script:SelectedLanguage = $null
[string] $script:SelectedToolLang = ''
[string] $script:regExMatch = '((?:.|\s)+?)(?:(?:[A-Z\- ]+:\n)|(?:#>))' # Used for all RegEx search matching used in the check comments
[string] $script:toolName = 'QA Settings Configuration Tool' # QASCT Name
[string] $script:toolVersion = 'v4.18.0412' # QASCT Version (v4.yy.mmdd)
###################################################################################################
## ##
## Various Required Scripts ##
## ##
###################################################################################################
#region Various Required Scripts
Function New-IconComboItem { Return (New-Object -TypeName 'PSObject' -Property @{'Icon' = ''; 'Name' = ''; 'Text' = ''; }) }
[System.Collections.ArrayList]$script:IconCombo_Items = @{} # - Holds current items
[System.Collections.ArrayList]$script:IC_T1_ToolLang = @{} # \
[System.Collections.ArrayList]$script:IC_T1_Language = @{} # Holds all the custom
[System.Collections.ArrayList]$script:IC_T1_Settings = @{} # items for all the
[System.Collections.ArrayList]$script:IC_AS_Timeout = @{} # Combo Boxes
[System.Collections.ArrayList]$script:IC_AS_Concurrent = @{} # /
# Enable Cue Banner text to be applied to textbox controls
$Definition = @'
[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool SendNotifyMessage(IntPtr hWnd, int msg, int wParam, string lParam);
'@
$DefFunc = Add-Type -MemberDefinition $Definition -Name 'User32' -Namespace 'Win32' -PassThru
Function SendMessage([intptr]$ControlHandle, [string]$DisplayString) { Return $DefFunc::SendNotifyMessage($ControlHandle, '&H1501', 0, $DisplayString) }
Function Get-Folder ([string]$Description, [string]$InitialDirectory, [boolean]$ShowNewFolderButton)
{
[string]$return = ''
If ([threading.thread]::CurrentThread.GetApartmentState() -eq 'STA')
{
$FolderBrowser = (New-Object -TypeName 'System.Windows.Forms.FolderBrowserDialog')
$FolderBrowser.RootFolder = 'MyComputer'
$FolderBrowser.Description = $Description
$FolderBrowser.ShowNewFolderButton = $ShowNewFolderButton
If ([string]::IsNullOrEmpty($InitialDirectory) -eq $False) { $FolderBrowser.SelectedPath = $InitialDirectory }
If ($FolderBrowser.ShowDialog($MainForm) -eq [System.Windows.Forms.DialogResult]::OK) { $return = $($FolderBrowser.SelectedPath) }
Try { $FolderBrowser.Dispose() } Catch {}
}
Else
{
# Workaround for MTA not showing the dialog box.
# Initial Directory is not possible when using the COM Object
$Description += "`n$($script:ToolLangINI['page1']['FolderOpen2'])"
$comObject = (New-Object -ComObject 'Shell.Application')
$FolderBrowser = $comObject.BrowseForFolder(0, $Description, 512, '') # 512 = No 'New Folder' button, '' = Initial folder (Desktop)
If ([string]::IsNullOrEmpty($FolderBrowser) -eq $False) { $return = $($FolderBrowser.Self.Path) } Else { $return = '' }
[void][System.Runtime.Interopservices.Marshal]::ReleaseComObject($comObject) # Dispose COM object
}
Return $return
}
Function Open-File ([string]$InitialDirectory, [string]$Title)
{
[string]$return = ''
$OpenFile = (New-Object -TypeName 'System.Windows.Forms.OpenFileDialog')
$OpenFile.InitialDirectory = $InitialDirectory
$OpenFile.Multiselect = $False
$OpenFile.Title = $Title
$OpenFile.Filter = 'Compiled QA Scripts|*.ps1'
If ([threading.thread]::CurrentThread.GetApartmentState() -ne 'STA') { $OpenFile.ShowHelp = $True } # Workaround for MTA issues not showing dialog box
If ($OpenFile.ShowDialog($MainFORM) -eq [System.Windows.Forms.DialogResult]::OK) { $return = ($OpenFile.FileName) }
Try { $OpenFile.Dispose() } Catch {}
Return $return
}
Function Save-File ([string]$InitialDirectory, [string]$Title, [string]$InitialFileName)
{
[string]$return = ''
$SaveFile = (New-Object -TypeName 'System.Windows.Forms.SaveFileDialog')
$SaveFile.InitialDirectory = $InitialDirectory
$SaveFile.Title = $Title
$SaveFile.FileName = $InitialFileName
$SaveFile.Filter = 'QA Configuration Settings|*.ini'
If ([threading.thread]::CurrentThread.GetApartmentState() -ne 'STA') { $SaveFile.ShowHelp = $True } # Workaround for MTA issues not showing dialog box
If ($SaveFile.ShowDialog($MainForm) -eq [System.Windows.Forms.DialogResult]::OK) { $return = ($SaveFile.FileName) }
Try { $SaveFile.Dispose() } Catch {}
Return $return
}
Function Load-ComboBoxIcon ([System.Windows.Forms.ComboBox]$ComboBox, [string[]]$Items, [string]$SelectedItem, [switch]$Clear, [string]$Type)
{
If ($Clear) { $ComboBox.Items.Clear() }
If ($Items[0] -eq $($script:ToolLangINI['page1']['LangMissing']))
{
$newItem = (New-IconComboItem)
$newItem.Icon = $img_MainForm.Images[3]; $newItem.Name = $Items[0]; $newItem.Text = $Items[0]
[void]$script:IC_T1_Language.Add($newItem); $newItem = $null
[void]$ComboBox.Items.AddRange($script:IC_T1_Language); $ComboBox.SelectedIndex = 0
Return
}
# Clear each of the collections
Switch ($Type)
{
'Timeout' { [void]$script:IC_AS_Timeout.Clear() }
'ToolLang' { [void]$script:IC_T1_ToolLang.Clear() }
'Language' { [void]$script:IC_T1_Language.Clear() }
'Settings' { [void]$script:IC_T1_Settings.Clear() }
'Concurrent' { [void]$script:IC_AS_Concurrent.Clear() }
}
[int]$SelectedIndex = -1
$Items | ForEach-Object -Process {
$newItem = (New-IconComboItem)
$newItem.Name = "$_"
$newItem.Text = "$_"
If (($Type -eq 'Language') -or ($Type -eq 'ToolLang'))
{
Try
{
# This method does not lock the image files as [System.Drawing.Image]::FromFile() does
$bytes = [System.IO.File]::ReadAllBytes("$script:scriptLocation\i18n\$($_).png")
$MemSt = (New-Object -TypeName 'System.IO.MemoryStream'(,$bytes))
$newItem.Icon = [System.Drawing.Image]::FromStream($MemSt)
$MemSt.Flush(); $MemSt.Dispose()
}
Catch
{
If (($newItem.Name -eq 'default-settings') -or ($newItem.Name -eq 'en-GB')) { $newItem.Icon = $img_MainForm.Images[4] } # Built-in British flag
Else { $newItem.Icon = $img_MainForm.Images[3] } # Unknown flag
}
# Load INI Value for this language and get the icon index
[string]$filePart = ''; If ($Type -eq 'ToolLang') { $filePart = '-tool' }
Try { [string]$TextName = (Load-IniFile -Inputfile "$script:scriptLocation\i18n\$($_)$filePart.ini").Language.Name } Catch { Return }
$newItem.Text = $TextName # Overwrite above default
If ($Type -eq 'Language') { [void]$script:IC_T1_Language.Add($newItem) } Else { [void]$script:IC_T1_ToolLang.Add($newItem) }
}
ElseIf ($Type -eq 'Settings')
{
If ($_ -eq 'default-settings') { $newItem.Icon = $img_MainForm.Images[0] } Else { $newItem.Icon = $img_MainForm.Images[1] }
[void]$script:IC_T1_Settings.Add($newItem)
}
ElseIf ($Type -eq 'TimeOut')
{
$newItem.Icon = $img_MainForm.Images[5]
[void]$script:IC_AS_Timeout.Add($newItem)
If ($_ -eq $SelectedItem) { $SelectedIndex = $script:IC_AS_Timeout.Count - 1 }
}
ElseIf ($Type -eq 'Concurrent')
{
$newItem.Icon = $img_MainForm.Images[6]
[void]$script:IC_AS_Concurrent.Add($newItem)
If ($_ -eq $SelectedItem) { $SelectedIndex = $script:IC_AS_Concurrent.Count - 1 }
}
Else
{
Write-Warning "Load-ComboBoxIcon: Wrong TYPE entered: $Type"
}
$newItem = $null
}
Switch ($Type)
{
'ToolLang' { $script:IC_T1_ToolLang = @($script:IC_T1_ToolLang | Sort-Object -Property 'Text'); [void]$ComboBox.Items.AddRange($script:IC_T1_ToolLang ) }
'Language' { $script:IC_T1_Language = @($script:IC_T1_Language | Sort-Object -Property 'Text'); [void]$ComboBox.Items.AddRange($script:IC_T1_Language ) }
'Settings' { $script:IC_T1_Settings = @($script:IC_T1_Settings | Sort-Object -Property 'Text'); [void]$ComboBox.Items.AddRange($script:IC_T1_Settings ) }
'Timeout' { [void]$ComboBox.Items.AddRange($script:IC_AS_Timeout ) }
'Concurrent' { [void]$ComboBox.Items.AddRange($script:IC_AS_Concurrent) }
}
If ($SelectedIndex -eq -1) {
For ($x=0; $x -lt $ComboBox.Items.Count; $x++) { If ($ComboBox.Items[$x].Name -eq $SelectedItem) { $ComboBox.SelectedIndex = $x; Break } }
} Else { $ComboBox.SelectedIndex = $SelectedIndex }
}
Function ComboIcons_OnDrawItem ([System.Windows.Forms.ComboBox]$Control)
{
[System.Windows.Forms.DrawItemEventArgs]$e = $_
$e.DrawBackground()
$e.DrawFocusRectangle()
If ($Control.Enabled -eq $False) { $Control.BackColor = [System.Drawing.SystemColors]::Control }
Else { $Control.BackColor = [System.Drawing.SystemColors]::Window }
[System.Drawing.Rectangle]$bounds = $e.Bounds
If (($e.Index -gt -1) -and ($e.Index -lt $Control.Items.Count))
{
$currItem = $Control.Items[$e.Index]
[System.Drawing.Image] $icon = $null
[System.Drawing.SolidBrush]$solidBrush = [System.Drawing.SolidBrush]$e.ForeColor
Try { $icon = $currItem.Icon } Catch { $icon = $img_MainForm.Images[3] } # Unknown flag on failure
# Specific for this tool - Resize the image just in case it's not 16x16 - can't trust anyone.!
If (($icon.Width -ne 16) -or ($icon.Height -ne 16)) { $icon = (New-Object -TypeName 'System.Drawing.Bitmap'($icon, 16, 16)) }
# Format and display the image/text
$middle = ((($bounds.Top) + ((($bounds.Height) - ($icon.Height)) / 2)) -as [int])
$iconRect = (New-Object -TypeName 'System.Drawing.RectangleF'((($bounds.Left) + 5), $middle, $icon.Width, $icon.Width))
$textRect = (New-Object -TypeName 'System.Drawing.RectangleF'((($bounds.Left) + ($iconRect.Width) + 9), $middle, (($bounds.Width) - ($iconRect.Width) - 9), $icon.Width))
$format = (New-Object -TypeName 'System.Drawing.StringFormat')
$format.Alignment = [System.Drawing.StringAlignment]::Near # Left aligned
$format.LineAlignment = [System.Drawing.StringAlignment]::Center # Verically centered
$format.Trimming = [System.Drawing.StringTrimming ]::EllipsisCharacter # Trim trailing characters
$e.Graphics.DrawImage($icon, $iconRect)
$e.Graphics.DrawString($currItem.Text, $e.Font, $solidBrush, $textRect, $format)
$e.Graphics.Dispose()
$icon = $null
}
}
Function Add-ListViewItem ([System.Windows.Forms.ListView]$ListView, [string]$Name, [int]$ImageIndex = -1, [string[]]$SubItems, [string]$Group, [switch]$Clear, [boolean]$Enabled )
{
[System.Windows.Forms.ListViewGroup]$lvGroup = $null
If ($ListView -ne $null)
{
If ($Clear) { [void]$ListView.Items.Clear() }
ForEach ($groupItem in $ListView.Groups) { If ($groupItem.Name -eq $Group) { $lvGroup = $groupItem; Break } }
If ($lvGroup -eq $null) { $lvGroup = $ListView.Groups.Add($Group, "ERR: $Group") }
}
# Create item
$lvItem = (New-Object -TypeName 'System.Windows.Forms.ListViewItem')
$lvItem.Name = $Name
If ($Name.StartsWith('*') -eq $false) { $lvItem.Text = $Name } Else { $lvItem.Text = '' }
$lvItem.ImageIndex = $ImageIndex
$lvItem.Group = $lvGroup
$lvItem.Tag = $Group
$lvitem.Checked = $false
$lvItem.SubItems.AddRange($SubItems)
# Used for each tab section items, not the check selection window
If (($Enabled -eq $false) -and ($lvItem.Text -ne ' ')) { $lvItem.ForeColor = 'ControlDark'; $lvItem.ImageIndex = 2 }
# Add or return item
If ($ListView -ne $null) { $ListView.Items.Add($lvItem) } Else { Return $lvItem }
}
Function Load-IniFile ([string]$Inputfile, [hashtable]$ExistingHashTable = $null)
{
[string] $comment = ";"
[string] $header = "^\s*(?!$($comment))\s*\[\s*(.*[^\s*])\s*]\s*$"
[string] $item = "^\s*(?!$($comment))\s*([^=]*)\s*=\s*(.*)\s*$"
[hashtable]$ini = @{}
If ($ExistingHashTable -ne $null) { $ini = $ExistingHashTable.Clone() }
If ((Test-Path -LiteralPath $inputfile) -eq $False) { Write-Warning "Load-IniFile: Path not found: $inputfile"; Return $null }
[string]$name = $null
[string]$section = $null
Switch -Regex -File $inputfile {
"$($header)" {
[string]$section = (($matches[1] -replace ' ','_').Trim().Trim("'"))
If ($section.StartsWith('com') -eq $true) { $section = "tol$($section.Substring(3))" }
If ([string]::IsNullOrEmpty($ini[$section]) -eq $true) { $ini[$section] = @{} }
}
"$($item)" {
[string]$name, $value = $matches[1..2]
If (([string]::IsNullOrEmpty($name) -eq $False) -and ([string]::IsNullOrEmpty($section) -eq $False))
{
$value = (($value -split ' #')[0]).Trim() # Remove any comments
If ($inputfile.Contains('\settings\') -eq $False) { $value = $value.Trim("'") }
$ini[$section][$name.Trim()] = ($value.Replace('`n', "`n"))
}
}
}
Return $ini
}
Function Get-DefaultINISettings ()
{
[hashtable]$defaultINI = @{}
[object[]] $folders = (Get-ChildItem -Path "$script:scriptLocation\checks" | Where-Object -FilterScript { $_.PsIsContainer -eq $True } | Select-Object -ExpandProperty 'Name' | Sort-Object -Property 'Name' )
ForEach ($folder In ($folders | Sort-Object -Property 'Name'))
{
[object[]]$scripts = (Get-ChildItem -Path "$script:scriptLocation\checks\$folder" -Filter '???-??-*.ps1' | Select-Object -ExpandProperty 'Name' | Sort-Object -Property 'Name' )
If ([string]::IsNullOrEmpty($scripts) -eq $False)
{
ForEach ($script In ($scripts | Sort-Object -Property 'Name'))
{
[string]$getContent = ((Get-Content -Path "$script:scriptLocation\checks\$folder\$script" -TotalCount 50) -join "`n")
[string]$checkCode = ($script.Substring(0, 6).Replace('-','')) # Get check code: "acc-01-local-user.ps1" --> "acc01"
# Get default state (ENABLED / SKIPPED)
$regExE = [regex]::Match($getContent, "DEFAULT-STATE:$script:regExMatch")
If ($regExE.Groups[1].Value.Trim() -ne 'Enabled') { $checkCode += '-skip' }
# Add check
$defaultINI[$checkCode] = @{}
# Get default values
$regExV = [regex]::Match($getContent, "DEFAULT-VALUES:$script:regExMatch")
[string[]]$Values = ($regExV.Groups[1].Value.Trim()).Split("`n")
If (([string]::IsNullOrEmpty($Values) -eq $false) -and ($Values -ne 'None'))
{
ForEach ($EachValue In $Values) { $defaultINI[$checkCode][(($EachValue -split ' = ')[0]).Trim()] = (($EachValue -split ' = ')[1]).Trim() }
}
}
}
}
Return $defaultINI
}
#endregion
###################################################################################################
## ##
## Secondary Forms ##
## ##
###################################################################################################
#region Secondary Forms
Function Show-InputForm
{
Param
(
[parameter(Mandatory=$True )][string] $Type,
[parameter(Mandatory=$True )][string] $Title,
[parameter(Mandatory=$True )][string] $Description,
[parameter(Mandatory=$false)][string] $Validation = 'None',
[parameter(Mandatory=$false)][string[]]$InputList,
[parameter(Mandatory=$false)][string[]]$CurrentValue,
[parameter(Mandatory=$false)][string ]$InputDescription = '',
[parameter(Mandatory=$false)][int ]$MaxNumberInputBoxes
)
# [ValidateSet('Simple', 'Check', 'Option', 'List', 'Large')]
# [ValidateSet('None', 'AZ', 'Numeric', 'Integer', 'Decimal', 'Symbol', 'File', 'URL', 'Email', 'IPv4', 'IPv6')]
#region Form Scripts
$ChkButton_Click = {
If ($ChkButton.Text -eq $($script:ToolLangINI['input']['CheckAll'])) {
$ChkButton.Text = $($script:ToolLangINI['input']['CheckNone'])
[boolean]$checked = $True
} Else {
$ChkButton.Text = $($script:ToolLangINI['input']['CheckAll'])
[boolean]$checked = $False
}
ForEach ($Control In $floPanel.Controls) { If ($control -is [System.Windows.Forms.CheckBox]) { $control.Checked = $checked } }
}
# Start form validation and make sure everything entered is correct
$btn_Accept_Click = {
[string[]]$currentValues = @('')
[boolean] $ValidatedInput = $True
ForEach ($Control In $floPanel.Controls)
{
If (($Control -is [System.Windows.Forms.TextBox]) -and ($Control.Visible -eq $True))
{
$Control.BackColor = 'Window'
If (($Type -eq 'LIST') -and ($Control.Text.Contains(';') -eq $True))
{
[string[]]$ControlText = ($Control.Text).Split(';')
$Control.Text = '' # Remove current data so that it can be used as a landing control for the split data
ForEach ($item In $ControlText) { AddButton_Click -Value $item -Override $false -AddType 'TEXT' }
}
}
}
# Reset Control Loop for any new fields that may have been added
[string]$validationText = $($script:ToolLangINI['input']['ValidationFail'])
ForEach ($Control In $floPanel.Controls)
{
If (($Control -is [System.Windows.Forms.TextBox]) -and ($Control.Visible -eq $True))
{
$ValidatedInput = $(ValidateInputBox -Control $Control)
If ($ValidatedInput -eq $True)
{
If (($Type -eq 'LIST') -and (([string]::IsNullOrEmpty($Control.Text) -eq $false) -and ($currentValues -contains ($Control.text))))
{
$ValidatedInput = $false
$validationText = $($script:ToolLangINI['input']['DuplicateFound'])
}
Else { $currentValues += $Control.Text }
}
If ($ValidatedInput -eq $false)
{
$Control.Focus()
$Control.SelectAll()
$ToolTip.Show($validationText, $Control, 12, $Control.Height, 2500)
$Control.BackColor = 'Info'
Break
}
}
}
$currentValues = $null
If ($ValidatedInput -eq $True) { $frm_Input.DialogResult = [System.Windows.Forms.DialogResult]::OK }
}
$frm_Input_Resize = {
# Change textbox widths for the scroll bar
If ($Type -eq 'LIST')
{
ForEach ($Control In $floPanel.Controls)
{
If ($Control -is [System.Windows.Forms.TextBox])
{
If ($floPanel.VerticalScroll.Visible -eq $false) { $Control.Width = 340 }
Else { $Control.Width = 340 - [System.Windows.Forms.SystemInformation]::VerticalScrollBarWidth }
}
}
}
}
[int]$numberOfTextBoxes = 0
$AddButton_Click = { AddButton_Click -Value '' -Override $false -AddType 'TEXT' }
Function AddButton_Click ([string]$Value, [boolean]$Override, [string]$AddType, [string]$ItemTip)
{
[int]$BoxNumber = 0
ForEach ($Control In $floPanel.Controls) { If (($Control -is [System.Windows.Forms.TextBox]) -or ($Control -is [System.Windows.Forms.CheckBox])) { $BoxNumber++ } }
If ($BoxNumber -eq ($MaxNumberInputBoxes - 1)) { $AddButton.Visible = $false } # Hide 'Add' button if required
If ($BoxNumber -eq ($MaxNumberInputBoxes)) { Return }
If ($AddType -eq 'TEXT')
{
ForEach ($control In $floPanel.Controls) {
If ($control -is [System.Windows.Forms.TextBox]) {
[System.Windows.Forms.TextBox]$isEmtpy = $null
If ([string]::IsNullOrEmpty($control.Text) -eq $True) { $isEmtpy = $control; Break }
}
}
If ($Override -eq $True) { $isEmtpy = $null }
If ($isEmtpy -ne $null)
{
$isEmtpy.Select()
$isEmtpy.Text = $Value
Return
}
}
# Increase form size, move buttons down, add new field
$numberOfTextBoxes++
If ($AddType -eq 'TEXT')
{
# Add new counter label
$labelCounter = (New-Object -TypeName 'System.Windows.Forms.Label')
$labelCounter.Size = ' 21, 23'
$labelCounter.Font = $sysFont
$labelCounter.Text = "$($BoxNumber + 1):"
$labelCounter.TextAlign = 'MiddleRight'
$labelCounter.Margin = '1, 1, 6, 2' # Using Margin as we are relying on
$labelCounter.Padding = '0, 0, 0, 0' # the flow panel to position controls: Left,Top,Right,Bottom
$floPanel.Controls.Add($labelCounter)
# Add new text box and select it for focus
$textBox = (New-Object -TypeName 'System.Windows.Forms.TextBox')
$textBox.Size = '340, 23'
$textBox.Font = $sysFont
$textBox.Name = "textBox$BoxNumber"
$textBox.Text = $Value.Trim()
$textBox.Margin = '1, 1, 0, 2'
$textBox.Padding = '0, 0, 0, 0'
If (($Validation -ne 'None') -and (($Type -eq 'Simple') -or ($Type -eq 'List'))) {
[void](SendMessage -ControlHandle $textBox.Handle -DisplayString $($lbl_Validation.Text))
}
$floPanel.Controls.Add($textBox)
$floPanel.Controls["textbox$BoxNumber"].Select()
$frm_Input_Resize.Invoke()
}
ElseIf ($AddType -eq 'CHECK')
{
# Add new check box
$chkBox = (New-Object -TypeName 'System.Windows.Forms.CheckBox')
$chkBox.Size = "$(370 - 2 - [System.Windows.Forms.SystemInformation]::VerticalScrollBarWidth), 23"
$chkBox.Font = $sysFont
$chkBox.Name = "chkBox$BoxNumber"
$chkBox.Text = $Value + $ItemTip
$chkBox.TextAlign = 'MiddleLeft'
$chkBox.Margin = '1, 1, 0, 2'
$chkBox.Padding = '0, 0, 0, 0'
$floPanel.Controls.Add($chkBox)
$floPanel.Controls["chkbox$BoxNumber"].Select()
}
Else { }
}
Function Change-Form ([string]$ChangeTo)
{
If (($Type -eq 'Check') -or ($Type -eq 'List') -or ($Type -eq 'Large'))
{ # Large form
$frm_Input.ClientSize = '394, 251'
$btn_Accept.Location = '307, 214'
$btn_Cancel.Location = '220, 214'
}
Else
{ # Small form
$frm_Input.ClientSize = '394, 147'
$btn_Accept.Location = '307, 110'
$btn_Cancel.Location = '220, 110'
}
$frm_Input.MinimumSize = $frm_Input.Size
If (($Type -eq 'List') -or ($Type -eq 'Check')) { $frm_Input.MaximumSize = "$($frm_Input.Width), 9999"; $frm_Input.SizeGripStyle = [System.Windows.Forms.SizeGripStyle]::Show }
Else { $frm_Input.MaximumSize = $frm_Input.Size ; $frm_Input.SizeGripStyle = [System.Windows.Forms.SizeGripStyle]::Hide }
}
Function ValidateInputBox ([System.Windows.Forms.Control]$Control)
{
$Control.Text = ($Control.Text.Trim())
[boolean]$ValidateResult = $false
[string] $StringToCheck = $($Control.Text)
# Ignore for LARGE fields
If ($Type -eq 'LARGE') { Return $True }
# Ignore control if empty
If ([string]::IsNullOrEmpty($StringToCheck) -eq $True) { Return $True }
# Validate
Switch ($Validation)
{
'AZ' { $ValidateResult = ($StringToCheck -match "^[A-Za-z]+$"); Break } # Letters only (A-Za-z)
'Numeric' { $ValidateResult = ($StringToCheck -match '^(-)?([\d]+)?\.?[\d]+$'); Break } # Both integer and decimal numbers
'Integer' { $ValidateResult = ($StringToCheck -match '^(-)?[\d]+$'); Break } # Integer numbers only
'Decimal' { $ValidateResult = ($StringToCheck -match '^(-)?[\d]+\.[\d]+$'); Break } # Decimal numbers only
'Symbol' { $ValidateResult = ($StringToCheck -match '^[^A-Za-z0-9]+$'); Break } # Any symbol (not numbers or letters)
'File' { # Valid file or folder name
$StringToCheck = $StringToCheck.TrimEnd('\')
$ValidateResult = ($StringToCheck -match "^(?:[a-zA-Z]\:|\\\\[\w\.]+\\[\w.$]+)\\(?:[\w]+\\)*\w([\w.])+$")
Break
}
'URL' { # URL
[url] $url = ''
[boolean]$ValidURL1 = ($StringToCheck -match '^(ht|(s)?f|)tp(s)?:\/\/(.*)\/([a-z]+\.[a-z]+)') # http(s):// or (s)ftp(s)://
[boolean]$ValidURL2 = ([System.Uri]::TryCreate($StringToCheck, [System.UriKind]::Absolute, [ref]$url))
$ValidateResult = ($ValidURL1 -and $ValidURL2)
Break
}
'Email' { # [email protected]
Try { $ValidateResult = (($StringToCheck -as [System.Net.Mail.MailAddress]).Address -eq $StringToCheck) }
Catch { $ValidateResult = $false }
Break
}
'IPv4' { # IPv4 address (1.2.3.4)
[boolean]$Octets = (($StringToCheck.Split('.') | Measure-Object).Count -eq 4)
[boolean]$ValidIP = ($StringToCheck -as [ipaddress]) -as [boolean]
$ValidateResult = ($ValidIP -and $Octets)
Break
}
'IPv6' { # IPv6 address (REGEX from 'https://www.powershellgallery.com/packages/IPv6Regex/1.1.1')
[string]$IPv6 = @"
^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4]\d|1\d\d|[1-9]?[0-9])|:))|(([0-9a-f]
{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4]\d|1\d\d|[1-9]?[0-9])|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]
{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4]\d|1\d\d|[1-9]?[0-9]))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|
2[0-4]\d|1\d\d|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4]\d|1\d\d|[1-9]?[0-9]))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]
?[0-9])\.){3}(25[0-5]|2[0-4]\d|1\d\d|[1-9]?[0-9]))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?[0-9])\.){3}(25[0-5]|
2[0-4]\d|1\d\d|[1-9]?[0-9]))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4]\d|1\d\d|[1-9]?[0-9]))|:)))$
"@
$ValidateResult = ($StringToCheck -match $IPv6)
Break
}
Default { # No Validation
$ValidateResult = $True
}
}
Return $ValidateResult
}
$frm_Input_Cleanup_FormClosed = {
Try {
$btn_Accept.Remove_Click($btn_Accept_Click)
$AddButton.Remove_Click($AddButton_Click)
} Catch {}
$frm_Input.Remove_Resize($frm_Input_Resize)
$frm_Input.Remove_FormClosed($frm_Input_Cleanup_FormClosed)
}
#endregion
#region Input Form Controls
[System.Windows.Forms.Application]::EnableVisualStyles()
$frm_Input = (New-Object -TypeName 'System.Windows.Forms.Form')
$frm_Input.FormBorderStyle = 'Sizable'
$frm_Input.Text = " $Title"
$frm_Input.MaximizeBox = $False
$frm_Input.MinimizeBox = $False
$frm_Input.ControlBox = $True
$frm_Input.ShowIcon = $False
$frm_Input.ShowInTaskbar = $False
$frm_Input.AutoScaleDimensions = '6, 13'
$frm_Input.AutoScaleMode = 'None'
$frm_Input.ClientSize = '394, 147' # 400 x 175
$frm_Input.StartPosition = 'CenterScreen' # 'CenterParent'
$frm_Input.Add_Resize($frm_Input_Resize)
$ToolTip = (New-Object -TypeName 'System.Windows.Forms.ToolTip')
$lbl_Description = (New-Object -TypeName 'System.Windows.Forms.Label')
$lbl_Description.Location = ' 12, 12'
$lbl_Description.Size = '370, 48'
$lbl_Description.Font = $sysFont
$lbl_Description.Text = $($Description.Trim())
$frm_Input.Controls.Add($lbl_Description)
If (($Validation -ne 'None') -and (($Type -eq 'Simple') -or ($Type -eq 'List')))
{
$lbl_Validation = (New-Object -TypeName 'System.Windows.Forms.Label')
$lbl_Validation.Location = '212, 60'
$lbl_Validation.Size = '170, 15'
$lbl_Validation.Text = "$($script:ToolLangINI['input']['Validation']) $($script:ToolLangINI['input'][$Validation])"
$lbl_Validation.TextAlign = 'BottomRight'
$frm_Input.Controls.Add($lbl_Validation)
}
$btn_Accept = (New-Object -TypeName 'System.Windows.Forms.Button')
$btn_Accept.Location = '307, 110'
$btn_Accept.Size = ' 75, 25'
$btn_Accept.Font = $sysFont
$btn_Accept.Text = $($script:ToolLangINI['input']['OK'])
$btn_Accept.Anchor = 'Bottom, Right'
$btn_Accept.Add_Click($btn_Accept_Click)
If ($Type -ne 'LARGE') { $frm_Input.AcceptButton = $btn_Accept }
$frm_Input.Controls.Add($btn_Accept)
$btn_Cancel = (New-Object -TypeName 'System.Windows.Forms.Button')
$btn_Cancel.Location = '220, 110'
$btn_Cancel.Size = ' 75, 25'
$btn_Cancel.Font = $sysFont
$btn_Cancel.Text = $($script:ToolLangINI['input']['Cancel'])
$btn_Cancel.Anchor = 'Bottom, Right'
$btn_Cancel.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$frm_Input.CancelButton = $btn_Cancel
$frm_Input.Controls.Add($btn_Cancel)
$frm_Input.Add_FormClosed($frm_Input_Cleanup_FormClosed)
$floPanel = (New-Object -TypeName 'System.Windows.Forms.FlowLayoutPanel')
$floPanel.Location = ' 11, 74'
$floPanel.Size = '372, 26'
$floPanel.AutoScroll = $True
$floPanel.Padding = '0, 0, 0, 0'
$floPanel.AutoScrollMargin = '0, 0'
$floPanel.Anchor = 'Top, Bottom, Left, Right'
$frm_Input.Controls.Add($floPanel)
#endregion
#region Input Form Controls Part 2
[string]$ItemTip = ''
Switch ($Type)
{
'LIST' {
# List of text boxes
[int]$itemCount = ($CurrentValue.Count)
If ($itemCount -ge 5) { [int]$numberOfTextBoxes = $itemCount + 1 } Else { [int]$numberOfTextBoxes = 5 }
$numberOfTextBoxes-- # Count from zero
# Add 'Add' button
$AddButton = (New-Object -TypeName 'System.Windows.Forms.Button')
$AddButton.Location = " 39, $($btn_Accept.Top)"
$AddButton.Size = ' 75, 25'
$AddButton.Font = $sysFont
$AddButton.Text = $($script:ToolLangINI['input']['Add'])
$AddButton.Anchor = 'Bottom, Left'
$AddButton.Add_Click($AddButton_Click)
$frm_Input.Controls.Add($AddButton)
# Add initial textboxes
For ($i = 0; $i -le $numberOfTextBoxes; $i++) { AddButton_Click -Value ($CurrentValue[$i]) -Override $True -AddType 'TEXT' }
$floPanel.Controls['textbox0'].Select()
Break
}
'CHECK' {
# Add 'Check All' button
$ChkButton = (New-Object -TypeName 'System.Windows.Forms.Button')
$ChkButton.Location = " 12, $($btn_Accept.Top)"
$ChkButton.Size = '125, 25'
$ChkButton.Font = $sysFont
$ChkButton.Text = $($script:ToolLangINI['input']['CheckAll'])
$ChkButton.Anchor = 'Bottom, Left'
$ChkButton.Add_Click($ChkButton_Click)
$frm_Input.Controls.Add($ChkButton)
# Add initial textboxes
[int]$i = 0
If ($InputDescription -ne '') { For ($x=0;$x-lt$InputList.Count;$x++) { ForEach ($iDec In $InputDescription.Split('|')) { If ($iDec.StartsWith($InputList[$x] + ': ') -eq $true) { $InputList[$x] = $iDec } } } }
ForEach ($item In $InputList)
{
AddButton_Click -Value ($item.Trim()) -Override $True -AddType 'CHECK'
If ([string]::IsNullOrEmpty($CurrentValue) -eq $false) { If ($CurrentValue.Contains($item.Split(':')[0].Trim())) { $floPanel.Controls["chkBox$i"].Checked = $True } }
$i++
}
$floPanel.Controls['chkBox0'].Select()
Break
}
'OPTION' {
# Drop down selection list
If ($InputDescription -ne '') { For ($x=0;$x-lt$InputList.Count;$x++) { ForEach ($iDec In $InputDescription.Split('|')) { If ($iDec.StartsWith($InputList[$x] + ': ') -eq $true) { $InputList[$x] = $iDec } } } }
$comboBox = (New-Object -TypeName 'System.Windows.Forms.ComboBox')
$comboBox.Size = '370, 23'
$comboBox.Font = $sysFont
$comboBox.DropDownStyle = 'DropDownList'
$comboBox.Margin = '1, 1, 1, 1'
$comboBox.Padding = '0, 0, 0, 0'
$floPanel.Controls.Add($comboBox)
[void]$comboBox.Items.AddRange(($InputList.Trim()))
$frm_Input.Add_Shown({$comboBox.Select()})
$comboBox.SelectedIndex = -1
ForEach ($item In $InputList) { If ([string]::IsNullOrEmpty($CurrentValue) -eq $false) { if ($CurrentValue[0].Contains($item.Split(':')[0].Trim())) { $comboBox.SelectedItem = $item } } }
Break
}
'LARGE' {
# Multi-line text entry
$textBox = (New-Object -TypeName 'System.Windows.Forms.TextBox')
$textBox.Size = '370, 127'
$textBox.Font = $sysFont
$textBox.Multiline = $True
$textBox.ScrollBars = 'Vertical'
$textBox.Margin = '1, 1, 1, 1'
$textBox.Padding = '0, 0, 0, 0'
$floPanel.Controls.Add($textBox)
$frm_Input.Add_Shown({$textBox.Select()})
$textBox.Text = (($CurrentValue.Trim()) -join "`r`n")
$textBox.Select()
Break
}
'SIMPLE' {
# Add default text box
$textBox = (New-Object -TypeName 'System.Windows.Forms.TextBox')
$textBox.Size = '370, 23'
$textBox.Margin = '1, 1, 1, 1'
$textBox.Padding = '0, 0, 0, 0'
$textBox.Font = $sysFont
$floPanel.Controls.Add($textBox)
$textBox.Text = (($CurrentValue.Trim()) -join "`r`n")
If (($Validation -ne 'None') -and (($Type -eq 'Simple') -or ($Type -eq 'List'))) {
[void](SendMessage -hWnd $textBox.Handle -msg '&H1501' -wParam 1 -lParam $($lbl_Validation.Text))
}
$textBox.Select()
Break
}
Default { Write-Warning "Input Form: Invalid Type: $Type" }
}
Change-Form -ChangeTo $Type
#endregion
#region Show Form And Return Value
ForEach ($control In $frm_Input.Controls) { $control.Font = $sysFont; Try { $control.FlatStyle = 'Standard' } Catch {} }
ForEach ($control In $floPanel.Controls) { $control.Font = $sysFont; Try { $control.FlatStyle = 'Standard' } Catch {} }
If (($Validation -ne 'None') -and (($Type -eq 'Simple') -or ($Type -eq 'List'))) { $lbl_Validation.Font = $sysFontItalic }
$result = $frm_Input.ShowDialog($MainForm)
If ($result -eq [System.Windows.Forms.DialogResult]::OK)
{
Switch ($Type)
{
'LIST' {
[string[]]$return = @()
ForEach ($control In $floPanel.Controls) { If ($control -is [System.Windows.Forms.TextBox]) {
If ([string]::IsNullOrEmpty($control.Text) -eq $false) { $return += ($($control.Text.Trim())) } }
} Return $return
}
'CHECK' {
[string[]]$return = @()
ForEach ($Control In $floPanel.Controls) { If ($control -is [System.Windows.Forms.CheckBox]) {
If ($control.Checked -eq $True) { $return += ($($control.Text.Split(':')[0].Trim())) } }
} Return $return
}
'LARGE' {
Do { [string]$return = $($textBox.Text.Trim()).Replace("`r`n", ' ') }
While ( $return.IndexOf("`r`n") -gt -1 ); Return ($return.Trim("`r`n"))
}
'SIMPLE' {
Do { [string]$return = $($textBox.Text.Trim()).Replace("`r`n", ' ') }
While ( $return.IndexOf("`r`n") -gt -1 ); Return ($return.Trim("`r`n"))
}
'OPTION' {
Return $($comboBox.SelectedItem.Split(':')[0].Trim())
}
Default {
Return "Invalid return type: $Type"
}
}
}
ElseIf ($result -eq [System.Windows.Forms.DialogResult]::Cancel) { Return '!!-CANCELLED-!!' }
#endregion
}
Function Show-AdditionalOptions ()
{
#region FORM SCRIPTS
$frm_Additional_Cleanup_FormClosed = {
Try { $btn_Accept.Remove_Click($btn_Accept_Click) } Catch {}
$frm_Additional.Remove_FormClosed($frm_Additional_Cleanup_FormClosed)
$frm_Additional.Dispose()
}
$btn_Module_Click = {
[string] $title = "$($script:ToolLangINI['additional']['Button']) - $($script:ToolLangINI['add-page4']['Tab'])"
[string] $description = $($script:ToolLangINI['add-page4']['Description'])
[string[]]$currentVal = @('')
If ($lbl_ModuleList.Text -ne $($script:ToolLangINI['add-page4']['None'])) { [string[]]$currentVal = $($lbl_ModuleList.Text) -split ",`n" }
[string[]]$returnValue = @(Show-InputForm -Type 'List' -Title $title -Description $description -CurrentValue $currentVal -MaxNumberInputBoxes 5)
If ([string]::IsNullOrEmpty($returnValue) -eq $True) { $lbl_ModuleList.Text = $($script:ToolLangINI['add-page4']['None']) }
If ($returnValue -ne '!!-CANCELLED-!!') { $lbl_ModuleList.Text = $($returnValue -join ",`n") }
}
$btn_Save_Click = {
# Save the results before closing the form...
$script:settings.Timeout = $($cmo_TimeOut.SelectedItem.Text.Trim())
$script:settings.Concurrent = $($cmo_Concurrent.SelectedItem.Text.Trim())
$script:settings.OutputLocation = $($txt_Location.Text.Trim())
$script:settings.SessionPort = $($txt_Port.Text.Trim())
$script:settings.SessionUseSSL = $($chk_UseSSL.Checked.ToString())
If ($lbl_ModuleList.Text -eq $($script:ToolLangINI['add-page4']['None'])) { $script:settings.Modules = '' }
Else { $script:settings.Modules = $($lbl_ModuleList.Text.Replace("`n", '')) }
$frm_Additional.DialogResult = [System.Windows.Forms.DialogResult]::OK
}
#endregion
#region MAIN FORM
$frm_Additional = (New-Object -TypeName 'System.Windows.Forms.Form')
$frm_Additional.FormBorderStyle = 'FixedDialog'
$frm_Additional.MaximizeBox = $False
$frm_Additional.MinimizeBox = $False
$frm_Additional.ControlBox = $False
$frm_Additional.Text = $($script:ToolLangINI['additional']['Button'])
$frm_Additional.ShowInTaskbar = $False
$frm_Additional.AutoScaleDimensions = '6, 13'
$frm_Additional.AutoScaleMode = 'None'
$frm_Additional.ClientSize = '494, 351' # 500 x 379
$frm_Additional.StartPosition = 'CenterParent'
$frm_Additional.Add_FormClosed($frm_Additional_Cleanup_FormClosed)
$lbl_Description = (New-Object -TypeName 'System.Windows.Forms.Label')
$lbl_Description.Location = ' 12, 12'
$lbl_Description.Size = '470, 33'
$lbl_Description.Text = $($script:ToolLangINI['additional']['Description'])
$frm_Additional.Controls.Add($lbl_Description)
$tab_PagesExt = (New-Object -TypeName 'System.Windows.Forms.TabControl')
$tab_PagesExt.Location = ' 12, 60'
$tab_PagesExt.Size = '470, 239'
$tab_PagesExt.Padding = ' 12, 6'
$tab_PagesExt.SelectedIndex = 0
$tab_PagesExt.Add_SelectedIndexChanged($tab_Pages_SelectedIndexChanged)
$frm_Additional.Controls.Add($tab_PagesExt)
$ext_Page1 = (New-Object -TypeName 'System.Windows.Forms.TabPage')
$ext_Page1.BackColor = 'Control'
$ext_Page1.Text = ($script:ToolLangINI['add-page1']['Tab'])
$tab_PagesExt.Controls.Add($ext_Page1)
$ext_Page2 = (New-Object -TypeName 'System.Windows.Forms.TabPage')
$ext_Page2.BackColor = 'Control'
$ext_Page2.Text = ($script:ToolLangINI['add-page2']['Tab'])
$tab_PagesExt.Controls.Add($ext_Page2)
$ext_Page3 = (New-Object -TypeName 'System.Windows.Forms.TabPage')
$ext_Page3.BackColor = 'Control'
$ext_Page3.Text = ($script:ToolLangINI['add-page3']['Tab'])
$tab_PagesExt.Controls.Add($ext_Page3)
$ext_Page4 = (New-Object -TypeName 'System.Windows.Forms.TabPage')
$ext_Page4.BackColor = 'Control'
$ext_Page4.Text = ($script:ToolLangINI['add-page4']['Tab'])
$tab_PagesExt.Controls.Add($ext_Page4)
#endregion
#region BUTTONS
$btn_Reset = (New-Object -TypeName 'System.Windows.Forms.Button')
$btn_Reset.Location = ' 12, 314'
$btn_Reset.Size = '125, 25'
$btn_Reset.Font = $sysFont
$btn_Reset.Text = $($script:ToolLangINI['additional']['Button_Reset'])
$btn_Reset.Add_Click({
# Reset all values to defaults
$cmo_Timeout.SelectedIndex = 2 # 60
$cmo_Concurrent.SelectedIndex = 2 # 5
$txt_Location.Text = 'C:\QA\Results\'
$chk_UseSSL.Checked = $false
$txt_Port.Text = '5985'
$lbl_ModuleList.Text = $($script:ToolLangINI['add-page4']['None']) # (none)
})
$frm_Additional.Controls.Add($btn_Reset)
$btn_Save = (New-Object -TypeName 'System.Windows.Forms.Button')
$btn_Save.Location = '407, 314'
$btn_Save.Size = ' 75, 25'
$btn_Save.Font = $sysFont
$btn_Save.Text = $($script:ToolLangINI['additional']['Button_Save'])
$btn_Save.Add_Click($btn_Save_Click)
$frm_Additional.AcceptButton = $btn_Save
$frm_Additional.Controls.Add($btn_Save)
$btn_Cancel = (New-Object -TypeName 'System.Windows.Forms.Button')
$btn_Cancel.Location = '317, 314'
$btn_Cancel.Size = ' 75, 25'
$btn_Cancel.Font = $sysFont
$btn_Cancel.Text = $($script:ToolLangINI['additional']['Button_Cancel'])
$btn_Cancel.Add_Click({$frm_Additional.DialogResult = [System.Windows.Forms.DialogResult]::Cancel})
$frm_Additional.CancelButton = $btn_Cancel
$frm_Additional.Controls.Add($btn_Cancel)
#endregion
#region TAP PAGES
# PAGE 1
$lbl_Title1 = (New-Object -TypeName 'System.Windows.Forms.Label')
$lbl_Title1.Location = ' 12, 12'
$lbl_Title1.Size = '438, 33'
$lbl_Title1.Text = $($script:ToolLangINI['add-page1']['Title'])
$ext_Page1.Controls.Add($lbl_Title1)
$lbl_TimeOut1 = (New-Object -TypeName 'System.Windows.Forms.Label')
$lbl_TimeOut1.Location = ' 12, 60'
$lbl_TimeOut1.Size = '150, 27'
$lbl_TimeOut1.Text = $($script:ToolLangINI['add-page1']['Timeout'])
$lbl_TimeOut1.TextAlign = 'MiddleRight'
$ext_Page1.Controls.Add($lbl_Timeout1)
$cmo_TimeOut = (New-Object -TypeName 'System.Windows.Forms.ComboBox')
$cmo_TimeOut.Location = '168, 60'
$cmo_TimeOut.Size = ' 75, 27'
$cmo_TimeOut.ItemHeight = ' 21'
$cmo_TimeOut.DrawMode = 'OwnerDrawFixed'
$cmo_TimeOut.DropDownStyle = 'DropDownList'
$cmo_TimeOut.Add_DrawItem( { ComboIcons_OnDrawItem -Control $this })
$cmo_TimeOut.Add_SelectedIndexChanged({ cmo_t1_SelectedIndexChanged -Control $this })
$ext_Page1.Controls.Add($cmo_TimeOut)
Load-ComboBoxIcon -ComboBox $cmo_TimeOut -Items @('30','45','60','75','90','120') -SelectedItem $($script:settings.Timeout) -Type 'TimeOut' -Clear
$lbl_TimeOut2 = (New-Object -TypeName 'System.Windows.Forms.Label')
$lbl_TimeOut2.Location = '249, 60'
$lbl_TimeOut2.Size = '201, 27'
$lbl_TimeOut2.Text = $($script:ToolLangINI['add-page1']['SecondsPer'])
$lbl_TimeOut2.TextAlign = 'MiddleLeft'
$ext_Page1.Controls.Add($lbl_TimeOut2)
$lbl_Concurrent1 = (New-Object -TypeName 'System.Windows.Forms.Label')
$lbl_Concurrent1.Location = ' 12, 96'
$lbl_Concurrent1.Size = '150, 27'
$lbl_Concurrent1.Text = $($script:ToolLangINI['add-page1']['Concurrency'])
$lbl_Concurrent1.TextAlign = 'MiddleRight'
$ext_Page1.Controls.Add($lbl_Concurrent1)
$cmo_Concurrent = (New-Object -TypeName 'System.Windows.Forms.ComboBox')
$cmo_Concurrent.Location = '168, 96'
$cmo_Concurrent.Size = ' 75, 27'
$cmo_Concurrent.ItemHeight = ' 21'
$cmo_Concurrent.DrawMode = 'OwnerDrawFixed'
$cmo_Concurrent.DropDownStyle = 'DropDownList'
$cmo_Concurrent.Add_DrawItem( { ComboIcons_OnDrawItem -Control $this })
$cmo_Concurrent.Add_SelectedIndexChanged({ cmo_t1_SelectedIndexChanged -Control $this })