1+ param ([string ] $Version )
2+
3+ If (-not ($Version ))
4+ {
5+ Throw " Parameter -Version is required" ;
6+ }
7+
18Set-Location $PSScriptRoot
29
310[Net.ServicePointManager ]::SecurityProtocol = [Net.SecurityProtocolType ]::Tls12
411$ExtractRootPath = ' ../references'
5- $AssetToDownloadName = ' GitExtensions-Portable-3.0.2.5232 .zip' ;
6- $AssetToDownloadUrl = ' https://github.com/gitextensions/gitextensions/releases/download/v3.0.2/GitExtensions-Portable-3.0.2.5232.zip ' ;
12+ $AssetToDownloadName = ' GitExtensions-' + $Version + ' .zip' ;
13+ $AssetToDownloadUrl = $null ;
714
8- if (! ($null -eq $AssetToDownloadUrl ))
15+ $DownloadName = [System.IO.Path ]::GetFileName($AssetToDownloadName );
16+ $DownloadFilePath = [System.IO.Path ]::Combine($ExtractRootPath , $DownloadName );
17+ if (Test-Path $DownloadFilePath )
918{
10- $DownloadName = [System.IO.Path ]::GetFileName($AssetToDownloadName );
11- $DownloadFilePath = [System.IO.Path ]::Combine($ExtractRootPath , $DownloadName );
12- $ExtractPath = $ExtractRootPath ;
19+ Write-Host (' Download "' + $DownloadName + ' " already exists.' );
20+ Pop-Location
21+ exit ;
22+ }
1323
14- if (! (Test-Path $DownloadFilePath ))
24+ # Find release and asset.
25+ $Releases = Invoke-RestMethod - Uri ' https://api.github.com/repos/gitextensions/gitextensions/releases'
26+ foreach ($Release in $Releases )
27+ {
28+ if ($Release.tag_name -eq $Version )
1529 {
16- if (! (Test-Path $ExtractRootPath ))
17- {
18- New-Item - ItemType directory - Path $ExtractRootPath | Out-Null ;
19- }
30+ Write-Host (' Selected release "' + $Release.name + ' ".' );
31+ foreach ($Asset in $Release.assets )
32+ {
33+ if ($Asset.content_type -eq " application/zip" -and $Asset.name.Contains (' Portable' ))
34+ {
35+ Write-Host (' Selected asset "' + $Asset.name + ' ".' );
36+ $AssetToDownloadUrl = $Asset.browser_download_url ;
37+ break ;
38+ }
39+ }
2040
21- if (! (Test-Path $ExtractPath ))
22- {
23- New-Item - ItemType directory - Path $ExtractPath | Out-Null ;
24- }
41+ if (! ($null -eq $AssetToDownloadUrl ))
42+ {
43+ break ;
44+ }
45+ }
46+ }
2547
26- Write-Host (' Downloading "' + $DownloadName + ' ".' );
48+ # Download and extract zip.
49+ if (! ($null -eq $AssetToDownloadUrl ))
50+ {
51+ $ExtractPath = $ExtractRootPath ;
2752
28- Invoke-WebRequest - Uri $AssetToDownloadUrl - OutFile $DownloadFilePath ;
29- Expand-Archive $DownloadFilePath - DestinationPath $ExtractPath - Force
53+ if (! (Test-Path $ExtractRootPath ))
54+ {
55+ New-Item - ItemType directory - Path $ExtractRootPath | Out-Null ;
3056 }
31- else
57+
58+ if (! (Test-Path $ExtractPath ))
3259 {
33- Write-Host ( ' Download " ' + $DownloadName + ' " already exists. ' ) ;
60+ New-Item - ItemType directory - Path $ExtractPath | Out-Null ;
3461 }
62+
63+ Write-Host (' Downloading "' + $DownloadName + ' " from URL "' + $AssetToDownloadUrl + ' ".' );
64+
65+ Invoke-WebRequest - Uri $AssetToDownloadUrl - OutFile $DownloadFilePath ;
66+ Expand-Archive $DownloadFilePath - DestinationPath $ExtractPath - Force
67+
68+ Write-Host (' Extraction at "' + $ExtractPath + ' " completed.' );
69+ }
70+ else
71+ {
72+ Write-Host (' Download for version "' + $Version + ' " not found.' );
3573}
3674
3775Pop-Location
0 commit comments