aboutsummaryrefslogtreecommitdiff
path: root/scripts/VcpkgPowershellUtils.ps1
diff options
context:
space:
mode:
authorAlexander Karatarakis <alkarata@microsoft.com>2018-04-03 21:05:31 -0700
committerAlexander Karatarakis <alkarata@microsoft.com>2018-04-06 17:24:45 -0700
commit31377dee20dad9b95357934732996e2448f2eaf5 (patch)
tree770015c4607ba633588ee3c1364544f2949026f9 /scripts/VcpkgPowershellUtils.ps1
parent997fddb3c1a3acb7579e1fe0ab82436b227a0dc4 (diff)
downloadvcpkg-31377dee20dad9b95357934732996e2448f2eaf5.tar.gz
vcpkg-31377dee20dad9b95357934732996e2448f2eaf5.zip
Use 7z for extracting. Extract tools in downloads/tools
Diffstat (limited to 'scripts/VcpkgPowershellUtils.ps1')
-rw-r--r--scripts/VcpkgPowershellUtils.ps158
1 files changed, 10 insertions, 48 deletions
diff --git a/scripts/VcpkgPowershellUtils.ps1 b/scripts/VcpkgPowershellUtils.ps1
index 92e0f21d0..988c6dbf0 100644
--- a/scripts/VcpkgPowershellUtils.ps1
+++ b/scripts/VcpkgPowershellUtils.ps1
@@ -1,8 +1,3 @@
-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)
@@ -160,54 +155,21 @@ function vcpkgDownloadFile( [Parameter(Mandatory=$true)][string]$url,
Move-Item -Path $downloadPartPath -Destination $downloadPath
}
-function vcpkgExtractFile( [Parameter(Mandatory=$true)][string]$archivePath,
- [Parameter(Mandatory=$true)][string]$destinationDir,
- [Parameter(Mandatory=$true)][string]$outFilename)
+function vcpkgExtractFile( [Parameter(Mandatory=$true)][string]$sevenZipExe,
+ [Parameter(Mandatory=$true)][string]$archivePath,
+ [Parameter(Mandatory=$true)][string]$destinationDir)
{
- vcpkgCreateDirectoryIfNotExists $destinationDir
- $output = "$destinationDir\$outFilename"
- vcpkgRemoveItem $output
- $destinationPartial = "$destinationDir\partially-extracted"
-
+ vcpkgRemoveItem $destinationDir
+ $destinationPartial = "$destinationDir.partial"
vcpkgRemoveItem $destinationPartial
vcpkgCreateDirectoryIfNotExists $destinationPartial
-
- 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')
- {
- 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
- }
- }
-
- $items = @(Get-ChildItem "$destinationPartial")
- $itemCount = $items.Count
-
- if ($itemCount -eq 1)
- {
- $item = $items | Select-Object -first 1
- Write-Host "$item"
- Move-Item -Path "$destinationPartial\$item" -Destination $output
- vcpkgRemoveItem $destinationPartial
- }
- else
+ $ec = vcpkgInvokeCommand "$sevenZipExe" "x `"$archivePath`" -o`"$destinationPartial`" -y"
+ if ($ec -ne 0)
{
- Move-Item -Path "$destinationPartial" -Destination $output
+ Write-Host "Could not extract $archivePath"
+ throw
}
+ Rename-Item -Path "$destinationPartial" -NewName $destinationDir
}
function vcpkgInvokeCommand()