| 1 |
try |
| 2 |
{ |
| 3 |
Write-Host "Checking latest windeps package..." |
| 4 |
|
| 5 |
$headers = @{ "Accept" = "application/vnd.github.v3+json" } |
| 6 |
|
| 7 |
# Use the API token provided by Github Actions if available |
| 8 |
If ([string]::IsNullOrEmpty($env:GITHUB_API_TOKEN) -eq $false) |
| 9 |
{ |
| 10 |
Write-Host "Using API Token to access the releases" |
| 11 |
$headers.Add("Authorization", "Bearer " + $env:GITHUB_API_TOKEN) |
| 12 |
} |
| 13 |
|
| 14 |
$uri = "https://api.github.com/repos/codereader/DarkRadiant_windeps/releases" |
| 15 |
$releases = Invoke-RestMethod -Headers $headers -Uri $uri |
| 16 |
|
| 17 |
$latest = $releases | sort created_at -Descending | select -First 1 |
| 18 |
|
| 19 |
$windeps_package = $latest.assets | ? { $_.name -eq "windeps.7z" } |
| 20 |
|
| 21 |
if ($null -eq $windeps_package) |
| 22 |
{ |
| 23 |
throw "Could not find the windows dependencies package URL" |
| 24 |
} |
| 25 |
|
| 26 |
$package_filename = [System.IO.Path]::GetFileNameWithoutExtension($windeps_package.name) + ` |
| 27 |
"_" + $windeps_package.id + [System.IO.Path]::GetExtension($windeps_package.name) |
| 28 |
|
| 29 |
$target_folder = Join-Path (Get-Location) "..\..\" |
| 30 |
$package_path = Join-Path $target_folder $package_filename |
| 31 |
|
| 32 |
Write-Host ("Found package {1} ({0:0.0} MB)" -f ($windeps_package.size / 1024 / 1024), $windeps_package.name) |
| 33 |
|
| 34 |
if ((Get-ChildItem $package_path -ErrorAction SilentlyContinue).Length -eq $windeps_package.size) |
| 35 |
{ |
| 36 |
Write-Host "Package has already been downloaded to $package_path" |
| 37 |
} |
| 38 |
else |
| 39 |
{ |
| 40 |
Write-Host ("Downloading dependencies package ({0:0.0} MB)" -f ($windeps_package.size / 1024 / 1024)) |
| 41 |
Invoke-WebRequest $windeps_package.browser_download_url -OutFile $package_path |
| 42 |
} |
| 43 |
|
| 44 |
Write-Host ("Cleaning up old dependencies...") |
| 45 |
|
| 46 |
Remove-Item (Join-Path $target_folder "w32deps") -Recurse -ErrorAction SilentlyContinue |
| 47 |
Remove-Item (Join-Path $target_folder "w64deps") -Recurse -ErrorAction SilentlyContinue |
| 48 |
Remove-Item (Join-Path $target_folder "windeps") -Recurse -ErrorAction SilentlyContinue |
| 49 |
|
| 50 |
Write-Host ("Extracting dependencies package...") |
| 51 |
|
| 52 |
& ..\7z\7za.exe x $package_path -o"$target_folder" -aoa |
| 53 |
|
| 54 |
if ((Get-ChildItem "..\..\windeps" -ErrorAction SilentlyContinue) -eq $null) |
| 55 |
{ |
| 56 |
throw "windeps folder still not present after download... cannot continue" |
| 57 |
} |
| 58 |
} |
| 59 |
catch |
| 60 |
{ |
| 61 |
Write-Host -Foreground Red ("Error: {0}" -f $_) |
| 62 |
exit 1 |
| 63 |
} |