From e6618f21a3aefa777a7b165ac0f901db078171ce Mon Sep 17 00:00:00 2001 From: Jack Bennett Date: Thu, 10 Apr 2014 18:34:31 +0100 Subject: [PATCH] Try to find 7-zip if it's installed before an error. Create an alias to 7z.exe in the script scope. --- scripts/utils.ps1 | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/utils.ps1 b/scripts/utils.ps1 index 4717176..4b5165b 100644 --- a/scripts/utils.ps1 +++ b/scripts/utils.ps1 @@ -1,15 +1,20 @@ function Ensure-Exists ($path) { if (-not (Test-Path $path)) { - Write-Error "Missing required $path file" + Write-Error "Missing required $path! Ensure it is installed" exit 1 } + return $true > $null } function Ensure-Executable ($command) { try { Get-Command $command -ErrorAction Stop > $null } catch { - Write-Error "Missing $command! Ensure it is installed and on in the PATH" - exit 1 + if( ($command -eq "7z") -and (Ensure-Exists "$env:programfiles\7-zip\7z.exe") ){ + set-alias -Name "7z" -Value "$env:programfiles\7-zip\7z.exe" -Scope script + } else { + Write-Error "Missing $command! Ensure it is installed and on in the PATH" + exit 1 + } } }