@@ -49,21 +49,31 @@ class UnitySetupInstance {
49
49
[string ]$Path
50
50
51
51
UnitySetupInstance([string ]$path ) {
52
-
53
52
$currentOS = Get-OperatingSystem
54
- $executable = switch ($currentOS ) {
55
- ([OperatingSystem ]::Windows) { ' Editor\Unity.exe' }
56
- ([OperatingSystem ]::Linux) { throw " UnitySetupInstance has not been implemented on the Linux platform. Contributions welcomed!" ; }
57
- ([OperatingSystem ]::Mac) { ' Unity.app/Contents/MacOS/Unity/Unity.exe' } # TODO Validate path
53
+
54
+ # First we'll attempt to search for the version using the ivy.xml definitions for legacy editor compatibility.
55
+ $ivy = Get-ChildItem - Path $path - Filter ivy.xml - Recurse - ErrorAction SilentlyContinue - Force | Select-Object - First 1
56
+ $version = $null
57
+
58
+ if ( Test-Path $ivy.FullName ){
59
+ [xml ]$xmlDoc = Get-Content $ivy.FullName
60
+ $version = $xmlDoc .' ivy-module' .info.unityVersion
58
61
}
62
+ else {
63
+ # No ivy files found, so search the new modules.json for the version
64
+ $modules = (Get-Content " $path \modules.json" - Raw) | ConvertFrom-Json
59
65
60
- $executable = [io.path ]::Combine(" $path " , $executable );
61
- if (! (Test-Path $executable )) { throw " Path is not a Unity setup: $path " }
66
+ foreach ( $module in $modules ) {
67
+ $module.DownloadUrl -match " (\d+)\.(\d+)\.(\d+)([fpb])(\d+)" | Out-Null
68
+ if ( $Matches [0 ] -ne $null ){
69
+ $version = $Matches [0 ]
70
+ break
71
+ }
72
+ }
73
+ }
62
74
63
- $version = switch ($currentOS ) {
64
- ([OperatingSystem ]::Windows) { Split-Path (Split-Path - Path $executable - Parent | Split-Path - Parent) - Leaf }
65
- ([OperatingSystem ]::Linux) { throw " UnitySetupInstance has not been implemented on the Linux platform. Contributions welcomed!" ; }
66
- ([OperatingSystem ]::Mac) { ??? }
75
+ if ( $version -eq $null ) {
76
+ throw " Failed to find a valid installation at $path !" ;
67
77
}
68
78
69
79
$this.Path = $path
0 commit comments