Skip to content

Commit 31008bc

Browse files
authored
Merge pull request #170 from StephenHodgson/dev-search-paths
adds both archive and beta pages for searching
2 parents bfa1374 + 7ea64d4 commit 31008bc

File tree

1 file changed

+41
-28
lines changed

1 file changed

+41
-28
lines changed

UnitySetup/UnitySetup.psm1

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class UnityVersion : System.IComparable {
162162
UnityVersion([string] $version) {
163163
$parts = $version.Split('-')
164164

165-
$parts[0] -match "(\d+)\.(\d+)\.(\d+)([fpb])(\d+)" | Out-Null
165+
$parts[0] -match "(\d+)\.(\d+)\.(\d+)([fpba])(\d+)" | Out-Null
166166
if ( $Matches.Count -ne 6 ) { throw "Invalid unity version: $version" }
167167
$this.Major = [int]($Matches[1]);
168168
$this.Minor = [int]($Matches[2]);
@@ -290,20 +290,20 @@ function Find-UnitySetupInstaller {
290290
$currentOS = Get-OperatingSystem
291291
switch ($currentOS) {
292292
([OperatingSystem]::Windows) {
293-
$unitySetupRegEx = "^(.+)\/([a-z0-9]+)\/Windows64EditorInstaller\/UnitySetup64-(\d+)\.(\d+)\.(\d+)([fpb])(\d+).exe$"
294293
$targetSupport = "TargetSupportInstaller"
295294
$installerExtension = "exe"
296295
}
297296
([OperatingSystem]::Linux) {
298297
throw "Find-UnitySetupInstaller has not been implemented on the Linux platform. Contributions welcomed!";
299298
}
300299
([OperatingSystem]::Mac) {
301-
$unitySetupRegEx = "^(.+)\/([a-z0-9]+)\/MacEditorInstaller\/Unity-(\d+)\.(\d+)\.(\d+)([fpb])(\d+).pkg$"
302300
$targetSupport = "MacEditorTargetInstaller"
303301
$installerExtension = "pkg"
304302
}
305303
}
306304

305+
$unitySetupRegEx = "^(.+)\/([a-z0-9]+)\/(.+)\/(.+)-(\d+)\.(\d+)\.(\d+)([fpba])(\d+).$installerExtension$"
306+
307307
$knownBaseUrls = @(
308308
"https://download.unity3d.com/download_unity",
309309
"https://netstorage.unity3d.com/unity",
@@ -312,7 +312,8 @@ function Find-UnitySetupInstaller {
312312

313313
$installerTemplates = @{
314314
[UnitySetupComponent]::UWP = "$targetSupport/UnitySetup-UWP-.NET-Support-for-Editor-$Version.$installerExtension",
315-
"$targetSupport/UnitySetup-Metro-Support-for-Editor-$Version.$installerExtension";
315+
"$targetSupport/UnitySetup-Metro-Support-for-Editor-$Version.$installerExtension",
316+
"$targetSupport/UnitySetup-Universal-Windows-Platform-Support-for-Editor-$Version.$installerExtension";
316317
[UnitySetupComponent]::UWP_IL2CPP = , "$targetSupport/UnitySetup-UWP-IL2CPP-Support-for-Editor-$Version.$installerExtension";
317318
[UnitySetupComponent]::Android = , "$targetSupport/UnitySetup-Android-Support-for-Editor-$Version.$installerExtension";
318319
[UnitySetupComponent]::iOS = , "$targetSupport/UnitySetup-iOS-Support-for-Editor-$Version.$installerExtension";
@@ -362,8 +363,23 @@ function Find-UnitySetupInstaller {
362363
# Every release type has a different pattern for finding installers
363364
$searchPages = @()
364365
switch ($Version.Release) {
365-
'f' { $searchPages += "https://unity3d.com/get-unity/download/archive" }
366-
'b' { $searchPages += "https://unity3d.com/unity/beta/unity$Version" }
366+
'a' { $searchPages += "https://unity3d.com/alpha/$($Version.Major).$($Version.Minor)" }
367+
'b' {
368+
$searchPages += "https://unity3d.com/unity/beta/unity$Version",
369+
"https://unity3d.com/unity/beta/$($Version.Major).$($Version.Minor)",
370+
"https://unity3d.com/unity/beta/$Version"
371+
}
372+
'f' {
373+
$searchPages += "https://unity3d.com/get-unity/download/archive",
374+
"https://unity3d.com/unity/whats-new/$($Version.Major).$($Version.Minor).$($Version.Revision)"
375+
376+
# Just in case it's a release candidate search the beta as well.
377+
if ($Version.Revision -eq '0') {
378+
$searchPages += "https://unity3d.com/unity/beta/unity$Version",
379+
"https://unity3d.com/unity/beta/$($Version.Major).$($Version.Minor)",
380+
"https://unity3d.com/unity/beta/$Version"
381+
}
382+
}
367383
'p' {
368384
$patchPage = "https://unity3d.com/unity/qa/patch-releases?version=$($Version.Major).$($Version.Minor)"
369385
$searchPages += $patchPage
@@ -376,35 +392,32 @@ function Find-UnitySetupInstaller {
376392
}
377393

378394
foreach ($page in $searchPages) {
379-
$webResult = Invoke-WebRequest $page -UseBasicParsing
380-
$prototypeLink = $webResult.Links | Select-Object -ExpandProperty href -ErrorAction SilentlyContinue | Where-Object {
381-
$_ -match "$($installerTemplates[$setupComponent])$"
382-
}
383-
384-
if ($null -ne $prototypeLink) { break }
385-
}
386-
387-
if ($null -eq $prototypeLink) {
388-
# Attempt to find Unity version and setup links based off builtin_shaders download.
389-
Write-Verbose "Attempting version search with builtin_shaders fallback"
390-
foreach ($page in $searchPages) {
395+
try {
391396
$webResult = Invoke-WebRequest $page -UseBasicParsing
392397
$prototypeLink = $webResult.Links | Select-Object -ExpandProperty href -ErrorAction SilentlyContinue | Where-Object {
393-
$_ -match "builtin_shaders-$($Version).zip$"
394-
}
398+
$link = $_
395399

396-
if ($null -ne $prototypeLink) { break }
397-
}
400+
foreach ( $installer in $installerTemplates.Keys ) {
401+
foreach ( $template in $installerTemplates[$installer] ) {
402+
if ( $link -like "*$template*" ) { return $true }
403+
}
404+
}
405+
406+
return $false
407+
408+
} | Select-Object -First 1
398409

399-
if ($null -eq $prototypeLink) {
400-
throw "Could not find archives for Unity version $Version"
410+
if ($null -ne $prototypeLink) { break }
401411
}
402-
else {
403-
# Regex needs to be reconfigured to parse builtin_shaders's url link
404-
$unitySetupRegEx = "^(.+)\/([a-z0-9]+)\/builtin_shaders-(\d+)\.(\d+)\.(\d+)([fpb])(\d+).zip$"
412+
catch {
413+
Write-Verbose "$page failed: $($_.Exception.Message)"
405414
}
406415
}
407416

417+
if ($null -eq $prototypeLink) {
418+
throw "Could not find archives for Unity version $Version"
419+
}
420+
408421
$linkComponents = $prototypeLink -split $unitySetupRegEx -ne ""
409422

410423
if ($knownBaseUrls -notcontains $linkComponents[0]) {
@@ -446,7 +459,7 @@ function Find-UnitySetupInstaller {
446459
break
447460
}
448461
catch {
449-
Write-Verbose "$endpoint failed: $_"
462+
Write-Verbose "$endpoint failed: $($_.Exception.Message)"
450463
}
451464
}
452465

0 commit comments

Comments
 (0)