diff --git a/README.md b/README.md index e0320f0..9f7673a 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,8 @@ App windows use the PrintMaster logo and attribution. The scan-folder desktop sh Click the gear icon to enable/disable individual steps. +Choosing **Cancel** or closing the initial setup window exits normally without running the selected setup steps or displaying a loader error. + ![Settings](img/scans-settings.png) Wait for the utility to complete all changes. diff --git a/src/scans.ps1 b/src/scans.ps1 index 4084a50..e4d9b18 100644 --- a/src/scans.ps1 +++ b/src/scans.ps1 @@ -735,7 +735,7 @@ if ($setupResult -eq $true) { } else { Write-Verbose "User canceled scanning setup" - Exit 1 + Exit 0 } $details = New-Object System.Collections.ArrayList $script:progressMax = 2 diff --git a/tests/Scans.Tests.ps1 b/tests/Scans.Tests.ps1 index 40dbba4..8065391 100644 --- a/tests/Scans.Tests.ps1 +++ b/tests/Scans.Tests.ps1 @@ -201,6 +201,30 @@ Describe 'Scan account password errors' { } } +Describe 'Setup cancellation' { + It 'exits successfully without continuing setup when Cancel or window close dismisses the dialog' { + $decision = $ast.Find({ + param($node) + $node -is [System.Management.Automation.Language.IfStatementAst] -and + $node.Clauses[0].Item1.Extent.Text -eq '$setupResult -eq $true' + }, $true) + $decision | Should Not BeNullOrEmpty + foreach ($result in @('$false', '$null')) { + $childScript = @( + '$ErrorActionPreference = "Stop"' + "`$setupResult = $result" + $decision.Extent.Text + 'throw "Canceled setup must not continue."' + ) -join "`n" + $encoded = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($childScript)) + $executable = (Get-Process -Id $PID).Path + $output = & $executable -NoProfile -NonInteractive -STA -EncodedCommand $encoded 2>&1 + $LASTEXITCODE | Should Be 0 + ($output | Out-String).Trim() | Should BeNullOrEmpty + } + } +} + Describe 'Account-dependent setup steps' { BeforeEach { $source = Get-Content $sourcePath -Raw