Skip to content

Commit 0505144

Browse files
authored
Merge pull request #228 from jwittner/dev/improveSetupSearchSpeed
Performance enhancements for Get-UnitySetupInstance
2 parents 782e8a7 + f6f807f commit 0505144

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

UnitySetup/UnitySetup.psm1

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,10 +1265,24 @@ function Get-UnitySetupInstanceVersion {
12651265
}
12661266

12671267
# Search through any header files which might define the unity version
1268-
Write-Verbose "Looking for .h files with UNITY_VERSION defined under $path\Editor\ "
1269-
$headerMatchInfo = Get-ChildItem -Path "$path\Editor\*.h" -Recurse -ErrorAction Ignore -Force -File |
1270-
Select-String -Pattern "UNITY_VERSION\s`"(\d+\.\d+\.\d+[fpba]\d+)`"" |
1271-
Select-Object -First 1
1268+
[string[]]$knownHeaders = @(
1269+
"$path\Editor\Data\PlaybackEngines\windowsstandalonesupport\Source\WindowsPlayer\WindowsPlayer\UnityConfigureVersion.gen.h"
1270+
)
1271+
foreach ($header in $knownHeaders) {
1272+
Write-Verbose "Looking for UNITY_VERSION defined in $header"
1273+
if (Test-Path -PathType Leaf -Path $header) {
1274+
$headerMatchInfo = Select-String -Path $header -Pattern "UNITY_VERSION\s`"(\d+\.\d+\.\d+[fpba]\d+)`""
1275+
}
1276+
}
1277+
1278+
if ($null -eq $headerMatchInfo) {
1279+
Write-Verbose "Looking for .h files with UNITY_VERSION defined under $path\Editor\ "
1280+
$headerMatchInfo = do {
1281+
Get-ChildItem -Path "$path\Editor\*.h" -Recurse -ErrorAction Ignore -Force -File |
1282+
Select-String -Pattern "UNITY_VERSION\s`"(\d+\.\d+\.\d+[fpba]\d+)`"" |
1283+
ForEach-Object { $_; break; } # Stop the pipeline after the first result
1284+
} while ($false);
1285+
}
12721286

12731287
if ( $headerMatchInfo.Matches.Groups.Count -gt 1 ) {
12741288
Write-Verbose "`tFound version!"

0 commit comments

Comments
 (0)