-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDownload-Emulators.ps1
More file actions
94 lines (86 loc) · 3.53 KB
/
Download-Emulators.ps1
File metadata and controls
94 lines (86 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
function Get-LatestRelease() {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[String]$User,
[Parameter(Mandatory = $true)]
[String]$Repository,
[Parameter(Mandatory = $false)]
[String]$DestinationPath,
[Parameter(Mandatory = $true)]
[String]$Platform,
[Parameter(Mandatory = $false)]
[Switch]$Authenticated
)
process {
if (-not $DestinationPath) {
$DestinationPath = Join-Path -Path $env:USERPROFILE -ChildPath "Downloads"
}
if ($Authenticated) {
[String]$Command = "gh api --method GET /repos/$User/$Repository/releases/latest"
[PSCustomObject]$ReleaseInfo = Invoke-Expression -Command $Command | ConvertFrom-Json
}
else {
[String]$URL = "https://api.github.com/repos/$User/$Repository/releases/latest"
[String]$Command = Invoke-WebRequest -Uri $URL -UserAgent 'Mozilla/5.0'
[PSCustomObject]$ReleaseInfo = $Command | ConvertFrom-Json
}
[Array]$Assets = $ReleaseInfo.assets
foreach ($Asset in $Assets) {
[String]$DownloadUrl = $Asset.browser_download_url
[String]$FileName = Split-Path -Path $DownloadUrl -Leaf
[String]$FileExtension = [System.IO.Path]::GetExtension($FileName)
[String]$FilePath = Join-Path -Path $DestinationPath -ChildPath $FileName
try {
switch ($Platform.ToLower()) {
'linux' {
if ($FileExtension -eq '.AppImage' -or $FileExtension -eq '.flatpak' -and $FileName.Contains('linux')) {
if (-not(Test-Path -LiteralPath $FilePath)) {
Write-Host "Downloading $FileName to $FilePath..."
Invoke-WebRequest -Uri $DownloadUrl -OutFile $FilePath
}
else {
Write-Error -Message "File $FilePath already exists."
}
}
}
'windows' {
if ($FileExtension -eq '.exe' -and $FileName.Contains('windows') ) {
if (-not(Test-Path -LiteralPath $FilePath)) {
Write-Host "Downloading $FileName to $FilePath..."
Invoke-WebRequest -Uri $DownloadUrl -OutFile $FilePath
}
else {
Write-Warning -Message "File $FilePath already exists."
}
}
}
'mac' {
throw "macOS is not implemented."
}
Default {
throw "Unknown platform: $Platform"
}
}
}
catch {
throw;
}
}
}
}
$Platforms = @('windows', 'linux')
$Repositories = @(
@{ User = 'PCSX2'; Repo = 'pcsx2' },
@{ User = 'stenzek'; Repo = 'duckstation' },
@{ User = 'RPCS3'; Repo = 'rpcs3-binaries-win' },
@{ User = 'RPCS3'; Repo = 'rpcs3-binaries-linux' }
)
foreach ($Platform in $Platforms) {
foreach ($Repository in $Repositories) {
Get-LatestRelease -DestinationPath "$env:USERPROFILE\Downloads" `
-User $Repository.User `
-Repository $Repository.Repo `
-Platform $Platform
}
}