Restore powershell extracting because shell may not be available (see #3252)

This commit is contained in:
Alexander Karatarakis 2018-04-12 18:15:38 -07:00
parent 7a1003f2ce
commit dc207a2c89
2 changed files with 32 additions and 12 deletions

View File

@ -1,3 +1,8 @@
function vcpkgHasModule([Parameter(Mandatory=$true)][string]$moduleName)
{
return [bool](Get-Module -ListAvailable -Name $moduleName)
}
function vcpkgHasProperty([Parameter(Mandatory=$true)][AllowNull()]$object, [Parameter(Mandatory=$true)]$propertyName)
{
if ($object -eq $null)
@ -183,9 +188,9 @@ function vcpkgDownloadFileWithAria2( [Parameter(Mandatory=$true)][string]$ari
Move-Item -Path $downloadPartPath -Destination $downloadPath
}
function vcpkgExtractFile( [Parameter(Mandatory=$true)][string]$sevenZipExe,
[Parameter(Mandatory=$true)][string]$archivePath,
[Parameter(Mandatory=$true)][string]$destinationDir)
function vcpkgExtractFileWith7z([Parameter(Mandatory=$true)][string]$sevenZipExe,
[Parameter(Mandatory=$true)][string]$archivePath,
[Parameter(Mandatory=$true)][string]$destinationDir)
{
vcpkgRemoveItem $destinationDir
$destinationPartial = "$destinationDir.partial"
@ -200,20 +205,35 @@ function vcpkgExtractFile( [Parameter(Mandatory=$true)][string]$sevenZipExe,
Rename-Item -Path "$destinationPartial" -NewName $destinationDir
}
function vcpkgExtractZipFileWithShell( [Parameter(Mandatory=$true)][string]$archivePath,
[Parameter(Mandatory=$true)][string]$destinationDir)
function vcpkgExtractZipFile( [Parameter(Mandatory=$true)][string]$archivePath,
[Parameter(Mandatory=$true)][string]$destinationDir)
{
vcpkgRemoveItem $destinationDir
$destinationPartial = "$destinationDir.partial"
vcpkgRemoveItem $destinationPartial
vcpkgCreateDirectoryIfNotExists $destinationPartial
$shell = new-object -com shell.application
$zip = $shell.NameSpace($(Get-Item $archivePath).fullname)
foreach($item in $zip.items())
if (vcpkgHasCommand -commandName 'Microsoft.PowerShell.Archive\Expand-Archive')
{
# Piping to Out-Null is used to block until finished
$shell.Namespace($destinationPartial).copyhere($item) | Out-Null
Write-Verbose("Extracting with Microsoft.PowerShell.Archive\Expand-Archive")
Microsoft.PowerShell.Archive\Expand-Archive -path $archivePath -destinationpath $destinationPartial
}
elseif (vcpkgHasCommand -commandName 'Pscx\Expand-Archive')
{
Write-Verbose("Extracting with Pscx\Expand-Archive")
Pscx\Expand-Archive -path $archivePath -OutputPath $destinationPartial
}
else
{
Write-Verbose("Extracting via shell")
$shell = new-object -com shell.application
$zip = $shell.NameSpace($(Get-Item $archivePath).fullname)
foreach($item in $zip.items())
{
# Piping to Out-Null is used to block until finished
$shell.Namespace($destinationPartial).copyhere($item) | Out-Null
}
}
Rename-Item -Path "$destinationPartial" -NewName $destinationDir

View File

@ -73,7 +73,7 @@ function fetchToolInternal([Parameter(Mandatory=$true)][string]$tool)
# Extract aria2 with shell because we need it to download 7zip
if ($tool -eq "7zip920" -or $tool -eq "aria2")
{
vcpkgExtractZipFileWithShell -ArchivePath $downloadPath -DestinationDir $toolPath
vcpkgExtractZipFile -ArchivePath $downloadPath -DestinationDir $toolPath
}
elseif ($tool -eq "7zip")
{
@ -88,7 +88,7 @@ function fetchToolInternal([Parameter(Mandatory=$true)][string]$tool)
else
{
$sevenZipExe = fetchToolInternal "7zip"
vcpkgExtractFile -sevenZipExe "$sevenZipExe" -ArchivePath $downloadPath -DestinationDir $toolPath
vcpkgExtractFileWith7z -sevenZipExe "$sevenZipExe" -ArchivePath $downloadPath -DestinationDir $toolPath
}
Write-Host "Extracting $tool... done."
}