@@ -18,52 +18,58 @@ $form.Controls.Add($label)
18
18
19
19
# Create checkboxes dynamically based on the content of the script
20
20
$checkBoxes = @ ()
21
- $packages = @ {}
22
- $currentCategory = " "
21
+ # $packages = @{}
22
+ # $currentCategory = ""
23
23
24
24
$scriptPath = Join-Path - Path $PSScriptRoot - ChildPath " ..\chocolatey_install_all.ps1" # Set the correct relative path to the base script
25
25
26
26
# Read the content of the base script
27
27
$scriptContent = Get-Content - Path $scriptPath
28
28
29
29
# Parse the content and extract package names and categories
30
+ $groupLabels = $scriptContent | Select-String - Pattern " ^##\s(.+)" | ForEach-Object { $_.Matches.Groups [1 ].Value }
31
+
32
+ $currentY = 50
33
+ $checkBoxWidth = $form.ClientSize.Width - 60 # Adjusted width based on form width
34
+ $groupPackages = @ {}
35
+ foreach ($groupLabel in $groupLabels ) {
36
+ # Initialize packages array for the group label
37
+ $groupPackages [$groupLabel ] = @ ()
38
+
39
+ }
40
+
30
41
foreach ($line in $scriptContent ) {
31
- if ($line -match " ^# (.+)$" ) {
42
+ if ($line -match " ^##\s (.+)$" ) {
32
43
$currentCategory = $matches [1 ]
33
44
} elseif ($line -match " choco install ([^\s]+)" ) {
34
45
$packageName = $matches [1 ]
35
- $packages [ $packageName ] = $currentCategory
46
+ $groupPackages [ $currentCategory ] + = $packageName
36
47
}
37
48
}
38
49
39
- $currentY = 50
40
- $checkBoxWidth = $form.ClientSize.Width - 60 # Adjusted width based on form width
41
- foreach ($package in $packages.GetEnumerator () | Sort-Object - Property Value) {
42
- $packageName = $package.Key
43
- $category = $package.Value
44
-
45
- # Add category label if it's a new category
46
- if ($category -ne $currentCategory ) {
47
- $currentY += 30
48
- $categoryLabel = New-Object System.Windows.Forms.Label
49
- $categoryLabel.Location = New-Object System.Drawing.Point(20 , $currentY )
50
- $categoryLabel.AutoSize = $true # Adjusted to enable label resizing
51
- $categoryLabel.Text = $category
52
- $form.Controls.Add ($categoryLabel )
53
-
54
- $currentCategory = $category
50
+ foreach ($groupLabel in $groupLabels ) {
51
+ # Add category label
52
+ $currentY += 30
53
+ $categoryLabel = New-Object System.Windows.Forms.Label
54
+ $categoryLabel.Location = New-Object System.Drawing.Point(20 , $currentY )
55
+ $categoryLabel.AutoSize = $true # Adjusted to enable label resizing
56
+ $categoryLabel.Text = $groupLabel
57
+ $form.Controls.Add ($categoryLabel )
58
+
59
+ # Find corresponding packages for the group label
60
+ $groupPackages [$groupLabel ] | ForEach-Object {
61
+ $currentY += 25
62
+ $checkBox = New-Object System.Windows.Forms.CheckBox
63
+ $checkBox.Location = New-Object System.Drawing.Point(40 , $currentY )
64
+ $checkBox.Size = New-Object System.Drawing.Size($checkBoxWidth , 20 ) # Adjusted size based on form width
65
+ $checkBox.Text = $_
66
+ $checkBoxes += $checkBox
67
+ $form.Controls.Add ($checkBox )
55
68
}
56
-
57
- # Create checkbox for each package
58
- $currentY += 25
59
- $checkBox = New-Object System.Windows.Forms.CheckBox
60
- $checkBox.Location = New-Object System.Drawing.Point(40 , $currentY )
61
- $checkBox.Size = New-Object System.Drawing.Size($checkBoxWidth , 20 ) # Adjusted size based on form width
62
- $checkBox.Text = $packageName
63
- $checkBoxes += $checkBox
64
- $form.Controls.Add ($checkBox )
65
69
}
66
70
71
+
72
+
67
73
# Create the "OK" button
68
74
$okButton = New-Object System.Windows.Forms.Button
69
75
$okButton.Location = New-Object System.Drawing.Point([int ](($form.ClientSize.Width - $okButton.Width ) / 2 ), [int ]($currentY + 40 ))
0 commit comments