From fdbe134e34d3fe2ac6e1269ce8936f9f7554d5d3 Mon Sep 17 00:00:00 2001 From: Dmitry Nefedov Date: Mon, 10 Jul 2023 23:21:48 +0300 Subject: [PATCH] Small fixes --- .../Module/Sophia.psm1 | 50 +++++++++++++----- .../Module/Sophia.psm1 | 50 +++++++++++++----- .../Module/Sophia.psm1 | 50 +++++++++++++----- .../Module/Sophia.psm1 | 50 +++++++++++++----- .../Module/Sophia.psm1 | 52 +++++++++++++------ .../Module/Sophia.psm1 | 50 +++++++++++++----- 6 files changed, 216 insertions(+), 86 deletions(-) diff --git a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 index af6e63da1..331101678 100644 --- a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 @@ -844,8 +844,20 @@ public static string GetString(uint strId) .SYNOPSIS The "Show menu" function with the up/down arrow keys and enter key to make a selection + .PARAMETER Title + Add title + + .PARAMETER Menu + Array of items to choose from + + .PARAMETER Default + Default selected item in array + + .PARAMETER AddSkip + Add localized extracted "Skip" string from shell32.dll + .EXAMPLE - Show-Menu -Menu $ListOfItems -Default $DefaultChoice + Show-Menu -Menu $Items -Default 1 .LINK https://qna.habr.com/answer?answer_id=1522379 @@ -865,7 +877,11 @@ public static string GetString(uint strId) [Parameter(Mandatory = $true)] [int] - $Default + $Default, + + [Parameter(Mandatory = $false)] + [switch] + $AddSkip ) Write-Information -MessageData $Title -InformationAction Continue @@ -873,6 +889,12 @@ public static string GetString(uint strId) # Extract the localized "Waiting for confirmation" string from shell32.dll $Menu += [WinAPI.GetStr]::GetString(33252) + if ($AddSkip) + { + # Extract the localized "Skip" string from shell32.dll + $Menu += [WinAPI.GetStr]::GetString(16956) + } + # https://github.com/microsoft/terminal/issues/14992 [System.Console]::BufferHeight += $Menu.Count $minY = [Console]::CursorTop @@ -7274,11 +7296,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Desktop -FolderPath "$($Choice)\Desktop" -RemoveDesktopINI } @@ -7302,11 +7324,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Documents -FolderPath "$($Choice)\Documents" -RemoveDesktopINI } @@ -7330,11 +7352,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Downloads -FolderPath "$($Choice)\Downloads" -RemoveDesktopINI } @@ -7358,11 +7380,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Music -FolderPath "$($Choice)\Music" -RemoveDesktopINI } @@ -7386,11 +7408,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Pictures -FolderPath "$($Choice)\Pictures" -RemoveDesktopINI } @@ -7414,11 +7436,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Videos -FolderPath "$($Choice)\Videos" -RemoveDesktopINI } diff --git a/src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1 index 4101c877f..cee1c7f91 100644 --- a/src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1 @@ -694,8 +694,20 @@ public static string GetString(uint strId) .SYNOPSIS The "Show menu" function with the up/down arrow keys and enter key to make a selection + .PARAMETER Title + Add title + + .PARAMETER Menu + Array of items to choose from + + .PARAMETER Default + Default selected item in array + + .PARAMETER AddSkip + Add localized extracted "Skip" string from shell32.dll + .EXAMPLE - Show-Menu -Menu $ListOfItems -Default $DefaultChoice + Show-Menu -Menu $Items -Default 1 .LINK https://qna.habr.com/answer?answer_id=1522379 @@ -715,7 +727,11 @@ public static string GetString(uint strId) [Parameter(Mandatory = $true)] [int] - $Default + $Default, + + [Parameter(Mandatory = $false)] + [switch] + $AddSkip ) Write-Information -MessageData $Title -InformationAction Continue @@ -723,6 +739,12 @@ public static string GetString(uint strId) # Extract the localized "Waiting for confirmation" string from shell32.dll $Menu += [WinAPI.GetStr]::GetString(33252) + if ($AddSkip) + { + # Extract the localized "Skip" string from shell32.dll + $Menu += [WinAPI.GetStr]::GetString(16956) + } + # https://github.com/microsoft/terminal/issues/14992 [System.Console]::BufferHeight += $Menu.Count $minY = [Console]::CursorTop @@ -5909,11 +5931,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Desktop -FolderPath "$($Choice)\Desktop" -RemoveDesktopINI } @@ -5937,11 +5959,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Documents -FolderPath "$($Choice)\Documents" -RemoveDesktopINI } @@ -5965,11 +5987,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Downloads -FolderPath "$($Choice)\Downloads" -RemoveDesktopINI } @@ -5993,11 +6015,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Music -FolderPath "$($Choice)\Music" -RemoveDesktopINI } @@ -6021,11 +6043,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Pictures -FolderPath "$($Choice)\Pictures" -RemoveDesktopINI } @@ -6049,11 +6071,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Videos -FolderPath "$($Choice)\Videos" -RemoveDesktopINI } diff --git a/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 index 4d028df37..bfcc06cad 100644 --- a/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 @@ -697,8 +697,20 @@ public static string GetString(uint strId) .SYNOPSIS The "Show menu" function with the up/down arrow keys and enter key to make a selection + .PARAMETER Title + Add title + + .PARAMETER Menu + Array of items to choose from + + .PARAMETER Default + Default selected item in array + + .PARAMETER AddSkip + Add localized extracted "Skip" string from shell32.dll + .EXAMPLE - Show-Menu -Menu $ListOfItems -Default $DefaultChoice + Show-Menu -Menu $Items -Default 1 .LINK https://qna.habr.com/answer?answer_id=1522379 @@ -718,7 +730,11 @@ public static string GetString(uint strId) [Parameter(Mandatory = $true)] [int] - $Default + $Default, + + [Parameter(Mandatory = $false)] + [switch] + $AddSkip ) Write-Information -MessageData $Title -InformationAction Continue @@ -726,6 +742,12 @@ public static string GetString(uint strId) # Extract the localized "Waiting for confirmation" string from shell32.dll $Menu += [WinAPI.GetStr]::GetString(33252) + if ($AddSkip) + { + # Extract the localized "Skip" string from shell32.dll + $Menu += [WinAPI.GetStr]::GetString(16956) + } + # https://github.com/microsoft/terminal/issues/14992 [System.Console]::BufferHeight += $Menu.Count $minY = [Console]::CursorTop @@ -6299,11 +6321,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Desktop -FolderPath "$($Choice)\Desktop" -RemoveDesktopINI } @@ -6327,11 +6349,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Documents -FolderPath "$($Choice)\Documents" -RemoveDesktopINI } @@ -6355,11 +6377,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Downloads -FolderPath "$($Choice)\Downloads" -RemoveDesktopINI } @@ -6383,11 +6405,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Music -FolderPath "$($Choice)\Music" -RemoveDesktopINI } @@ -6411,11 +6433,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Pictures -FolderPath "$($Choice)\Pictures" -RemoveDesktopINI } @@ -6439,11 +6461,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Videos -FolderPath "$($Choice)\Videos" -RemoveDesktopINI } diff --git a/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 index 0b47904f1..2593daaac 100644 --- a/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 @@ -848,8 +848,20 @@ public static string GetString(uint strId) .SYNOPSIS The "Show menu" function with the up/down arrow keys and enter key to make a selection + .PARAMETER Title + Add title + + .PARAMETER Menu + Array of items to choose from + + .PARAMETER Default + Default selected item in array + + .PARAMETER AddSkip + Add localized extracted "Skip" string from shell32.dll + .EXAMPLE - Show-Menu -Menu $ListOfItems -Default $DefaultChoice + Show-Menu -Menu $Items -Default 1 .LINK https://qna.habr.com/answer?answer_id=1522379 @@ -869,7 +881,11 @@ public static string GetString(uint strId) [Parameter(Mandatory = $true)] [int] - $Default + $Default, + + [Parameter(Mandatory = $false)] + [switch] + $AddSkip ) Write-Information -MessageData $Title -InformationAction Continue @@ -877,6 +893,12 @@ public static string GetString(uint strId) # Extract the localized "Waiting for confirmation" string from shell32.dll $Menu += [WinAPI.GetStr]::GetString(33252) + if ($AddSkip) + { + # Extract the localized "Skip" string from shell32.dll + $Menu += [WinAPI.GetStr]::GetString(16956) + } + # https://github.com/microsoft/terminal/issues/14992 [System.Console]::BufferHeight += $Menu.Count $minY = [Console]::CursorTop @@ -7277,11 +7299,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Desktop -FolderPath "$($Choice)\Desktop" -RemoveDesktopINI } @@ -7305,11 +7327,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Documents -FolderPath "$($Choice)\Documents" -RemoveDesktopINI } @@ -7333,11 +7355,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Downloads -FolderPath "$($Choice)\Downloads" -RemoveDesktopINI } @@ -7361,11 +7383,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Music -FolderPath "$($Choice)\Music" -RemoveDesktopINI } @@ -7389,11 +7411,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Pictures -FolderPath "$($Choice)\Pictures" -RemoveDesktopINI } @@ -7417,11 +7439,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Videos -FolderPath "$($Choice)\Videos" -RemoveDesktopINI } diff --git a/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 index 81f7f9542..731c32be4 100644 --- a/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 @@ -895,8 +895,20 @@ public static string GetString(uint strId) .SYNOPSIS The "Show menu" function with the up/down arrow keys and enter key to make a selection + .PARAMETER Title + Add title + + .PARAMETER Menu + Array of items to choose from + + .PARAMETER Default + Default selected item in array + + .PARAMETER AddSkip + Add localized extracted "Skip" string from shell32.dll + .EXAMPLE - Show-Menu -Menu $ListOfItems -Default $DefaultChoice + Show-Menu -Menu $Items -Default 1 .LINK https://qna.habr.com/answer?answer_id=1522379 @@ -916,7 +928,11 @@ public static string GetString(uint strId) [Parameter(Mandatory = $true)] [int] - $Default + $Default, + + [Parameter(Mandatory = $false)] + [switch] + $AddSkip ) Write-Information -MessageData $Title -InformationAction Continue @@ -924,6 +940,12 @@ public static string GetString(uint strId) # Extract the localized "Waiting for confirmation" string from shell32.dll $Menu += [WinAPI.GetStr]::GetString(33252) + if ($AddSkip) + { + # Extract the localized "Skip" string from shell32.dll + $Menu += [WinAPI.GetStr]::GetString(16956) + } + # https://github.com/microsoft/terminal/issues/14992 [System.Console]::BufferHeight += $Menu.Count $minY = [Console]::CursorTop @@ -7169,8 +7191,6 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int # Store all fixed disks' letters to use them within Show-Menu function # https://learn.microsoft.com/en-us/dotnet/api/system.io.drivetype?view=net-7.0#fields $DriveLetters = @((Get-CimInstance -ClassName CIM_LogicalDisk | Where-Object -FilterScript {$_.DriveType -eq 3}).DeviceID | Sort-Object) - # Add $Skip to $DriveLetters array - $DriveLetters = $DriveLetters += $Skip # Desktop Write-Information -MessageData "" -InformationAction Continue @@ -7182,11 +7202,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Desktop -FolderPath "$($Choice)\Desktop" -RemoveDesktopINI } @@ -7210,11 +7230,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Documents -FolderPath "$($Choice)\Documents" -RemoveDesktopINI } @@ -7238,11 +7258,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Downloads -FolderPath "$($Choice)\Downloads" -RemoveDesktopINI } @@ -7266,11 +7286,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Music -FolderPath "$($Choice)\Music" -RemoveDesktopINI } @@ -7294,11 +7314,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Pictures -FolderPath "$($Choice)\Pictures" -RemoveDesktopINI } @@ -7322,11 +7342,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Videos -FolderPath "$($Choice)\Videos" -RemoveDesktopINI } diff --git a/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 index f4ae42f04..c04a9d1e2 100644 --- a/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 @@ -896,8 +896,20 @@ public static string GetString(uint strId) .SYNOPSIS The "Show menu" function with the up/down arrow keys and enter key to make a selection + .PARAMETER Title + Add title + + .PARAMETER Menu + Array of items to choose from + + .PARAMETER Default + Default selected item in array + + .PARAMETER AddSkip + Add localized extracted "Skip" string from shell32.dll + .EXAMPLE - Show-Menu -Menu $ListOfItems -Default $DefaultChoice + Show-Menu -Menu $Items -Default 1 .LINK https://qna.habr.com/answer?answer_id=1522379 @@ -917,7 +929,11 @@ public static string GetString(uint strId) [Parameter(Mandatory = $true)] [int] - $Default + $Default, + + [Parameter(Mandatory = $false)] + [switch] + $AddSkip ) Write-Information -MessageData $Title -InformationAction Continue @@ -925,6 +941,12 @@ public static string GetString(uint strId) # Extract the localized "Waiting for confirmation" string from shell32.dll $Menu += [WinAPI.GetStr]::GetString(33252) + if ($AddSkip) + { + # Extract the localized "Skip" string from shell32.dll + $Menu += [WinAPI.GetStr]::GetString(16956) + } + # https://github.com/microsoft/terminal/issues/14992 [System.Console]::BufferHeight += $Menu.Count $minY = [Console]::CursorTop @@ -7184,11 +7206,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Desktop -FolderPath "$($Choice)\Desktop" -RemoveDesktopINI } @@ -7212,11 +7234,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Documents -FolderPath "$($Choice)\Documents" -RemoveDesktopINI } @@ -7240,11 +7262,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Downloads -FolderPath "$($Choice)\Downloads" -RemoveDesktopINI } @@ -7268,11 +7290,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Music -FolderPath "$($Choice)\Music" -RemoveDesktopINI } @@ -7296,11 +7318,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Pictures -FolderPath "$($Choice)\Pictures" -RemoveDesktopINI } @@ -7324,11 +7346,11 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int do { - $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] + $Choice = Show-Menu -Title "" -Menu $DriveLetters -Default $DriveLetters.Count[-1] -AddSkip switch ($Choice) { - {$DriveLetters -notcontains $Skip} + {$DriveLetters -contains $Choice} { Set-UserShellFolder -UserFolder Videos -FolderPath "$($Choice)\Videos" -RemoveDesktopINI }