github.com/jfrog/frogbot@v1.1.1-0.20231221090046-821a26f50338/action/node_modules/@actions/tool-cache/scripts/Invoke-7zdec.ps1 (about) 1 [CmdletBinding()] 2 param( 3 [Parameter(Mandatory = $true)] 4 [string]$Source, 5 6 [Parameter(Mandatory = $true)] 7 [string]$Target) 8 9 # This script translates the output from 7zdec into UTF8. Node has limited 10 # built-in support for encodings. 11 # 12 # 7zdec uses the system default code page. The system default code page varies 13 # depending on the locale configuration. On an en-US box, the system default code 14 # page is Windows-1252. 15 # 16 # Note, on a typical en-US box, testing with the 'ç' character is a good way to 17 # determine whether data is passed correctly between processes. This is because 18 # the 'ç' character has a different code point across each of the common encodings 19 # on a typical en-US box, i.e. 20 # 1) the default console-output code page (IBM437) 21 # 2) the system default code page (i.e. CP_ACP) (Windows-1252) 22 # 3) UTF8 23 24 $ErrorActionPreference = 'Stop' 25 26 # Redefine the wrapper over STDOUT to use UTF8. Node expects UTF8 by default. 27 $stdout = [System.Console]::OpenStandardOutput() 28 $utf8 = New-Object System.Text.UTF8Encoding($false) # do not emit BOM 29 $writer = New-Object System.IO.StreamWriter($stdout, $utf8) 30 [System.Console]::SetOut($writer) 31 32 # All subsequent output must be written using [System.Console]::WriteLine(). In 33 # PowerShell 4, Write-Host and Out-Default do not consider the updated stream writer. 34 35 Set-Location -LiteralPath $Target 36 37 # Print the ##command. 38 $_7zdec = Join-Path -Path "$PSScriptRoot" -ChildPath "externals/7zdec.exe" 39 [System.Console]::WriteLine("##[command]$_7zdec x `"$Source`"") 40 41 # The $OutputEncoding variable instructs PowerShell how to interpret the output 42 # from the external command. 43 $OutputEncoding = [System.Text.Encoding]::Default 44 45 # Note, the output from 7zdec.exe needs to be iterated over. Otherwise PowerShell.exe 46 # will launch the external command in such a way that it inherits the streams. 47 & $_7zdec x $Source 2>&1 | 48 ForEach-Object { 49 if ($_ -is [System.Management.Automation.ErrorRecord]) { 50 [System.Console]::WriteLine($_.Exception.Message) 51 } 52 else { 53 [System.Console]::WriteLine($_) 54 } 55 } 56 [System.Console]::WriteLine("##[debug]7zdec.exe exit code '$LASTEXITCODE'") 57 [System.Console]::Out.Flush() 58 if ($LASTEXITCODE -ne 0) { 59 exit $LASTEXITCODE 60 }