diff --git a/scripts/Common/Scripts/Config.ps1 b/scripts/Common/Scripts/Config.ps1 index 279592ca..c0d44153 100644 --- a/scripts/Common/Scripts/Config.ps1 +++ b/scripts/Common/Scripts/Config.ps1 @@ -1,4 +1,5 @@ using namespace Microsoft.Win32; +using namespace System.Management.Automation.Host; using namespace System.Security.AccessControl; using namespace System.Security.Principal; @@ -32,6 +33,54 @@ $null = New-Module { [string] $finishedOption = "Finished"; [RegistryKey] $key = $null; + <# + .SYNOPSIS + Prompts the user to select a profile to act on. + #> + function Show-ProfileNamePrompt { + . "$PSScriptRoot/../../Windows/Types/WindowsInstallerAction.ps1"; + + $profiles = & { + . "$PSScriptRoot/SoftwareManagement.ps1"; + + if (Test-Command "wsl") { + return Invoke-ConfigScript "getProfiles"; + } else { + return Get-ChildItem "$PSScriptRoot/../../../.config" | ForEach-Object { Split-Path -LeafBase $_ }; + } + }; + + $choice = $Host.UI.PromptForChoice( + "Select Profile", + (& { + switch (Get-Stage) { + ([WindowsInstallerAction]::Backup) { + "Which profile do you wish to back up?"; + } + ([WindowsInstallerAction]::Install) { + "Which profile do you wish to install?"; + } + $null { + "Which profile do you wish to set up?"; + } + } + }), + (& { + for ($i = 0; $i -lt $profiles.Count; $i++) { + [ChoiceDescription]"&$i - $($profiles[$i])"; + } + + [ChoiceDescription]"&Abort"; + }), + $profiles.Count); + + if ($choice -eq $profiles.Count) { + exit; + } else { + $env:CONFIG_NAME = $profiles[$choice]; + } + } + <# .SYNOPSIS Converts the specified path to linux and escapes it for the use in a script.