@@ -50,42 +50,10 @@ class UnitySetupInstance {
50
50
51
51
UnitySetupInstance([string ]$path ) {
52
52
$currentOS = Get-OperatingSystem
53
- $foundVersion = $false
54
-
55
- Write-Verbose " Attempting to get Unity Setup Instance at $path "
56
-
57
- if ( Test-Path " $path \modules.json" ) {
58
-
59
- $modules = (Get-Content " $path \modules.json" - Raw) | ConvertFrom-Json
60
-
61
- foreach ( $module in $modules ) {
62
- Write-Verbose " Found module $ ( $module.id ) "
63
- Write-Verbose " Download Url $ ( $module.DownloadUrl ) "
64
-
65
- if ( $module.DownloadUrl -match " (\d+)\.(\d+)\.(\d+)([fpab])(\d+)" ) {
66
- $this.Version = [UnityVersion ]$Matches [0 ]
67
- $foundVersion = $true
68
- Write-Verbose " Found $ ( $this.Version ) "
69
- break
70
- }
71
- }
72
- }
73
- else {
74
- # We'll attempt to search for the version using the ivy.xml definitions for legacy editor compatibility.
75
- $ivy = Get-ChildItem - Path $path - Filter ivy.xml - Recurse - ErrorAction SilentlyContinue - Force | Select-Object - First 1
76
-
77
- if ( $null -ne $ivy ) {
78
- [xml ]$xmlDoc = Get-Content $ivy.FullName
79
- $this.Version = [UnityVersion ]$xmlDoc .' ivy-module' .info.unityVersion
80
- $foundVersion = $true
81
- }
82
- }
83
-
84
- if ( $foundVersion -eq $false ) {
85
- throw " Failed to find a valid version identifier for installation at $path !" ;
86
- }
87
53
88
54
$this.Path = $path
55
+ $this.Version = Get-UnitySetupInstanceVersion - Path $path
56
+ if ( -not $this.Version ) { throw " Unable to find version for $path " }
89
57
90
58
$playbackEnginePath = $null
91
59
$componentTests = switch ($currentOS ) {
@@ -903,8 +871,6 @@ function Install-UnitySetupInstance {
903
871
$defaultInstallPath = $BasePath
904
872
}
905
873
906
- $unitySetupInstances = Get-UnitySetupInstance - BasePath $BasePath
907
-
908
874
$versionInstallers = @ {}
909
875
}
910
876
process {
@@ -1109,16 +1075,79 @@ function Get-UnitySetupInstance {
1109
1075
}
1110
1076
}
1111
1077
1112
- $searchPaths = Get-ChildItem $BasePath - Directory
1113
- $setupInstances = [UnitySetupInstance []]@ ()
1114
-
1115
- foreach ( $path in $searchPaths ) {
1116
- if ( $path -match " (\d+)\.(\d+)\.(\d+)([fpab])(\d+)" ) {
1117
- $setupInstances += , [UnitySetupInstance ]::new($path )
1078
+ $results = Get-ChildItem $BasePath - Directory | Where-Object {
1079
+ Test-Path (Join-Path $_.FullName ' Editor\Unity.exe' ) - PathType Leaf
1080
+ } | ForEach-Object {
1081
+ $path = $_.FullName
1082
+ try {
1083
+ Write-Verbose " Creating UnitySetupInstance for $path "
1084
+ [UnitySetupInstance ]::new($path )
1085
+ }
1086
+ catch {
1087
+ Write-Warning " $_ "
1118
1088
}
1119
1089
}
1120
1090
1121
- return $setupInstances
1091
+ $results
1092
+ }
1093
+
1094
+ <#
1095
+ . Synopsis
1096
+ Gets the UnityVersion for a UnitySetupInstance at Path
1097
+ . DESCRIPTION
1098
+ Given a set of unity setup instances, this will select the best one matching your requirements
1099
+ . PARAMETER Path
1100
+ Path to a UnitySetupInstance
1101
+ . OUTPUTS
1102
+ UnityVersion
1103
+ Returns the UnityVersion for the UnitySetupInstance at Path, or nothing if there isn't one
1104
+ . EXAMPLE
1105
+ Get-UnitySetupInstanceVersion -Path 'C:\Program Files\Unity'
1106
+ #>
1107
+ function Get-UnitySetupInstanceVersion {
1108
+ [CmdletBinding ()]
1109
+ param (
1110
+ [ValidateNotNullOrEmpty ()]
1111
+ [ValidateScript ( {Test-Path $_ - PathType Container})]
1112
+ [Parameter (Mandatory = $true , Position = 0 )]
1113
+ [string ]$Path
1114
+ )
1115
+
1116
+ Write-Verbose " Attempting to find UnityVersion in $path "
1117
+
1118
+ if ( Test-Path " $path \modules.json" - PathType Leaf ) {
1119
+
1120
+ Write-Verbose " Searching $path \modules.json for module versions"
1121
+ $modules = (Get-Content " $path \modules.json" - Raw) | ConvertFrom-Json
1122
+
1123
+ foreach ( $module in $modules ) {
1124
+ Write-Verbose " `t Testing DownloadUrl $ ( $module.DownloadUrl ) "
1125
+ if ( $module.DownloadUrl -notmatch " (\d+)\.(\d+)\.(\d+)([fpab])(\d+)" ) { continue ; }
1126
+
1127
+ Write-Verbose " `t Found version!"
1128
+ return [UnityVersion ]$Matches [0 ]
1129
+ }
1130
+ }
1131
+
1132
+ if ( Test-Path " $path \Editor" - PathType Container ) {
1133
+ # We'll attempt to search for the version using the ivy.xml definitions for legacy editor compatibility.
1134
+
1135
+ Write-Verbose " Looking for ivy.xml files under $path \Editor\"
1136
+ $ivyFiles = Get-ChildItem - Path " $path \Editor\" - Filter ' ivy.xml' - Recurse - ErrorAction SilentlyContinue - Force - File
1137
+ foreach ( $ivy in $ivyFiles ) {
1138
+ if ( $null -eq $ivy ) { continue ; }
1139
+
1140
+ Write-Verbose " `t Looking for version in $ ( $ivy.FullName ) "
1141
+
1142
+ [xml ]$xmlDoc = Get-Content $ivy.FullName
1143
+
1144
+ [string ]$version = $xmlDoc .' ivy-module' .info.unityVersion
1145
+ if ( -not $version ) { continue ; }
1146
+
1147
+ Write-Verbose " `t Found version!"
1148
+ return [UnityVersion ]$version
1149
+ }
1150
+ }
1122
1151
}
1123
1152
1124
1153
<#
0 commit comments