From 0d2176c0ea6fbd0f9986aeb4b317790d452cd49a Mon Sep 17 00:00:00 2001 From: Josh Wittner Date: Mon, 5 Aug 2019 11:04:26 -0700 Subject: [PATCH 1/2] Fixups for base/destination handling --- UnitySetup/UnitySetup.psm1 | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 95867bd..61155be 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -903,12 +903,15 @@ function Install-UnitySetupInstance { [UnitySetupInstaller[]] $Installers, [parameter(Mandatory = $false)] + [ValidateNotNullOrEmpty()] [string]$BasePath, [parameter(Mandatory = $false)] + [ValidateNotNullOrEmpty()] [string]$Destination, [parameter(Mandatory = $false)] + [ValidateNotNullOrEmpty()] [string]$Cache = [io.Path]::Combine("~", ".unitysetup") ) begin { @@ -918,7 +921,7 @@ function Install-UnitySetupInstance { } if ( -not $PSBoundParameters.ContainsKey('BasePath') ) { - $defaultInstallPath = switch ($currentOS) { + $BasePath = switch ($currentOS) { ([OperatingSystem]::Windows) { "C:\Program Files\Unity\Hub\Editor\" } @@ -930,10 +933,6 @@ function Install-UnitySetupInstance { } } } - else { - $defaultInstallPath = $BasePath - } - $versionInstallers = @{} } process { @@ -948,16 +947,16 @@ function Install-UnitySetupInstance { $installerInstances = $versionInstallers[$installVersion] if ( $PSBoundParameters.ContainsKey('Destination') ) { - # Slight API change here. If BasePath is also provided treat Destination as a relative path. + # If BasePath is also provided treat Destination as a relative path. if ( $PSBoundParameters.ContainsKey('BasePath') ) { - $installPath = $Destination + $installPath = [io.path]::Combine($BasePath, $Destination) } else { - $installPath = [io.path]::Combine($BasePath, $Destination) + $installPath = $Destination } } else { - $installPath = [io.path]::Combine($defaultInstallPath, $installVersion) + $installPath = [io.path]::Combine($BasePath, $installVersion) } if ($currentOS -eq [OperatingSystem]::Mac) { From 2041b39e7260fc9311ea46b00f5f593284dbe738 Mon Sep 17 00:00:00 2001 From: Josh Wittner Date: Mon, 5 Aug 2019 11:04:40 -0700 Subject: [PATCH 2/2] Remove redundant test for directories --- UnitySetup/UnitySetup.psm1 | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 61155be..8a5ee21 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -1138,17 +1138,17 @@ function Get-UnitySetupInstance { } - $BasePath | Where-Object { Test-Path $_ -PathType Container } | - Get-ChildItem -Directory | Where-Object { (Get-UnityEditor $_.FullName).Count -gt 0 } | + $BasePath | Get-ChildItem -Directory | + Where-Object { (Get-UnityEditor $_.FullName).Count -gt 0 } | ForEach-Object { - $path = $_.FullName - try { - Write-Verbose "Creating UnitySetupInstance for $path" - [UnitySetupInstance]::new($path) - } - catch { - Write-Warning "$_" - } + $path = $_.FullName + try { + Write-Verbose "Creating UnitySetupInstance for $path" + [UnitySetupInstance]::new($path) + } + catch { + Write-Warning "$_" + } } }