Skip to content

Commit 6f7c6de

Browse files
committed
More exhaustive searching. Fix for alpha search pages
1 parent b7b2a22 commit 6f7c6de

File tree

1 file changed

+37
-33
lines changed

1 file changed

+37
-33
lines changed

UnitySetup/UnitySetup.psm1

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -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+)([fpba])(\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+)([fpba])(\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,16 +363,22 @@ function Find-UnitySetupInstaller {
362363
# Every release type has a different pattern for finding installers
363364
$searchPages = @()
364365
switch ($Version.Release) {
365-
'a' { $searchPages += "https://unity3d.com/unity/beta/unity$Version" }
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+
}
367371
'f' {
368-
$searchPages += "https://unity3d.com/get-unity/download/archive"
369-
370-
# Just in case it's a release candidate search the beta as well.
371-
if($Version.Revision -eq '0') {
372-
$searchPages += "https://unity3d.com/unity/beta/unity$Version"
373-
}
372+
$searchPages += "https://unity3d.com/get-unity/download/archive",
373+
"https://unity3d.com/unity/whats-new/$($Version.Major).$($Version.Minor).$($Version.Revision)"
374+
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+
$searchPages += "https://unity3d.com/unity/beta/$($Version.Major).$($Version.Minor)"
374380
}
381+
}
375382
'p' {
376383
$patchPage = "https://unity3d.com/unity/qa/patch-releases?version=$($Version.Major).$($Version.Minor)"
377384
$searchPages += $patchPage
@@ -384,35 +391,32 @@ function Find-UnitySetupInstaller {
384391
}
385392

386393
foreach ($page in $searchPages) {
387-
$webResult = Invoke-WebRequest $page -UseBasicParsing
388-
$prototypeLink = $webResult.Links | Select-Object -ExpandProperty href -ErrorAction SilentlyContinue | Where-Object {
389-
$_ -match "$($installerTemplates[$setupComponent])$"
390-
}
391-
392-
if ($null -ne $prototypeLink) { break }
393-
}
394-
395-
if ($null -eq $prototypeLink) {
396-
# Attempt to find Unity version and setup links based off builtin_shaders download.
397-
Write-Verbose "Attempting version search with builtin_shaders fallback"
398-
foreach ($page in $searchPages) {
394+
try {
399395
$webResult = Invoke-WebRequest $page -UseBasicParsing
400396
$prototypeLink = $webResult.Links | Select-Object -ExpandProperty href -ErrorAction SilentlyContinue | Where-Object {
401-
$_ -match "builtin_shaders-$($Version).zip$"
402-
}
397+
$link = $_
403398

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

407-
if ($null -eq $prototypeLink) {
408-
throw "Could not find archives for Unity version $Version"
409+
if ($null -ne $prototypeLink) { break }
409410
}
410-
else {
411-
# Regex needs to be reconfigured to parse builtin_shaders's url link
412-
$unitySetupRegEx = "^(.+)\/([a-z0-9]+)\/builtin_shaders-(\d+)\.(\d+)\.(\d+)([fpba])(\d+).zip$"
411+
catch {
412+
Write-Verbose "$page failed: $($_.Exception.Message)"
413413
}
414414
}
415415

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

418422
if ($knownBaseUrls -notcontains $linkComponents[0]) {
@@ -454,7 +458,7 @@ function Find-UnitySetupInstaller {
454458
break
455459
}
456460
catch {
457-
Write-Verbose "$endpoint failed: $_"
461+
Write-Verbose "$endpoint failed: $($_.Exception.Message)"
458462
}
459463
}
460464

0 commit comments

Comments
 (0)