From 1edea460c080afab0c5692dab6dc3abe613af376 Mon Sep 17 00:00:00 2001 From: StephenHodgson Date: Thu, 18 Apr 2019 21:59:25 -0700 Subject: [PATCH 01/19] Updated the UnitySetupInstance to search for the executable path and validate the version that way. --- UnitySetup/UnitySetup.psm1 | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 4f83a9f..8169b47 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -51,22 +51,23 @@ class UnitySetupInstance { UnitySetupInstance([string]$path) { $currentOS = Get-OperatingSystem - $ivyPath = switch ($currentOS) { - ([OperatingSystem]::Windows) { 'Editor\Data\UnityExtensions\Unity\Networking\ivy.xml' } + $executable = switch ($currentOS) { + ([OperatingSystem]::Windows) { 'Editor\Unity.exe' } ([OperatingSystem]::Linux) { throw "UnitySetupInstance has not been implemented on the Linux platform. Contributions welcomed!"; } - ([OperatingSystem]::Mac) { 'Unity.app/Contents/UnityExtensions/Unity/Networking/ivy.xml' } + ([OperatingSystem]::Mac) { 'Unity.app/Contents/MacOS/Unity/Unity.exe' } # TODO Validate path } - $ivyPath = [io.path]::Combine("$path", $ivyPath); - if (!(Test-Path $ivyPath)) { throw "Path is not a Unity setup: $path"} - [xml]$xmlDoc = Get-Content $ivyPath + $executable = [io.path]::Combine("$path", $executable); + if (!(Test-Path $executable)) { throw "Path is not a Unity setup: $path"} - if ( !($xmlDoc.'ivy-module'.info.unityVersion)) { - throw "Unity setup ivy is missing version: $ivyPath" + $version = switch($currentOS) { + ([OperatingSystem]::Windows) { Split-Path (Split-Path -Path $executable -Parent | Split-Path -Parent) -Leaf } + ([OperatingSystem]::Linux) { throw "UnitySetupInstance has not been implemented on the Linux platform. Contributions welcomed!"; } + ([OperatingSystem]::Mac) { ??? } } $this.Path = $path - $this.Version = $xmlDoc.'ivy-module'.info.unityVersion + $this.Version = $version $playbackEnginePath = $null $componentTests = switch ($currentOS) { @@ -970,7 +971,7 @@ function Install-UnitySetupInstance { $editorInstaller = $installerPaths | Where-Object { $_.ComponentType -band $editorComponent } if ($null -ne $editorInstaller) { - Write-Verbose "Installing $($editorInstaller.ComponentType)" + Write-Verbose "Installing $($editorInstaller.ComponentType) Editor" Install-UnitySetupPackage -Package $editorInstaller -Destination $packageDestination } From a9afbc3dc3dbfad4339e897e982a1465c0cbc011 Mon Sep 17 00:00:00 2001 From: StephenHodgson Date: Sat, 20 Apr 2019 10:07:07 -0700 Subject: [PATCH 02/19] recursively search for legacy ivy.xml files, and then modules.json as a fallback for unity version --- UnitySetup/UnitySetup.psm1 | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 1ab154f..76d5f8b 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -49,21 +49,31 @@ class UnitySetupInstance { [string]$Path UnitySetupInstance([string]$path) { - $currentOS = Get-OperatingSystem - $executable = switch ($currentOS) { - ([OperatingSystem]::Windows) { 'Editor\Unity.exe' } - ([OperatingSystem]::Linux) { throw "UnitySetupInstance has not been implemented on the Linux platform. Contributions welcomed!"; } - ([OperatingSystem]::Mac) { 'Unity.app/Contents/MacOS/Unity/Unity.exe' } # TODO Validate path + + # First we'll attempt to search for the version using the ivy.xml definitions for legacy editor compatibility. + $ivy = Get-ChildItem -Path $path -Filter ivy.xml -Recurse -ErrorAction SilentlyContinue -Force | Select-Object -First 1 + $version = $null + + if ( Test-Path $ivy.FullName ){ + [xml]$xmlDoc = Get-Content $ivy.FullName + $version = $xmlDoc.'ivy-module'.info.unityVersion } + else { + # No ivy files found, so search the new modules.json for the version + $modules = (Get-Content "$path\modules.json" -Raw) | ConvertFrom-Json - $executable = [io.path]::Combine("$path", $executable); - if (!(Test-Path $executable)) { throw "Path is not a Unity setup: $path"} + foreach ( $module in $modules ) { + $module.DownloadUrl -match "(\d+)\.(\d+)\.(\d+)([fpb])(\d+)" | Out-Null + if( $Matches[0] -ne $null ){ + $version = $Matches[0] + break + } + } + } - $version = switch($currentOS) { - ([OperatingSystem]::Windows) { Split-Path (Split-Path -Path $executable -Parent | Split-Path -Parent) -Leaf } - ([OperatingSystem]::Linux) { throw "UnitySetupInstance has not been implemented on the Linux platform. Contributions welcomed!"; } - ([OperatingSystem]::Mac) { ??? } + if ( $version -eq $null ) { + throw "Failed to find a valid installation at $path!"; } $this.Path = $path From 8c7fd7e32c41fe7d0e29254429cf9f281cd3f1e0 Mon Sep 17 00:00:00 2001 From: StephenHodgson Date: Sat, 20 Apr 2019 10:10:04 -0700 Subject: [PATCH 03/19] minor formatting changes --- UnitySetup/UnitySetup.psm1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 76d5f8b..dd05410 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -49,11 +49,11 @@ class UnitySetupInstance { [string]$Path UnitySetupInstance([string]$path) { + $version = $null $currentOS = Get-OperatingSystem # First we'll attempt to search for the version using the ivy.xml definitions for legacy editor compatibility. $ivy = Get-ChildItem -Path $path -Filter ivy.xml -Recurse -ErrorAction SilentlyContinue -Force | Select-Object -First 1 - $version = $null if ( Test-Path $ivy.FullName ){ [xml]$xmlDoc = Get-Content $ivy.FullName @@ -65,7 +65,8 @@ class UnitySetupInstance { foreach ( $module in $modules ) { $module.DownloadUrl -match "(\d+)\.(\d+)\.(\d+)([fpb])(\d+)" | Out-Null - if( $Matches[0] -ne $null ){ + + if ( $Matches[0] -ne $null ) { $version = $Matches[0] break } From 869b396ebeaf5f1ab96e677777ff1ce022d0916b Mon Sep 17 00:00:00 2001 From: StephenHodgson Date: Sat, 20 Apr 2019 10:12:22 -0700 Subject: [PATCH 04/19] even brackets need spaces --- UnitySetup/UnitySetup.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index dd05410..73e5c9b 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -55,7 +55,7 @@ class UnitySetupInstance { # First we'll attempt to search for the version using the ivy.xml definitions for legacy editor compatibility. $ivy = Get-ChildItem -Path $path -Filter ivy.xml -Recurse -ErrorAction SilentlyContinue -Force | Select-Object -First 1 - if ( Test-Path $ivy.FullName ){ + if ( Test-Path $ivy.FullName ) { [xml]$xmlDoc = Get-Content $ivy.FullName $version = $xmlDoc.'ivy-module'.info.unityVersion } From 48e4aab715923ac7876cbda97a51997933696a2f Mon Sep 17 00:00:00 2001 From: StephenHodgson Date: Sat, 20 Apr 2019 10:18:32 -0700 Subject: [PATCH 05/19] cast strings to unity versions and check match for null array --- UnitySetup/UnitySetup.psm1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 73e5c9b..90a8991 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -57,7 +57,7 @@ class UnitySetupInstance { if ( Test-Path $ivy.FullName ) { [xml]$xmlDoc = Get-Content $ivy.FullName - $version = $xmlDoc.'ivy-module'.info.unityVersion + $version = [UnityVersion]$xmlDoc.'ivy-module'.info.unityVersion } else { # No ivy files found, so search the new modules.json for the version @@ -66,8 +66,8 @@ class UnitySetupInstance { foreach ( $module in $modules ) { $module.DownloadUrl -match "(\d+)\.(\d+)\.(\d+)([fpb])(\d+)" | Out-Null - if ( $Matches[0] -ne $null ) { - $version = $Matches[0] + if ( $Matches -ne $null ) { + $version = [UnityVersion]$Matches[0] break } } From 342a15a070188975f14a88dd9f01fc42d2631580 Mon Sep 17 00:00:00 2001 From: StephenHodgson Date: Sat, 20 Apr 2019 11:03:11 -0700 Subject: [PATCH 06/19] search modules.json first as a recursive file search may be slower --- UnitySetup/UnitySetup.psm1 | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 90a8991..5843d37 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -52,15 +52,7 @@ class UnitySetupInstance { $version = $null $currentOS = Get-OperatingSystem - # First we'll attempt to search for the version using the ivy.xml definitions for legacy editor compatibility. - $ivy = Get-ChildItem -Path $path -Filter ivy.xml -Recurse -ErrorAction SilentlyContinue -Force | Select-Object -First 1 - - if ( Test-Path $ivy.FullName ) { - [xml]$xmlDoc = Get-Content $ivy.FullName - $version = [UnityVersion]$xmlDoc.'ivy-module'.info.unityVersion - } - else { - # No ivy files found, so search the new modules.json for the version + if ( Test-Path "$path\modules.json" ) { $modules = (Get-Content "$path\modules.json" -Raw) | ConvertFrom-Json foreach ( $module in $modules ) { @@ -72,6 +64,15 @@ class UnitySetupInstance { } } } + else { + # We'll attempt to search for the version using the ivy.xml definitions for legacy editor compatibility. + $ivy = Get-ChildItem -Path $path -Filter ivy.xml -Recurse -ErrorAction SilentlyContinue -Force | Select-Object -First 1 + + if ( Test-Path $ivy.FullName ) { + [xml]$xmlDoc = Get-Content $ivy.FullName + $version = [UnityVersion]$xmlDoc.'ivy-module'.info.unityVersion + } + } if ( $version -eq $null ) { throw "Failed to find a valid installation at $path!"; From cfd172179fc2bd70427f9d39b714df562eafdf01 Mon Sep 17 00:00:00 2001 From: StephenHodgson Date: Sat, 20 Apr 2019 15:03:35 -0700 Subject: [PATCH 07/19] updated Get-UnitySetupInstance to use the same modules.json and ivy.xml recursive search pattern --- UnitySetup/UnitySetup.psm1 | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 5843d37..01afd19 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -1092,7 +1092,6 @@ function Get-UnitySetupInstance { if (-not $BasePath) { $BasePath = @('C:\Program Files*\Unity*', 'C:\Program Files\Unity\Hub\Editor\*') } - $ivyPath = 'Editor\Data\UnityExtensions\Unity\Networking\ivy.xml' } ([OperatingSystem]::Linux) { throw "Get-UnitySetupInstance has not been implemented on the Linux platform. Contributions welcomed!"; @@ -1101,12 +1100,21 @@ function Get-UnitySetupInstance { if (-not $BasePath) { $BasePath = @('/Applications/Unity*', '/Applications/Unity/Hub/Editor/*') } - $ivyPath = 'Unity.app/Contents/UnityExtensions/Unity/Networking/ivy.xml' } } foreach ( $folder in $BasePath ) { - $path = [io.path]::Combine("$folder", $ivyPath); + + if ( Test-Path "$folder\modules.json" ) { + $path = $folder + } + else { + $ivy = Get-ChildItem -Path $folder -Filter ivy.xml -Recurse -ErrorAction SilentlyContinue -Force | Select-Object -First 1 + + if ( Test-Path $ivy.FullName ) { + $path = $ivy.FullName + } + } Get-ChildItem $path -Recurse -ErrorAction Ignore | ForEach-Object { From 183b28f8e3b77abb77b6d0be4ace360b9b1846b6 Mon Sep 17 00:00:00 2001 From: StephenHodgson Date: Sat, 20 Apr 2019 16:20:16 -0700 Subject: [PATCH 08/19] Filter out just the needed paths to get the setup instances --- UnitySetup/UnitySetup.psm1 | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 01afd19..8bd2115 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -1103,24 +1103,15 @@ function Get-UnitySetupInstance { } } - foreach ( $folder in $BasePath ) { + $searchPaths = Get-ChildItem $BasePath | Get-ChildItem | ForEach-Object { $_.Directory.FullName } + $searchPaths = $searchPaths | select -uniq + $setupInstances = [UnitySetupInstance[]]@() - if ( Test-Path "$folder\modules.json" ) { - $path = $folder - } - else { - $ivy = Get-ChildItem -Path $folder -Filter ivy.xml -Recurse -ErrorAction SilentlyContinue -Force | Select-Object -First 1 - - if ( Test-Path $ivy.FullName ) { - $path = $ivy.FullName - } - } - - Get-ChildItem $path -Recurse -ErrorAction Ignore | - ForEach-Object { - [UnitySetupInstance]::new((Join-Path $_.Directory "..\..\..\..\..\" | Convert-Path)) - } + foreach ( $path in $searchPaths ) { + $setupInstances += , [UnitySetupInstance]::new($path) } + + return $setupInstances } <# From e7ffdb4af0caee64ec177bb91095fda189691255 Mon Sep 17 00:00:00 2001 From: StephenHodgson Date: Mon, 22 Apr 2019 13:02:42 -0700 Subject: [PATCH 09/19] PR feedback --- UnitySetup/UnitySetup.psm1 | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 8bd2115..a9713bc 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -49,7 +49,6 @@ class UnitySetupInstance { [string]$Path UnitySetupInstance([string]$path) { - $version = $null $currentOS = Get-OperatingSystem if ( Test-Path "$path\modules.json" ) { @@ -59,7 +58,7 @@ class UnitySetupInstance { $module.DownloadUrl -match "(\d+)\.(\d+)\.(\d+)([fpb])(\d+)" | Out-Null if ( $Matches -ne $null ) { - $version = [UnityVersion]$Matches[0] + $this.Version = [UnityVersion]$Matches[0] break } } @@ -68,18 +67,17 @@ class UnitySetupInstance { # We'll attempt to search for the version using the ivy.xml definitions for legacy editor compatibility. $ivy = Get-ChildItem -Path $path -Filter ivy.xml -Recurse -ErrorAction SilentlyContinue -Force | Select-Object -First 1 - if ( Test-Path $ivy.FullName ) { + if ( $null -ne $ivy ) { [xml]$xmlDoc = Get-Content $ivy.FullName - $version = [UnityVersion]$xmlDoc.'ivy-module'.info.unityVersion + $this.Version = [UnityVersion]$xmlDoc.'ivy-module'.info.unityVersion } } if ( $version -eq $null ) { - throw "Failed to find a valid installation at $path!"; + throw "Failed to find a valid version identifier for installation at $path!"; } $this.Path = $path - $this.Version = $version $playbackEnginePath = $null $componentTests = switch ($currentOS) { @@ -1104,7 +1102,7 @@ function Get-UnitySetupInstance { } $searchPaths = Get-ChildItem $BasePath | Get-ChildItem | ForEach-Object { $_.Directory.FullName } - $searchPaths = $searchPaths | select -uniq + $searchPaths = $searchPaths | Select-Object -uniq $setupInstances = [UnitySetupInstance[]]@() foreach ( $path in $searchPaths ) { From f9a98c2f151037f2de2ef6769a2c62d606052727 Mon Sep 17 00:00:00 2001 From: StephenHodgson Date: Mon, 22 Apr 2019 13:11:13 -0700 Subject: [PATCH 10/19] check if version is valid --- UnitySetup/UnitySetup.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index a9713bc..23e3fdc 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -73,7 +73,7 @@ class UnitySetupInstance { } } - if ( $version -eq $null ) { + if ( -not $this.Version ) { throw "Failed to find a valid version identifier for installation at $path!"; } From b5e85bbec60c2fa5cc347faa5c53fb3ac1b9957f Mon Sep 17 00:00:00 2001 From: StephenHodgson Date: Mon, 22 Apr 2019 13:35:05 -0700 Subject: [PATCH 11/19] Don't use global match --- UnitySetup/UnitySetup.psm1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 23e3fdc..8fe9830 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -55,10 +55,10 @@ class UnitySetupInstance { $modules = (Get-Content "$path\modules.json" -Raw) | ConvertFrom-Json foreach ( $module in $modules ) { - $module.DownloadUrl -match "(\d+)\.(\d+)\.(\d+)([fpb])(\d+)" | Out-Null + $match = $module.DownloadUrl -match "(\d+)\.(\d+)\.(\d+)([fpb])(\d+)" | Out-Null - if ( $Matches -ne $null ) { - $this.Version = [UnityVersion]$Matches[0] + if ( $null -ne $match ) { + $this.Version = [UnityVersion]$match break } } From 1cff3ea4644608353c8f3a8d9acf176f5a9d5f98 Mon Sep 17 00:00:00 2001 From: Stephen Hodgson Date: Tue, 23 Apr 2019 13:10:12 -0700 Subject: [PATCH 12/19] Apply suggestions from code review --- UnitySetup/UnitySetup.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 8fe9830..dd25c2b 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -55,7 +55,7 @@ class UnitySetupInstance { $modules = (Get-Content "$path\modules.json" -Raw) | ConvertFrom-Json foreach ( $module in $modules ) { - $match = $module.DownloadUrl -match "(\d+)\.(\d+)\.(\d+)([fpb])(\d+)" | Out-Null + $match = $module.DownloadUrl -match "(\d+)\.(\d+)\.(\d+)([fpab])(\d+)" | Out-Null if ( $null -ne $match ) { $this.Version = [UnityVersion]$match @@ -73,7 +73,7 @@ class UnitySetupInstance { } } - if ( -not $this.Version ) { + if ( $this.Version -ne $null ) { throw "Failed to find a valid version identifier for installation at $path!"; } From 531fdaef2cd8a9a6d4fb4293a303ea89e7b5aa12 Mon Sep 17 00:00:00 2001 From: StephenHodgson Date: Tue, 23 Apr 2019 13:28:25 -0700 Subject: [PATCH 13/19] Simplified search paths --- UnitySetup/UnitySetup.psm1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index dd25c2b..b4083f3 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -1101,8 +1101,7 @@ function Get-UnitySetupInstance { } } - $searchPaths = Get-ChildItem $BasePath | Get-ChildItem | ForEach-Object { $_.Directory.FullName } - $searchPaths = $searchPaths | Select-Object -uniq + $searchPaths = Get-ChildItem $BasePath -Directory $setupInstances = [UnitySetupInstance[]]@() foreach ( $path in $searchPaths ) { From 64ac7974e53e85d6a42ac629a98ed4b05f7b3ddf Mon Sep 17 00:00:00 2001 From: StephenHodgson Date: Tue, 23 Apr 2019 14:21:41 -0700 Subject: [PATCH 14/19] filtered out Unity Hub path and better version found --- UnitySetup/UnitySetup.psm1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index b4083f3..9fa59f4 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -50,6 +50,7 @@ class UnitySetupInstance { UnitySetupInstance([string]$path) { $currentOS = Get-OperatingSystem + $foundVersion = $false if ( Test-Path "$path\modules.json" ) { $modules = (Get-Content "$path\modules.json" -Raw) | ConvertFrom-Json @@ -59,6 +60,7 @@ class UnitySetupInstance { if ( $null -ne $match ) { $this.Version = [UnityVersion]$match + $foundVersion = $true break } } @@ -70,10 +72,11 @@ class UnitySetupInstance { if ( $null -ne $ivy ) { [xml]$xmlDoc = Get-Content $ivy.FullName $this.Version = [UnityVersion]$xmlDoc.'ivy-module'.info.unityVersion + $foundVersion = $true } } - if ( $this.Version -ne $null ) { + if ( $foundVersion -eq $false ) { throw "Failed to find a valid version identifier for installation at $path!"; } @@ -1105,6 +1108,7 @@ function Get-UnitySetupInstance { $setupInstances = [UnitySetupInstance[]]@() foreach ( $path in $searchPaths ) { + if( $path -like '*Unity Hub*' ) { continue } $setupInstances += , [UnitySetupInstance]::new($path) } From 51d8d9432dad06dfaaa3de896c6f460cde93950e Mon Sep 17 00:00:00 2001 From: StephenHodgson Date: Tue, 23 Apr 2019 15:16:14 -0700 Subject: [PATCH 15/19] finalized matching in modules --- UnitySetup/UnitySetup.psm1 | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 9fa59f4..c9c1201 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -52,15 +52,20 @@ class UnitySetupInstance { $currentOS = Get-OperatingSystem $foundVersion = $false + Write-Verbose "Attempting to get Unity Setup Instance at $path" + if ( Test-Path "$path\modules.json" ) { + $modules = (Get-Content "$path\modules.json" -Raw) | ConvertFrom-Json foreach ( $module in $modules ) { - $match = $module.DownloadUrl -match "(\d+)\.(\d+)\.(\d+)([fpab])(\d+)" | Out-Null + Write-Verbose "Found module $($module.id)" + Write-Verbose "Download Url $($module.DownloadUrl)" - if ( $null -ne $match ) { - $this.Version = [UnityVersion]$match + if ( $module.DownloadUrl -match "(\d+)\.(\d+)\.(\d+)([fpab])(\d+)" ) { + $this.Version = [UnityVersion]$Matches[0] $foundVersion = $true + Write-Verbose "Found $($this.Version)" break } } @@ -1108,8 +1113,9 @@ function Get-UnitySetupInstance { $setupInstances = [UnitySetupInstance[]]@() foreach ( $path in $searchPaths ) { - if( $path -like '*Unity Hub*' ) { continue } - $setupInstances += , [UnitySetupInstance]::new($path) + if( $path -match "(\d+)\.(\d+)\.(\d+)([fpab])(\d+)") { + $setupInstances += , [UnitySetupInstance]::new($path) + } } return $setupInstances From 700c48141039ed6ec205cd73365c4356ca81c116 Mon Sep 17 00:00:00 2001 From: Josh Wittner Date: Tue, 23 Apr 2019 16:52:36 -0700 Subject: [PATCH 16/19] Fix instance discovery, better error handling --- UnitySetup/UnitySetup.psm1 | 115 +++++++++++++++++++++++-------------- 1 file changed, 72 insertions(+), 43 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index c9c1201..2dac40d 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -50,42 +50,10 @@ class UnitySetupInstance { UnitySetupInstance([string]$path) { $currentOS = Get-OperatingSystem - $foundVersion = $false - - Write-Verbose "Attempting to get Unity Setup Instance at $path" - - if ( Test-Path "$path\modules.json" ) { - - $modules = (Get-Content "$path\modules.json" -Raw) | ConvertFrom-Json - - foreach ( $module in $modules ) { - Write-Verbose "Found module $($module.id)" - Write-Verbose "Download Url $($module.DownloadUrl)" - - if ( $module.DownloadUrl -match "(\d+)\.(\d+)\.(\d+)([fpab])(\d+)" ) { - $this.Version = [UnityVersion]$Matches[0] - $foundVersion = $true - Write-Verbose "Found $($this.Version)" - break - } - } - } - else { - # We'll attempt to search for the version using the ivy.xml definitions for legacy editor compatibility. - $ivy = Get-ChildItem -Path $path -Filter ivy.xml -Recurse -ErrorAction SilentlyContinue -Force | Select-Object -First 1 - - if ( $null -ne $ivy ) { - [xml]$xmlDoc = Get-Content $ivy.FullName - $this.Version = [UnityVersion]$xmlDoc.'ivy-module'.info.unityVersion - $foundVersion = $true - } - } - - if ( $foundVersion -eq $false ) { - throw "Failed to find a valid version identifier for installation at $path!"; - } $this.Path = $path + $this.Version = Get-UnitySetupInstanceVersion -Path $path + if ( -not $this.Version ) { throw "Unable to find version for $path" } $playbackEnginePath = $null $componentTests = switch ($currentOS) { @@ -903,8 +871,6 @@ function Install-UnitySetupInstance { $defaultInstallPath = $BasePath } - $unitySetupInstances = Get-UnitySetupInstance -BasePath $BasePath - $versionInstallers = @{} } process { @@ -1109,16 +1075,79 @@ function Get-UnitySetupInstance { } } - $searchPaths = Get-ChildItem $BasePath -Directory - $setupInstances = [UnitySetupInstance[]]@() - - foreach ( $path in $searchPaths ) { - if( $path -match "(\d+)\.(\d+)\.(\d+)([fpab])(\d+)") { - $setupInstances += , [UnitySetupInstance]::new($path) + $results = Get-ChildItem $BasePath -Directory | Where-Object { + Test-Path (Join-Path $_.FullName 'Editor\Unity.exe') -PathType Leaf + } | ForEach-Object { + $path = $_.FullName + try { + Write-Verbose "Creating UnitySetupInstance for $path" + [UnitySetupInstance]::new($path) + } + catch { + Write-Warning "$_" } } - return $setupInstances + $results +} + +<# +.Synopsis + Gets the UnityVersion for a UnitySetupInstance at Path +.DESCRIPTION + Given a set of unity setup instances, this will select the best one matching your requirements +.PARAMETER Path + Path to a UnitySetupInstance +.OUTPUTS + UnityVersion + Returns the UnityVersion for the UnitySetupInstance at Path, or nothing if there isn't one +.EXAMPLE + Get-UnitySetupInstanceVersion -Path 'C:\Program Files\Unity' +#> +function Get-UnitySetupInstanceVersion { + [CmdletBinding()] + param( + [ValidateNotNullOrEmpty()] + [ValidateScript( {Test-Path $_ -PathType Container})] + [Parameter(Mandatory = $true, Position = 0)] + [string]$Path + ) + + Write-Verbose "Attempting to find UnityVersion in $path" + + if ( Test-Path "$path\modules.json" -PathType Leaf ) { + + Write-Verbose "Searching $path\modules.json for module versions" + $modules = (Get-Content "$path\modules.json" -Raw) | ConvertFrom-Json + + foreach ( $module in $modules ) { + Write-Verbose "`tTesting DownloadUrl $($module.DownloadUrl)" + if ( $module.DownloadUrl -notmatch "(\d+)\.(\d+)\.(\d+)([fpab])(\d+)" ) { continue; } + + Write-Verbose "`tFound version!" + return [UnityVersion]$Matches[0] + } + } + + if ( Test-Path "$path\Editor" -PathType Container ) { + # We'll attempt to search for the version using the ivy.xml definitions for legacy editor compatibility. + + Write-Verbose "Looking for ivy.xml files under $path\Editor\" + $ivyFiles = Get-ChildItem -Path "$path\Editor\" -Filter 'ivy.xml' -Recurse -ErrorAction SilentlyContinue -Force -File + foreach ( $ivy in $ivyFiles) { + if ( $null -eq $ivy ) { continue; } + + Write-Verbose "`tLooking for version in $($ivy.FullName)" + + [xml]$xmlDoc = Get-Content $ivy.FullName + + [string]$version = $xmlDoc.'ivy-module'.info.unityVersion + if ( -not $version ) { continue; } + + Write-Verbose "`tFound version!" + return [UnityVersion]$version + } + } } <# From ad69b80399483cef984589003789ee1e66349334 Mon Sep 17 00:00:00 2001 From: Josh Wittner Date: Tue, 23 Apr 2019 16:56:52 -0700 Subject: [PATCH 17/19] Write output as it's built to better support pipelining --- UnitySetup/UnitySetup.psm1 | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 2dac40d..72826d6 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -64,8 +64,8 @@ class UnitySetupInstance { [UnitySetupComponent]::Documentation = , [io.path]::Combine("$Path", "Editor\Data\Documentation"); [UnitySetupComponent]::StandardAssets = , [io.path]::Combine("$Path", "Editor\Standard Assets"); [UnitySetupComponent]::Windows_IL2CPP = , [io.path]::Combine("$playbackEnginePath", "windowsstandalonesupport\Variations\win32_development_il2cpp"); - [UnitySetupComponent]::UWP = [io.path]::Combine("$playbackEnginePath", "MetroSupport\Templates\UWP_.NET_D3D"), - [io.path]::Combine("$playbackEnginePath", "MetroSupport\Templates\UWP_D3D"); + [UnitySetupComponent]::UWP = [io.path]::Combine("$playbackEnginePath", "MetroSupport\Templates\UWP_.NET_D3D"), + [io.path]::Combine("$playbackEnginePath", "MetroSupport\Templates\UWP_D3D"); [UnitySetupComponent]::UWP_IL2CPP = , [io.path]::Combine("$playbackEnginePath", "MetroSupport\Templates\UWP_IL2CPP_D3D"); [UnitySetupComponent]::Linux = , [io.path]::Combine("$playbackEnginePath", "LinuxStandaloneSupport"); [UnitySetupComponent]::Mac = , [io.path]::Combine("$playbackEnginePath", "MacStandaloneSupport"); @@ -90,12 +90,12 @@ class UnitySetupInstance { } # Common playback engines: - $componentTests[[UnitySetupComponent]::Android] = , [io.path]::Combine("$playbackEnginePath", "AndroidPlayer"); - $componentTests[[UnitySetupComponent]::iOS] = , [io.path]::Combine("$playbackEnginePath", "iOSSupport"); - $componentTests[[UnitySetupComponent]::AppleTV] = , [io.path]::Combine("$playbackEnginePath", "AppleTVSupport"); + $componentTests[[UnitySetupComponent]::Android] = , [io.path]::Combine("$playbackEnginePath", "AndroidPlayer"); + $componentTests[[UnitySetupComponent]::iOS] = , [io.path]::Combine("$playbackEnginePath", "iOSSupport"); + $componentTests[[UnitySetupComponent]::AppleTV] = , [io.path]::Combine("$playbackEnginePath", "AppleTVSupport"); $componentTests[[UnitySetupComponent]::Facebook] = , [io.path]::Combine("$playbackEnginePath", "Facebook"); - $componentTests[[UnitySetupComponent]::Vuforia] = , [io.path]::Combine("$playbackEnginePath", "VuforiaSupport"); - $componentTests[[UnitySetupComponent]::WebGL] = , [io.path]::Combine("$playbackEnginePath", "WebGLSupport"); + $componentTests[[UnitySetupComponent]::Vuforia] = , [io.path]::Combine("$playbackEnginePath", "VuforiaSupport"); + $componentTests[[UnitySetupComponent]::WebGL] = , [io.path]::Combine("$playbackEnginePath", "WebGLSupport"); $componentTests.Keys | ForEach-Object { foreach ( $test in $componentTests[$_] ) { @@ -298,16 +298,16 @@ function Find-UnitySetupInstaller { ) $installerTemplates = @{ - [UnitySetupComponent]::UWP = "$targetSupport/UnitySetup-UWP-.NET-Support-for-Editor-$Version.$installerExtension", - "$targetSupport/UnitySetup-Metro-Support-for-Editor-$Version.$installerExtension"; + [UnitySetupComponent]::UWP = "$targetSupport/UnitySetup-UWP-.NET-Support-for-Editor-$Version.$installerExtension", + "$targetSupport/UnitySetup-Metro-Support-for-Editor-$Version.$installerExtension"; [UnitySetupComponent]::UWP_IL2CPP = , "$targetSupport/UnitySetup-UWP-IL2CPP-Support-for-Editor-$Version.$installerExtension"; [UnitySetupComponent]::Android = , "$targetSupport/UnitySetup-Android-Support-for-Editor-$Version.$installerExtension"; [UnitySetupComponent]::iOS = , "$targetSupport/UnitySetup-iOS-Support-for-Editor-$Version.$installerExtension"; [UnitySetupComponent]::AppleTV = , "$targetSupport/UnitySetup-AppleTV-Support-for-Editor-$Version.$installerExtension"; [UnitySetupComponent]::Facebook = , "$targetSupport/UnitySetup-Facebook-Games-Support-for-Editor-$Version.$installerExtension"; [UnitySetupComponent]::Linux = , "$targetSupport/UnitySetup-Linux-Support-for-Editor-$Version.$installerExtension"; - [UnitySetupComponent]::Mac = "$targetSupport/UnitySetup-Mac-Support-for-Editor-$Version.$installerExtension", - "$targetSupport/UnitySetup-Mac-Mono-Support-for-Editor-$Version.$installerExtension"; + [UnitySetupComponent]::Mac = "$targetSupport/UnitySetup-Mac-Support-for-Editor-$Version.$installerExtension", + "$targetSupport/UnitySetup-Mac-Mono-Support-for-Editor-$Version.$installerExtension"; [UnitySetupComponent]::Mac_IL2CPP = , "$targetSupport/UnitySetup-Mac-IL2CPP-Support-for-Editor-$Version.$installerExtension"; [UnitySetupComponent]::Vuforia = , "$targetSupport/UnitySetup-Vuforia-AR-Support-for-Editor-$Version.$installerExtension"; [UnitySetupComponent]::WebGL = , "$targetSupport/UnitySetup-WebGL-Support-for-Editor-$Version.$installerExtension"; @@ -1075,7 +1075,7 @@ function Get-UnitySetupInstance { } } - $results = Get-ChildItem $BasePath -Directory | Where-Object { + Get-ChildItem $BasePath -Directory | Where-Object { Test-Path (Join-Path $_.FullName 'Editor\Unity.exe') -PathType Leaf } | ForEach-Object { $path = $_.FullName @@ -1087,8 +1087,6 @@ function Get-UnitySetupInstance { Write-Warning "$_" } } - - $results } <# From 48a911e20c206041c26ae9519ae782e828f4fad4 Mon Sep 17 00:00:00 2001 From: StephenHodgson Date: Tue, 23 Apr 2019 18:01:03 -0700 Subject: [PATCH 18/19] reverted whitespace chagnes --- UnitySetup/UnitySetup.psm1 | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 72826d6..b5e024b 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -64,8 +64,8 @@ class UnitySetupInstance { [UnitySetupComponent]::Documentation = , [io.path]::Combine("$Path", "Editor\Data\Documentation"); [UnitySetupComponent]::StandardAssets = , [io.path]::Combine("$Path", "Editor\Standard Assets"); [UnitySetupComponent]::Windows_IL2CPP = , [io.path]::Combine("$playbackEnginePath", "windowsstandalonesupport\Variations\win32_development_il2cpp"); - [UnitySetupComponent]::UWP = [io.path]::Combine("$playbackEnginePath", "MetroSupport\Templates\UWP_.NET_D3D"), - [io.path]::Combine("$playbackEnginePath", "MetroSupport\Templates\UWP_D3D"); + [UnitySetupComponent]::UWP = [io.path]::Combine("$playbackEnginePath", "MetroSupport\Templates\UWP_.NET_D3D"), + [io.path]::Combine("$playbackEnginePath", "MetroSupport\Templates\UWP_D3D"); [UnitySetupComponent]::UWP_IL2CPP = , [io.path]::Combine("$playbackEnginePath", "MetroSupport\Templates\UWP_IL2CPP_D3D"); [UnitySetupComponent]::Linux = , [io.path]::Combine("$playbackEnginePath", "LinuxStandaloneSupport"); [UnitySetupComponent]::Mac = , [io.path]::Combine("$playbackEnginePath", "MacStandaloneSupport"); @@ -90,12 +90,12 @@ class UnitySetupInstance { } # Common playback engines: - $componentTests[[UnitySetupComponent]::Android] = , [io.path]::Combine("$playbackEnginePath", "AndroidPlayer"); - $componentTests[[UnitySetupComponent]::iOS] = , [io.path]::Combine("$playbackEnginePath", "iOSSupport"); - $componentTests[[UnitySetupComponent]::AppleTV] = , [io.path]::Combine("$playbackEnginePath", "AppleTVSupport"); + $componentTests[[UnitySetupComponent]::Android] = , [io.path]::Combine("$playbackEnginePath", "AndroidPlayer"); + $componentTests[[UnitySetupComponent]::iOS] = , [io.path]::Combine("$playbackEnginePath", "iOSSupport"); + $componentTests[[UnitySetupComponent]::AppleTV] = , [io.path]::Combine("$playbackEnginePath", "AppleTVSupport"); $componentTests[[UnitySetupComponent]::Facebook] = , [io.path]::Combine("$playbackEnginePath", "Facebook"); - $componentTests[[UnitySetupComponent]::Vuforia] = , [io.path]::Combine("$playbackEnginePath", "VuforiaSupport"); - $componentTests[[UnitySetupComponent]::WebGL] = , [io.path]::Combine("$playbackEnginePath", "WebGLSupport"); + $componentTests[[UnitySetupComponent]::Vuforia] = , [io.path]::Combine("$playbackEnginePath", "VuforiaSupport"); + $componentTests[[UnitySetupComponent]::WebGL] = , [io.path]::Combine("$playbackEnginePath", "WebGLSupport"); $componentTests.Keys | ForEach-Object { foreach ( $test in $componentTests[$_] ) { @@ -306,8 +306,8 @@ function Find-UnitySetupInstaller { [UnitySetupComponent]::AppleTV = , "$targetSupport/UnitySetup-AppleTV-Support-for-Editor-$Version.$installerExtension"; [UnitySetupComponent]::Facebook = , "$targetSupport/UnitySetup-Facebook-Games-Support-for-Editor-$Version.$installerExtension"; [UnitySetupComponent]::Linux = , "$targetSupport/UnitySetup-Linux-Support-for-Editor-$Version.$installerExtension"; - [UnitySetupComponent]::Mac = "$targetSupport/UnitySetup-Mac-Support-for-Editor-$Version.$installerExtension", - "$targetSupport/UnitySetup-Mac-Mono-Support-for-Editor-$Version.$installerExtension"; + [UnitySetupComponent]::Mac = "$targetSupport/UnitySetup-Mac-Support-for-Editor-$Version.$installerExtension", + "$targetSupport/UnitySetup-Mac-Mono-Support-for-Editor-$Version.$installerExtension"; [UnitySetupComponent]::Mac_IL2CPP = , "$targetSupport/UnitySetup-Mac-IL2CPP-Support-for-Editor-$Version.$installerExtension"; [UnitySetupComponent]::Vuforia = , "$targetSupport/UnitySetup-Vuforia-AR-Support-for-Editor-$Version.$installerExtension"; [UnitySetupComponent]::WebGL = , "$targetSupport/UnitySetup-WebGL-Support-for-Editor-$Version.$installerExtension"; @@ -1075,8 +1075,8 @@ function Get-UnitySetupInstance { } } - Get-ChildItem $BasePath -Directory | Where-Object { - Test-Path (Join-Path $_.FullName 'Editor\Unity.exe') -PathType Leaf + Get-ChildItem $BasePath -Directory | Where-Object { + Test-Path (Join-Path $_.FullName 'Editor\Unity.exe') -PathType Leaf } | ForEach-Object { $path = $_.FullName try { @@ -1126,7 +1126,7 @@ function Get-UnitySetupInstanceVersion { return [UnityVersion]$Matches[0] } } - + if ( Test-Path "$path\Editor" -PathType Container ) { # We'll attempt to search for the version using the ivy.xml definitions for legacy editor compatibility. @@ -1136,12 +1136,12 @@ function Get-UnitySetupInstanceVersion { if ( $null -eq $ivy ) { continue; } Write-Verbose "`tLooking for version in $($ivy.FullName)" - + [xml]$xmlDoc = Get-Content $ivy.FullName [string]$version = $xmlDoc.'ivy-module'.info.unityVersion if ( -not $version ) { continue; } - + Write-Verbose "`tFound version!" return [UnityVersion]$version } From 114e936a2cb9edac8e236bc0442b3e2bd787d543 Mon Sep 17 00:00:00 2001 From: StephenHodgson Date: Tue, 23 Apr 2019 18:01:23 -0700 Subject: [PATCH 19/19] reverted more whitespace changes --- UnitySetup/UnitySetup.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index b5e024b..51cce20 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -298,8 +298,8 @@ function Find-UnitySetupInstaller { ) $installerTemplates = @{ - [UnitySetupComponent]::UWP = "$targetSupport/UnitySetup-UWP-.NET-Support-for-Editor-$Version.$installerExtension", - "$targetSupport/UnitySetup-Metro-Support-for-Editor-$Version.$installerExtension"; + [UnitySetupComponent]::UWP = "$targetSupport/UnitySetup-UWP-.NET-Support-for-Editor-$Version.$installerExtension", + "$targetSupport/UnitySetup-Metro-Support-for-Editor-$Version.$installerExtension"; [UnitySetupComponent]::UWP_IL2CPP = , "$targetSupport/UnitySetup-UWP-IL2CPP-Support-for-Editor-$Version.$installerExtension"; [UnitySetupComponent]::Android = , "$targetSupport/UnitySetup-Android-Support-for-Editor-$Version.$installerExtension"; [UnitySetupComponent]::iOS = , "$targetSupport/UnitySetup-iOS-Support-for-Editor-$Version.$installerExtension";