@@ -49,24 +49,11 @@ class UnitySetupInstance {
49
49
[string ]$Path
50
50
51
51
UnitySetupInstance([string ]$path ) {
52
-
53
52
$currentOS = Get-OperatingSystem
54
- $ivyPath = switch ($currentOS ) {
55
- ([OperatingSystem ]::Windows) { ' Editor\Data\UnityExtensions\Unity\Networking\ivy.xml' }
56
- ([OperatingSystem ]::Linux) { throw " UnitySetupInstance has not been implemented on the Linux platform. Contributions welcomed!" ; }
57
- ([OperatingSystem ]::Mac) { ' Unity.app/Contents/UnityExtensions/Unity/Networking/ivy.xml' }
58
- }
59
-
60
- $ivyPath = [io.path ]::Combine(" $path " , $ivyPath );
61
- if (! (Test-Path $ivyPath )) { throw " Path is not a Unity setup: $path " }
62
- [xml ]$xmlDoc = Get-Content $ivyPath
63
-
64
- if ( ! ($xmlDoc .' ivy-module' .info.unityVersion)) {
65
- throw " Unity setup ivy is missing version: $ivyPath "
66
- }
67
53
68
54
$this.Path = $path
69
- $this.Version = $xmlDoc .' ivy-module' .info.unityVersion
55
+ $this.Version = Get-UnitySetupInstanceVersion - Path $path
56
+ if ( -not $this.Version ) { throw " Unable to find version for $path " }
70
57
71
58
$playbackEnginePath = $null
72
59
$componentTests = switch ($currentOS ) {
@@ -897,8 +884,6 @@ function Install-UnitySetupInstance {
897
884
$defaultInstallPath = $BasePath
898
885
}
899
886
900
- $unitySetupInstances = Get-UnitySetupInstance - BasePath $BasePath
901
-
902
887
$versionInstallers = @ {}
903
888
}
904
889
process {
@@ -983,7 +968,7 @@ function Install-UnitySetupInstance {
983
968
984
969
$editorInstaller = $installerPaths | Where-Object { $_.ComponentType -band $editorComponent }
985
970
if ($null -ne $editorInstaller ) {
986
- Write-Verbose " Installing $ ( $editorInstaller.ComponentType ) "
971
+ Write-Verbose " Installing $ ( $editorInstaller.ComponentType ) Editor "
987
972
Install-UnitySetupPackage - Package $editorInstaller - Destination $packageDestination
988
973
}
989
974
@@ -1092,7 +1077,6 @@ function Get-UnitySetupInstance {
1092
1077
if (-not $BasePath ) {
1093
1078
$BasePath = @ (' C:\Program Files*\Unity*' , ' C:\Program Files\Unity\Hub\Editor\*' )
1094
1079
}
1095
- $ivyPath = ' Editor\Data\UnityExtensions\Unity\Networking\ivy.xml'
1096
1080
}
1097
1081
([OperatingSystem ]::Linux) {
1098
1082
throw " Get-UnitySetupInstance has not been implemented on the Linux platform. Contributions welcomed!" ;
@@ -1101,16 +1085,78 @@ function Get-UnitySetupInstance {
1101
1085
if (-not $BasePath ) {
1102
1086
$BasePath = @ (' /Applications/Unity*' , ' /Applications/Unity/Hub/Editor/*' )
1103
1087
}
1104
- $ivyPath = ' Unity.app/Contents/UnityExtensions/Unity/Networking/ivy.xml'
1105
1088
}
1106
1089
}
1107
1090
1108
- foreach ( $folder in $BasePath ) {
1109
- $path = [io.path ]::Combine(" $folder " , $ivyPath );
1091
+ Get-ChildItem $BasePath - Directory | Where-Object {
1092
+ Test-Path (Join-Path $_.FullName ' Editor\Unity.exe' ) - PathType Leaf
1093
+ } | ForEach-Object {
1094
+ $path = $_.FullName
1095
+ try {
1096
+ Write-Verbose " Creating UnitySetupInstance for $path "
1097
+ [UnitySetupInstance ]::new($path )
1098
+ }
1099
+ catch {
1100
+ Write-Warning " $_ "
1101
+ }
1102
+ }
1103
+ }
1104
+
1105
+ <#
1106
+ . Synopsis
1107
+ Gets the UnityVersion for a UnitySetupInstance at Path
1108
+ . DESCRIPTION
1109
+ Given a set of unity setup instances, this will select the best one matching your requirements
1110
+ . PARAMETER Path
1111
+ Path to a UnitySetupInstance
1112
+ . OUTPUTS
1113
+ UnityVersion
1114
+ Returns the UnityVersion for the UnitySetupInstance at Path, or nothing if there isn't one
1115
+ . EXAMPLE
1116
+ Get-UnitySetupInstanceVersion -Path 'C:\Program Files\Unity'
1117
+ #>
1118
+ function Get-UnitySetupInstanceVersion {
1119
+ [CmdletBinding ()]
1120
+ param (
1121
+ [ValidateNotNullOrEmpty ()]
1122
+ [ValidateScript ( {Test-Path $_ - PathType Container})]
1123
+ [Parameter (Mandatory = $true , Position = 0 )]
1124
+ [string ]$Path
1125
+ )
1126
+
1127
+ Write-Verbose " Attempting to find UnityVersion in $path "
1128
+
1129
+ if ( Test-Path " $path \modules.json" - PathType Leaf ) {
1130
+
1131
+ Write-Verbose " Searching $path \modules.json for module versions"
1132
+ $modules = (Get-Content " $path \modules.json" - Raw) | ConvertFrom-Json
1133
+
1134
+ foreach ( $module in $modules ) {
1135
+ Write-Verbose " `t Testing DownloadUrl $ ( $module.DownloadUrl ) "
1136
+ if ( $module.DownloadUrl -notmatch " (\d+)\.(\d+)\.(\d+)([fpab])(\d+)" ) { continue ; }
1137
+
1138
+ Write-Verbose " `t Found version!"
1139
+ return [UnityVersion ]$Matches [0 ]
1140
+ }
1141
+ }
1142
+
1143
+ if ( Test-Path " $path \Editor" - PathType Container ) {
1144
+ # We'll attempt to search for the version using the ivy.xml definitions for legacy editor compatibility.
1145
+
1146
+ Write-Verbose " Looking for ivy.xml files under $path \Editor\"
1147
+ $ivyFiles = Get-ChildItem - Path " $path \Editor\" - Filter ' ivy.xml' - Recurse - ErrorAction SilentlyContinue - Force - File
1148
+ foreach ( $ivy in $ivyFiles ) {
1149
+ if ( $null -eq $ivy ) { continue ; }
1150
+
1151
+ Write-Verbose " `t Looking for version in $ ( $ivy.FullName ) "
1152
+
1153
+ [xml ]$xmlDoc = Get-Content $ivy.FullName
1154
+
1155
+ [string ]$version = $xmlDoc .' ivy-module' .info.unityVersion
1156
+ if ( -not $version ) { continue ; }
1110
1157
1111
- Get-ChildItem $path - Recurse - ErrorAction Ignore |
1112
- ForEach-Object {
1113
- [UnitySetupInstance ]::new((Join-Path $_.Directory " ..\..\..\..\..\" | Convert-Path ))
1158
+ Write-Verbose " `t Found version!"
1159
+ return [UnityVersion ]$version
1114
1160
}
1115
1161
}
1116
1162
}
0 commit comments