1
+ param ([string ] $Version )
2
+
3
+ If (-not ($Version ))
4
+ {
5
+ Throw " Parameter -Version is required" ;
6
+ }
7
+
1
8
Set-Location $PSScriptRoot
2
9
3
10
[Net.ServicePointManager ]::SecurityProtocol = [Net.SecurityProtocolType ]::Tls12
4
11
$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 ;
7
14
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 )
9
18
{
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
+ }
13
23
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 )
15
29
{
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
+ }
20
40
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
+ }
25
47
26
- Write-Host (' Downloading "' + $DownloadName + ' ".' );
48
+ # Download and extract zip.
49
+ if (! ($null -eq $AssetToDownloadUrl ))
50
+ {
51
+ $ExtractPath = $ExtractRootPath ;
27
52
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 ;
30
56
}
31
- else
57
+
58
+ if (! (Test-Path $ExtractPath ))
32
59
{
33
- Write-Host ( ' Download " ' + $DownloadName + ' " already exists. ' ) ;
60
+ New-Item - ItemType directory - Path $ExtractPath | Out-Null ;
34
61
}
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.' );
35
73
}
36
74
37
75
Pop-Location
0 commit comments