-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkavasinstaller.ps1
610 lines (536 loc) · 24.2 KB
/
kavasinstaller.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
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
# Load shell32.dll and extract the icon
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
public class Shell32
{
[DllImport("shell32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr ExtractIcon(IntPtr hinst, string lpszExeFileName, int nIconIndex);
}
"@
$appVersion = "1.0"
$translations = @{
"en-US" = @{
"Compression" = "Compression";
"Development" = "Development";
"Documents" = "Documents";
"Imaging" = "Imaging";
"Messaging" = "Messaging";
"Web Browsers" = "Web Browsers";
"File Sharing" = "File Sharing";
"Media" = "Media";
"Gaming" = "Gaming";
"Utilities" = "Utilities";
"Virtualization" = "Virtualization";
"Security" = "Security";
"Dependencices" = "Dependencies";
"Title" = "Kavas Installer $appVersion";
"Install" = "Install";
"Complete" = "Installation Complete";
"NoSelection" = "No applications selected.";
"Waiting" = "Waiting for installation to start...";
"Installing" = "Installing";
"Search" = "Start typing to search";
"wingetNotInstalled" = "winget is not installed. Please install it manually through the Microsoft Store by searching for 'App Installer' or check the documentation for your Windows version for alternative installation methods.";
"Save" = "Save selected apps to JSON file";
"Load" = "Load selected apps from JSON file";
"Import" = "▼ Import";
"Export" = "▲ Export";
}
"tr-TR" = @{
"Compression" = "Sıkıştırma";
"Development" = "Geliştirme";
"Documents" = "Dokümanlar";
"Imaging" = "Görüntüleme";
"Messaging" = "Mesajlaşma";
"Web Browsers" = "Web Tarayıcılar";
"File Sharing" = "Dosya Paylaşımı";
"Media" = "Medya";
"Gaming" = "Oyunlar";
"Utilities" = "Araçlar";
"Virtualization" = "Sanallaştırma";
"Security" = "Güvenlik";
"Dependencies" = "Bağımlılıklar";
"Title" = "Kavas Yükleyici $appVersion";
"Install" = "Yükle";
"Complete" = "Yükleme Tamamlandı";
"NoSelection" = "Hiçbir uygulama seçilmedi.";
"Waiting" = "Yüklemenin başlaması bekleniyor...";
"Installing" = "Yükleniyor";
"Search" = "Aramak için yazmaya başlayın";
"wingetNotInstalled" = "winget yüklü değil. Lütfen 'App Installer' uygulamasını Microsoft Store'dan arayarak manuel olarak yükleyin veya alternatif yükleme yöntemleri için Windows sürümünüzün belgelerine bakın.";
"Save" = "Seçilen uygulamaları JSON'a kaydet";
"Load" = "Seçilen uygulamaları JSON'dan yükle";
"Import" = "▼ İçe Aktar";
"Export" = "▲ Dışa Aktar";
}
}
function Get-LocalizedText {
param (
[string]$key
)
$currentCulture = (Get-Culture).Name
if ($translations.ContainsKey($currentCulture) -and $translations[$currentCulture].ContainsKey($key)) {
return $translations[$currentCulture][$key]
} elseif ($translations["en-US"].ContainsKey($key)) {
# Fallback to English if the current culture is not supported or the key is missing
return $translations["en-US"][$key]
} else {
return "Undefined"
}
}
function Get-Image {
param (
[string]$url
)
$tempFilePath = [System.IO.Path]::GetTempFileName()
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri $url -OutFile $tempFilePath
return $tempFilePath
}
function Save-File($selectedApps) {
# Create a new SaveFileDialog object
$saveFileDialog = New-Object System.Windows.Forms.SaveFileDialog
# Set the properties of the SaveFileDialog
$saveFileDialog.Title = "Save File"
$saveFileDialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
$saveFileDialog.DefaultExt = "txt"
$saveFileDialog.AddExtension = $true
if ($saveFileDialog.ShowDialog() -eq 'OK') {
# Save the selected applications to the file
Write-Output $selectedApps | ConvertTo-Json | Out-File -FilePath $saveFileDialog.FileName
}
}
# Check if winget is available
if (-not(Get-Command winget -ErrorAction SilentlyContinue)) {
Write-Output $(Get-LocalizedText -key 'wingetNotInstalled')
exit
}
# Create a new form
$form = New-Object System.Windows.Forms.Form
$form.Text = Get-LocalizedText -key 'Title'
$form.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen
$form.FormBorderStyle = 'None'
$url = "https://preview.redd.it/w0qg2oanfel51.png?width=1080&crop=smart&auto=webp&s=46e6727910dc87c062f10ea077f2485d70eb428f"
$backgroundImage = $(Get-Image -url $url)
$form.BackgroundImage = [System.Drawing.Image]::FromFile($backgroundImage)
$form.BackgroundImageLayout = 'Stretch'
# Create the close button
$closeButton = New-Object System.Windows.Forms.Button
$closeButton.Text = "x"
$closeButton.ForeColor = 'Gray'
$closeButton.BackColor = 'Red'
$closeButton.Width = 15
$closeButton.Height = 15
$closeButton.Location = New-Object System.Drawing.Point(10, 10)
$closeButton.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat
$closeButton.FlatAppearance.BorderSize = 0
$closeButton.Font = New-Object System.Drawing.Font("Microsoft Sans Serif", 8.25, [System.Drawing.FontStyle]::Bold)
$closeButton.Region = New-Object System.Drawing.Region([System.Drawing.Drawing2D.GraphicsPath]::new())
$closeButton.Region.MakeInfinite()
$closeButton.Region.Exclude([System.Drawing.Rectangle]::new(0, 0, 20, 20))
$closeButton.Region.Exclude([System.Drawing.Rectangle]::new(1, 1, 18, 18))
$path = New-Object System.Drawing.Drawing2D.GraphicsPath
$path.AddEllipse(0, 0, $closeButton.Width, $closeButton.Height)
$closeButton.Region = New-Object System.Drawing.Region($path)
$closeButton.Add_Click({
$form.Close()
})
$form.Controls.Add($closeButton)
# Create the minimize button
$minimizeButton = New-Object System.Windows.Forms.Button
$minimizeButton.Text = "-"
$minimizeButton.ForeColor = 'Gray'
$minimizeButton.BackColor = 'Orange'
$minimizeButton.Width = 15
$minimizeButton.Height = 15
$minimizeButton.Location = New-Object System.Drawing.Point(30, 10)
$minimizeButton.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat
$minimizeButton.FlatAppearance.BorderSize = 0
$minimizeButton.Font = New-Object System.Drawing.Font("Microsoft Sans Serif", 8.25, [System.Drawing.FontStyle]::Bold)
$minimizeButton.Region = New-Object System.Drawing.Region([System.Drawing.Drawing2D.GraphicsPath]::new())
$minimizeButton.Region.MakeInfinite()
$minimizeButton.Region.Exclude([System.Drawing.Rectangle]::new(0, 0, 20, 20))
$minimizeButton.Region.Exclude([System.Drawing.Rectangle]::new(1, 1, 18, 18))
$path = New-Object System.Drawing.Drawing2D.GraphicsPath
$path.AddEllipse(0, 0, $minimizeButton.Width, $minimizeButton.Height)
$minimizeButton.Region = New-Object System.Drawing.Region($path)
$minimizeButton.Add_Click({
$form.WindowState = [System.Windows.Forms.FormWindowState]::Minimized
})
$form.Controls.Add($minimizeButton)
# Create a label for the title
$titleLabel = New-Object System.Windows.Forms.Label
$titleLabel.Text = Get-LocalizedText -key 'Title'
$titleLabel.Location = New-Object System.Drawing.Point(60, 10)
$titleLabel.AutoSize = $true
$titleLabel.BackColor = [System.Drawing.Color]::Transparent
$titleLabel.ForeColor = [System.Drawing.Color]::White
$titleLabel.Font = New-Object System.Drawing.Font($titleLabel.Font, [System.Drawing.FontStyle]::Bold)
$form.Controls.Add($titleLabel)
$apps = @"
[
{
"Name": "Compression",
"Value": [
{ "ID": "7zip.7zip", "Name": "7-Zip" },
{ "ID": "Giorgiotani.Peazip", "Name": "PeaZip" },
{ "ID": "RARLab.WinRAR", "Name": "WinRAR" }
]
},
{
"Name": "Development",
"Value": [
{ "ID": "Notepad++.Notepad++", "Name": "Notepad++" },
{ "ID": "Microsoft.VisualStudioCode", "Name": "Visual Studio Code" },
{ "ID": "Python.Python.3.12", "Name": "Python 3.12" },
{ "ID": "PuTTY.PuTTY", "Name": "PuTTY" },
{ "ID": "WinSCP.WinSCP", "Name": "WinSCP" },
{ "ID": "WinMerge.WinMerge", "Name": "WinMerge" },
{ "ID": "Git.Git", "Name": "Git" }
]
},
{
"Name": "Dependencies",
"Value": [
{ "ID": "abbodi1406.vcredist", "Name": "MS Visual C++ AIO" },
{ "ID": "Microsoft.DirectX", "Name": "DirectX" }
]
},
{
"Name": "Documents",
"Value": [
{ "ID": "Microsoft.Office", "Name": "Office 365" },
{ "ID": "Adobe.Acrobat.Reader.64-bit", "Name": "Adobe Acrobat Reader" },
{ "ID": "Foxit.FoxitReader", "Name": "Foxit PDF Reader" },
{ "ID": "TheDocumentFoundation.LibreOffice", "Name": "LibreOffice" },
{ "ID": "Kingsoft.WPSOffice.CN", "Name": "WPS Office" },
{ "ID": "Apache.OpenOffice", "Name": "OpenOffice" }
]
},
{
"Name": "Imaging",
"Value": [
{ "ID": "IrfanSkiljan.IrfanView", "Name": "IrfanView" },
{ "ID": "dotPDNLLC.paintdotnet", "Name": "Paint.NET" },
{ "ID": "GIMP.GIMP", "Name": "GIMP" },
{ "ID": "BlenderFoundation.Blender", "Name": "Blender" }
]
},
{
"Name": "Messaging",
"Value": [
{ "ID": "Discord.Discord", "Name": "Discord" },
{ "ID": "Microsoft.Skype", "Name": "Skype" },
{ "ID": "Mozilla.Thunderbird", "Name": "Thunderbird" },
{ "ID": "Zoom.Zoom", "Name": "Zoom" },
{ "ID": "9NKSQGP7F2NH", "Name": "WhatsApp" },
{ "ID": "Telegram.TelegramDesktop", "Name": "Telegram" }
]
},
{
"Name": "Web Browsers",
"Value": [
{ "ID": "Ablaze.Floorp", "Name": "Floorp" },
{ "ID": "Brave.Brave", "Name": "Brave" },
{ "ID": "Google.Chrome", "Name": "Google Chrome" },
{ "ID": "Mozilla.Firefox", "Name": "Firefox" },
{ "ID": "Vivaldi.Vivaldi", "Name": "Vivaldi" },
{ "ID": "Opera.Opera", "Name": "Opera" },
{ "ID": "Opera.OperaGX", "Name": "Opera GX" }
]
},
{
"Name": "File Sharing",
"Value": [
{ "ID": "qBittorrent.qBittorrent", "Name": "qBittorrent" },
{ "ID": "Tonec.InternetDownloadManager", "Name": "Internet Download Manager" },
{ "ID": "Transmission.Transmission", "Name": "Transmission" },
{ "ID": "CometNetwork.BitComet", "Name": "BitComet" },
{ "ID": "DelugeTeam.Deluge", "Name": "Deluge" },
{ "ID": "AppWork.JDownloader", "Name": "JDownloader 2" }
]
},
{
"Name": "Media",
"Value": [
{ "ID": "VideoLAN.VLC", "Name": "VLC Media Player" },
{ "ID": "CodecGuide.K-LiteCodecPack.Full", "Name": "K-Lite Codec Pack" },
{ "ID": "GOMLab.GOMPlayer", "Name": "GOM Player" },
{ "ID": "Spotify.Spotify", "Name": "Spotify" }
]
},
{
"Name": "Virtualization",
"Value": [
{ "ID": "Oracle.VirtualBox", "Name": "VirtualBox" },
{ "ID": "VMware.WorkstationPro", "Name": "VMware Workstation" },
{ "ID": "Docker.DockerDesktop", "Name": "Docker Desktop" },
{ "ID": "BlueStack.BlueStacks", "Name": "BlueStacks" }
]
},
{
"Name": "Gaming",
"Value": [
{ "ID": "Valve.Steam", "Name": "Steam" },
{ "ID": "EpicGames.EpicGamesLauncher", "Name": "Epic Games Launcher" },
{ "ID": "Ubisoft.Connect", "Name": "Ubisoft Connect" }
]
},
{
"Name": "Utilities",
"Value": [
{ "ID": "TeamViewer.TeamViewer", "Name": "TeamViewer" },
{ "ID": "CodeSector.TeraCopy", "Name": "TeraCopy" },
{ "ID": "WinDirStat.WinDirStat", "Name": "WinDirStat" },
{ "ID": "Open-Shell.Open-Shell-Menu", "Name": "Open Shell" },
{ "ID": "Piriform.CCleaner", "Name": "CCleaner" },
{ "ID": "AntibodySoftware.WizTree", "Name": "WizTree" },
{ "ID": "Guru3D.Afterburner", "Name": "MSI Afterburner" },
{ "ID": "FxSoundLLC.FxSound", "Name": "FxSound" },
{ "ID": "HiBitSoftware.StartUpManager", "Name": "HiBit StartUp Manager" },
{ "ID": "HiBitSoftware.HiBitUninstaller", "Name": "HiBit Uninstaller" },
{ "ID": "RevoUninstaller.RevoUninstaller", "Name": "Revo Uninstaller" },
{ "ID": "Nilesoft.Shell", "Name": "Nilesoft Shell"}
]
},
{
"Name": "Security",
"Value": [
{ "ID": "9P6PMZTM93LR", "Name": "Microsoft Defender" },
{ "ID": "XPDNZJFNCR1B07", "Name": "Avast Free Antivirus" },
{ "ID": "XP8BX2DWV7TF50", "Name": "AVG AntiVirus Free" },
{ "ID": "Malwarebytes.Malwarebytes", "Name": "Malwarebytes" }
]
}
]
"@
$groupedApplications = $apps | ConvertFrom-Json
$categoryPerColumn = 3
$columnsNeeded = [math]::Floor($groupedApplications.Count / $categoryPerColumn)
$columnWidth = 200 # Define column width
$formWidth = ($columnWidth * $columnsNeeded) # Calculate form width based on columns needed
# Layout variables
$xPos = 10
$yPos = 10
$columnHeight = 0
# Create search box
$searchBox = New-Object System.Windows.Forms.TextBox
$searchBoxXPos = $formWidth
$searchBox.Location = New-Object System.Drawing.Point($searchBoxXPos, $yPos)
$searchBox.Size = New-Object System.Drawing.Size(180, 20)
#searchbox placeholder text
$searchBox.Text = Get-LocalizedText -key 'Search'
$searchBox.Add_TextChanged({
$searchText = $searchBox.Text.ToLower()
# if search text is empty, reset the font to regular
if ($searchText -eq "") {
foreach ($checkbox in $checkboxes) {
# if font is already regular, skip
if ($checkbox.Font.Bold -eq $false) {
continue
}
$checkbox.Font = New-Object System.Drawing.Font($checkbox.Font, [System.Drawing.FontStyle]::Regular)
}
} else {
# Check if the checkbox text contains the search text, if so, make the font bold
foreach ($checkbox in $checkboxes) {
if ($checkbox.Text.ToLower().Contains($searchText)) {
$checkbox.Font = New-Object System.Drawing.Font($checkbox.Font, [System.Drawing.FontStyle]::Bold)
} else {
$checkbox.Font = New-Object System.Drawing.Font($checkbox.Font, [System.Drawing.FontStyle]::Regular)
}
}
}
})
$form.Controls.Add($searchBox)
$yPos += 60
# Create UI elements grouped by category and adjust for columns
$idx = 1
$checkboxes = @()
foreach ($group in $groupedApplications) {
# Add category icon
$image = Get-Image -url "https://raw.githubusercontent.com/emircankavas/kavasinstaller/main/icons/categories/$($group.Name).png"
$icon = [System.Drawing.Image]::FromFile($image)
$pictureBox = new-object Windows.Forms.PictureBox
$pictureBox.Location = New-Object System.Drawing.Size(($xPos + 5), $yPos)
$pictureBox.Size = New-Object System.Drawing.Size(20,20)
$pictureBox.SizeMode = [System.Windows.Forms.PictureBoxSizeMode]::StretchImage
$pictureBox.Image = $icon
$pictureBox.BackColor = [System.Drawing.Color]::Transparent
$Form.controls.add($pictureBox)
# Create a label for the category
$label = New-Object System.Windows.Forms.Label
$label.Text = Get-LocalizedText -key $group.Name
$label.Location = New-Object System.Drawing.Point(($xPos + 25), $yPos)
$label.AutoSize = $true
$label.BackColor = [System.Drawing.Color]::Transparent
$label.ForeColor = [System.Drawing.Color]::White
$label.Font = New-Object System.Drawing.Font($label.Font, [System.Drawing.FontStyle]::Bold)
$form.Controls.Add($label)
$yPos += 25
# Create a checkbox for each application in the category
foreach ($app in $group.Value) {
$checkbox = New-Object System.Windows.Forms.CheckBox
$checkbox.Text = $app.Name
$checkbox.Tag = $app.ID # Use the Tag property to store the application ID
$checkboxLoc = $xPos + 10
$checkbox.Location = New-Object System.Drawing.Point($checkboxLoc, $yPos) # Indent checkboxes for visual grouping
$checkbox.AutoSize = $true
$checkbox.BackColor = [System.Drawing.Color]::Transparent
$checkbox.ForeColor = [System.Drawing.Color]::White
$form.Controls.Add($checkbox)
$yPos += 20
$checkboxes += $checkbox
}
$yPos += 10 # Add some space before the next category
$columnHeight = [math]::Max($columnHeight, $yPos) # Track max column height
# Increment column index after every second category
# Reset yPos for each new column, and adjust xPos based on columnIndex
if (($idx % $categoryPerColumn) -eq 0) {
$xPos += $columnWidth
$yPos = 70
}
$idx++
}
# Adjust yPos for the progress bar and install button based on the tallest column
$yPos = $columnHeight + 10
# Initialize and place the progress bar at the bottom, spanning across all columns
$progressBar = New-Object System.Windows.Forms.ProgressBar
$progressBar.Location = New-Object System.Drawing.Point(10, $yPos)
$progressBar.Style = 'Continuous'
$progressBar.Minimum = 0
$progressBar.Maximum = 100
$progressBar.Value = 0
$progressBar.Step = 1
$progressBarSize = $formWidth + 165
$progressBar.Size = New-Object System.Drawing.Size($progressBarSize, 10) # Span across the form width
$form.Controls.Add($progressBar)
# Initialize and place the label for current installing program above the progress bar
$installingLabel = New-Object System.Windows.Forms.Label
$installingLabelLocation = $yPos + 25
$installingLabel.Location = New-Object System.Drawing.Point(10, $installingLabelLocation) # Position above the progress bar
$installingLabel.Size = New-Object System.Drawing.Size($progressBarSize, 20) # Same width as the progress bar for alignment
$installingLabel.Text = Get-LocalizedText -key 'Waiting'
$installingLabel.BackColor = [System.Drawing.Color]::Transparent
$installingLabel.ForeColor = [System.Drawing.Color]::White
$form.Controls.Add($installingLabel)
# Update yPos for the progress bar based on the new label, adding space
$yPos += 20 # Adjust if needed based on actual layout
# Update yPos for the install button, adding space after the progress bar
$yPos += 50
# Initialize and center the install button below the progress bar
$buttonInstall = New-Object System.Windows.Forms.Button
$buttonInstall.Text = Get-LocalizedText -key 'Install'
$buttonInstallLocation = ($formWidth + 100) / 2 # Center the button
$buttonInstall.Location = New-Object System.Drawing.Point($buttonInstallLocation, $yPos) # Center the button
$buttonInstall.Size = New-Object System.Drawing.Size(100, 50)
$icon = [System.Drawing.Icon]::ExtractAssociatedIcon([System.Environment]::GetFolderPath('System') + '\msiexec.exe')
$buttonInstall.Image = $icon.ToBitmap()
$buttonInstall.BackColor = [System.Drawing.Color]::Transparent
$buttonInstall.TextAlign = 'MiddleRight'
$buttonInstall.TextImageRelation = 'ImageBeforeText'
$buttonInstall.ForeColor = [System.Drawing.Color]::White
$buttonInstall.Font = New-Object System.Drawing.Font($buttonInstall.Font, [System.Drawing.FontStyle]::Bold)
$form.Controls.Add($buttonInstall)
# Add an event handler for the install button click
$buttonInstall.Add_Click({
$buttonInstall.Enabled = $false
# Initialize an array to hold selected applications
$selectedApps = @()
# Iterate through the form's controls to find checked checkboxes
$form.Controls | Where-Object { $_ -is [System.Windows.Forms.CheckBox] -and $_.Checked } | ForEach-Object {
# Add each selected application to the array
$selectedApp = @{ID = $_.Tag; Name = $_.Text}
$selectedApps += $selectedApp
}
# Check if any applications were selected
if ($selectedApps.Count -gt 0) {
$progressBar.Value = 0
$progressBar.Maximum = $selectedApps.Count
foreach ($app in $selectedApps) {
# Update label with the current installing application's name
$installingLabel.Text = "[$($ProgressBar.Value + 1)/$($selectedApps.Count)] $(Get-LocalizedText -key 'Installing'): $($app.Name)"
winget.exe install $app.ID --accept-package-agreements
$progressBar.PerformStep()
}
[System.Windows.Forms.MessageBox]::Show((Get-LocalizedText -key "Complete"))
$installingLabel.Text = Get-LocalizedText -key "Complete"
} else {
[System.Windows.Forms.MessageBox]::Show((Get-LocalizedText -key "NoSelection"))
}
$buttonInstall.Enabled = $true
})
$form.Controls.Add($buttonInstall)
# Add button which named "Load selected apps". It will load selected apps from a file.
$buttonLoad = New-Object System.Windows.Forms.Button
# Set button text
$buttonLoad.Text = Get-LocalizedText -key 'Import'
# transparent background and no border
$buttonLoad.BackColor = [System.Drawing.Color]::Transparent
$buttonLoad.ForeColor = [System.Drawing.Color]::White
$buttonLoad.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat
$buttonLoad.FlatAppearance.BorderSize = 0
# Locate button to right of the search box
$buttonLoadXPos = $searchBoxXPos + 30
$buttonLoad.Location = New-Object System.Drawing.Point($buttonLoadXPos, ($yPos + 30))
$buttonLoad.Size = New-Object System.Drawing.Size(75, 24)
# Create the ToolTip
$toolTip = New-Object System.Windows.Forms.ToolTip
# Set up the delay for the tooltip (optional)
$toolTip.InitialDelay = 500
$toolTip.ReshowDelay = 100
# Set the tooltip text for the button
$toolTip.SetToolTip($buttonLoad, $(Get-LocalizedText -key 'Load'))
$buttonLoad.Add_Click({
$openFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$openFileDialog.Title = "Open File"
$openFileDialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
$openFileDialog.DefaultExt = "txt"
$openFileDialog.AddExtension = $true
if ($openFileDialog.ShowDialog() -eq 'OK') {
$selectedApps = Get-Content -Path $openFileDialog.FileName | ConvertFrom-Json
foreach ($app in $selectedApps) {
$form.Controls | Where-Object { $_ -is [System.Windows.Forms.CheckBox] -and $_.Tag -eq $app.ID } | ForEach-Object {
$_.Checked = $true
}
}
}
})
$form.Controls.Add($buttonLoad)
# Add button which named "Save selected apps". It will save selected apps to a file.
$buttonSave = New-Object System.Windows.Forms.Button
# Set button text
$buttonSave.Text = Get-LocalizedText -key 'Export'
# Locate button to the right of load button
$buttonSaveLocation = $buttonLoadXPos + 70
$buttonSave.Location = New-Object System.Drawing.Point($buttonSaveLocation, ($yPos + 30))
$buttonSave.Size = New-Object System.Drawing.Size(90, 24)
# transparent background and no border
$buttonSave.BackColor = [System.Drawing.Color]::Transparent
$buttonSave.ForeColor = [System.Drawing.Color]::White
$buttonSave.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat
$buttonSave.FlatAppearance.BorderSize = 0
# Create the ToolTip
$toolTip = New-Object System.Windows.Forms.ToolTip
# Set up the delay for the tooltip (optional)
$toolTip.InitialDelay = 500
$toolTip.ReshowDelay = 100
# Set the tooltip text for the button
$toolTip.SetToolTip($buttonSave, $(Get-LocalizedText -key 'Save'))
$buttonSave.Add_Click({
$selectedApps = @()
$form.Controls | Where-Object { $_ -is [System.Windows.Forms.CheckBox] -and $_.Checked } | ForEach-Object {
$selectedApp = @{ID = $_.Tag; Name = $_.Text}
$selectedApps += $selectedApp
}
Write-Output $selectedApps
Save-File -selectedApps $selectedApps
})
$form.Controls.Add($buttonSave)
# Add button which named "Recommended". It will select recommended apps.
$form.Width = $formWidth + 200
$form.Height = $yPos + 70
$form.ShowDialog() | Out-Null