-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunUninstallWizard.ps1
More file actions
831 lines (696 loc) · 29.4 KB
/
Copy pathrunUninstallWizard.ps1
File metadata and controls
831 lines (696 loc) · 29.4 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
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
#Requires -Version 5.1
<#
.SYNOPSIS
Graphical uninstall wizard for Data Entry Autonoma.
.DESCRIPTION
Removes installed application files, optional user data, apply-state.ini,
and Desktop / Start Menu shortcuts from a chosen install folder.
Run from the project root, release zip, or install folder:
.\runUninstallWizard.ps1
#>
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$ErrorActionPreference = "Stop"
# =============================================================================
# Constants
# =============================================================================
$APP_DISPLAY_NAME = "Data Entry Autonoma"
$APP_FOLDER_NAME = "DataEntryAutonoma"
$EXE_FILE_NAME = "DataEntryAutonoma.exe"
$SHORTCUT_FILE_NAME = "$APP_DISPLAY_NAME.lnk"
$LICENSE_FILE_NAME = "LICENSE"
$README_FILE_NAME = "README.md"
$CHANGELOG_FILE_NAME = "CHANGELOG.md"
$VERSION_FILE_NAME = "VERSION"
$INSTALL_WIZARD_PS1 = "runInstallWizard.ps1"
$INSTALL_WIZARD_BAT = "runInstallWizard.bat"
$APP_VERSION_FALLBACK = "1.3.0"
$APPLY_STATE_FILE_NAME = "apply-state.ini"
$RECORDINGS_FOLDER_NAME = "recordings"
$SAVED_INPUTS_FOLDER_NAME = "saved-inputs"
$CSV_BATCHES_FOLDER_NAME = "csv-batches"
$ASSETS_FOLDER_NAME = "assets"
$UNINSTALL_SCRIPT_NAME = "runUninstallWizard.ps1"
$UNINSTALL_BATCH_NAME = "runUninstallWizard.bat"
$DEFAULT_INSTALL_DIR = Join-Path (Join-Path $env:LOCALAPPDATA "Programs") $APP_FOLDER_NAME
$WIZARD_WIDTH = 520
$WIZARD_HEIGHT = 480
$CONTENT_WIDTH = 460
$COLOR_BG = [System.Drawing.Color]::FromArgb(248, 249, 250)
$COLOR_TEXT = [System.Drawing.Color]::FromArgb(26, 26, 26)
$COLOR_MUTED = [System.Drawing.Color]::FromArgb(107, 114, 128)
$COLOR_SUCCESS = [System.Drawing.Color]::FromArgb(6, 95, 70)
$COLOR_ERROR = [System.Drawing.Color]::FromArgb(185, 28, 28)
$COLOR_WARNING = [System.Drawing.Color]::FromArgb(180, 83, 9)
$SCRIPT_ROOT = $PSScriptRoot
# =============================================================================
# Uninstall helpers
# =============================================================================
# Returns true when the install folder contains the application exe.
function Test-InstallFolderValid {
param([string]$InstallDir)
if (-not $InstallDir) {
return $false
}
if (-not (Test-Path $InstallDir)) {
return $false
}
$exePath = Join-Path $InstallDir $EXE_FILE_NAME
return Test-Path $exePath
}
# Returns true when this wizard is running from inside the install folder.
function Test-RunningFromInstallDir {
param([string]$InstallDir)
$scriptRoot = $SCRIPT_ROOT.TrimEnd('\')
$installRoot = $InstallDir.TrimEnd('\')
return ($scriptRoot -eq $installRoot)
}
# Returns the installed app version from VERSION in the install folder.
function Get-InstalledVersion {
param([string]$InstallDir)
if (-not $InstallDir) {
return ""
}
$versionPath = Join-Path $InstallDir $VERSION_FILE_NAME
if (Test-Path $versionPath) {
return (Get-Content -LiteralPath $versionPath -Raw).Trim()
}
return ""
}
# Returns VERSION from the wizard script folder when not running from an install dir.
function Get-LocalWizardVersion {
$versionPath = Join-Path $SCRIPT_ROOT $VERSION_FILE_NAME
if (Test-Path $versionPath) {
return (Get-Content -LiteralPath $versionPath -Raw).Trim()
}
return $APP_VERSION_FALLBACK
}
# Returns the uninstall wizard window title with the active version label.
function Get-UninstallWizardFormTitle {
param([string]$Version = $script:WizardAppVersion)
if ($Version) {
return "$APP_DISPLAY_NAME Uninstall v$Version"
}
return "$APP_DISPLAY_NAME Uninstall"
}
# Updates the uninstall wizard form title from the current version label.
function Update-UninstallWizardFormTitle {
param([string]$Version = $script:WizardAppVersion)
if ($form) {
$form.Text = Get-UninstallWizardFormTitle -Version $Version
}
}
# Removes a file or folder when it exists.
function Remove-IfExists {
param([string]$Path)
if (-not (Test-Path $Path)) {
return
}
Remove-Item -LiteralPath $Path -Recurse -Force
}
# Removes Desktop and/or Start Menu shortcuts for the app.
function Remove-InstallShortcuts {
param(
[bool]$RemoveDesktopShortcut,
[bool]$RemoveStartMenuShortcut
)
if ($RemoveDesktopShortcut) {
Remove-IfExists (Join-Path ([Environment]::GetFolderPath("Desktop")) $SHORTCUT_FILE_NAME)
}
if ($RemoveStartMenuShortcut) {
$programsDir = Join-Path $env:APPDATA "Microsoft\Windows\Start Menu\Programs"
Remove-IfExists (Join-Path $programsDir $SHORTCUT_FILE_NAME)
}
}
# Schedules deletion of uninstaller scripts and optionally the install folder after this wizard exits.
function Schedule-PostUninstallCleanup {
param(
[string]$InstallDir,
[bool]$RemoveEntireFolder
)
$uninstallScriptPath = Join-Path $InstallDir $UNINSTALL_SCRIPT_NAME
$uninstallBatchPath = Join-Path $InstallDir $UNINSTALL_BATCH_NAME
$cleanupBatchPath = Join-Path $env:TEMP ("DataEntryAutonoma_cleanup_{0}.bat" -f ([guid]::NewGuid().ToString("N")))
if ($RemoveEntireFolder) {
$batchContent = @"
@echo off
ping 127.0.0.1 -n 3 > nul
rd /s /q "$InstallDir"
del /f /q "%~f0"
"@
} else {
$batchContent = @"
@echo off
ping 127.0.0.1 -n 3 > nul
del /f /q "$uninstallScriptPath" 2>nul
del /f /q "$uninstallBatchPath" 2>nul
del /f /q "%~f0"
"@
}
Set-Content -LiteralPath $cleanupBatchPath -Value $batchContent -Encoding ASCII
Start-Process -FilePath $cleanupBatchPath -WindowStyle Hidden
}
# Performs the selected uninstall actions.
function Invoke-UninstallApplication {
param(
[string]$InstallDir,
[bool]$RemoveAppFiles,
[bool]$RemoveUserData,
[bool]$RemoveApplyState,
[bool]$RemoveDesktopShortcut,
[bool]$RemoveStartMenuShortcut
)
$runningFromInstallDir = Test-RunningFromInstallDir -InstallDir $InstallDir
$removedItems = New-Object System.Collections.Generic.List[string]
Remove-InstallShortcuts `
-RemoveDesktopShortcut $RemoveDesktopShortcut `
-RemoveStartMenuShortcut $RemoveStartMenuShortcut
if ($RemoveDesktopShortcut) {
$removedItems.Add("Desktop shortcut") | Out-Null
}
if ($RemoveStartMenuShortcut) {
$removedItems.Add("Start Menu shortcut") | Out-Null
}
if ($RemoveApplyState) {
$applyStatePath = Join-Path $InstallDir $APPLY_STATE_FILE_NAME
if (Test-Path $applyStatePath) {
Remove-IfExists $applyStatePath
$removedItems.Add($APPLY_STATE_FILE_NAME) | Out-Null
}
}
if ($RemoveUserData) {
$recordingsPath = Join-Path $InstallDir $RECORDINGS_FOLDER_NAME
$savedInputsPath = Join-Path $InstallDir $SAVED_INPUTS_FOLDER_NAME
$csvBatchesPath = Join-Path $InstallDir $CSV_BATCHES_FOLDER_NAME
if (Test-Path $recordingsPath) {
Remove-IfExists $recordingsPath
$removedItems.Add("$RECORDINGS_FOLDER_NAME\ folder") | Out-Null
}
if (Test-Path $savedInputsPath) {
Remove-IfExists $savedInputsPath
$removedItems.Add("$SAVED_INPUTS_FOLDER_NAME\ folder") | Out-Null
}
if (Test-Path $csvBatchesPath) {
Remove-IfExists $csvBatchesPath
$removedItems.Add("$CSV_BATCHES_FOLDER_NAME\ folder") | Out-Null
}
}
if ($RemoveAppFiles) {
$appPaths = @(
(Join-Path $InstallDir $EXE_FILE_NAME),
(Join-Path $InstallDir $LICENSE_FILE_NAME),
(Join-Path $InstallDir $README_FILE_NAME),
(Join-Path $InstallDir $CHANGELOG_FILE_NAME),
(Join-Path $InstallDir $VERSION_FILE_NAME),
(Join-Path $InstallDir $INSTALL_WIZARD_PS1),
(Join-Path $InstallDir $INSTALL_WIZARD_BAT),
(Join-Path $InstallDir $ASSETS_FOLDER_NAME)
)
foreach ($path in $appPaths) {
if (Test-Path $path) {
Remove-IfExists $path
}
}
$removedItems.Add("Application files ($EXE_FILE_NAME, docs, wizards, $ASSETS_FOLDER_NAME\)") | Out-Null
if ($runningFromInstallDir) {
$remainingItems = @(Get-ChildItem -LiteralPath $InstallDir -Force -ErrorAction SilentlyContinue | Where-Object {
$_.Name -ne $UNINSTALL_SCRIPT_NAME -and $_.Name -ne $UNINSTALL_BATCH_NAME
})
$removeEntireFolder = ($remainingItems.Count -eq 0)
Schedule-PostUninstallCleanup -InstallDir $InstallDir -RemoveEntireFolder $removeEntireFolder
if ($removeEntireFolder) {
$removedItems.Add("Remaining install folder (scheduled after wizard closes)") | Out-Null
} else {
$removedItems.Add("Uninstaller scripts (scheduled after wizard closes)") | Out-Null
}
} else {
Remove-IfExists (Join-Path $InstallDir $UNINSTALL_SCRIPT_NAME)
Remove-IfExists (Join-Path $InstallDir $UNINSTALL_BATCH_NAME)
$remainingItems = @(Get-ChildItem -LiteralPath $InstallDir -Force -ErrorAction SilentlyContinue)
if ($remainingItems.Count -eq 0) {
Remove-IfExists $InstallDir
$removedItems.Add("Install folder") | Out-Null
}
}
}
return $removedItems
}
# Builds a summary string for the confirmation step.
function Get-UninstallSummaryText {
param(
[string]$InstallDir,
[bool]$RemoveAppFiles,
[bool]$RemoveUserData,
[bool]$RemoveApplyState,
[bool]$RemoveDesktopShortcut,
[bool]$RemoveStartMenuShortcut
)
$installedVersion = Get-InstalledVersion -InstallDir $InstallDir
$lines = New-Object System.Collections.Generic.List[string]
if ($installedVersion) {
$lines.Add("Installed version: v$installedVersion") | Out-Null
$lines.Add("") | Out-Null
}
$lines.Add("Install folder:") | Out-Null
$lines.Add($InstallDir) | Out-Null
$lines.Add("") | Out-Null
$lines.Add("The following will be removed:") | Out-Null
if ($RemoveAppFiles) {
$lines.Add(" - Application files ($EXE_FILE_NAME, $VERSION_FILE_NAME, $CHANGELOG_FILE_NAME, wizards, $ASSETS_FOLDER_NAME\)") | Out-Null
}
if ($RemoveUserData) {
$lines.Add(" - User data ($RECORDINGS_FOLDER_NAME\, $SAVED_INPUTS_FOLDER_NAME\, and $CSV_BATCHES_FOLDER_NAME\)") | Out-Null
}
if ($RemoveApplyState) {
$lines.Add(" - $APPLY_STATE_FILE_NAME") | Out-Null
}
if ($RemoveDesktopShortcut) {
$lines.Add(" - Desktop shortcut") | Out-Null
}
if ($RemoveStartMenuShortcut) {
$lines.Add(" - Start Menu shortcut") | Out-Null
}
$selectedCount = 0
if ($RemoveAppFiles) { $selectedCount++ }
if ($RemoveUserData) { $selectedCount++ }
if ($RemoveApplyState) { $selectedCount++ }
if ($RemoveDesktopShortcut) { $selectedCount++ }
if ($RemoveStartMenuShortcut) { $selectedCount++ }
if ($selectedCount -eq 0) {
$lines.Add(" - Nothing selected") | Out-Null
}
if (Test-RunningFromInstallDir -InstallDir $InstallDir) {
$lines.Add("") | Out-Null
$lines.Add("Note: The uninstaller is running from the install folder.") | Out-Null
$lines.Add("Any remaining files will be deleted after this wizard closes.") | Out-Null
}
return ($lines -join "`r`n")
}
# =============================================================================
# Wizard UI
# =============================================================================
[System.Windows.Forms.Application]::EnableVisualStyles()
[System.Windows.Forms.Application]::SetUnhandledExceptionMode([System.Windows.Forms.UnhandledExceptionMode]::CatchException)
[System.Windows.Forms.Application]::add_ThreadException({
param($sender, $eventArgs)
[System.Windows.Forms.MessageBox]::Show(
"Uninstall error:`r`n$($eventArgs.Exception.Message)",
$APP_DISPLAY_NAME,
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Error
) | Out-Null
$eventArgs.ExceptionHandled = $true
})
$script:CurrentStep = 0
$script:InstallDir = $DEFAULT_INSTALL_DIR
$script:WizardAppVersion = Get-InstalledVersion -InstallDir $DEFAULT_INSTALL_DIR
if (-not $script:WizardAppVersion) {
$script:WizardAppVersion = Get-LocalWizardVersion
}
$script:RemoveAppFiles = $true
$script:RemoveUserData = $true
$script:RemoveApplyState = $true
$script:RemoveDesktopShortcut = $true
$script:RemoveStartMenuShortcut = $true
$script:LastUninstallResult = $null
$script:Step4_Failed = $false
$form = New-Object System.Windows.Forms.Form
$form.Text = Get-UninstallWizardFormTitle -Version $script:WizardAppVersion
$form.ClientSize = New-Object System.Drawing.Size($WIZARD_WIDTH, $WIZARD_HEIGHT)
$form.FormBorderStyle = "FixedDialog"
$form.MaximizeBox = $false
$form.MinimizeBox = $false
$form.StartPosition = "CenterScreen"
$form.BackColor = $COLOR_BG
$form.Font = New-Object System.Drawing.Font("Segoe UI", 10)
$contentPanel = New-Object System.Windows.Forms.Panel
$contentPanel.Location = New-Object System.Drawing.Point(30, 20)
$contentPanel.Size = New-Object System.Drawing.Size($CONTENT_WIDTH, 320)
$contentPanel.BackColor = $COLOR_BG
$form.Controls.Add($contentPanel)
$btnBack = New-Object System.Windows.Forms.Button
$btnBack.Text = "< Back"
$btnBack.Size = New-Object System.Drawing.Size(90, 32)
$btnBack.Location = New-Object System.Drawing.Point(230, 370)
$form.Controls.Add($btnBack)
$btnNext = New-Object System.Windows.Forms.Button
$btnNext.Text = "Next >"
$btnNext.Size = New-Object System.Drawing.Size(90, 32)
$btnNext.Location = New-Object System.Drawing.Point(330, 370)
$form.Controls.Add($btnNext)
$btnCancel = New-Object System.Windows.Forms.Button
$btnCancel.Text = "Cancel"
$btnCancel.Size = New-Object System.Drawing.Size(90, 32)
$btnCancel.Location = New-Object System.Drawing.Point(420, 370)
$form.Controls.Add($btnCancel)
function Clear-ContentPanel {
$contentPanel.Controls.Clear()
}
function New-TitleLabel {
param([string]$Text)
$label = New-Object System.Windows.Forms.Label
$label.Text = $Text
$label.AutoSize = $false
$label.Size = New-Object System.Drawing.Size($CONTENT_WIDTH, 32)
$label.Font = New-Object System.Drawing.Font("Segoe UI", 14, [System.Drawing.FontStyle]::Bold)
$label.ForeColor = $COLOR_TEXT
return $label
}
function New-BodyLabel {
param(
[string]$Text,
[int]$Height = 120
)
$label = New-Object System.Windows.Forms.Label
$label.Text = $Text
$label.AutoSize = $false
$label.Size = New-Object System.Drawing.Size($CONTENT_WIDTH, $Height)
$label.ForeColor = $COLOR_MUTED
return $label
}
function Show-WizardStep {
Clear-ContentPanel
switch ($script:CurrentStep) {
0 {
$btnBack.Enabled = $false
$btnNext.Text = "Next >"
$btnCancel.Enabled = $true
$title = New-TitleLabel "Welcome"
$title.Location = New-Object System.Drawing.Point(0, 0)
$contentPanel.Controls.Add($title)
$welcomeText = @"
This wizard removes $APP_DISPLAY_NAME from your computer.
You can choose which files, user data, and shortcuts to remove. Recordings, saved presets, and CSV bulk inputs in csv-batches can be deleted permanently if you select that option.
"@
if ($script:WizardAppVersion) {
$welcomeText += "`r`n`r`nInstalled version: v$($script:WizardAppVersion)"
}
$welcomeText += "`r`n`r`nReinstall later with runInstallWizard.bat from a release zip.`r`n`r`nClick Next to choose the install folder and select what to remove."
$body = New-BodyLabel $welcomeText $(if ($script:WizardAppVersion) { 260 } else { 240 })
$body.Location = New-Object System.Drawing.Point(0, 44)
$contentPanel.Controls.Add($body)
}
1 {
$btnBack.Enabled = $true
$btnNext.Text = "Next >"
$btnCancel.Enabled = $true
$title = New-TitleLabel "Install location"
$title.Location = New-Object System.Drawing.Point(0, 0)
$contentPanel.Controls.Add($title)
$body = New-BodyLabel "Choose the folder where $APP_DISPLAY_NAME is installed." 40
$body.Location = New-Object System.Drawing.Point(0, 44)
$contentPanel.Controls.Add($body)
$pathBox = New-Object System.Windows.Forms.TextBox
$pathBox.Text = $script:InstallDir
$pathBox.Size = New-Object System.Drawing.Size(350, 28)
$pathBox.Location = New-Object System.Drawing.Point(0, 92)
$contentPanel.Controls.Add($pathBox)
$btnBrowse = New-Object System.Windows.Forms.Button
$btnBrowse.Text = "Browse..."
$btnBrowse.Size = New-Object System.Drawing.Size(90, 28)
$btnBrowse.Location = New-Object System.Drawing.Point(360, 90)
$contentPanel.Controls.Add($btnBrowse)
$hint = New-BodyLabel "Default location: $DEFAULT_INSTALL_DIR`r`nThe folder must contain $EXE_FILE_NAME." 72
$hint.Location = New-Object System.Drawing.Point(0, 130)
$contentPanel.Controls.Add($hint)
$btnBrowse.Add_Click({
$dialog = New-Object System.Windows.Forms.FolderBrowserDialog
$dialog.Description = "Select install folder"
if (Test-Path $pathBox.Text) {
$dialog.SelectedPath = $pathBox.Text
} else {
$dialog.SelectedPath = $DEFAULT_INSTALL_DIR
}
if ($dialog.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) {
$pathBox.Text = $dialog.SelectedPath
}
})
$script:Step1_PathBox = $pathBox
}
2 {
$btnBack.Enabled = $true
$btnNext.Text = "Next >"
$btnCancel.Enabled = $true
$title = New-TitleLabel "Removal options"
$title.Location = New-Object System.Drawing.Point(0, 0)
$contentPanel.Controls.Add($title)
$chkAppFiles = New-Object System.Windows.Forms.CheckBox
$chkAppFiles.Text = "Remove application files ($EXE_FILE_NAME, $VERSION_FILE_NAME, $CHANGELOG_FILE_NAME, wizards, $ASSETS_FOLDER_NAME\)"
$chkAppFiles.AutoSize = $true
$chkAppFiles.Location = New-Object System.Drawing.Point(0, 44)
$chkAppFiles.Checked = $script:RemoveAppFiles
$contentPanel.Controls.Add($chkAppFiles)
$chkUserData = New-Object System.Windows.Forms.CheckBox
$chkUserData.Text = "Remove recordings, saved presets, and CSV bulk inputs (deletes your user data permanently)"
$chkUserData.AutoSize = $true
$chkUserData.Location = New-Object System.Drawing.Point(0, 74)
$chkUserData.Checked = $script:RemoveUserData
$contentPanel.Controls.Add($chkUserData)
$chkApplyState = New-Object System.Windows.Forms.CheckBox
$chkApplyState.Text = "Remove $APPLY_STATE_FILE_NAME (last selected recording, preset, and CSV)"
$chkApplyState.AutoSize = $true
$chkApplyState.Location = New-Object System.Drawing.Point(0, 104)
$chkApplyState.Checked = $script:RemoveApplyState
$contentPanel.Controls.Add($chkApplyState)
$chkDesktop = New-Object System.Windows.Forms.CheckBox
$chkDesktop.Text = "Remove Desktop shortcut"
$chkDesktop.AutoSize = $true
$chkDesktop.Location = New-Object System.Drawing.Point(0, 134)
$chkDesktop.Checked = $script:RemoveDesktopShortcut
$contentPanel.Controls.Add($chkDesktop)
$chkStart = New-Object System.Windows.Forms.CheckBox
$chkStart.Text = "Remove Start Menu shortcut"
$chkStart.AutoSize = $true
$chkStart.Location = New-Object System.Drawing.Point(0, 164)
$chkStart.Checked = $script:RemoveStartMenuShortcut
$contentPanel.Controls.Add($chkStart)
$warn = New-BodyLabel "Warning: Removing recordings, presets, and CSV files cannot be undone. You will be asked to confirm on the next step." 56
$warn.ForeColor = $COLOR_WARNING
$warn.Location = New-Object System.Drawing.Point(0, 200)
$contentPanel.Controls.Add($warn)
$script:Step2_AppFiles = $chkAppFiles
$script:Step2_UserData = $chkUserData
$script:Step2_ApplyState = $chkApplyState
$script:Step2_Desktop = $chkDesktop
$script:Step2_Start = $chkStart
}
3 {
$btnBack.Enabled = $true
$btnNext.Text = "Uninstall"
$btnCancel.Enabled = $true
$title = New-TitleLabel "Confirm removal"
$title.Location = New-Object System.Drawing.Point(0, 0)
$contentPanel.Controls.Add($title)
$summaryText = Get-UninstallSummaryText `
-InstallDir $script:InstallDir `
-RemoveAppFiles $script:RemoveAppFiles `
-RemoveUserData $script:RemoveUserData `
-RemoveApplyState $script:RemoveApplyState `
-RemoveDesktopShortcut $script:RemoveDesktopShortcut `
-RemoveStartMenuShortcut $script:RemoveStartMenuShortcut
$summary = New-BodyLabel $summaryText 250
$summary.Location = New-Object System.Drawing.Point(0, 44)
$contentPanel.Controls.Add($summary)
}
4 {
$btnBack.Enabled = $false
$btnNext.Text = "Finish"
$btnCancel.Enabled = $false
$title = New-TitleLabel "Removing"
$title.Location = New-Object System.Drawing.Point(0, 0)
$contentPanel.Controls.Add($title)
$progress = New-Object System.Windows.Forms.ProgressBar
$progress.Style = "Marquee"
$progress.MarqueeAnimationSpeed = 30
$progress.Size = New-Object System.Drawing.Size($CONTENT_WIDTH, 24)
$progress.Location = New-Object System.Drawing.Point(0, 56)
$contentPanel.Controls.Add($progress)
$status = New-BodyLabel "Removing selected items..." 180
$status.Location = New-Object System.Drawing.Point(0, 92)
$contentPanel.Controls.Add($status)
try {
[System.Windows.Forms.Application]::DoEvents()
$script:LastUninstallResult = Invoke-UninstallApplication `
-InstallDir $script:InstallDir `
-RemoveAppFiles $script:RemoveAppFiles `
-RemoveUserData $script:RemoveUserData `
-RemoveApplyState $script:RemoveApplyState `
-RemoveDesktopShortcut $script:RemoveDesktopShortcut `
-RemoveStartMenuShortcut $script:RemoveStartMenuShortcut
$progress.Style = "Continuous"
$progress.Value = 100
$status.ForeColor = $COLOR_SUCCESS
$resultLines = @("Uninstall completed successfully.", "", "Removed:")
foreach ($item in $script:LastUninstallResult) {
$resultLines += " - $item"
}
if ($script:LastUninstallResult.Count -eq 0) {
$resultLines += " - No matching files or shortcuts were found."
}
if (Test-RunningFromInstallDir -InstallDir $script:InstallDir -and $script:RemoveAppFiles) {
$resultLines += ""
$resultLines += "Remaining install files will be removed shortly after you close this wizard."
}
$status.Text = ($resultLines -join "`r`n")
} catch {
$progress.Style = "Continuous"
$progress.Value = 0
$status.ForeColor = $COLOR_ERROR
$status.Text = "Uninstall failed:`r`n$($_.Exception.Message)"
$script:Step4_Failed = $true
$btnNext.Text = "Close"
}
}
5 {
$btnBack.Enabled = $false
$btnNext.Text = "Close"
$btnCancel.Enabled = $false
$title = New-TitleLabel "Uninstall complete"
$title.Location = New-Object System.Drawing.Point(0, 0)
$contentPanel.Controls.Add($title)
$bodyText = @"
$APP_DISPLAY_NAME has been removed based on your selections.
If you removed application files, the app is no longer installed on this PC. To install again, run runInstallWizard.bat from a release zip.
"@
if (Test-RunningFromInstallDir -InstallDir $script:InstallDir -and $script:RemoveAppFiles) {
$bodyText += @"
The install folder and uninstaller will be deleted automatically after you close this wizard if no other files remain.
"@
}
$body = New-BodyLabel $bodyText 180
$body.Location = New-Object System.Drawing.Point(0, 44)
$contentPanel.Controls.Add($body)
}
}
}
function Save-CurrentStepState {
switch ($script:CurrentStep) {
1 {
$script:InstallDir = $script:Step1_PathBox.Text.Trim()
$script:WizardAppVersion = Get-InstalledVersion -InstallDir $script:InstallDir
if (-not $script:WizardAppVersion) {
$script:WizardAppVersion = Get-LocalWizardVersion
}
Update-UninstallWizardFormTitle -Version $script:WizardAppVersion
}
2 {
$script:RemoveAppFiles = $script:Step2_AppFiles.Checked
$script:RemoveUserData = $script:Step2_UserData.Checked
$script:RemoveApplyState = $script:Step2_ApplyState.Checked
$script:RemoveDesktopShortcut = $script:Step2_Desktop.Checked
$script:RemoveStartMenuShortcut = $script:Step2_Start.Checked
}
}
}
function Test-CurrentStepValid {
switch ($script:CurrentStep) {
1 {
$path = $script:Step1_PathBox.Text.Trim()
if (-not $path) {
[System.Windows.Forms.MessageBox]::Show(
"Please choose an install folder.",
$APP_DISPLAY_NAME,
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Warning
) | Out-Null
return $false
}
$script:InstallDir = $path
if (-not (Test-Path $script:InstallDir)) {
[System.Windows.Forms.MessageBox]::Show(
@"
The install folder was not found:
$script:InstallDir
Choose the folder where $APP_DISPLAY_NAME is installed, or cancel if the app is not installed on this PC.
"@,
$APP_DISPLAY_NAME,
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Information
) | Out-Null
return $false
}
if (-not (Test-InstallFolderValid -InstallDir $script:InstallDir)) {
[System.Windows.Forms.MessageBox]::Show(
@"
$EXE_FILE_NAME was not found in:
$script:InstallDir
This folder does not look like a $APP_DISPLAY_NAME installation. Choose the correct folder or cancel.
"@,
$APP_DISPLAY_NAME,
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Information
) | Out-Null
return $false
}
}
2 {
if (-not ($script:Step2_AppFiles.Checked -or
$script:Step2_UserData.Checked -or
$script:Step2_ApplyState.Checked -or
$script:Step2_Desktop.Checked -or
$script:Step2_Start.Checked)) {
[System.Windows.Forms.MessageBox]::Show(
"Select at least one item to remove, or click Cancel to exit.",
$APP_DISPLAY_NAME,
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Warning
) | Out-Null
return $false
}
}
3 {
if ($script:RemoveUserData) {
$confirm = [System.Windows.Forms.MessageBox]::Show(
@"
You selected removal of recordings, saved presets, and CSV bulk inputs.
This permanently deletes your user data and cannot be undone.
Continue with uninstall?
"@,
$APP_DISPLAY_NAME,
[System.Windows.Forms.MessageBoxButtons]::YesNo,
[System.Windows.Forms.MessageBoxIcon]::Warning
)
if ($confirm -ne [System.Windows.Forms.DialogResult]::Yes) {
return $false
}
}
}
}
return $true
}
$btnCancel.Add_Click({ $form.Close() })
$btnBack.Add_Click({
if ($script:CurrentStep -gt 0) {
Save-CurrentStepState
$script:CurrentStep -= 1
Show-WizardStep
}
})
$btnNext.Add_Click({
if ($script:CurrentStep -eq 5) {
$form.Close()
return
}
if ($script:CurrentStep -eq 4) {
$form.Close()
return
}
Save-CurrentStepState
if (-not (Test-CurrentStepValid)) {
return
}
if ($script:CurrentStep -eq 3) {
$script:Step4_Failed = $false
$script:CurrentStep = 4
Show-WizardStep
if (-not $script:Step4_Failed) {
$script:CurrentStep = 5
Show-WizardStep
}
return
}
$script:CurrentStep += 1
Show-WizardStep
})
Show-WizardStep
[void]$form.ShowDialog()