From 2ba18fd87e2af7461dd675bfefd6326c1c1e444f Mon Sep 17 00:00:00 2001 From: TitanSnow Date: Sat, 22 Apr 2017 14:54:31 +0800 Subject: fix Invoke-Expression quickly exit when error --- scripts/get.ps1 | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'scripts') diff --git a/scripts/get.ps1 b/scripts/get.ps1 index c6de72b14..92db7c666 100644 --- a/scripts/get.ps1 +++ b/scripts/get.ps1 @@ -4,6 +4,14 @@ & { +Function myExit($code){ + if($code -is [int] -and $code -ne 0){ + throw $Error[0] + }else{ + break + } +} + $temppath=($env:TMP,$env:TEMP,'.' -ne $null)[0] $outfile=$temppath+"\$pid-xmake-installer.exe" try{ @@ -12,7 +20,7 @@ try{ }catch{ Write-Host 'Cannot write to temp path' Write-Host 'Please set environment var "TMP" to another path' - Exit 1 + myExit 1 } $ver='v2.1.3' Write-Host 'Start downloading... Hope amazon S3 is not broken again' @@ -21,7 +29,7 @@ try{ }catch{ Write-Host 'Download failed!' Write-Host 'Check your network or... the news of S3 break' - Exit 1 + myExit 1 } Write-Host 'Start installation... Hope your antivirus doesn''t trouble' $installdir=$HOME+'\xmake' @@ -32,7 +40,7 @@ try{ Remove-Item "$outfile" Write-Host 'Install failed!' Write-Host 'Close your antivirus then try again' - Exit 1 + myExit 1 } Remove-Item "$outfile" Write-Host 'Adding to PATH... almost done' @@ -43,7 +51,7 @@ try{ }catch{ Write-Host 'Everything is showing installation has finished' Write-Host 'But xmake could not run... Why?' - Exit 1 + myExit 1 } $branch='master' Write-Host "Pulling xmake from branch $branch" @@ -53,7 +61,7 @@ try{ }catch{ Write-Host 'Pull Failed!' Write-Host 'xmake is now available but may not be newest' - Exit + myExit } Write-Host 'Expanding archive...' New-Item -Path "$temppath" -Name "$pid-xmake-repo" -ItemType "directory" -Force -- cgit v1.3.1