@@ -117,16 +117,16 @@ class UnityProjectInstance {
117
117
118
118
UnityProjectInstance([string ]$path ) {
119
119
$versionFile = [io.path ]::Combine($path , " ProjectSettings\ProjectVersion.txt" )
120
- if (! (Test-Path $versionFile )) { throw " Path is not a Unity project: $path " }
120
+ if (! (Test-Path $versionFile )) { throw " Path is not a Unity project: $path " }
121
121
122
122
$fileVersion = (Get-Content $versionFile - Raw | ConvertFrom-Yaml )[' m_EditorVersion' ];
123
- if (! $fileVersion ) { throw " Project is missing a version in: $versionFile " }
123
+ if (! $fileVersion ) { throw " Project is missing a version in: $versionFile " }
124
124
125
125
$projectSettingsFile = [io.path ]::Combine($path , " ProjectSettings\ProjectSettings.asset" )
126
- if (! (Test-Path $projectSettingsFile )) { throw " Project is missing ProjectSettings.asset" }
126
+ if (! (Test-Path $projectSettingsFile )) { throw " Project is missing ProjectSettings.asset" }
127
127
128
128
$prodName = ((Get-Content $projectSettingsFile - Raw | ConvertFrom-Yaml )[' playerSettings' ])[' productName' ]
129
- if (! $prodName ) { throw " ProjectSettings is missing productName" }
129
+ if (! $prodName ) { throw " ProjectSettings is missing productName" }
130
130
131
131
$this.Path = $path
132
132
$this.Version = $fileVersion
@@ -144,7 +144,7 @@ class UnityVersion : System.IComparable {
144
144
145
145
[string ] ToString() {
146
146
$result = " $ ( $this.Major ) .$ ( $this.Minor ) .$ ( $this.Revision ) $ ( $this.Release ) $ ( $this.Build ) "
147
- if ( $this.Suffix ) { $result += " -$ ( $this.Suffix ) " }
147
+ if ( $this.Suffix ) { $result += " -$ ( $this.Suffix ) " }
148
148
return $result
149
149
}
150
150
@@ -166,7 +166,7 @@ class UnityVersion : System.IComparable {
166
166
167
167
[int ] CompareTo([object ]$obj ) {
168
168
if ($null -eq $obj ) { return 1 }
169
- if ($obj -isnot [UnityVersion ]) { throw " Object is not a UnityVersion" }
169
+ if ($obj -isnot [UnityVersion ]) { throw " Object is not a UnityVersion" }
170
170
171
171
return [UnityVersion ]::Compare($this , $obj )
172
172
}
@@ -245,7 +245,7 @@ function Get-OperatingSystem {
245
245
function Get-UnityEditor {
246
246
[CmdletBinding ()]
247
247
param (
248
- [ValidateScript ( {Test-Path $_ - PathType Container} )]
248
+ [ValidateScript ( { Test-Path $_ - PathType Container } )]
249
249
[Parameter (Mandatory = $false , ValueFromPipeline = $true , Position = 0 , ParameterSetName = " Path" )]
250
250
[string []]$Path = $PWD ,
251
251
@@ -426,27 +426,30 @@ function Find-UnitySetupInstaller {
426
426
$searchPages += $patchPage
427
427
428
428
$webResult = Invoke-WebRequest $patchPage - UseBasicParsing
429
- $searchPages += $webResult.Links | Where-Object {
430
- $_.href -match " \/unity\/qa\/patch-releases\?version=$ ( $Version.Major ) \.$ ( $Version.Minor ) &page=(\d+)" -and $Matches [1 ] -gt 1
431
- } | ForEach-Object { " https://unity3d.com$ ( $_.href ) " }
429
+ $searchPages += $webResult.Links |
430
+ Where-Object { $_.href -match " \/unity\/qa\/patch-releases\?version=$ ( $Version.Major ) \.$ ( $Version.Minor ) &page=(\d+)" -and $Matches [1 ] -gt 1 } |
431
+ ForEach-Object { " https://unity3d.com$ ( $_.href ) " }
432
432
}
433
433
}
434
434
435
435
foreach ($page in $searchPages ) {
436
436
try {
437
437
$webResult = Invoke-WebRequest $page - UseBasicParsing
438
- $prototypeLink = $webResult.Links | Select-Object - ExpandProperty href - ErrorAction SilentlyContinue | Where-Object {
439
- $link = $_
440
-
441
- foreach ( $installer in $installerTemplates.Keys ) {
442
- foreach ( $template in $installerTemplates [$installer ] ) {
443
- if ( $link -like " *$template *" ) { return $true }
438
+ $prototypeLink = $webResult.Links |
439
+ Select-Object - ExpandProperty href - ErrorAction SilentlyContinue |
440
+ Where-Object {
441
+ $link = $_
442
+
443
+ foreach ( $installer in $installerTemplates.Keys ) {
444
+ foreach ( $template in $installerTemplates [$installer ] ) {
445
+ if ( $link -like " *$template *" ) { return $true }
446
+ }
444
447
}
445
- }
446
448
447
- return $false
449
+ return $false
448
450
449
- } | Select-Object - First 1
451
+ } |
452
+ Select-Object - First 1
450
453
451
454
if ($null -ne $prototypeLink ) { break }
452
455
}
@@ -465,10 +468,10 @@ function Find-UnitySetupInstaller {
465
468
$knownBaseUrls = $linkComponents [0 ], $knownBaseUrls
466
469
}
467
470
else {
468
- $knownBaseUrls = $knownBaseUrls | Sort-Object - Property @ { Expression = {[math ]::Abs(($_.CompareTo ($linkComponents [0 ])))}; Ascending = $true }
471
+ $knownBaseUrls = $knownBaseUrls | Sort-Object - Property @ { Expression = { [math ]::Abs(($_.CompareTo ($linkComponents [0 ]))) }; Ascending = $true }
469
472
}
470
473
471
- $installerTemplates.Keys | Where-Object { $Components -band $_ } | ForEach-Object {
474
+ $installerTemplates.Keys | Where-Object { $Components -band $_ } | ForEach-Object {
472
475
$templates = $installerTemplates.Item ($_ );
473
476
$result = $null
474
477
foreach ($template in $templates ) {
@@ -679,7 +682,7 @@ function Request-UnitySetupInstaller {
679
682
$downloads = @ ()
680
683
681
684
try {
682
- $global :downloadData = [ordered ]@ {}
685
+ $global :downloadData = [ordered ]@ { }
683
686
$downloadIndex = 1
684
687
685
688
$allInstallers | ForEach-Object {
@@ -934,7 +937,7 @@ function Install-UnitySetupInstance {
934
937
$defaultInstallPath = $BasePath
935
938
}
936
939
937
- $versionInstallers = @ {}
940
+ $versionInstallers = @ { }
938
941
}
939
942
process {
940
943
# Sort each installer received from the pipe into versions
@@ -1138,19 +1141,18 @@ function Get-UnitySetupInstance {
1138
1141
}
1139
1142
}
1140
1143
1141
-
1142
- $BasePath | Where-Object { Test-Path $_ - PathType Container } |
1143
- Get-ChildItem - Directory | Where-Object { (Get-UnityEditor $_.FullName ).Count -gt 0 } |
1144
+ Get-ChildItem - Path $BasePath - Directory - ErrorAction Ignore |
1145
+ Where-Object { (Get-UnityEditor $_.FullName ).Count -gt 0 } |
1144
1146
ForEach-Object {
1145
- $path = $_.FullName
1146
- try {
1147
- Write-Verbose " Creating UnitySetupInstance for $path "
1148
- [UnitySetupInstance ]::new($path )
1149
- }
1150
- catch {
1151
- Write-Warning " $_ "
1147
+ $path = $_.FullName
1148
+ try {
1149
+ Write-Verbose " Creating UnitySetupInstance for $path "
1150
+ [UnitySetupInstance ]::new($path )
1151
+ }
1152
+ catch {
1153
+ Write-Warning " $_ "
1154
+ }
1152
1155
}
1153
- }
1154
1156
}
1155
1157
1156
1158
<#
@@ -1170,13 +1172,14 @@ function Get-UnitySetupInstanceVersion {
1170
1172
[CmdletBinding ()]
1171
1173
param (
1172
1174
[ValidateNotNullOrEmpty ()]
1173
- [ValidateScript ( {Test-Path $_ - PathType Container})]
1175
+ [ValidateScript ( { Test-Path $_ - PathType Container })]
1174
1176
[Parameter (Mandatory = $true , Position = 0 )]
1175
1177
[string ]$Path
1176
1178
)
1177
1179
1178
1180
Write-Verbose " Attempting to find UnityVersion in $path "
1179
1181
1182
+ # Try to look in the modules.json file for installer paths that contain version info
1180
1183
if ( Test-Path " $path \modules.json" - PathType Leaf ) {
1181
1184
1182
1185
Write-Verbose " Searching $path \modules.json for module versions"
@@ -1191,9 +1194,10 @@ function Get-UnitySetupInstanceVersion {
1191
1194
}
1192
1195
}
1193
1196
1197
+ # No version found, start digging deeper
1194
1198
if ( Test-Path " $path \Editor" - PathType Container ) {
1195
- # We'll attempt to search for the version using the ivy.xml definitions for legacy editor compatibility.
1196
-
1199
+
1200
+ # Search for the version using the ivy.xml definitions for legacy editor compatibility.
1197
1201
Write-Verbose " Looking for ivy.xml files under $path \Editor\"
1198
1202
$ivyFiles = Get-ChildItem - Path " $path \Editor\" - Filter ' ivy.xml' - Recurse - ErrorAction SilentlyContinue - Force - File
1199
1203
foreach ( $ivy in $ivyFiles ) {
@@ -1203,11 +1207,22 @@ function Get-UnitySetupInstanceVersion {
1203
1207
1204
1208
[xml ]$xmlDoc = Get-Content $ivy.FullName
1205
1209
1206
- [string ]$version = $xmlDoc .' ivy-module' .info.unityVersion
1207
- if ( -not $version ) { continue ; }
1210
+ [string ]$ivyVersion = $xmlDoc .' ivy-module' .info.unityVersion
1211
+ if ( -not $ivyVersion ) { continue ; }
1212
+
1213
+ Write-Verbose " `t Found version!"
1214
+ return [UnityVersion ]$ivyVersion
1215
+ }
1216
+
1217
+ # Search through any header files which might define the unity version
1218
+ Write-Verbose " Looking for .h files with UNITY_VERSION defined under $path \Editor\ "
1219
+ $headerMatchInfo = Get-ChildItem - Path " $path \Editor\*.h" - Recurse - ErrorAction Ignore - Force - File |
1220
+ Select-String - Pattern " UNITY_VERSION\s`" (\d+\.\d+\.\d+[fpba]\d+)`" " |
1221
+ Select-Object - First 1
1208
1222
1223
+ if ( $headerMatchInfo.Matches.Groups.Count -gt 1 ) {
1209
1224
Write-Verbose " `t Found version!"
1210
- return [UnityVersion ]$version
1225
+ return [UnityVersion ]( $headerMatchInfo .Matches.Groups [ 1 ].Value)
1211
1226
}
1212
1227
}
1213
1228
}
@@ -1309,11 +1324,11 @@ function Get-UnityProjectInstance {
1309
1324
1310
1325
Get-ChildItem @args |
1311
1326
ForEach-Object {
1312
- $path = [io.path ]::Combine($_.FullName , " ProjectVersion.txt" )
1313
- if ( Test-Path $path ) {
1314
- [UnityProjectInstance ]::new((Join-Path $_.FullName " ..\" | Convert-Path ))
1327
+ $path = [io.path ]::Combine($_.FullName , " ProjectVersion.txt" )
1328
+ if ( Test-Path $path ) {
1329
+ [UnityProjectInstance ]::new((Join-Path $_.FullName " ..\" | Convert-Path ))
1330
+ }
1315
1331
}
1316
- }
1317
1332
}
1318
1333
1319
1334
<#
@@ -1594,8 +1609,8 @@ function Start-UnityEditor {
1594
1609
if ( $instanceArgs [$i ] ) { $unityArgs += $instanceArgs [$i ] }
1595
1610
1596
1611
$actionString = " $editor $unityArgs "
1597
- if ( $Credential ) { $actionString += " -password (hidden)" }
1598
- if ( $Serial ) { $actionString += " -serial (hidden)" }
1612
+ if ( $Credential ) { $actionString += " -password (hidden)" }
1613
+ if ( $Serial ) { $actionString += " -serial (hidden)" }
1599
1614
1600
1615
if (-not $PSCmdlet.ShouldProcess ($actionString , " System.Diagnostics.Process.Start()" )) {
1601
1616
continue
0 commit comments