aboutsummaryrefslogtreecommitdiff
path: root/scripts/VcpkgPowershellUtils.ps1
diff options
context:
space:
mode:
authorxoviat <xoviat@users.noreply.github.com>2017-12-20 13:24:59 -0600
committerGitHub <noreply@github.com>2017-12-20 13:24:59 -0600
commitf1f373b189453f33a944e9db8b3451b1c785e223 (patch)
tree8713b7dc28734e4d4ad0ebba76459850955ce004 /scripts/VcpkgPowershellUtils.ps1
parent6363688b6d2f3522a4ce48cedb60da31775cd923 (diff)
parent6cb6a61aaf5ef2c143f974e9f731778bcd3f5cbe (diff)
downloadvcpkg-f1f373b189453f33a944e9db8b3451b1c785e223.tar.gz
vcpkg-f1f373b189453f33a944e9db8b3451b1c785e223.zip
Merge branch 'master' into fftw
Diffstat (limited to 'scripts/VcpkgPowershellUtils.ps1')
-rw-r--r--scripts/VcpkgPowershellUtils.ps154
1 files changed, 30 insertions, 24 deletions
diff --git a/scripts/VcpkgPowershellUtils.ps1 b/scripts/VcpkgPowershellUtils.ps1
index d32c3ae6b..e394e540e 100644
--- a/scripts/VcpkgPowershellUtils.ps1
+++ b/scripts/VcpkgPowershellUtils.ps1
@@ -11,19 +11,25 @@ function vcpkgCreateDirectoryIfNotExists([Parameter(Mandatory=$true)][string]$di
}
}
-function vcpkgRemoveDirectory([Parameter(Mandatory=$true)][string]$dirPath)
+function vcpkgCreateParentDirectoryIfNotExists([Parameter(Mandatory=$true)][string]$path)
{
- if (Test-Path $dirPath)
+ $parentDir = split-path -parent $path
+ if ([string]::IsNullOrEmpty($parentDir))
{
- Remove-Item $dirPath -Recurse -Force
+ return
+ }
+
+ if (!(Test-Path $parentDir))
+ {
+ New-Item -ItemType Directory -Path $parentDir | Out-Null
}
}
-function vcpkgRemoveFile([Parameter(Mandatory=$true)][string]$filePath)
+function vcpkgRemoveItem([Parameter(Mandatory=$true)][string]$dirPath)
{
- if (Test-Path $filePath)
+ if (Test-Path $dirPath)
{
- Remove-Item $filePath -Force
+ Remove-Item $dirPath -Recurse -Force
}
}
@@ -101,11 +107,10 @@ function vcpkgDownloadFile( [Parameter(Mandatory=$true)][string]$url,
return
}
- $downloadDir = split-path -parent $downloadPath
- vcpkgCreateDirectoryIfNotExists $downloadDir
+ vcpkgCreateParentDirectoryIfNotExists $downloadPath
$downloadPartPath = "$downloadPath.part"
- vcpkgRemoveFile $downloadPartPath
+ vcpkgRemoveItem $downloadPartPath
$wc = New-Object System.Net.WebClient
$proxyAuth = !$wc.Proxy.IsBypassed($url)
@@ -131,7 +136,7 @@ function vcpkgDownloadFile( [Parameter(Mandatory=$true)][string]$url,
catch [System.Exception]
{
# If BITS fails for any reason, delete any potentially partially downloaded files and continue
- vcpkgRemoveFile $downloadPartPath
+ vcpkgRemoveItem $downloadPartPath
}
}
@@ -141,16 +146,21 @@ function vcpkgDownloadFile( [Parameter(Mandatory=$true)][string]$url,
}
function vcpkgExtractFile( [Parameter(Mandatory=$true)][string]$file,
- [Parameter(Mandatory=$true)][string]$destinationDir)
+ [Parameter(Mandatory=$true)][string]$destinationDir,
+ [Parameter(Mandatory=$true)][string]$outFilename)
{
- $parentPath = split-path -parent $destinationDir
- vcpkgCreateDirectoryIfNotExists $parentPath
- $baseName = (Get-ChildItem $file).BaseName
- $destinationPartial = "$destinationDir\$baseName-partially_extracted"
+ vcpkgCreateDirectoryIfNotExists $destinationDir
+ $output = "$destinationDir\$outFilename"
+ vcpkgRemoveItem $output
+ $destinationPartial = "$destinationDir\partially-extracted"
- vcpkgRemoveDirectory $destinationPartial
+ vcpkgRemoveItem $destinationPartial
vcpkgCreateDirectoryIfNotExists $destinationPartial
+ $shell = new-object -com shell.application
+ $zip = $shell.NameSpace($file)
+ $itemCount = $zip.Items().Count
+
if (vcpkgHasCommand -commandName 'Microsoft.PowerShell.Archive\Expand-Archive')
{
Write-Verbose("Extracting with Microsoft.PowerShell.Archive\Expand-Archive")
@@ -164,8 +174,6 @@ function vcpkgExtractFile( [Parameter(Mandatory=$true)][string]$file,
else
{
Write-Verbose("Extracting via shell")
- $shell = new-object -com shell.application
- $zip = $shell.NameSpace($file)
foreach($item in $zip.items())
{
# Piping to Out-Null is used to block until finished
@@ -173,16 +181,14 @@ function vcpkgExtractFile( [Parameter(Mandatory=$true)][string]$file,
}
}
- $hasASingleItem = (Get-ChildItem $destinationPartial | Measure-Object).Count -eq 1;
-
- if ($hasASingleItem)
+ if ($itemCount -eq 1)
{
- Move-Item -Path "$destinationPartial\*" -Destination $destinationDir
- vcpkgRemoveDirectory $destinationPartial
+ Move-Item -Path "$destinationPartial\*" -Destination $output
+ vcpkgRemoveItem $destinationPartial
}
else
{
- Rename-Item -Path $destinationPartial -NewName $baseName
+ Move-Item -Path $destinationPartial -Destination $output
}
}