@@ -50,24 +50,11 @@ class UnitySetupInstance {
50
50
[string ]$Path
51
51
52
52
UnitySetupInstance([string ]$path ) {
53
-
54
53
$currentOS = Get-OperatingSystem
55
- $ivyPath = switch ($currentOS ) {
56
- ([OperatingSystem ]::Windows) { ' Editor\Data\UnityExtensions\Unity\Networking\ivy.xml' }
57
- ([OperatingSystem ]::Linux) { throw " UnitySetupInstance has not been implemented on the Linux platform. Contributions welcomed!" ; }
58
- ([OperatingSystem ]::Mac) { ' Unity.app/Contents/UnityExtensions/Unity/Networking/ivy.xml' }
59
- }
60
-
61
- $ivyPath = [io.path ]::Combine(" $path " , $ivyPath );
62
- if (! (Test-Path $ivyPath )) { throw " Path is not a Unity setup: $path " }
63
- [xml ]$xmlDoc = Get-Content $ivyPath
64
-
65
- if ( ! ($xmlDoc .' ivy-module' .info.unityVersion)) {
66
- throw " Unity setup ivy is missing version: $ivyPath "
67
- }
68
54
69
55
$this.Path = $path
70
- $this.Version = $xmlDoc .' ivy-module' .info.unityVersion
56
+ $this.Version = Get-UnitySetupInstanceVersion - Path $path
57
+ if ( -not $this.Version ) { throw " Unable to find version for $path " }
71
58
72
59
$playbackEnginePath = $null
73
60
$componentTests = switch ($currentOS ) {
@@ -164,7 +151,7 @@ class UnityVersion : System.IComparable {
164
151
UnityVersion([string ] $version ) {
165
152
$parts = $version.Split (' -' )
166
153
167
- $parts [0 ] -match " (\d+)\.(\d+)\.(\d+)([fpb ])(\d+)" | Out-Null
154
+ $parts [0 ] -match " (\d+)\.(\d+)\.(\d+)([fpba ])(\d+)" | Out-Null
168
155
if ( $Matches.Count -ne 6 ) { throw " Invalid unity version: $version " }
169
156
$this.Major = [int ]($Matches [1 ]);
170
157
$this.Minor = [int ]($Matches [2 ]);
@@ -292,20 +279,20 @@ function Find-UnitySetupInstaller {
292
279
$currentOS = Get-OperatingSystem
293
280
switch ($currentOS ) {
294
281
([OperatingSystem ]::Windows) {
295
- $unitySetupRegEx = " ^(.+)\/([a-z0-9]+)\/Windows64EditorInstaller\/UnitySetup64-(\d+)\.(\d+)\.(\d+)([fpb])(\d+).exe$"
296
282
$targetSupport = " TargetSupportInstaller"
297
283
$installerExtension = " exe"
298
284
}
299
285
([OperatingSystem ]::Linux) {
300
286
throw " Find-UnitySetupInstaller has not been implemented on the Linux platform. Contributions welcomed!" ;
301
287
}
302
288
([OperatingSystem ]::Mac) {
303
- $unitySetupRegEx = " ^(.+)\/([a-z0-9]+)\/MacEditorInstaller\/Unity-(\d+)\.(\d+)\.(\d+)([fpb])(\d+).pkg$"
304
289
$targetSupport = " MacEditorTargetInstaller"
305
290
$installerExtension = " pkg"
306
291
}
307
292
}
308
293
294
+ $unitySetupRegEx = " ^(.+)\/([a-z0-9]+)\/(.+)\/(.+)-(\d+)\.(\d+)\.(\d+)([fpba])(\d+).$installerExtension $"
295
+
309
296
$knownBaseUrls = @ (
310
297
" https://download.unity3d.com/download_unity" ,
311
298
" https://netstorage.unity3d.com/unity" ,
@@ -314,7 +301,8 @@ function Find-UnitySetupInstaller {
314
301
315
302
$installerTemplates = @ {
316
303
[UnitySetupComponent ]::UWP = " $targetSupport /UnitySetup-UWP-.NET-Support-for-Editor-$Version .$installerExtension " ,
317
- " $targetSupport /UnitySetup-Metro-Support-for-Editor-$Version .$installerExtension " ;
304
+ " $targetSupport /UnitySetup-Metro-Support-for-Editor-$Version .$installerExtension " ,
305
+ " $targetSupport /UnitySetup-Universal-Windows-Platform-Support-for-Editor-$Version .$installerExtension " ;
318
306
[UnitySetupComponent ]::UWP_IL2CPP = , " $targetSupport /UnitySetup-UWP-IL2CPP-Support-for-Editor-$Version .$installerExtension " ;
319
307
[UnitySetupComponent ]::Android = , " $targetSupport /UnitySetup-Android-Support-for-Editor-$Version .$installerExtension " ;
320
308
[UnitySetupComponent ]::iOS = , " $targetSupport /UnitySetup-iOS-Support-for-Editor-$Version .$installerExtension " ;
@@ -365,8 +353,23 @@ function Find-UnitySetupInstaller {
365
353
# Every release type has a different pattern for finding installers
366
354
$searchPages = @ ()
367
355
switch ($Version.Release ) {
368
- ' f' { $searchPages += " https://unity3d.com/get-unity/download/archive" }
369
- ' b' { $searchPages += " https://unity3d.com/unity/beta/unity$Version " }
356
+ ' a' { $searchPages += " https://unity3d.com/alpha/$ ( $Version.Major ) .$ ( $Version.Minor ) " }
357
+ ' b' {
358
+ $searchPages += " https://unity3d.com/unity/beta/unity$Version " ,
359
+ " https://unity3d.com/unity/beta/$ ( $Version.Major ) .$ ( $Version.Minor ) " ,
360
+ " https://unity3d.com/unity/beta/$Version "
361
+ }
362
+ ' f' {
363
+ $searchPages += " https://unity3d.com/get-unity/download/archive" ,
364
+ " https://unity3d.com/unity/whats-new/$ ( $Version.Major ) .$ ( $Version.Minor ) .$ ( $Version.Revision ) "
365
+
366
+ # Just in case it's a release candidate search the beta as well.
367
+ if ($Version.Revision -eq ' 0' ) {
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
+ }
370
373
' p' {
371
374
$patchPage = " https://unity3d.com/unity/qa/patch-releases?version=$ ( $Version.Major ) .$ ( $Version.Minor ) "
372
375
$searchPages += $patchPage
@@ -379,35 +382,32 @@ function Find-UnitySetupInstaller {
379
382
}
380
383
381
384
foreach ($page in $searchPages ) {
382
- $webResult = Invoke-WebRequest $page - UseBasicParsing
383
- $prototypeLink = $webResult.Links | Select-Object - ExpandProperty href - ErrorAction SilentlyContinue | Where-Object {
384
- $_ -match " $ ( $installerTemplates [$setupComponent ]) $"
385
- }
386
-
387
- if ($null -ne $prototypeLink ) { break }
388
- }
389
-
390
- if ($null -eq $prototypeLink ) {
391
- # Attempt to find Unity version and setup links based off builtin_shaders download.
392
- Write-Verbose " Attempting version search with builtin_shaders fallback"
393
- foreach ($page in $searchPages ) {
385
+ try {
394
386
$webResult = Invoke-WebRequest $page - UseBasicParsing
395
387
$prototypeLink = $webResult.Links | Select-Object - ExpandProperty href - ErrorAction SilentlyContinue | Where-Object {
396
- $_ -match " builtin_shaders-$ ( $Version ) .zip$"
397
- }
388
+ $link = $_
398
389
399
- if ($null -ne $prototypeLink ) { break }
400
- }
390
+ foreach ( $installer in $installerTemplates.Keys ) {
391
+ foreach ( $template in $installerTemplates [$installer ] ) {
392
+ if ( $link -like " *$template *" ) { return $true }
393
+ }
394
+ }
395
+
396
+ return $false
397
+
398
+ } | Select-Object - First 1
401
399
402
- if ($null -eq $prototypeLink ) {
403
- throw " Could not find archives for Unity version $Version "
400
+ if ($null -ne $prototypeLink ) { break }
404
401
}
405
- else {
406
- # Regex needs to be reconfigured to parse builtin_shaders's url link
407
- $unitySetupRegEx = " ^(.+)\/([a-z0-9]+)\/builtin_shaders-(\d+)\.(\d+)\.(\d+)([fpb])(\d+).zip$"
402
+ catch {
403
+ Write-Verbose " $page failed: $ ( $_.Exception.Message ) "
408
404
}
409
405
}
410
406
407
+ if ($null -eq $prototypeLink ) {
408
+ throw " Could not find archives for Unity version $Version "
409
+ }
410
+
411
411
$linkComponents = $prototypeLink -split $unitySetupRegEx -ne " "
412
412
413
413
if ($knownBaseUrls -notcontains $linkComponents [0 ]) {
@@ -449,7 +449,7 @@ function Find-UnitySetupInstaller {
449
449
break
450
450
}
451
451
catch {
452
- Write-Verbose " $endpoint failed: $_ "
452
+ Write-Verbose " $endpoint failed: $ ( $_ .Exception.Message ) "
453
453
}
454
454
}
455
455
@@ -887,8 +887,6 @@ function Install-UnitySetupInstance {
887
887
$defaultInstallPath = $BasePath
888
888
}
889
889
890
- $unitySetupInstances = Get-UnitySetupInstance - BasePath $BasePath
891
-
892
890
$versionInstallers = @ {}
893
891
}
894
892
process {
@@ -973,7 +971,7 @@ function Install-UnitySetupInstance {
973
971
974
972
$editorInstaller = $installerPaths | Where-Object { $_.ComponentType -band $editorComponent }
975
973
if ($null -ne $editorInstaller ) {
976
- Write-Verbose " Installing $ ( $editorInstaller.ComponentType ) "
974
+ Write-Verbose " Installing $ ( $editorInstaller.ComponentType ) Editor "
977
975
Install-UnitySetupPackage - Package $editorInstaller - Destination $packageDestination
978
976
}
979
977
@@ -1082,7 +1080,6 @@ function Get-UnitySetupInstance {
1082
1080
if (-not $BasePath ) {
1083
1081
$BasePath = @ (' C:\Program Files*\Unity*' , ' C:\Program Files\Unity\Hub\Editor\*' )
1084
1082
}
1085
- $ivyPath = ' Editor\Data\UnityExtensions\Unity\Networking\ivy.xml'
1086
1083
}
1087
1084
([OperatingSystem ]::Linux) {
1088
1085
throw " Get-UnitySetupInstance has not been implemented on the Linux platform. Contributions welcomed!" ;
@@ -1091,16 +1088,78 @@ function Get-UnitySetupInstance {
1091
1088
if (-not $BasePath ) {
1092
1089
$BasePath = @ (' /Applications/Unity*' , ' /Applications/Unity/Hub/Editor/*' )
1093
1090
}
1094
- $ivyPath = ' Unity.app/Contents/UnityExtensions/Unity/Networking/ivy.xml'
1095
1091
}
1096
1092
}
1097
1093
1098
- foreach ( $folder in $BasePath ) {
1099
- $path = [io.path ]::Combine(" $folder " , $ivyPath );
1094
+ Get-ChildItem $BasePath - Directory | Where-Object {
1095
+ Test-Path (Join-Path $_.FullName ' Editor\Unity.exe' ) - PathType Leaf
1096
+ } | ForEach-Object {
1097
+ $path = $_.FullName
1098
+ try {
1099
+ Write-Verbose " Creating UnitySetupInstance for $path "
1100
+ [UnitySetupInstance ]::new($path )
1101
+ }
1102
+ catch {
1103
+ Write-Warning " $_ "
1104
+ }
1105
+ }
1106
+ }
1107
+
1108
+ <#
1109
+ . Synopsis
1110
+ Gets the UnityVersion for a UnitySetupInstance at Path
1111
+ . DESCRIPTION
1112
+ Given a set of unity setup instances, this will select the best one matching your requirements
1113
+ . PARAMETER Path
1114
+ Path to a UnitySetupInstance
1115
+ . OUTPUTS
1116
+ UnityVersion
1117
+ Returns the UnityVersion for the UnitySetupInstance at Path, or nothing if there isn't one
1118
+ . EXAMPLE
1119
+ Get-UnitySetupInstanceVersion -Path 'C:\Program Files\Unity'
1120
+ #>
1121
+ function Get-UnitySetupInstanceVersion {
1122
+ [CmdletBinding ()]
1123
+ param (
1124
+ [ValidateNotNullOrEmpty ()]
1125
+ [ValidateScript ( {Test-Path $_ - PathType Container})]
1126
+ [Parameter (Mandatory = $true , Position = 0 )]
1127
+ [string ]$Path
1128
+ )
1129
+
1130
+ Write-Verbose " Attempting to find UnityVersion in $path "
1131
+
1132
+ if ( Test-Path " $path \modules.json" - PathType Leaf ) {
1133
+
1134
+ Write-Verbose " Searching $path \modules.json for module versions"
1135
+ $modules = (Get-Content " $path \modules.json" - Raw) | ConvertFrom-Json
1136
+
1137
+ foreach ( $module in $modules ) {
1138
+ Write-Verbose " `t Testing DownloadUrl $ ( $module.DownloadUrl ) "
1139
+ if ( $module.DownloadUrl -notmatch " (\d+)\.(\d+)\.(\d+)([fpab])(\d+)" ) { continue ; }
1140
+
1141
+ Write-Verbose " `t Found version!"
1142
+ return [UnityVersion ]$Matches [0 ]
1143
+ }
1144
+ }
1145
+
1146
+ if ( Test-Path " $path \Editor" - PathType Container ) {
1147
+ # We'll attempt to search for the version using the ivy.xml definitions for legacy editor compatibility.
1148
+
1149
+ Write-Verbose " Looking for ivy.xml files under $path \Editor\"
1150
+ $ivyFiles = Get-ChildItem - Path " $path \Editor\" - Filter ' ivy.xml' - Recurse - ErrorAction SilentlyContinue - Force - File
1151
+ foreach ( $ivy in $ivyFiles ) {
1152
+ if ( $null -eq $ivy ) { continue ; }
1153
+
1154
+ Write-Verbose " `t Looking for version in $ ( $ivy.FullName ) "
1155
+
1156
+ [xml ]$xmlDoc = Get-Content $ivy.FullName
1157
+
1158
+ [string ]$version = $xmlDoc .' ivy-module' .info.unityVersion
1159
+ if ( -not $version ) { continue ; }
1100
1160
1101
- Get-ChildItem $path - Recurse - ErrorAction Ignore |
1102
- ForEach-Object {
1103
- [UnitySetupInstance ]::new((Join-Path $_.Directory " ..\..\..\..\..\" | Convert-Path ))
1161
+ Write-Verbose " `t Found version!"
1162
+ return [UnityVersion ]$version
1104
1163
}
1105
1164
}
1106
1165
}
0 commit comments