aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorAlexander Karatarakis <alkarata@microsoft.com>2017-12-08 15:16:35 -0800
committerAlexander Karatarakis <alkarata@microsoft.com>2017-12-08 15:16:35 -0800
commit1f3013bea303736d216361a47e2f323577ab9c46 (patch)
tree2ddc080872d85df7540ae74f0c33912ef9274226 /scripts
parent583ee9ee91a0d7abb5487580faf3ff1f302a642d (diff)
downloadvcpkg-1f3013bea303736d216361a47e2f323577ab9c46.tar.gz
vcpkg-1f3013bea303736d216361a47e2f323577ab9c46.zip
Improve vcpkgExtractFile. Also merge vcpkgRemoveDirectory/File
Diffstat (limited to 'scripts')
-rw-r--r--scripts/VcpkgPowershellUtils.ps141
-rw-r--r--scripts/fetchDependency.ps14
2 files changed, 20 insertions, 25 deletions
diff --git a/scripts/VcpkgPowershellUtils.ps1 b/scripts/VcpkgPowershellUtils.ps1
index 28e818437..45f52b225 100644
--- a/scripts/VcpkgPowershellUtils.ps1
+++ b/scripts/VcpkgPowershellUtils.ps1
@@ -25,7 +25,7 @@ function vcpkgCreateParentDirectoryIfNotExists([Parameter(Mandatory=$true)][stri
}
}
-function vcpkgRemoveDirectory([Parameter(Mandatory=$true)][string]$dirPath)
+function vcpkgRemoveItem([Parameter(Mandatory=$true)][string]$dirPath)
{
if (Test-Path $dirPath)
{
@@ -33,14 +33,6 @@ function vcpkgRemoveDirectory([Parameter(Mandatory=$true)][string]$dirPath)
}
}
-function vcpkgRemoveFile([Parameter(Mandatory=$true)][string]$filePath)
-{
- if (Test-Path $filePath)
- {
- Remove-Item $filePath -Force
- }
-}
-
function vcpkgHasCommand([Parameter(Mandatory=$true)][string]$commandName)
{
return [bool](Get-Command -Name $commandName -ErrorAction SilentlyContinue)
@@ -118,7 +110,7 @@ function vcpkgDownloadFile( [Parameter(Mandatory=$true)][string]$url,
vcpkgCreateParentDirectoryIfNotExists $downloadPath
$downloadPartPath = "$downloadPath.part"
- vcpkgRemoveFile $downloadPartPath
+ vcpkgRemoveItem $downloadPartPath
$wc = New-Object System.Net.WebClient
$proxyAuth = !$wc.Proxy.IsBypassed($url)
@@ -144,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
}
}
@@ -154,14 +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)
{
- vcpkgCreateParentDirectoryIfNotExists $destinationDir
- $destinationPartial = "$destinationDir-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")
@@ -175,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
@@ -184,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
{
- Move-Item -Path $destinationPartial -Destination $destinationDir
+ Move-Item -Path $destinationPartial -Destination $output
}
}
diff --git a/scripts/fetchDependency.ps1 b/scripts/fetchDependency.ps1
index 830ec7064..f62fe450c 100644
--- a/scripts/fetchDependency.ps1
+++ b/scripts/fetchDependency.ps1
@@ -88,8 +88,8 @@ function SelectProgram([Parameter(Mandatory=$true)][string]$Dependency)
{
if (-not (Test-Path $executableFromDownload))
{
- $extractFolderName = (Get-ChildItem $downloadPath).BaseName
- vcpkgExtractFile -File $downloadPath -DestinationDir "$downloadsDir\$extractFolderName"
+ $outFilename = (Get-ChildItem $downloadPath).BaseName
+ vcpkgExtractFile -File $downloadPath -DestinationDir $downloadsDir -outFilename $outFilename
}
}
elseif($extractionType -eq $ExtractionType_SELF_EXTRACTING_7Z)