[VcpkgPowershellUtils] Minor tweaks

This commit is contained in:
Alexander Karatarakis 2017-11-27 00:25:29 -08:00
parent 7938006022
commit c4c079f86e

View File

@ -11,6 +11,20 @@ function vcpkgCreateDirectoryIfNotExists([Parameter(Mandatory=$true)][string]$di
} }
} }
function vcpkgCreateParentDirectoryIfNotExists([Parameter(Mandatory=$true)][string]$path)
{
$parentDir = split-path -parent $path
if ([string]::IsNullOrEmpty($parentDir))
{
return
}
if (!(Test-Path $dirPath))
{
New-Item -ItemType Directory -Path $parentDir | Out-Null
}
}
function vcpkgRemoveDirectory([Parameter(Mandatory=$true)][string]$dirPath) function vcpkgRemoveDirectory([Parameter(Mandatory=$true)][string]$dirPath)
{ {
if (Test-Path $dirPath) if (Test-Path $dirPath)
@ -101,8 +115,7 @@ function vcpkgDownloadFile( [Parameter(Mandatory=$true)][string]$url,
return return
} }
$downloadDir = split-path -parent $downloadPath vcpkgCreateParentDirectoryIfNotExists $downloadPath
vcpkgCreateDirectoryIfNotExists $downloadDir
$downloadPartPath = "$downloadPath.part" $downloadPartPath = "$downloadPath.part"
vcpkgRemoveFile $downloadPartPath vcpkgRemoveFile $downloadPartPath
@ -143,10 +156,10 @@ function vcpkgDownloadFile( [Parameter(Mandatory=$true)][string]$url,
function vcpkgExtractFile( [Parameter(Mandatory=$true)][string]$file, function vcpkgExtractFile( [Parameter(Mandatory=$true)][string]$file,
[Parameter(Mandatory=$true)][string]$destinationDir) [Parameter(Mandatory=$true)][string]$destinationDir)
{ {
$parentPath = split-path -parent $destinationDir vcpkgCreateParentDirectoryIfNotExists $destinationDir
vcpkgCreateDirectoryIfNotExists $parentPath
$baseName = (Get-ChildItem $file).BaseName $baseName = (Get-ChildItem $file).BaseName
$destinationPartial = "$destinationDir\$baseName-partially_extracted" $destination = "$destinationDir\$baseName"
$destinationPartial = "$destination-partially_extracted"
vcpkgRemoveDirectory $destinationPartial vcpkgRemoveDirectory $destinationPartial
vcpkgCreateDirectoryIfNotExists $destinationPartial vcpkgCreateDirectoryIfNotExists $destinationPartial
@ -179,10 +192,12 @@ function vcpkgExtractFile( [Parameter(Mandatory=$true)][string]$file,
{ {
Move-Item -Path "$destinationPartial\*" -Destination $destinationDir Move-Item -Path "$destinationPartial\*" -Destination $destinationDir
vcpkgRemoveDirectory $destinationPartial vcpkgRemoveDirectory $destinationPartial
return $destination
} }
else else
{ {
Rename-Item -Path $destinationPartial -NewName $baseName Rename-Item -Path $destinationPartial -NewName $baseName
return $destination
} }
} }