Skip to content

Commit bcb624b

Browse files
committed
Merge branch 'ui' into dev
2 parents f9b6801 + 57dac1e commit bcb624b

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

Diff for: ui/form.ps1

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
Add-Type -AssemblyName System.Windows.Forms
2+
3+
# Create a new form
4+
$form = New-Object System.Windows.Forms.Form
5+
$form.Text = "Chocolatey Install"
6+
$form.Size = New-Object System.Drawing.Size(300, 400)
7+
$form.FormBorderStyle = 'FixedDialog'
8+
$form.MaximizeBox = $false
9+
10+
# Create a label
11+
$label = New-Object System.Windows.Forms.Label
12+
$label.Location = New-Object System.Drawing.Point(10, 20)
13+
$label.Size = New-Object System.Drawing.Size(280, 20)
14+
$label.Text = "Select packages to install:"
15+
$form.Controls.Add($label)
16+
17+
# Create checkboxes dynamically based on the content of the script
18+
$checkBoxes = @()
19+
$packages = @()
20+
$scriptPath = Join-Path -Path $PSScriptRoot -ChildPath "..\chocolatey_install_all.ps1" # Set the correct relative path to the base script
21+
22+
# Read the content of the base script
23+
$scriptContent = Get-Content -Path $scriptPath
24+
25+
# Parse the content and extract package names
26+
foreach ($line in $scriptContent) {
27+
if ($line -match "choco install ([^\s]+)") {
28+
$packageName = $matches[1]
29+
$packages += $packageName
30+
}
31+
}
32+
33+
for ($i = 0; $i -lt $packages.Count; $i++) {
34+
$checkBox = New-Object System.Windows.Forms.CheckBox
35+
$checkBox.Location = [System.Drawing.Point]::new(20, 50 + $i * 25)
36+
# $checkBox.Size = New-Object System.Drawing.Size(200, 20)
37+
$checkBox.Text = $packages[$i]
38+
$checkBoxes += $checkBox
39+
$form.Controls.Add($checkBox)
40+
}
41+
42+
# Create the "OK" button
43+
$okButton = New-Object System.Windows.Forms.Button
44+
$okButton.Location = New-Object System.Drawing.Point(100, 350)
45+
$okButton.Size = New-Object System.Drawing.Size(75, 23)
46+
$okButton.Text = "OK"
47+
$okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
48+
$form.AcceptButton = $okButton
49+
$form.Controls.Add($okButton)
50+
51+
# Show the form and handle the result
52+
$result = $form.ShowDialog()
53+
54+
# Process the selected checkboxes
55+
if ($result -eq [System.Windows.Forms.DialogResult]::OK) {
56+
$selectedPackages = @()
57+
foreach ($checkBox in $checkBoxes) {
58+
if ($checkBox.Checked) {
59+
$selectedPackages += $checkBox.Text
60+
}
61+
}
62+
63+
# Install selected packages using Chocolatey
64+
foreach ($package in $selectedPackages) {
65+
Write-Host "Installing package: $package"
66+
choco install $package -y
67+
}
68+
}
69+
70+
# Dispose the form
71+
$form.Dispose()

0 commit comments

Comments
 (0)