Skip to content

Commit 13d017c

Browse files
committed
Search header files for UNITY_VERSION, support 2019.2
1 parent 31a3618 commit 13d017c

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

UnitySetup/UnitySetup.psm1

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,7 @@ function Get-UnitySetupInstanceVersion {
11771177

11781178
Write-Verbose "Attempting to find UnityVersion in $path"
11791179

1180+
# Try to look in the modules.json file for installer paths that contain version info
11801181
if ( Test-Path "$path\modules.json" -PathType Leaf ) {
11811182

11821183
Write-Verbose "Searching $path\modules.json for module versions"
@@ -1191,9 +1192,10 @@ function Get-UnitySetupInstanceVersion {
11911192
}
11921193
}
11931194

1195+
# No version found, start digging deeper
11941196
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-
1197+
1198+
# Search for the version using the ivy.xml definitions for legacy editor compatibility.
11971199
Write-Verbose "Looking for ivy.xml files under $path\Editor\"
11981200
$ivyFiles = Get-ChildItem -Path "$path\Editor\" -Filter 'ivy.xml' -Recurse -ErrorAction SilentlyContinue -Force -File
11991201
foreach ( $ivy in $ivyFiles) {
@@ -1203,11 +1205,22 @@ function Get-UnitySetupInstanceVersion {
12031205

12041206
[xml]$xmlDoc = Get-Content $ivy.FullName
12051207

1206-
[string]$version = $xmlDoc.'ivy-module'.info.unityVersion
1207-
if ( -not $version ) { continue; }
1208+
[string]$ivyVersion = $xmlDoc.'ivy-module'.info.unityVersion
1209+
if ( -not $ivyVersion ) { continue; }
1210+
1211+
Write-Verbose "`tFound version!"
1212+
return [UnityVersion]$ivyVersion
1213+
}
1214+
1215+
# Search through any header files which might define the unity version
1216+
Write-Verbose "Looking for .h files with UNITY_VERSION defined under $path\Editor\ "
1217+
$headerMatchInfo = Get-ChildItem -Path "$path\Editor\*.h" -Recurse -ErrorAction Ignore -Force -File |
1218+
Select-String -Pattern "UNITY_VERSION\s`"(\d+\.\d+\.\d+[fpba]\d+)`"" |
1219+
Select-Object -First 1
12081220

1221+
if ( $headerMatchInfo.Matches.Groups.Count -gt 1 ) {
12091222
Write-Verbose "`tFound version!"
1210-
return [UnityVersion]$version
1223+
return [UnityVersion]($headerMatchInfo.Matches.Groups[1].Value)
12111224
}
12121225
}
12131226
}

0 commit comments

Comments
 (0)