Skip to content

Commit a9afbc3

Browse files
recursively search for legacy ivy.xml files, and then modules.json as a fallback for unity version
1 parent 6d48640 commit a9afbc3

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

UnitySetup/UnitySetup.psm1

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,31 @@ class UnitySetupInstance {
4949
[string]$Path
5050

5151
UnitySetupInstance([string]$path) {
52-
5352
$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
5861
}
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
5965

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+
}
6274

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!";
6777
}
6878

6979
$this.Path = $path

0 commit comments

Comments
 (0)