diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2018-04-12 18:15:38 -0700 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2018-04-12 18:15:38 -0700 |
| commit | dc207a2c891fe6deb2710ccde0abf48078f64fcd (patch) | |
| tree | dbe3d517060d68a06e7b0ac58104b0d7ea8547b6 /scripts | |
| parent | 7a1003f2ce11de88e261dcfa84d2f177a0d8d8ca (diff) | |
| download | vcpkg-dc207a2c891fe6deb2710ccde0abf48078f64fcd.tar.gz vcpkg-dc207a2c891fe6deb2710ccde0abf48078f64fcd.zip | |
Restore powershell extracting because shell may not be available (see #3252)
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/VcpkgPowershellUtils.ps1 | 40 | ||||
| -rw-r--r-- | scripts/fetchTool.ps1 | 4 |
2 files changed, 32 insertions, 12 deletions
diff --git a/scripts/VcpkgPowershellUtils.ps1 b/scripts/VcpkgPowershellUtils.ps1 index 3ab301c55..fdd89e7b9 100644 --- a/scripts/VcpkgPowershellUtils.ps1 +++ b/scripts/VcpkgPowershellUtils.ps1 @@ -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') + { + Write-Verbose("Extracting with Microsoft.PowerShell.Archive\Expand-Archive") + Microsoft.PowerShell.Archive\Expand-Archive -path $archivePath -destinationpath $destinationPartial + } + elseif (vcpkgHasCommand -commandName 'Pscx\Expand-Archive') { - # Piping to Out-Null is used to block until finished - $shell.Namespace($destinationPartial).copyhere($item) | Out-Null + 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 diff --git a/scripts/fetchTool.ps1 b/scripts/fetchTool.ps1 index be18656c7..dd3f0f9f4 100644 --- a/scripts/fetchTool.ps1 +++ b/scripts/fetchTool.ps1 @@ -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." } |
