From b0529f971390806504f98c1a0cd9d399cdbbdc0a Mon Sep 17 00:00:00 2001 From: Robert Onulak Date: Thu, 13 Sep 2018 08:09:19 -0700 Subject: [PATCH 01/67] Work in progress on mac install support. Restructures Install-UnitySetupInstance to handle ordering of installs slightly differently. Breaks out downloading installers into a separate function. --- UnitySetup/UnitySetup.psm1 | 298 ++++++++++++++++++++++++++++++------- 1 file changed, 242 insertions(+), 56 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 59f4759..c68fe0d 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -427,6 +427,134 @@ function Find-UnitySetupInstaller { } | Sort-Object -Property ComponentType } +function Test-UnitySetupInstance { + [CmdletBinding()] + param( + [parameter(Mandatory = $false)] + [UnityVersion] $Version, + + [parameter(Mandatory = $false)] + [string] $Path + ) + + $instance = Get-UnitySetupInstance | Select-UnitySetupInstance -Version $Version -Path $Path + return $null -ne $instance +} + +<# +.Synopsis + Select installers by a version and/or components. +.DESCRIPTION + Filters a list of `UnitySetupInstaller` down to a specific version and/or specific components. +.PARAMETER Installers + List of installers that needs to be reduced. +.PARAMETER Version + What version of UnitySetupInstaller that you want to keep. +.PARAMETER Components + What components should be maintained. +.EXAMPLE + $installers = Find-UnitySetupInstaller -Version 2017.3.0f3 + $installers += Find-UnitySetupInstaller -Version 2018.2.5f1 + $installers | Select-UnitySetupInstaller -Component Windows,Linux,Mac +#> +function Select-UnitySetupInstaller { + [CmdletBinding()] + param( + [parameter(ValueFromPipeline = $true)] + [UnitySetupInstaller[]] $Installers, + + [parameter(Mandatory = $false)] + [UnityVersion] $Version, + + [parameter(Mandatory = $false)] + [UnitySetupComponent] $Components = [UnitySetupComponent]::All + ) + begin { + $selectedInstallers = @() + } + process { + # Keep only the matching version specified. + if ( $PSBoundParameters.ContainsKey('Version') ) { + $Installers = $Installers | Where-Object { [UnityVersion]::Compare($_.Version, $Version) -eq 0 } + } + + # Keep only the matching component(s). + $Installers = $Installers | Where-Object { $Components -band $_.ComponentType } | ForEach-Object { $_ } + + $selectedInstallers += $Installers + } + end { + return $selectedInstallers + } +} + +function Request-UnitySetupInstaller { + [CmdletBinding()] + param( + [parameter(ValueFromPipeline = $true)] + [UnitySetupInstaller[]] $Installers, + + [parameter(Mandatory = $false)] + [string]$Cache = [io.Path]::Combine("~", ".unitysetup") + ) + begin { + # Note that this has to happen before calculating the full path since + # Resolve-Path throws an exception on missing paths. + if (!(Test-Path $Cache -PathType Container)) { + New-Item $Cache -ItemType Directory -ErrorAction Stop | Out-Null + } + + # Expanding '~' to the absolute path on the system. `WebClient` on macOS asumes + # relative path. macOS also treats alt directory separators as part of the file + # name and this corrects the separators to current environment. + $fullCachePath = (Resolve-Path -Path $Cache).Path + + $downloads = @() + } + process { + $Installers | ForEach-Object { + $installerFileName = [io.Path]::GetFileName($_.DownloadUrl) + $destination = [io.Path]::Combine($fullCachePath, "Installers", "Unity-$($_.Version)", "$installerFileName") + + # Already downloaded? + if ( Test-Path $destination ) { + $destinationItem = Get-Item $destination + if ( ($destinationItem.Length -eq $_.Length ) -and + ($destinationItem.LastWriteTime -eq $_.LastModified) ) { + Write-Verbose "Skipping download because it's already in the cache: $($_.DownloadUrl)" + + $downloads += ,$destination + return + } + } + + $destinationDirectory = [io.path]::GetDirectoryName($destination) + if (!(Test-Path $destinationDirectory -PathType Container)) { + New-Item "$destinationDirectory" -ItemType Directory | Out-Null + } + + try + { + Write-Verbose "Downloading $($_.DownloadUrl) to $destination" + (New-Object System.Net.WebClient).DownloadFile($_.DownloadUrl, $destination) + + # Re-writes the last modified time for ensuring downloads cache. + $downloadedFile = Get-Item $destination + $downloadedFile.LastWriteTime = $_.LastModified + + $downloads += ,$destination + } + catch [System.Net.WebException] + { + Write-Error "Failed downloading $($installerFileName): $($_.Exception.Message)" + } + } + } + end { + return $downloads + } +} + <# .Synopsis Installs a UnitySetup instance. @@ -434,14 +562,20 @@ function Find-UnitySetupInstaller { Downloads and installs UnitySetup installers found via Find-UnitySetupInstaller. .PARAMETER Installers What installers would you like to download and execute? +.PARAMETER BasePath + Under what base patterns is Unity customly installed at. .PARAMETER Destination Where would you like the UnitySetup instance installed? .PARAMETER Cache - Where should the installers be cached. This defaults to $env:USERPROFILE\.unitysetup. + Where should the installers be cached. This defaults to ~\.unitysetup. .EXAMPLE Find-UnitySetupInstaller -Version 2017.3.0f3 | Install-UnitySetupInstance .EXAMPLE Find-UnitySetupInstaller -Version 2017.3.0f3 | Install-UnitySetupInstance -Destination D:\Unity-2017.3.0f3 +.EXAMPLE + Find-UnitySetupInstaller -Version 2017.3.0f3 | Install-UnitySetupInstance -BasePath D:\UnitySetup\ +.EXAMPLE + Find-UnitySetupInstaller -Version 2017.3.0f3 | Install-UnitySetupInstance -BasePath D:\UnitySetup\ -Destination Unity-2017 #> function Install-UnitySetupInstance { [CmdletBinding()] @@ -449,79 +583,119 @@ function Install-UnitySetupInstance { [parameter(ValueFromPipeline = $true)] [UnitySetupInstaller[]] $Installers, + [parameter(Mandatory = $false)] + [string]$BasePath, + [parameter(Mandatory = $false)] [string]$Destination, [parameter(Mandatory = $false)] - [string]$Cache = [io.Path]::Combine($env:USERPROFILE, ".unitysetup") + [string]$Cache = [io.Path]::Combine("~", ".unitysetup") ) + begin { + $currentOS = Get-OperatingSystem + if ($currentOS == [OperatingSystem]::Linux) { + throw "Install-UnitySetupInstance has not been implemented on the Linux platform. Contributions welcomed!"; + } + + if ( -not $PSBoundParameters.ContainsKey('BasePath') ) { + $defaultInstallPath = switch ($currentOS) { + ([OperatingSystem]::Windows) { 'C:\Program Files\Unity' } + ([OperatingSystem]::Linux) { throw "Install-UnitySetupInstance has not been implemented on the Linux platform. Contributions welcomed!"; } + ([OperatingSystem]::Mac) { '/Applications/Unity' } + } + } + else { + $defaultInstallPath = $BasePath + } + + $unitySetupInstances = Get-UnitySetupInstance -BasePath $BasePath + $versionInstallers = @{} + } process { - if (!(Test-Path $Cache -PathType Container)) { - New-Item $Cache -ItemType Directory -ErrorAction Stop | Out-Null + # Sort each installer received from the pipe into versions + $Installers | ForEach-Object { + $versionInstallers[$_.Version] += , $_ } + } + end { + # foreach unity version + # If macOS, move previous install back to default directory + # Install main Unity setup installer first + # Install all components to default Unity version + # If macOS, move install to versioned directory + $versionInstallers.Keys | ForEach-Object { + $installVersion = $_ + $installerInstances = $versionInstallers[$installVersion] + + if ($currentOS == [OperatingSystem]::Mac) { + # On macOS we must notify the user to take an action if the default location + # is currently in use. Either there's a previous version of Unity installed + # manually or another install through UnitySetup possibly failed. + if (Test-UnitySetupInstance -Path /Applications/Unity/) { + # TODO: Work in a `$host.ui.PromptForChoice` / -Force param for resolving this. + throw "Install-UnitySetupInstance has not yet handled working around the base install directory already existing. Please move this manually and try again. Contributions welcomed!"; + } - $localInstallers = @() - $localDestinations = @() - $downloadSource = @() - $downloadDest = @() - foreach ( $i in $Installers) { - $fileName = [io.Path]::GetFileName($i.DownloadUrl) - $destPath = [io.Path]::Combine($Cache, "Installers\Unity-$($i.Version)\$fileName") + } - $localInstallers += , $destPath - if ($Destination) { - $localDestinations += , $Destination + if ( $PSBoundParameters.ContainsKey('Destination') ) { + # Slight API change here. If BasePath is also provided treat Destination as a relative path. + if ( $PSBoundParameters.ContainsKey('BasePath') ) { + $installPath = $Destination + } + else { + $installPath = [io.path]::Combine($BasePath, $Destination) + } } else { - $localDestinations += , "C:\Program Files\Unity-$($i.Version)" + $installPath = "$defaultInstallPath-$installVersion" } - if ( Test-Path $destPath ) { - $destItem = Get-Item $destPath - if ( ($destItem.Length -eq $i.Length ) -and ($destItem.LastWriteTime -eq $i.LastModified) ) { - Write-Verbose "Skipping download because it's already in the cache: $($i.DownloadUrl)" - continue - } - } + $installerPaths = $installerInstances | Request-UnitySetupInstaller -Cache $Cache - $downloadSource += $i.DownloadUrl - $downloadDest += $destPath - } + # TODO: Install Unity component first - if ( $downloadSource.Length -gt 0 ) { - for ($i = 0; $i -lt $downloadSource.Length; $i++) { - Write-Verbose "Downloading $($downloadSource[$i]) to $($downloadDest[$i])" - $destDirectory = [io.path]::GetDirectoryName($downloadDest[$i]) - if (!(Test-Path $destDirectory -PathType Container)) { - New-Item "$destDirectory" -ItemType Directory | Out-Null + foreach ($componentInstallerPath in $installerPaths) { + switch ($currentOS) { + ([OperatingSystem]::Windows) { + $startProcessArgs = @{ + 'FilePath' = $_; + 'ArgumentList' = @("/S", "/D=$installPath"); + 'PassThru' = $true; + 'Wait' = $true; + } + } + ([OperatingSystem]::Linux) { + throw "Install-UnitySetupInstance has not been implemented on the Linux platform. Contributions welcomed!"; + } + ([OperatingSystem]::Mac) { + $startProcessArgs = @{ + 'FilePath' = $installer; + 'ArgumentList' = @("/S", "/D=$destination"); + 'PassThru' = $true; + 'Wait' = $true; + } + } + } + + Write-Verbose "$(Get-Date): Installing $installer to $destination." + $process = Start-Process @startProcessArgs + if ( $process ) { + if ( $process.ExitCode -ne 0) { + Write-Error "$(Get-Date): Failed with exit code: $($process.ExitCode)" + } + else { + Write-Verbose "$(Get-Date): Succeeded." + } } - - (New-Object System.Net.WebClient).DownloadFile($downloadSource[$i], $downloadDest[$i]) } - } - - for ($i = 0; $i -lt $localInstallers.Length; $i++) { - $installer = $localInstallers[$i] - $destination = $localDestinations[$i] - $startProcessArgs = @{ - 'FilePath' = $installer; - 'ArgumentList' = @("/S", "/D=$destination"); - 'PassThru' = $true; - 'Wait' = $true; - } - - Write-Verbose "$(Get-Date): Installing $installer to $destination." - $process = Start-Process @startProcessArgs - if ( $process ) { - if ( $process.ExitCode -ne 0) { - Write-Error "$(Get-Date): Failed with exit code: $($process.ExitCode)" - } - else { - Write-Verbose "$(Get-Date): Succeeded." - } + # Move the install from the staging area to the desired destination + if ($currentOS == [OperatingSystem]::Mac) { + Move-Item -Path /Applications/Unity/ -Destination $installPath } } } @@ -626,14 +800,16 @@ function Get-UnitySetupInstance { Select the latest version available. .PARAMETER Version Select only instances matching Version. -.PARAMETER Project - Select only instances matching the version of the project at Project. +.PARAMETER Path + Select only instances matching the project at the provided path. .PARAMETER instances The list of instances to Select from. .EXAMPLE Get-UnitySetupInstance | Select-UnitySetupInstance -Latest .EXAMPLE Get-UnitySetupInstance | Select-UnitySetupInstance -Version 2017.1.0f3 +.EXAMPLE + Get-UnitySetupInstance | Select-UnitySetupInstance -Path (Get-Item /Applications/Unity*) #> function Select-UnitySetupInstance { [CmdletBinding()] @@ -644,11 +820,21 @@ function Select-UnitySetupInstance { [parameter(Mandatory = $false)] [UnityVersion] $Version, + [parameter(Mandatory = $false)] + [string] $Path, + [parameter(Mandatory = $true, ValueFromPipeline = $true)] [UnitySetupInstance[]] $Instances ) process { + if ( $PSBoundParameters.ContainsKey('Path') ) { + $Path = $Path.TrimEnd([io.path]::DirectorySeparatorChar) + $Instances = $Instances | Where-Object { + $Path -eq (Get-Item $_.Path).FullName.TrimEnd([io.path]::DirectorySeparatorChar) + } + } + if ( $Version ) { $Instances = $Instances | Where-Object { [UnityVersion]::Compare($_.Version, $Version) -eq 0 } } From bc79f16390a6241bf2c66d9807f1f0458756ba7f Mon Sep 17 00:00:00 2001 From: Robert Onulak Date: Fri, 14 Sep 2018 08:42:54 -0700 Subject: [PATCH 02/67] Shows progress of WebClient downloads. Creates separate install method for installing a single package. --- UnitySetup/UnitySetup.psm1 | 156 +++++++++++++++++++++++++++---------- 1 file changed, 114 insertions(+), 42 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index c68fe0d..2b02d55 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -29,6 +29,11 @@ enum OperatingSystem { Mac } +class UnitySetupResource { + [UnitySetupComponent] $ComponentType + [string] $Path +} + class UnitySetupInstaller { [UnitySetupComponent] $ComponentType [UnityVersion] $Version @@ -523,9 +528,25 @@ function Request-UnitySetupInstaller { ($destinationItem.LastWriteTime -eq $_.LastModified) ) { Write-Verbose "Skipping download because it's already in the cache: $($_.DownloadUrl)" - $downloads += ,$destination + $resource = New-Object UnitySetupResource -Property @{ + 'ComponentType' = $_.ComponentType + 'Path' = $destination + } + $downloads += , $resource return } + elseif ($destinationItem.Length -eq $_.Length ) { + Write-Verbose "Skipping download because file size is the same: $($_.DownloadUrl)" + + # Re-writes the last modified time for ensuring downloads cache. + $downloadedFile = Get-Item $destination + $downloadedFile.LastWriteTime = $_.LastModified + + $downloadedFile = Get-Item $destination + if ( ($downloadedFile.LastWriteTime -ne $_.LastModified) ) { + Write-Verbose "Modified time not set for $destination" + } + } } $destinationDirectory = [io.path]::GetDirectoryName($destination) @@ -536,13 +557,37 @@ function Request-UnitySetupInstaller { try { Write-Verbose "Downloading $($_.DownloadUrl) to $destination" - (New-Object System.Net.WebClient).DownloadFile($_.DownloadUrl, $destination) + + $webClient = New-Object System.Net.WebClient + Register-ObjectEvent -InputObject $webClient -EventName DownloadFileCompleted ` + -SourceIdentifier Web.DownloadFileCompleted -Action { + $global:isDownloaded = $true + } + Register-ObjectEvent -InputObject $webClient -EventName DownloadProgressChanged ` + -SourceIdentifier Web.DownloadProgressChanged -Action { + $global:DownloadProgressEvent = $event + } + $webClient.DownloadFileAsync($_.DownloadUrl, $destination) + + $totalBytes = $_.Length + while (-not $isDownloaded) { + $receivedBytes = $global:DownloadProgressEvent.SourceArgs.BytesReceived + $progress = [int](($receivedBytes / [double]$totalBytes) * 100) + + Write-Progress -Activity "Downloading $($_.DownloadUrl)..." -Status "$receivedBytes bytes \ $totalBytes bytes" -PercentComplete $progress + [System.Threading.Thread]::Sleep(500) + } + Write-Progress -Activity "Downloading $($_.DownloadUrl)..." -Status "$receivedBytes bytes \ $totalBytes bytes" -Completed # Re-writes the last modified time for ensuring downloads cache. $downloadedFile = Get-Item $destination $downloadedFile.LastWriteTime = $_.LastModified - $downloads += ,$destination + $resource = New-Object UnitySetupResource -Property @{ + 'ComponentType' = $_.ComponentType + 'Path' = $destination + } + $downloads += , $resource } catch [System.Net.WebException] { @@ -555,6 +600,53 @@ function Request-UnitySetupInstaller { } } +function Install-UnitySetupPackage { + [CmdletBinding()] + param( + [parameter(Mandatory = $true)] + [UnitySetupResource] $Package, + + [parameter(Mandatory = $false)] + [string]$Destination + ) + + $currentOS = Get-OperatingSystem + switch ($currentOS) { + ([OperatingSystem]::Windows) { + $startProcessArgs = @{ + 'FilePath' = $Package.Path; + 'ArgumentList' = @("/S", "/D=$Destination"); + 'PassThru' = $true; + 'Wait' = $true; + } + } + ([OperatingSystem]::Linux) { + throw "Install-UnitySetupPackage has not been implemented on the Linux platform. Contributions welcomed!"; + } + ([OperatingSystem]::Mac) { + # Note, ignores $Destination on Mac. + # sudo installer -package $Package.Path -target / + $startProcessArgs = @{ + 'FilePath' = 'sudo'; + 'ArgumentList' = @("installer", "-package", $Package.Path, "-target", "/"); + 'PassThru' = $true; + 'Wait' = $true; + } + } + } + + Write-Verbose "$(Get-Date): Installing $($Package.ComponentType) to $Destination." + $process = Start-Process @startProcessArgs + if ( $process ) { + if ( $process.ExitCode -ne 0) { + Write-Error "$(Get-Date): Failed with exit code: $($process.ExitCode)" + } + else { + Write-Verbose "$(Get-Date): Succeeded." + } + } +} + <# .Synopsis Installs a UnitySetup instance. @@ -637,8 +729,6 @@ function Install-UnitySetupInstance { # TODO: Work in a `$host.ui.PromptForChoice` / -Force param for resolving this. throw "Install-UnitySetupInstance has not yet handled working around the base install directory already existing. Please move this manually and try again. Contributions welcomed!"; } - - } if ( $PSBoundParameters.ContainsKey('Destination') ) { @@ -654,48 +744,30 @@ function Install-UnitySetupInstance { $installPath = "$defaultInstallPath-$installVersion" } + # TODO: Strip out components already installed in the destination. + $installerPaths = $installerInstances | Request-UnitySetupInstaller -Cache $Cache - # TODO: Install Unity component first - - foreach ($componentInstallerPath in $installerPaths) { - switch ($currentOS) { - ([OperatingSystem]::Windows) { - $startProcessArgs = @{ - 'FilePath' = $_; - 'ArgumentList' = @("/S", "/D=$installPath"); - 'PassThru' = $true; - 'Wait' = $true; - } - } - ([OperatingSystem]::Linux) { - throw "Install-UnitySetupInstance has not been implemented on the Linux platform. Contributions welcomed!"; - } - ([OperatingSystem]::Mac) { - $startProcessArgs = @{ - 'FilePath' = $installer; - 'ArgumentList' = @("/S", "/D=$destination"); - 'PassThru' = $true; - 'Wait' = $true; - } - } - } - - Write-Verbose "$(Get-Date): Installing $installer to $destination." - $process = Start-Process @startProcessArgs - if ( $process ) { - if ( $process.ExitCode -ne 0) { - Write-Error "$(Get-Date): Failed with exit code: $($process.ExitCode)" - } - else { - Write-Verbose "$(Get-Date): Succeeded." - } - } + # First install the Unity editor before other components. + $editorComponent = switch ($currentOS) { + ([OperatingSystem]::Windows) { [UnitySetupComponent]::Windows } + ([OperatingSystem]::Linux) { [UnitySetupComponent]::Linux } + ([OperatingSystem]::Mac) { [UnitySetupComponent]::Mac } + } + $editorInstaller = $installerPaths | Where-Object { $_.ComponentType -band $editorComponent } + if ($null -ne $editorInstaller) { + Write-Verbose "Installing $($editorInstaller.ComponentType)" + # Install-UnitySetupPackage -Package $editorInstaller -Destination $destination + } + + $installerPaths | ForEach-Object { + Write-Verbose "Installing $($editorInstaller.ComponentType)" + # Install-UnitySetupPackage -Package $_ -Destination $destination } # Move the install from the staging area to the desired destination if ($currentOS == [OperatingSystem]::Mac) { - Move-Item -Path /Applications/Unity/ -Destination $installPath + #Move-Item -Path /Applications/Unity/ -Destination $installPath } } } @@ -775,7 +847,7 @@ function Get-UnitySetupInstance { } ([OperatingSystem]::Mac) { if (-not $BasePath) { - $BasePath = @('/Applications/Unity*') + $BasePath = @('/Applications/Unity*', '/Applications/Unity/Hub/Editor/*') } $ivyPath = 'Unity.app/Contents/UnityExtensions/Unity/Networking/ivy.xml' } From 1a4197693746e82d4b610d188a8b41c5c981bd77 Mon Sep 17 00:00:00 2001 From: Robert Onulak Date: Fri, 14 Sep 2018 13:52:39 -0700 Subject: [PATCH 03/67] Corrects issues with displaying a progress bar for WebClient downloads. --- UnitySetup/UnitySetup.psm1 | 110 ++++++++++++++++++++++++------------- 1 file changed, 71 insertions(+), 39 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 2b02d55..90c011c 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -486,13 +486,26 @@ function Select-UnitySetupInstaller { # Keep only the matching component(s). $Installers = $Installers | Where-Object { $Components -band $_.ComponentType } | ForEach-Object { $_ } - $selectedInstallers += $Installers + if ($Installers.Length -ne 0) { + $selectedInstallers += $Installers + } } end { return $selectedInstallers } } +filter Get-FileSize { + return "{0:N2} {1}" -f $( + if ($_ -lt 1kb) { $_, 'Bytes' } + elseif ($_ -lt 1mb) { ($_/1kb), 'KB' } + elseif ($_ -lt 1gb) { ($_/1mb), 'MB' } + elseif ($_ -lt 1tb) { ($_/1gb), 'GB' } + elseif ($_ -lt 1pb) { ($_/1tb), 'TB' } + else { ($_/1pb), 'PB' } + ) +} + function Request-UnitySetupInstaller { [CmdletBinding()] param( @@ -535,18 +548,6 @@ function Request-UnitySetupInstaller { $downloads += , $resource return } - elseif ($destinationItem.Length -eq $_.Length ) { - Write-Verbose "Skipping download because file size is the same: $($_.DownloadUrl)" - - # Re-writes the last modified time for ensuring downloads cache. - $downloadedFile = Get-Item $destination - $downloadedFile.LastWriteTime = $_.LastModified - - $downloadedFile = Get-Item $destination - if ( ($downloadedFile.LastWriteTime -ne $_.LastModified) ) { - Write-Verbose "Modified time not set for $destination" - } - } } $destinationDirectory = [io.path]::GetDirectoryName($destination) @@ -554,45 +555,76 @@ function Request-UnitySetupInstaller { New-Item "$destinationDirectory" -ItemType Directory | Out-Null } + $webClient = New-Object System.Net.WebClient + + # Register to events for showing progress of file download. + Register-ObjectEvent -InputObject $webClient -EventName DownloadProgressChanged -SourceIdentifier DownloadProgressChanged -Action { + $global:DownloadProgressEvent = $event + } | Out-Null + Register-ObjectEvent -InputObject $webClient -EventName DownloadFileCompleted -SourceIdentifier DownloadFileCompleted -Action { + $global:isDownloaded = $true + } | Out-Null + try { - Write-Verbose "Downloading $($_.DownloadUrl) to $destination" + $startTime = Get-Date - $webClient = New-Object System.Net.WebClient - Register-ObjectEvent -InputObject $webClient -EventName DownloadFileCompleted ` - -SourceIdentifier Web.DownloadFileCompleted -Action { - $global:isDownloaded = $true - } - Register-ObjectEvent -InputObject $webClient -EventName DownloadProgressChanged ` - -SourceIdentifier Web.DownloadProgressChanged -Action { - $global:DownloadProgressEvent = $event - } + $global:DownloadProgressEvent = $null + $global:isDownloaded = $false + + Write-Verbose "Downloading $($_.DownloadUrl) to $destination" $webClient.DownloadFileAsync($_.DownloadUrl, $destination) + # Showing progress of file download $totalBytes = $_.Length - while (-not $isDownloaded) { + while (-not $global:isDownloaded) { + if ($null -eq $global:DownloadProgressEvent) { + continue + } + + $elapsedTime = (Get-Date) - $startTime + $receivedBytes = $global:DownloadProgressEvent.SourceArgs.BytesReceived $progress = [int](($receivedBytes / [double]$totalBytes) * 100) - Write-Progress -Activity "Downloading $($_.DownloadUrl)..." -Status "$receivedBytes bytes \ $totalBytes bytes" -PercentComplete $progress - [System.Threading.Thread]::Sleep(500) - } - Write-Progress -Activity "Downloading $($_.DownloadUrl)..." -Status "$receivedBytes bytes \ $totalBytes bytes" -Completed + # Average speed in Mbps + $averageSpeed = ($receivedBytes * 8 / 1mb) / $elapsedTime.TotalSeconds + $secondsRemaining = ($totalBytes - $receivedBytes) * 8 / 1mb / $averageSpeed - # Re-writes the last modified time for ensuring downloads cache. - $downloadedFile = Get-Item $destination - $downloadedFile.LastWriteTime = $_.LastModified + if ([double]::IsInfinity($secondsRemaining)) { + $averageSpeed = 0 + # -1 for Write-Progress prevents seconds remaining from showing. + $secondsRemaining = -1 + } - $resource = New-Object UnitySetupResource -Property @{ - 'ComponentType' = $_.ComponentType - 'Path' = $destination + # TODO: Display in Kbps on slow networks. + Write-Progress -Activity "$("{0:N2}" -f $averageSpeed) Mbps`nDownloading $($_.DownloadUrl)" ` + -Status "$($receivedBytes | Get-FileSize) of $($totalBytes | Get-FileSize)" ` + -SecondsRemaining $secondsRemaining ` + -PercentComplete $progress } - $downloads += , $resource } - catch [System.Net.WebException] - { - Write-Error "Failed downloading $($installerFileName): $($_.Exception.Message)" + catch [System.Net.WebException] { + Write-Error "Failed downloading $installerFileName - $($_.Exception.Message)" } + finally { + Unregister-Event -SourceIdentifier DownloadFileCompleted -Force + Unregister-Event -SourceIdentifier DownloadProgressChanged -Force + + $webClient.Dispose() + + Write-Progress -Activity "Downloading $($_.DownloadUrl)" -Status "Done" -Completed + } + + # Re-writes the last modified time for ensuring downloads are cached properly. + $downloadedFile = Get-Item $destination + $downloadedFile.LastWriteTime = $_.LastModified + + $resource = New-Object UnitySetupResource -Property @{ + 'ComponentType' = $_.ComponentType + 'Path' = $destination + } + $downloads += , $resource } } end { @@ -606,7 +638,7 @@ function Install-UnitySetupPackage { [parameter(Mandatory = $true)] [UnitySetupResource] $Package, - [parameter(Mandatory = $false)] + [parameter(Mandatory = $true)] [string]$Destination ) From d5f9aed59bc56ae2d0beccc12d02f873122bcc76 Mon Sep 17 00:00:00 2001 From: Robert Onulak Date: Fri, 14 Sep 2018 17:13:59 -0700 Subject: [PATCH 04/67] Corrects visual issues on macOS with the Write-Progress and newlines activity string. --- UnitySetup/UnitySetup.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 90c011c..813e23d 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -598,7 +598,7 @@ function Request-UnitySetupInstaller { } # TODO: Display in Kbps on slow networks. - Write-Progress -Activity "$("{0:N2}" -f $averageSpeed) Mbps`nDownloading $($_.DownloadUrl)" ` + Write-Progress -Activity "$("{0:N2}" -f $averageSpeed) Mbps | Downloading $installerFileName" ` -Status "$($receivedBytes | Get-FileSize) of $($totalBytes | Get-FileSize)" ` -SecondsRemaining $secondsRemaining ` -PercentComplete $progress From 8f34065e6d3c17eeb895a1f81ee5dec8e6c119f7 Mon Sep 17 00:00:00 2001 From: Robert Onulak Date: Fri, 14 Sep 2018 23:02:20 -0700 Subject: [PATCH 05/67] Improves download speeds to support more than just mbps. Enables package installs and moves final installs to proper directory on macOS. --- UnitySetup/UnitySetup.psm1 | 84 +++++++++++++++++++++++++------------- 1 file changed, 55 insertions(+), 29 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 813e23d..38c43cf 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -219,7 +219,7 @@ class UnityVersion : System.IComparable { ([OperatingSystem]::Mac) { echo "On Mac" } } .EXAMPLE - if (Get-OperatingSystem == [OperatingSystem]::Linux) { + if (Get-OperatingSystem -eq [OperatingSystem]::Linux) { echo "On Linux" } #> @@ -495,7 +495,7 @@ function Select-UnitySetupInstaller { } } -filter Get-FileSize { +filter Format-Bytes { return "{0:N2} {1}" -f $( if ($_ -lt 1kb) { $_, 'Bytes' } elseif ($_ -lt 1mb) { ($_/1kb), 'KB' } @@ -506,6 +506,30 @@ filter Get-FileSize { ) } +function Format-BitsPerSecond { + [CmdletBinding()] + param( + [parameter(Mandatory = $true)] + [int] $Bytes, + + [parameter(Mandatory = $true)] + [int] $Seconds + ) + if ($Seconds -le 0.001) { + return "0 Bps" + } + # Convert from bytes to bits + $Bits = ($Bytes * 8) / $Seconds + return "{0:N2} {1}" -f $( + if ($Bits -lt 1kb) { $Bits, 'Bps' } + elseif ($Bits -lt 1mb) { ($Bits/1kb), 'Kbps' } + elseif ($Bits -lt 1gb) { ($Bits/1mb), 'Mbps' } + elseif ($Bits -lt 1tb) { ($Bits/1gb), 'Gbps' } + elseif ($Bits -lt 1pb) { ($Bits/1tb), 'Tbps' } + else { ($Bits/1pb), 'Pbps' } + ) +} + function Request-UnitySetupInstaller { [CmdletBinding()] param( @@ -587,9 +611,8 @@ function Request-UnitySetupInstaller { $receivedBytes = $global:DownloadProgressEvent.SourceArgs.BytesReceived $progress = [int](($receivedBytes / [double]$totalBytes) * 100) - # Average speed in Mbps - $averageSpeed = ($receivedBytes * 8 / 1mb) / $elapsedTime.TotalSeconds - $secondsRemaining = ($totalBytes - $receivedBytes) * 8 / 1mb / $averageSpeed + $averageSpeed = $receivedBytes / $elapsedTime.TotalSeconds + $secondsRemaining = ($totalBytes - $receivedBytes) / $averageSpeed if ([double]::IsInfinity($secondsRemaining)) { $averageSpeed = 0 @@ -597,9 +620,10 @@ function Request-UnitySetupInstaller { $secondsRemaining = -1 } - # TODO: Display in Kbps on slow networks. - Write-Progress -Activity "$("{0:N2}" -f $averageSpeed) Mbps | Downloading $installerFileName" ` - -Status "$($receivedBytes | Get-FileSize) of $($totalBytes | Get-FileSize)" ` + $downloadSpeed = Format-BitsPerSecond -Bytes $receivedBytes -Seconds $elapsedTime.TotalSeconds + + Write-Progress -Activity "Downloading $installerFileName | $downloadSpeed" ` + -Status "$($receivedBytes | Format-Bytes) of $($totalBytes | Format-Bytes)" ` -SecondsRemaining $secondsRemaining ` -PercentComplete $progress } @@ -718,7 +742,7 @@ function Install-UnitySetupInstance { ) begin { $currentOS = Get-OperatingSystem - if ($currentOS == [OperatingSystem]::Linux) { + if ($currentOS -eq [OperatingSystem]::Linux) { throw "Install-UnitySetupInstance has not been implemented on the Linux platform. Contributions welcomed!"; } @@ -744,25 +768,10 @@ function Install-UnitySetupInstance { } } end { - # foreach unity version - # If macOS, move previous install back to default directory - # Install main Unity setup installer first - # Install all components to default Unity version - # If macOS, move install to versioned directory $versionInstallers.Keys | ForEach-Object { $installVersion = $_ $installerInstances = $versionInstallers[$installVersion] - if ($currentOS == [OperatingSystem]::Mac) { - # On macOS we must notify the user to take an action if the default location - # is currently in use. Either there's a previous version of Unity installed - # manually or another install through UnitySetup possibly failed. - if (Test-UnitySetupInstance -Path /Applications/Unity/) { - # TODO: Work in a `$host.ui.PromptForChoice` / -Force param for resolving this. - throw "Install-UnitySetupInstance has not yet handled working around the base install directory already existing. Please move this manually and try again. Contributions welcomed!"; - } - } - if ( $PSBoundParameters.ContainsKey('Destination') ) { # Slight API change here. If BasePath is also provided treat Destination as a relative path. if ( $PSBoundParameters.ContainsKey('BasePath') ) { @@ -776,6 +785,18 @@ function Install-UnitySetupInstance { $installPath = "$defaultInstallPath-$installVersion" } + if ($currentOS -eq [OperatingSystem]::Mac) { + # On macOS we must notify the user to take an action if the default location + # is currently in use. Either there's a previous version of Unity installed + # manually or another install through UnitySetup possibly failed. + if (Test-UnitySetupInstance -Path /Applications/Unity/) { + # TODO: Work in a `$host.ui.PromptForChoice` / -Force param for resolving this. + throw "Install-UnitySetupInstance has not yet handled working around the base install directory already existing. Please move this manually and try again. Contributions welcomed!"; + } + + # TODO: Test if $installPath contains a/this version of Unity to move back to /Applications/Unity/ + } + # TODO: Strip out components already installed in the destination. $installerPaths = $installerInstances | Request-UnitySetupInstaller -Cache $Cache @@ -789,17 +810,22 @@ function Install-UnitySetupInstance { $editorInstaller = $installerPaths | Where-Object { $_.ComponentType -band $editorComponent } if ($null -ne $editorInstaller) { Write-Verbose "Installing $($editorInstaller.ComponentType)" - # Install-UnitySetupPackage -Package $editorInstaller -Destination $destination + Install-UnitySetupPackage -Package $editorInstaller -Destination $installPath } $installerPaths | ForEach-Object { - Write-Verbose "Installing $($editorInstaller.ComponentType)" - # Install-UnitySetupPackage -Package $_ -Destination $destination + # Already installed this earlier. Skipping. + if ($_.ComponentType -band $editorComponent) { + return + } + + Write-Verbose "Installing $($_.ComponentType)" + Install-UnitySetupPackage -Package $_ -Destination $installPath } # Move the install from the staging area to the desired destination - if ($currentOS == [OperatingSystem]::Mac) { - #Move-Item -Path /Applications/Unity/ -Destination $installPath + if ($currentOS -eq [OperatingSystem]::Mac) { + Move-Item -Path /Applications/Unity/ -Destination $installPath } } } From 10fa727f8006bf8d921b6861c47b9426e25a6809 Mon Sep 17 00:00:00 2001 From: Robert Onulak Date: Mon, 17 Sep 2018 17:44:14 -0700 Subject: [PATCH 06/67] Enables support for installing Unity to any disk location by leveraging sparse bundle disks. --- UnitySetup/UnitySetup.psm1 | 62 +++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 14 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 38c43cf..f260a1d 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -438,11 +438,14 @@ function Test-UnitySetupInstance { [parameter(Mandatory = $false)] [UnityVersion] $Version, + [parameter(Mandatory = $false)] + [string] $BasePath, + [parameter(Mandatory = $false)] [string] $Path ) - $instance = Get-UnitySetupInstance | Select-UnitySetupInstance -Version $Version -Path $Path + $instance = Get-UnitySetupInstance -BasePath $BasePath | Select-UnitySetupInstance -Version $Version -Path $Path return $null -ne $instance } @@ -680,11 +683,11 @@ function Install-UnitySetupPackage { throw "Install-UnitySetupPackage has not been implemented on the Linux platform. Contributions welcomed!"; } ([OperatingSystem]::Mac) { - # Note, ignores $Destination on Mac. + # Note that $Destination has to be a disk path. # sudo installer -package $Package.Path -target / $startProcessArgs = @{ 'FilePath' = 'sudo'; - 'ArgumentList' = @("installer", "-package", $Package.Path, "-target", "/"); + 'ArgumentList' = @("installer", "-package", $Package.Path, "-target", $Destination); 'PassThru' = $true; 'Wait' = $true; } @@ -786,15 +789,28 @@ function Install-UnitySetupInstance { } if ($currentOS -eq [OperatingSystem]::Mac) { - # On macOS we must notify the user to take an action if the default location - # is currently in use. Either there's a previous version of Unity installed - # manually or another install through UnitySetup possibly failed. - if (Test-UnitySetupInstance -Path /Applications/Unity/) { - # TODO: Work in a `$host.ui.PromptForChoice` / -Force param for resolving this. - throw "Install-UnitySetupInstance has not yet handled working around the base install directory already existing. Please move this manually and try again. Contributions welcomed!"; + # Creating sparse bundle to host installing Unity in other locations + $unitySetupBundlePath = [io.path]::Combine($Cache, "UnitySetup.sparsebundle") + if (-not (Test-Path $unitySetupBundlePath)) { + Write-Verbose "Creating new sparse bundle disk image for installation." + & hdiutil create -size 32g -fs 'HFS+' -type 'SPARSEBUNDLE' -volname 'UnitySetup' $unitySetupBundlePath } + Write-Verbose "Mounting sparse bundle disk." + & hdiutil mount $unitySetupBundlePath - # TODO: Test if $installPath contains a/this version of Unity to move back to /Applications/Unity/ + # Previous version failed to remove. Cleaning up! + if (Test-Path /Volumes/UnitySetup/Applications/) { + Write-Verbose "Previous install did not clean up properly. Doing that now." + & sudo rm -Rf /Volumes/UnitySetup/Applications/ + } + + # Copy installed version back to the sparse bundle disk for Unity component installs. + if (Test-UnitySetupInstance -Path $installPath -BasePath $BasePath) { + Write-Verbose "Copying current installation to sparse bundle disk." + # -a for improved recursion to preserve file attributes and symlinks. + # appended '.' is to allow the copy of all files and folders, even hidden. + & sudo cp -a [io.path]::Combine($installPath, '.') /Volumes/UnitySetup/Applications/Unity/ + } } # TODO: Strip out components already installed in the destination. @@ -807,10 +823,17 @@ function Install-UnitySetupInstance { ([OperatingSystem]::Linux) { [UnitySetupComponent]::Linux } ([OperatingSystem]::Mac) { [UnitySetupComponent]::Mac } } + + $packageDestination = $installPath + # Installers in macOS get installed to the sparse bundle disk first. + if ($currentOS -eq [OperatingSystem]::Mac) { + $packageDestination = "/Volumes/UnitySetup/" + } + $editorInstaller = $installerPaths | Where-Object { $_.ComponentType -band $editorComponent } if ($null -ne $editorInstaller) { Write-Verbose "Installing $($editorInstaller.ComponentType)" - Install-UnitySetupPackage -Package $editorInstaller -Destination $installPath + Install-UnitySetupPackage -Package $editorInstaller -Destination $packageDestination } $installerPaths | ForEach-Object { @@ -820,12 +843,23 @@ function Install-UnitySetupInstance { } Write-Verbose "Installing $($_.ComponentType)" - Install-UnitySetupPackage -Package $_ -Destination $installPath + Install-UnitySetupPackage -Package $_ -Destination $packageDestination } - # Move the install from the staging area to the desired destination + # Move the install from the sparse bundle disk to the install directory. if ($currentOS -eq [OperatingSystem]::Mac) { - Move-Item -Path /Applications/Unity/ -Destination $installPath + Write-Verbose "Copying install to $installPath." + # Copy the files to the install directory. + & sudo cp -af /Volumes/UnitySetup/Applications/Unity/ $installPath + Write-Verbose "Freeing sparse bundle disk space and unmounting." + # Ensure the drive is cleaned up. + & sudo rm -Rf /Volumes/UnitySetup/Applications/ + + & hdiutil eject /Volumes/UnitySetup/ + # Free up disk space since deleting items in the volume send them to the trash + # Also note that -batteryallowed enables compacting while not connected to + # power. The compact is quite quick since the volume is small. + & hdiutil compact $unitySetupBundlePath -batteryallowed } } } From 4195789daa57f7a2fafc71b4c837a175d726b298 Mon Sep 17 00:00:00 2001 From: Robert Onulak Date: Wed, 19 Sep 2018 20:33:52 -0700 Subject: [PATCH 07/67] Resolves issues with installing future components to the same install path. --- UnitySetup/UnitySetup.psm1 | 39 +++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index f260a1d..c09c14f 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -789,6 +789,15 @@ function Install-UnitySetupInstance { } if ($currentOS -eq [OperatingSystem]::Mac) { + $volumeRoot = "/Volumes/UnitySetup/" + $volumeInstallPath = [io.path]::Combine($volumeRoot, "Applications/Unity/") + + # Make sure the install path ends with a trailing slash. This + # is required in some commands to treat as directory. + if (-not $installPath.EndsWith([io.path]::DirectorySeparatorChar)) { + $installPath += [io.path]::DirectorySeparatorChar + } + # Creating sparse bundle to host installing Unity in other locations $unitySetupBundlePath = [io.path]::Combine($Cache, "UnitySetup.sparsebundle") if (-not (Test-Path $unitySetupBundlePath)) { @@ -799,17 +808,22 @@ function Install-UnitySetupInstance { & hdiutil mount $unitySetupBundlePath # Previous version failed to remove. Cleaning up! - if (Test-Path /Volumes/UnitySetup/Applications/) { + if (Test-Path $volumeInstallPath) { Write-Verbose "Previous install did not clean up properly. Doing that now." - & sudo rm -Rf /Volumes/UnitySetup/Applications/ + & sudo rm -Rf ([io.path]::Combine($volumeRoot, '*')) } # Copy installed version back to the sparse bundle disk for Unity component installs. if (Test-UnitySetupInstance -Path $installPath -BasePath $BasePath) { - Write-Verbose "Copying current installation to sparse bundle disk." - # -a for improved recursion to preserve file attributes and symlinks. - # appended '.' is to allow the copy of all files and folders, even hidden. - & sudo cp -a [io.path]::Combine($installPath, '.') /Volumes/UnitySetup/Applications/Unity/ + Write-Verbose "Copying $installPath to $volumeInstallPath" + + # Ensure the path exists before copying the previous version to the sparse bundle disk. + & mkdir -p $volumeInstallPath + + # Copy the files (-r) and recreate symlinks (-l) to the install directory. + # Preserve permissions (-p) and owner (-o). + # Need to mark the files with read permissions or installs may fail. + & sudo rsync -rlpo $installPath $volumeInstallPath --chmod=+r } } @@ -827,7 +841,7 @@ function Install-UnitySetupInstance { $packageDestination = $installPath # Installers in macOS get installed to the sparse bundle disk first. if ($currentOS -eq [OperatingSystem]::Mac) { - $packageDestination = "/Volumes/UnitySetup/" + $packageDestination = $volumeRoot } $editorInstaller = $installerPaths | Where-Object { $_.ComponentType -band $editorComponent } @@ -849,13 +863,16 @@ function Install-UnitySetupInstance { # Move the install from the sparse bundle disk to the install directory. if ($currentOS -eq [OperatingSystem]::Mac) { Write-Verbose "Copying install to $installPath." - # Copy the files to the install directory. - & sudo cp -af /Volumes/UnitySetup/Applications/Unity/ $installPath + # Copy the files (-r) and recreate symlinks (-l) to the install directory. + # Preserve permissions (-p) and owner (-o). + # chmod gives files read permissions. + & sudo rsync -rlpo $volumeInstallPath $installPath --chmod=+r --remove-source-files + Write-Verbose "Freeing sparse bundle disk space and unmounting." # Ensure the drive is cleaned up. - & sudo rm -Rf /Volumes/UnitySetup/Applications/ + & sudo rm -Rf ([io.path]::Combine($volumeRoot, '*')) - & hdiutil eject /Volumes/UnitySetup/ + & hdiutil eject $volumeRoot # Free up disk space since deleting items in the volume send them to the trash # Also note that -batteryallowed enables compacting while not connected to # power. The compact is quite quick since the volume is small. From 07e595e70092412b0de88486bdb04e93ad003a74 Mon Sep 17 00:00:00 2001 From: Stephen Hodgson Date: Wed, 9 Jan 2019 08:39:31 -0800 Subject: [PATCH 08/67] updated default installation path to be the hub path --- UnitySetup/UnitySetup.psm1 | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 096b56d..5e8d818 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -475,7 +475,17 @@ function Install-UnitySetupInstance { $localDestinations += , $Destination } else { - $localDestinations += , "C:\Program Files\Unity-$($i.Version)" + switch (Get-OperatingSystem) { + ([OperatingSystem]::Windows) { + $localDestinations += , "C:\Program Files\Unity\Hub\Editor\$($i.Version)" + } + ([OperatingSystem]::Linux) { + throw "Install-UnitySetupInstance has not been implemented on the Linux platform. Contributions welcomed!"; + } + ([OperatingSystem]::Mac) { + $localDestinations += , "/Applications/Unity/Hub/Editor/$($i.Version)" + } + } } if ( Test-Path $destPath ) { @@ -617,7 +627,7 @@ function Get-UnitySetupInstance { } ([OperatingSystem]::Mac) { if (-not $BasePath) { - $BasePath = @('/Applications/Unity*') + $BasePath = @('/Applications/Unity*', '/Applications/Unity/Hub/Editor/*') } $ivyPath = 'Unity.app/Contents/UnityExtensions/Unity/Networking/ivy.xml' } From 17f41236c7ca14b1f660080f887bc360e4c6a97c Mon Sep 17 00:00:00 2001 From: Stephen Hodgson Date: Wed, 9 Jan 2019 08:54:29 -0800 Subject: [PATCH 09/67] added lumin component installers --- UnitySetup/UnitySetup.psm1 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 096b56d..ba5716f 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -19,7 +19,8 @@ enum UnitySetupComponent { Facebook = (1 -shl 11) Vuforia = (1 -shl 12) WebGL = (1 -shl 13) - All = (1 -shl 14) - 1 + Lumin = (1 -shl 14) + All = (1 -shl 15) - 1 } [Flags()] @@ -76,6 +77,7 @@ class UnitySetupInstance { [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"); + [UnitySetupComponent]::Lumin = , [io.path]::Combine("$playbackEnginePath", "LuminSupport"); } } ([OperatingSystem]::Linux) { @@ -309,6 +311,7 @@ function Find-UnitySetupInstaller { [UnitySetupComponent]::Vuforia = , "$targetSupport/UnitySetup-Vuforia-AR-Support-for-Editor-$Version.$installerExtension"; [UnitySetupComponent]::WebGL = , "$targetSupport/UnitySetup-WebGL-Support-for-Editor-$Version.$installerExtension"; [UnitySetupComponent]::Windows_IL2CPP = , "$targetSupport/UnitySetup-Windows-IL2CPP-Support-for-Editor-$Version.$installerExtension"; + [UnitySetupComponent]::Lumin = , "$targetSupport/UnitySetup-Lumin-Support-for-Editor-$Version.$installerExtension"; } switch ($currentOS) { @@ -819,7 +822,7 @@ function Start-UnityEditor { [parameter(Mandatory = $false)] [string]$LogFile, [parameter(Mandatory = $false)] - [ValidateSet('StandaloneOSX', 'StandaloneWindows', 'iOS', 'Android', 'StandaloneLinux', 'StandaloneWindows64', 'WebGL', 'WSAPlayer', 'StandaloneLinux64', 'StandaloneLinuxUniversal', 'Tizen', 'PSP2', 'PS4', 'XBoxOne', 'N3DS', 'WiiU', 'tvOS', 'Switch')] + [ValidateSet('StandaloneOSX', 'StandaloneWindows', 'iOS', 'Android', 'StandaloneLinux', 'StandaloneWindows64', 'WebGL', 'WSAPlayer', 'StandaloneLinux64', 'StandaloneLinuxUniversal', 'Tizen', 'PSP2', 'PS4', 'XBoxOne', 'N3DS', 'WiiU', 'tvOS', 'Switch', 'Lumin')] [string]$BuildTarget, [parameter(Mandatory = $false)] [switch]$AcceptAPIUpdate, From b03e8c63b75330b6f67dd12161fcd3102e34aa82 Mon Sep 17 00:00:00 2001 From: Stephen Hodgson Date: Wed, 9 Jan 2019 17:02:14 -0800 Subject: [PATCH 10/67] add quotes around project path --- UnitySetup/UnitySetup.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index beb346d..5919c70 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -963,7 +963,7 @@ function Start-UnityEditor { } $projectPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($($p.Path)) - $instanceArgs += , ("-projectPath", $projectPath) + $instanceArgs += , ("-projectPath", "$projectPath") $setupInstances += , $setupInstance } From 70edffbccf77a1eaf1b79f369dc3073d8875c3ba Mon Sep 17 00:00:00 2001 From: Robert Onulak Date: Thu, 10 Jan 2019 07:45:49 -0800 Subject: [PATCH 11/67] - Addesses PR feedback and exposes / documents methods that users could leverage in external scripts. --- UnitySetup/UnitySetup.psd1 | 3 +++ UnitySetup/UnitySetup.psm1 | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/UnitySetup/UnitySetup.psd1 b/UnitySetup/UnitySetup.psd1 index 2bc02e1..e4b2777 100644 --- a/UnitySetup/UnitySetup.psd1 +++ b/UnitySetup/UnitySetup.psd1 @@ -76,8 +76,11 @@ FunctionsToExport = @( 'Find-UnitySetupInstaller', + 'Select-UnitySetupInstaller', + 'Test-UnitySetupInstance', 'Get-UnityProjectInstance', 'Get-UnitySetupInstance', + 'Request-UnitySetupInstaller', 'Install-UnitySetupInstance', 'Select-UnitySetupInstance', 'Uninstall-UnitySetupInstance', diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 89edfdf..872ecb7 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -432,6 +432,22 @@ function Find-UnitySetupInstaller { } | Sort-Object -Property ComponentType } +<# +.Synopsis + Test if a Unity instance is installed. +.DESCRIPTION + Returns the status of a Unity install by Version and/or Path to install. +.PARAMETER Version + What version of Unity are you looking for? +.PARAMETER BasePath + Under what base patterns is Unity customly installed at. +.PARAMETER Path + Exact path you expect Unity to be installed at. +.EXAMPLE + Test-UnitySetupInstance -Version 2017.3.0f3 +.EXAMPLE + Test-UnitySetupInstance -BasePath D:/UnityInstalls/Unity2018 +#> function Test-UnitySetupInstance { [CmdletBinding()] param( @@ -533,6 +549,21 @@ function Format-BitsPerSecond { ) } +<# +.Synopsis + Download specified Unity installers. +.DESCRIPTION + Filters a list of `UnitySetupInstaller` down to a specific version and/or specific components. +.PARAMETER Installers + List of installers that needs to be downloaded. +.PARAMETER Cache + File path where installers will be downloaded to. +.EXAMPLE + $installers = Find-UnitySetupInstaller -Version 2017.3.0f3 + Request-UnitySetupInstaller -Installers $installers +.EXAMPLE + Find-UnitySetupInstaller -Version 2017.3.0f3 | Request-UnitySetupInstaller +#> function Request-UnitySetupInstaller { [CmdletBinding()] param( From 9cc8b4b19af04fa8ae464f6b0e452c194a201eb9 Mon Sep 17 00:00:00 2001 From: Robert Onulak Date: Thu, 10 Jan 2019 08:14:44 -0800 Subject: [PATCH 12/67] - Resolves issue with `Request-UnitySetupInstaller` not completing after all files finished downloading. --- UnitySetup/UnitySetup.psm1 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 872ecb7..679fac8 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -665,10 +665,11 @@ function Request-UnitySetupInstaller { } } + # Showing progress of all file downloads $totalDownloads = $global:downloadData.Count + do { + $installersDownloaded = 0 - # Showing progress of all file downloads - while ($global:downloadData.Count -gt 0) { $global:downloadData.Keys | ForEach-Object { $installerFileName = $_ $data = $global:downloadData[$installerFileName] @@ -720,7 +721,7 @@ function Request-UnitySetupInstaller { -PercentComplete $progress ` -Id $data.downloadIndex } - } + } while ($installersDownloaded -lt $totalDownloads) } finally { # If the script is stopped, e.g. Ctrl+C, we want to cancel any remaining downloads From 9fe346df78b46ec65019b2cac174ce6e9848f3fd Mon Sep 17 00:00:00 2001 From: Robert Onulak Date: Thu, 10 Jan 2019 08:57:54 -0800 Subject: [PATCH 13/67] - Resolves issue where the number of installers finished downloaded wasn't being calculated. Thus command was still blocking indefinitely. --- UnitySetup/UnitySetup.psm1 | 1 + 1 file changed, 1 insertion(+) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 679fac8..11d11c6 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -676,6 +676,7 @@ function Request-UnitySetupInstaller { # Finished downloading if ($null -eq $data.webClient) { + ++$installersDownloaded return } if ($data.isDownloaded) { From 2321718d02e2faa648d83bbb12a4f83dfe158135 Mon Sep 17 00:00:00 2001 From: Stephen Hodgson Date: Thu, 10 Jan 2019 14:20:55 -0800 Subject: [PATCH 14/67] Update UnitySetup/UnitySetup.psm1 --- UnitySetup/UnitySetup.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 5919c70..5a6854d 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -963,7 +963,7 @@ function Start-UnityEditor { } $projectPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($($p.Path)) - $instanceArgs += , ("-projectPath", "$projectPath") + $instanceArgs += , ("-projectPath", "`"$projectPath`"") $setupInstances += , $setupInstance } From 3b6b00274b7d67e5268d0395c46bc7b509d2a1b1 Mon Sep 17 00:00:00 2001 From: Robert Onulak Date: Mon, 28 Jan 2019 07:43:25 -0800 Subject: [PATCH 15/67] - Resolves issue with finding Unity 2018.3 or higher for macOS. - Resolves issues if recursive directories do not exist in install path for macOS. --- UnitySetup/UnitySetup.psm1 | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 53f7acb..2c595ec 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -374,7 +374,24 @@ function Find-UnitySetupInstaller { } if ($null -eq $prototypeLink) { - throw "Could not find archives for Unity version $Version" + # Attempt to find Unity version and setup links based off builtin_shaders download. + Write-Verbose "Attempting version search with builtin_shaders fallback" + foreach ($page in $searchPages) { + $webResult = Invoke-WebRequest $page -UseBasicParsing + $prototypeLink = $webResult.Links | Select-Object -ExpandProperty href -ErrorAction SilentlyContinue | Where-Object { + $_ -match "builtin_shaders-$($Version).zip$" + } + + if ($null -ne $prototypeLink) { break } + } + + if ($null -eq $prototypeLink) { + throw "Could not find archives for Unity version $Version" + } + else { + # Regex needs to be reconfigured to parse builtin_shaders's url link + $unitySetupRegEx = "^(.+)\/([a-z0-9]+)\/builtin_shaders-(\d+)\.(\d+)\.(\d+)([fpb])(\d+).zip$" + } } $linkComponents = $prototypeLink -split $unitySetupRegEx -ne "" @@ -959,11 +976,18 @@ function Install-UnitySetupInstance { # Move the install from the sparse bundle disk to the install directory. if ($currentOS -eq [OperatingSystem]::Mac) { + # rsync does not recursively create the directory path. + if (-not (Test-Path $installPath -PathType Container)) + { + Write-Verbose "Creating directory $installPath." + New-Item $installPath -ItemType Directory -ErrorAction Stop | Out-Null + } + Write-Verbose "Copying install to $installPath." # Copy the files (-r) and recreate symlinks (-l) to the install directory. # Preserve permissions (-p) and owner (-o). # chmod gives files read permissions. - & sudo rsync -rlpo $volumeInstallPath $installPath --chmod=+r --remove-source-files + & sudo rsync -rlpo $volumeInstallPath $installPath --chmod="+wr" --remove-source-files Write-Verbose "Freeing sparse bundle disk space and unmounting." # Ensure the drive is cleaned up. From ede42afc672088b1cc872c938d9751cf9713821a Mon Sep 17 00:00:00 2001 From: Niall Milsom Date: Fri, 22 Feb 2019 12:37:59 +0000 Subject: [PATCH 16/67] Add runTests flag to Start-UnityEditor Also added related flags testPlatform and testResults --- UnitySetup/UnitySetup.psm1 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 3a69a7e..30db7fe 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -776,6 +776,12 @@ function Get-UnityProjectInstance { Where to put the results? Unity states, "If the path is a folder, the command line uses a default file name. If not specified, it places the results in the project’s root folder." .PARAMETER RunEditorTests Should Unity run the editor tests? Unity states, "[...]it’s good practice to run it with batchmode argument. quit is not required, because the Editor automatically closes down after the run is finished." +.PARAMETER TestPlatform + The platform you want to run the tests on. Note that If unspecified, tests run in editmode by default. +.PARAMETER TestResults + The path indicating where Unity should save the result file. By default, Unity saves it in the Project’s root folder. +.PARAMETER RunTests + Should Unity run tests? Unity states, "[...]it’s good practice to run it with batchmode argument. quit is not required, because the Editor automatically closes down after the run is finished." .PARAMETER BatchMode Should the Unity Editor start in batch mode? .PARAMETER Quit @@ -850,6 +856,13 @@ function Start-UnityEditor { [parameter(Mandatory = $false)] [switch]$RunEditorTests, [parameter(Mandatory = $false)] + [ValidateSet('EditMode', 'PlayMode')] + [string]$TestPlatform, + [parameter(Mandatory = $false)] + [string]$TestResults, + [parameter(Mandatory = $false)] + [switch]$RunTests, + [parameter(Mandatory = $false)] [switch]$BatchMode, [parameter(Mandatory = $false)] [switch]$Quit, @@ -945,6 +958,9 @@ function Start-UnityEditor { if ( $EditorTestsFilter ) { $sharedArgs += '-editorTestsFilter', ($EditorTestsFilter -join ',') } if ( $EditorTestsResultFile ) { $sharedArgs += '-editorTestsResultFile', $EditorTestsResultFile } if ( $RunEditorTests ) { $sharedArgs += '-runEditorTests' } + if ( $TestPlatform ) { $sharedArgs += '-testPlatform', $TestPlatform } + if ( $TestResults ) { $sharedArgs += '-testResults', $TestResults } + if ( $RunTests ) { $sharedArgs += '-runTests' } if ( $ForceFree) { $sharedArgs += '-force-free' } $instanceArgs = @() From dd03ec0450dc6f00625d3a4de349f188bfacd0e6 Mon Sep 17 00:00:00 2001 From: Niall Milsom Date: Mon, 4 Mar 2019 14:08:05 +0000 Subject: [PATCH 17/67] Add AdditionalArguments flag This flag allows you to provide additional arguments for unity command line. This is useful for cases where we do not support unity command line flags. It is also useful for providing arbitrary arguments alongside ExecuteMethod. --- UnitySetup/UnitySetup.psm1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 30db7fe..de6105d 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -754,6 +754,8 @@ function Get-UnityProjectInstance { Force operation as though $PWD is not a unity project. .PARAMETER ExecuteMethod The script method for the Unity Editor to execute. +.PARAMETER AdditionalArguments + Additiong arguments for Unity or your custom method .PARAMETER OutputPath The output path that the Unity Editor should use. .PARAMETER LogFile @@ -825,6 +827,8 @@ function Start-UnityEditor { [parameter(Mandatory = $false)] [string]$ExecuteMethod, [parameter(Mandatory = $false)] + [string]$AdditionalArguments, + [parameter(Mandatory = $false)] [string[]]$ExportPackage, [parameter(Mandatory = $false)] [string]$ImportPackage, @@ -962,6 +966,7 @@ function Start-UnityEditor { if ( $TestResults ) { $sharedArgs += '-testResults', $TestResults } if ( $RunTests ) { $sharedArgs += '-runTests' } if ( $ForceFree) { $sharedArgs += '-force-free' } + if ( $AdditionalArguments) { $sharedArgs += $AdditionalArguments } $instanceArgs = @() foreach ( $p in $projectInstances ) { From c2935c66debe0f1c1580a25990301f7dbe373c8d Mon Sep 17 00:00:00 2001 From: Niall Milsom Date: Tue, 5 Mar 2019 15:53:47 +0000 Subject: [PATCH 18/67] Fix typo and add to docs --- README.md | 4 ++++ UnitySetup/UnitySetup.psd1 | 2 +- UnitySetup/UnitySetup.psm1 | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 86a8ae4..b882b2d 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,10 @@ Launch many projects at the same time: ```powershell Get-UnityProjectInstance -Recurse | Start-UnityEditor ``` +Invoke methods with arbitrary arguments: +```powershell +Start-UnityEditor -ExecuteMethod Build.Invoke -BatchMode -Quit -LogFile .\build.log -Wait -AdditionalArguments "-BuildArg1 -BuildArg2" +``` Find the installers for a particular version: ```powershell Find-UnitySetupInstaller -Version '2017.3.0f3' | Format-Table diff --git a/UnitySetup/UnitySetup.psd1 b/UnitySetup/UnitySetup.psd1 index 2bc02e1..27b77e0 100644 --- a/UnitySetup/UnitySetup.psd1 +++ b/UnitySetup/UnitySetup.psd1 @@ -14,7 +14,7 @@ RootModule = 'UnitySetup' # Version number of this module. - ModuleVersion = '5.0' + ModuleVersion = '5.1' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index de6105d..0307f2b 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -755,7 +755,7 @@ function Get-UnityProjectInstance { .PARAMETER ExecuteMethod The script method for the Unity Editor to execute. .PARAMETER AdditionalArguments - Additiong arguments for Unity or your custom method + Additional arguments for Unity or your custom method .PARAMETER OutputPath The output path that the Unity Editor should use. .PARAMETER LogFile @@ -797,7 +797,7 @@ function Get-UnityProjectInstance { .EXAMPLE Start-UnityEditor -Version 2017.3.0f3 .EXAMPLE - Start-UnityEditor -ExecuteMethod Build.Invoke -BatchMode -Quit -LogFile .\build.log -Wait + Start-UnityEditor -ExecuteMethod Build.Invoke -BatchMode -Quit -LogFile .\build.log -Wait -AdditionalArguments "-BuildArg1 -BuildArg2" .EXAMPLE Get-UnityProjectInstance -Recurse | Start-UnityEditor -BatchMode -Quit .EXAMPLE From 05d2f6bbb24e73ff8e78ee70c1e47e2c9a6a7fe1 Mon Sep 17 00:00:00 2001 From: Tim Gerken Date: Fri, 29 Mar 2019 17:13:37 +0000 Subject: [PATCH 19/67] Expose productName in UnityProjectInstance --- UnitySetup/UnitySetup.psm1 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index c65758d..353526b 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -122,6 +122,7 @@ class UnitySetupInstance { class UnityProjectInstance { [UnityVersion]$Version [string]$Path + [string]$ProductName UnityProjectInstance([string]$path) { $versionFile = [io.path]::Combine($path, "ProjectSettings\ProjectVersion.txt") @@ -130,8 +131,15 @@ class UnityProjectInstance { $fileVersion = (Get-Content $versionFile -Raw | ConvertFrom-Yaml)['m_EditorVersion']; if (!$fileVersion) { throw "Project is missing a version in: $versionFile"} + $projectSettingsFile = [io.path]::Combine($path, "ProjectSettings\ProjectSettings.asset") + if (!(Test-Path $projectSettingsFile)) { throw "Project is missing ProjectSettings.asset"} + + $prodName = ((Get-Content $projectSettingsFile -Raw | ConvertFrom-Yaml)['playerSettings'])['productName'] + if (!$prodName) { throw "ProjectSettings is missing productName"} + $this.Path = $path $this.Version = $fileVersion + $this.ProductName = $prodName } } From 2febb70772f04b8b833d8179abdd75958d5aab92 Mon Sep 17 00:00:00 2001 From: Tim Gerken Date: Fri, 29 Mar 2019 17:13:37 +0000 Subject: [PATCH 20/67] Expose productName in UnityProjectInstance --- README.md | 12 ++++++------ UnitySetup/UnitySetup.psm1 | 8 ++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b882b2d..422a355 100644 --- a/README.md +++ b/README.md @@ -55,12 +55,12 @@ Find all the Unity projects recursively: Get-UnityProjectInstance -Recurse # Example output: -# Version Path -# ------- ---- -# 2017.2.0f3 C:\Projects\Project1\OneUnity\ -# 2017.3.0f3 C:\Projects\Project1\TwoUnity\ -# 2017.1.1p1 C:\Projects\Project2\ -# 2017.1.2f1 C:\Projects\Project3\App.Unity\ +# Version Path ProductName +# ------- ---- ----------- +# 2017.2.0f3 C:\Projects\Project1\OneUnity\ Contoso +# 2017.3.0f3 C:\Projects\Project1\TwoUnity\ Northwind +# 2017.1.1p1 C:\Projects\Project2\ My Cool App +# 2017.1.2f1 C:\Projects\Project3\App.Unity\ TemplateProject ``` Launch the right Unity editor for a project: ```powershell diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index c65758d..353526b 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -122,6 +122,7 @@ class UnitySetupInstance { class UnityProjectInstance { [UnityVersion]$Version [string]$Path + [string]$ProductName UnityProjectInstance([string]$path) { $versionFile = [io.path]::Combine($path, "ProjectSettings\ProjectVersion.txt") @@ -130,8 +131,15 @@ class UnityProjectInstance { $fileVersion = (Get-Content $versionFile -Raw | ConvertFrom-Yaml)['m_EditorVersion']; if (!$fileVersion) { throw "Project is missing a version in: $versionFile"} + $projectSettingsFile = [io.path]::Combine($path, "ProjectSettings\ProjectSettings.asset") + if (!(Test-Path $projectSettingsFile)) { throw "Project is missing ProjectSettings.asset"} + + $prodName = ((Get-Content $projectSettingsFile -Raw | ConvertFrom-Yaml)['playerSettings'])['productName'] + if (!$prodName) { throw "ProjectSettings is missing productName"} + $this.Path = $path $this.Version = $fileVersion + $this.ProductName = $prodName } } From d22ec0c913e870a0b58560c9aacad65f912e87e0 Mon Sep 17 00:00:00 2001 From: Stephen Hodgson Date: Sun, 31 Mar 2019 20:07:00 -0700 Subject: [PATCH 21/67] Mac_IL2CPP component installer --- UnitySetup/UnitySetup.psm1 | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 353526b..bac4c11 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -19,7 +19,8 @@ enum UnitySetupComponent { Facebook = (1 -shl 11) Vuforia = (1 -shl 12) WebGL = (1 -shl 13) - All = (1 -shl 14) - 1 + Mac_IL2CPP = (1 -shl 14) + All = (1 -shl 15) - 1 } [Flags()] @@ -73,14 +74,12 @@ class UnitySetupInstance { $this.Components = [UnitySetupComponent]::Windows $playbackEnginePath = [io.path]::Combine("$Path", "Editor\Data\PlaybackEngines"); @{ - [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_IL2CPP = , [io.path]::Combine("$playbackEnginePath", "MetroSupport\Templates\UWP_IL2CPP_D3D"); - [UnitySetupComponent]::Linux = , [io.path]::Combine("$playbackEnginePath", "LinuxStandaloneSupport"); - [UnitySetupComponent]::Mac = , [io.path]::Combine("$playbackEnginePath", "MacStandaloneSupport"); + [UnitySetupComponent]::Documentation = , [io.path]::Combine("$Path", "Editor\Data\Documentation"); + [UnitySetupComponent]::StandardAssets = , [io.path]::Combine("$Path", "Editor\Standard Assets"); } } ([OperatingSystem]::Linux) { @@ -94,13 +93,15 @@ class UnitySetupInstance { @{ [UnitySetupComponent]::Documentation = , [io.path]::Combine("$Path", "Documentation"); [UnitySetupComponent]::StandardAssets = , [io.path]::Combine("$Path", "Standard Assets"); + #[UnitySetupComponent]::Mac_IL2CPP = , [io.path]::Combine("$playbackEnginePath", "???"); [UnitySetupComponent]::Windows = , [io.path]::Combine("$playbackEnginePath", "WindowsStandaloneSupport"); - [UnitySetupComponent]::Linux = , [io.path]::Combine("$playbackEnginePath", "LinuxStandaloneSupport"); } } } - + # Common playback engines: + $componentTests[[UnitySetupComponent]::Linux] = , [io.path]::Combine("$playbackEnginePath", "LinuxStandaloneSupport"); + $componentTests[[UnitySetupComponent]::Mac] = , [io.path]::Combine("$playbackEnginePath", "MacStandaloneSupport"); $componentTests[[UnitySetupComponent]::Android] = , [io.path]::Combine("$playbackEnginePath", "AndroidPlayer"); $componentTests[[UnitySetupComponent]::iOS] = , [io.path]::Combine("$playbackEnginePath", "iOSSupport"); $componentTests[[UnitySetupComponent]::AppleTV] = , [io.path]::Combine("$playbackEnginePath", "AppleTVSupport"); @@ -318,7 +319,8 @@ function Find-UnitySetupInstaller { [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"; + "$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"; [UnitySetupComponent]::Windows_IL2CPP = , "$targetSupport/UnitySetup-Windows-IL2CPP-Support-for-Editor-$Version.$installerExtension"; From b0980aa0c2e303a97b93e925872f89cc7c888383 Mon Sep 17 00:00:00 2001 From: Stephen Hodgson Date: Sun, 31 Mar 2019 20:08:43 -0700 Subject: [PATCH 22/67] reverted some line moves --- UnitySetup/UnitySetup.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index bac4c11..aedf7c1 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -74,12 +74,12 @@ class UnitySetupInstance { $this.Components = [UnitySetupComponent]::Windows $playbackEnginePath = [io.path]::Combine("$Path", "Editor\Data\PlaybackEngines"); @{ + [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_IL2CPP = , [io.path]::Combine("$playbackEnginePath", "MetroSupport\Templates\UWP_IL2CPP_D3D"); - [UnitySetupComponent]::Documentation = , [io.path]::Combine("$Path", "Editor\Data\Documentation"); - [UnitySetupComponent]::StandardAssets = , [io.path]::Combine("$Path", "Editor\Standard Assets"); } } ([OperatingSystem]::Linux) { From 18a36f952eef87d6d2b2374302a7b8a2c3859109 Mon Sep 17 00:00:00 2001 From: Stephen Hodgson Date: Sun, 31 Mar 2019 20:09:49 -0700 Subject: [PATCH 23/67] reverted whitespace change --- UnitySetup/UnitySetup.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index aedf7c1..b4d83f4 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -98,7 +98,7 @@ class UnitySetupInstance { } } } - + # Common playback engines: $componentTests[[UnitySetupComponent]::Linux] = , [io.path]::Combine("$playbackEnginePath", "LinuxStandaloneSupport"); $componentTests[[UnitySetupComponent]::Mac] = , [io.path]::Combine("$playbackEnginePath", "MacStandaloneSupport"); From 0d34c4ed4b006fdbad3479a0fd35092621fd66fd Mon Sep 17 00:00:00 2001 From: Stephen Hodgson Date: Sun, 31 Mar 2019 20:49:51 -0700 Subject: [PATCH 24/67] moved lumin playback engine into common section --- UnitySetup/UnitySetup.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 699dc5f..809359a 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -82,7 +82,6 @@ class UnitySetupInstance { [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"); - [UnitySetupComponent]::Lumin = , [io.path]::Combine("$playbackEnginePath", "LuminSupport"); } } ([OperatingSystem]::Linux) { @@ -103,6 +102,7 @@ class UnitySetupInstance { } # Common playback engines: + $componentTests[[UnitySetupComponent]::Lumin] = , [io.path]::Combine("$playbackEnginePath", "LuminSupport"); $componentTests[[UnitySetupComponent]::Android] = , [io.path]::Combine("$playbackEnginePath", "AndroidPlayer"); $componentTests[[UnitySetupComponent]::iOS] = , [io.path]::Combine("$playbackEnginePath", "iOSSupport"); $componentTests[[UnitySetupComponent]::AppleTV] = , [io.path]::Combine("$playbackEnginePath", "AppleTVSupport"); From ec50edf506e1c50d2dcf3d6e60a90aff9e103c5c Mon Sep 17 00:00:00 2001 From: Stephen Hodgson Date: Mon, 1 Apr 2019 18:54:14 -0700 Subject: [PATCH 25/67] revert formatting change --- UnitySetup/UnitySetup.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index b4d83f4..100fafe 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -319,7 +319,7 @@ function Find-UnitySetupInstaller { [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"; + "$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"; From b69eaa3f93ee72c9fd4936313b574513376d2c88 Mon Sep 17 00:00:00 2001 From: Stephen Hodgson Date: Mon, 1 Apr 2019 18:57:43 -0700 Subject: [PATCH 26/67] Removed Mac common platform test --- UnitySetup/UnitySetup.psm1 | 1 - 1 file changed, 1 deletion(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 100fafe..821454f 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -101,7 +101,6 @@ class UnitySetupInstance { # Common playback engines: $componentTests[[UnitySetupComponent]::Linux] = , [io.path]::Combine("$playbackEnginePath", "LinuxStandaloneSupport"); - $componentTests[[UnitySetupComponent]::Mac] = , [io.path]::Combine("$playbackEnginePath", "MacStandaloneSupport"); $componentTests[[UnitySetupComponent]::Android] = , [io.path]::Combine("$playbackEnginePath", "AndroidPlayer"); $componentTests[[UnitySetupComponent]::iOS] = , [io.path]::Combine("$playbackEnginePath", "iOSSupport"); $componentTests[[UnitySetupComponent]::AppleTV] = , [io.path]::Combine("$playbackEnginePath", "AppleTVSupport"); From 2cfada1d859a3c43109e1f9d36e35ba5e9438470 Mon Sep 17 00:00:00 2001 From: Stephen Hodgson Date: Mon, 1 Apr 2019 19:01:59 -0700 Subject: [PATCH 27/67] reverted mac component line --- UnitySetup/UnitySetup.psm1 | 1 + 1 file changed, 1 insertion(+) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 821454f..ba69425 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -80,6 +80,7 @@ class UnitySetupInstance { [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]::Mac = , [io.path]::Combine("$playbackEnginePath", "MacStandaloneSupport"); } } ([OperatingSystem]::Linux) { From 6c788881aced774928353e778613d5ebd6630eda Mon Sep 17 00:00:00 2001 From: Stephen Hodgson Date: Tue, 2 Apr 2019 09:21:16 -0700 Subject: [PATCH 28/67] Revert Linux move --- UnitySetup/UnitySetup.psm1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index ba69425..f6b067b 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -80,6 +80,7 @@ class UnitySetupInstance { [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"); } } @@ -96,12 +97,12 @@ class UnitySetupInstance { [UnitySetupComponent]::StandardAssets = , [io.path]::Combine("$Path", "Standard Assets"); #[UnitySetupComponent]::Mac_IL2CPP = , [io.path]::Combine("$playbackEnginePath", "???"); [UnitySetupComponent]::Windows = , [io.path]::Combine("$playbackEnginePath", "WindowsStandaloneSupport"); + [UnitySetupComponent]::Linux = , [io.path]::Combine("$playbackEnginePath", "LinuxStandaloneSupport"); } } } # Common playback engines: - $componentTests[[UnitySetupComponent]::Linux] = , [io.path]::Combine("$playbackEnginePath", "LinuxStandaloneSupport"); $componentTests[[UnitySetupComponent]::Android] = , [io.path]::Combine("$playbackEnginePath", "AndroidPlayer"); $componentTests[[UnitySetupComponent]::iOS] = , [io.path]::Combine("$playbackEnginePath", "iOSSupport"); $componentTests[[UnitySetupComponent]::AppleTV] = , [io.path]::Combine("$playbackEnginePath", "AppleTVSupport"); From 9f9dfbf0f6a1c5bbe8d987ba770bb970814fe1b4 Mon Sep 17 00:00:00 2001 From: Stephen Hodgson Date: Thu, 4 Apr 2019 07:36:01 -0700 Subject: [PATCH 29/67] Update UnitySetup/UnitySetup.psm1 Added Mac_IL2CPP component path --- UnitySetup/UnitySetup.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index f6b067b..f021c26 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -95,7 +95,7 @@ class UnitySetupInstance { @{ [UnitySetupComponent]::Documentation = , [io.path]::Combine("$Path", "Documentation"); [UnitySetupComponent]::StandardAssets = , [io.path]::Combine("$Path", "Standard Assets"); - #[UnitySetupComponent]::Mac_IL2CPP = , [io.path]::Combine("$playbackEnginePath", "???"); + #[UnitySetupComponent]::Mac_IL2CPP = , [io.path]::Combine("$playbackEnginePath", "MacStandaloneSupport/Variations/macosx64_development_il2cpp"); [UnitySetupComponent]::Windows = , [io.path]::Combine("$playbackEnginePath", "WindowsStandaloneSupport"); [UnitySetupComponent]::Linux = , [io.path]::Combine("$playbackEnginePath", "LinuxStandaloneSupport"); } From 2394ed83b35bd908504ee9f92a45903ff465db96 Mon Sep 17 00:00:00 2001 From: Stephen Hodgson Date: Thu, 4 Apr 2019 13:28:38 -0700 Subject: [PATCH 30/67] Enabled component --- UnitySetup/UnitySetup.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index f021c26..0aedb09 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -95,7 +95,7 @@ class UnitySetupInstance { @{ [UnitySetupComponent]::Documentation = , [io.path]::Combine("$Path", "Documentation"); [UnitySetupComponent]::StandardAssets = , [io.path]::Combine("$Path", "Standard Assets"); - #[UnitySetupComponent]::Mac_IL2CPP = , [io.path]::Combine("$playbackEnginePath", "MacStandaloneSupport/Variations/macosx64_development_il2cpp"); + [UnitySetupComponent]::Mac_IL2CPP = , [io.path]::Combine("$playbackEnginePath", "MacStandaloneSupport/Variations/macosx64_development_il2cpp"); [UnitySetupComponent]::Windows = , [io.path]::Combine("$playbackEnginePath", "WindowsStandaloneSupport"); [UnitySetupComponent]::Linux = , [io.path]::Combine("$playbackEnginePath", "LinuxStandaloneSupport"); } From a84f4eca76562f71c62754798fa3341b3a5b2397 Mon Sep 17 00:00:00 2001 From: Josh Wittner Date: Tue, 9 Apr 2019 16:09:00 -0700 Subject: [PATCH 31/67] Use system process to avoid false wait times --- UnitySetup/UnitySetup.psm1 | 39 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index c65758d..669782f 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -1492,24 +1492,11 @@ function Start-UnityEditor { $unityArgs = $sharedArgs | ForEach-Object { $_ } if ( $instanceArgs[$i] ) { $unityArgs += $instanceArgs[$i] } - $setProcessArgs = @{ - 'FilePath' = $editor; - 'PassThru' = $true; - 'ErrorAction' = 'Stop'; - 'RedirectStandardOutput' = New-TemporaryFile; - 'RedirectStandardError' = New-TemporaryFile; - } - - if ($Wait) { $setProcessArgs['Wait'] = $true } - - Write-Verbose "Redirecting standard output to $($setProcessArgs['RedirectStandardOutput'])" - Write-Verbose "Redirecting standard error to $($setProcessArgs['RedirectStandardError'])" - $actionString = "$editor $unityArgs" - if( $Credential ) { $actionString += " -password (hidden)"} - if( $Serial ) { $actionString += " -serial (hidden)"} + if ( $Credential ) { $actionString += " -password (hidden)"} + if ( $Serial ) { $actionString += " -serial (hidden)"} - if (-not $PSCmdlet.ShouldProcess($actionString, "Start-Process")) { + if (-not $PSCmdlet.ShouldProcess($actionString, "System.Diagnostics.Process.Start()")) { continue } @@ -1517,12 +1504,22 @@ function Start-UnityEditor { if ( $Credential ) { $unityArgs += '-password', $Credential.GetNetworkCredential().Password } if ( $Serial ) { $unityArgs += '-serial', [System.Net.NetworkCredential]::new($null, $Serial).Password } - if ($unityArgs -and $unityArgs.Length -gt 0) { - $setProcessArgs['ArgumentList'] = $unityArgs - } - - $process = Start-Process @setProcessArgs + # We've experienced issues with Start-Process -Wait and redirecting + # output so we're using the Process class directly now. + $process = New-Object System.Diagnostics.Process + $process.StartInfo.Filename = $editor + $process.StartInfo.Arguments = $unityArgs + $process.StartInfo.RedirectStandardOutput = $true + $process.StartInfo.RedirectStandardError = $true + $process.StartInfo.UseShellExecute = $false + $process.StartInfo.CreateNoWindow = $true + $process.StartInfo.WorkingDirectory = $PWD + $process.StartInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden + $process.Start() | Out-Null + if ( $Wait ) { + $process.WaitForExit() + if ( $LogFile -and (Test-Path $LogFile -Type Leaf) ) { # Note that Unity sometimes returns a success ExitCode despite the presence of errors, but we want # to make sure that we flag such errors. From eb016688954285860cce9d8f75e7babd3b480786 Mon Sep 17 00:00:00 2001 From: Josh Wittner Date: Tue, 9 Apr 2019 16:09:34 -0700 Subject: [PATCH 32/67] Auto formatting --- UnitySetup/UnitySetup.psm1 | 149 ++++++++++++++++++------------------- 1 file changed, 73 insertions(+), 76 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 669782f..6516d05 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -73,14 +73,14 @@ class UnitySetupInstance { $this.Components = [UnitySetupComponent]::Windows $playbackEnginePath = [io.path]::Combine("$Path", "Editor\Data\PlaybackEngines"); @{ - [UnitySetupComponent]::Documentation = , [io.path]::Combine("$Path", "Editor\Data\Documentation"); + [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"), + [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"); + [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"); } } ([OperatingSystem]::Linux) { @@ -92,10 +92,10 @@ class UnitySetupInstance { $this.Components = [UnitySetupComponent]::Mac $playbackEnginePath = [io.path]::Combine("$Path", "PlaybackEngines"); @{ - [UnitySetupComponent]::Documentation = , [io.path]::Combine("$Path", "Documentation"); + [UnitySetupComponent]::Documentation = , [io.path]::Combine("$Path", "Documentation"); [UnitySetupComponent]::StandardAssets = , [io.path]::Combine("$Path", "Standard Assets"); - [UnitySetupComponent]::Windows = , [io.path]::Combine("$playbackEnginePath", "WindowsStandaloneSupport"); - [UnitySetupComponent]::Linux = , [io.path]::Combine("$playbackEnginePath", "LinuxStandaloneSupport"); + [UnitySetupComponent]::Windows = , [io.path]::Combine("$playbackEnginePath", "WindowsStandaloneSupport"); + [UnitySetupComponent]::Linux = , [io.path]::Combine("$playbackEnginePath", "LinuxStandaloneSupport"); } } } @@ -301,18 +301,18 @@ 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_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", + [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]::Vuforia = , "$targetSupport/UnitySetup-Vuforia-AR-Support-for-Editor-$Version.$installerExtension"; - [UnitySetupComponent]::WebGL = , "$targetSupport/UnitySetup-WebGL-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"; [UnitySetupComponent]::Windows_IL2CPP = , "$targetSupport/UnitySetup-Windows-IL2CPP-Support-for-Editor-$Version.$installerExtension"; } @@ -426,10 +426,10 @@ function Find-UnitySetupInstaller { } $result = New-Object UnitySetupInstaller -Property @{ 'ComponentType' = $_; - 'Version' = $Version; - 'DownloadUrl' = $endpoint; - 'Length' = $installerLength; - 'LastModified' = $lastModified; + 'Version' = $Version; + 'DownloadUrl' = $endpoint; + 'Length' = $installerLength; + 'LastModified' = $lastModified; } break @@ -532,13 +532,13 @@ function Select-UnitySetupInstaller { } filter Format-Bytes { - return "{0:N2} {1}" -f $( - if ($_ -lt 1kb) { $_, 'Bytes' } - elseif ($_ -lt 1mb) { ($_/1kb), 'KB' } - elseif ($_ -lt 1gb) { ($_/1mb), 'MB' } - elseif ($_ -lt 1tb) { ($_/1gb), 'GB' } - elseif ($_ -lt 1pb) { ($_/1tb), 'TB' } - else { ($_/1pb), 'PB' } + return "{0:N2} {1}" -f $( + if ($_ -lt 1kb) { $_, 'Bytes' } + elseif ($_ -lt 1mb) { ($_ / 1kb), 'KB' } + elseif ($_ -lt 1gb) { ($_ / 1mb), 'MB' } + elseif ($_ -lt 1tb) { ($_ / 1gb), 'GB' } + elseif ($_ -lt 1pb) { ($_ / 1tb), 'TB' } + else { ($_ / 1pb), 'PB' } ) } @@ -556,13 +556,13 @@ function Format-BitsPerSecond { } # Convert from bytes to bits $Bits = ($Bytes * 8) / $Seconds - return "{0:N2} {1}" -f $( - if ($Bits -lt 1kb) { $Bits, 'Bps' } - elseif ($Bits -lt 1mb) { ($Bits/1kb), 'Kbps' } - elseif ($Bits -lt 1gb) { ($Bits/1mb), 'Mbps' } - elseif ($Bits -lt 1tb) { ($Bits/1gb), 'Gbps' } - elseif ($Bits -lt 1pb) { ($Bits/1tb), 'Tbps' } - else { ($Bits/1pb), 'Pbps' } + return "{0:N2} {1}" -f $( + if ($Bits -lt 1kb) { $Bits, 'Bps' } + elseif ($Bits -lt 1mb) { ($Bits / 1kb), 'Kbps' } + elseif ($Bits -lt 1gb) { ($Bits / 1mb), 'Mbps' } + elseif ($Bits -lt 1tb) { ($Bits / 1gb), 'Gbps' } + elseif ($Bits -lt 1pb) { ($Bits / 1tb), 'Tbps' } + else { ($Bits / 1pb), 'Pbps' } ) } @@ -630,7 +630,7 @@ function Request-UnitySetupInstaller { $resource = New-Object UnitySetupResource -Property @{ 'ComponentType' = $_.ComponentType - 'Path' = $destination + 'Path' = $destination } $downloads += , $resource return @@ -647,15 +647,15 @@ function Request-UnitySetupInstaller { ++$downloadIndex $global:downloadData[$installerFileName] = New-Object PSObject -Property @{ installerFileName = $installerFileName - startTime = Get-Date - totalBytes = $_.Length - receivedBytes = 0 - isDownloaded = $false - destination = $destination - lastModified = $_.LastModified - componentType = $_.ComponentType - webClient = $webClient - downloadIndex = $downloadIndex + startTime = Get-Date + totalBytes = $_.Length + receivedBytes = 0 + isDownloaded = $false + destination = $destination + lastModified = $_.LastModified + componentType = $_.ComponentType + webClient = $webClient + downloadIndex = $downloadIndex } # Register to events for showing progress of file download. @@ -666,8 +666,7 @@ function Request-UnitySetupInstaller { $global:downloadData[$event.MessageData].isDownloaded = $true } | Out-Null - try - { + try { Write-Verbose "Downloading $($_.DownloadUrl) to $destination" $webClient.DownloadFileAsync($_.DownloadUrl, $destination) } @@ -712,7 +711,7 @@ function Request-UnitySetupInstaller { $resource = New-Object UnitySetupResource -Property @{ 'ComponentType' = $data.componentType - 'Path' = $data.destination + 'Path' = $data.destination } $downloads += , $resource return @@ -781,10 +780,10 @@ function Install-UnitySetupPackage { switch ($currentOS) { ([OperatingSystem]::Windows) { $startProcessArgs = @{ - 'FilePath' = $Package.Path; + 'FilePath' = $Package.Path; 'ArgumentList' = @("/S", "/D=$Destination"); - 'PassThru' = $true; - 'Wait' = $true; + 'PassThru' = $true; + 'Wait' = $true; } } ([OperatingSystem]::Linux) { @@ -794,10 +793,10 @@ function Install-UnitySetupPackage { # Note that $Destination has to be a disk path. # sudo installer -package $Package.Path -target / $startProcessArgs = @{ - 'FilePath' = 'sudo'; + 'FilePath' = 'sudo'; 'ArgumentList' = @("installer", "-package", $Package.Path, "-target", $Destination); - 'PassThru' = $true; - 'Wait' = $true; + 'PassThru' = $true; + 'Wait' = $true; } } } @@ -977,8 +976,7 @@ function Install-UnitySetupInstance { # Move the install from the sparse bundle disk to the install directory. if ($currentOS -eq [OperatingSystem]::Mac) { # rsync does not recursively create the directory path. - if (-not (Test-Path $installPath -PathType Container)) - { + if (-not (Test-Path $installPath -PathType Container)) { Write-Verbose "Creating directory $installPath." New-Item $installPath -ItemType Directory -ErrorAction Stop | Out-Null } @@ -1031,10 +1029,10 @@ function Uninstall-UnitySetupInstance { } $startProcessArgs = @{ - 'FilePath' = $uninstaller; - 'PassThru' = $true; - 'Wait' = $true; - 'ErrorAction' = 'Stop'; + 'FilePath' = $uninstaller; + 'PassThru' = $true; + 'Wait' = $true; + 'ErrorAction' = 'Stop'; 'ArgumentList' = @("/S"); } @@ -1178,10 +1176,10 @@ function Get-UnityProjectInstance { ) $args = @{ - 'Path' = $BasePath; - 'Filter' = 'ProjectSettings'; + 'Path' = $BasePath; + 'Filter' = 'ProjectSettings'; 'ErrorAction' = 'Ignore'; - 'Directory' = $true; + 'Directory' = $true; } if ( $Recurse ) { @@ -1582,7 +1580,7 @@ function Get-IsUnityError { function ConvertTo-DateTime { param([string] $Text) - if( -not $text -or $text.Length -eq 0 ) { [DateTime]::MaxValue } + if ( -not $text -or $text.Length -eq 0 ) { [DateTime]::MaxValue } else { [DateTime]$Text } } @@ -1594,10 +1592,9 @@ function ConvertTo-DateTime { .EXAMPLE Get-UnityLicense #> -function Get-UnityLicense -{ +function Get-UnityLicense { [CmdletBinding()] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "", Justification="Used to convert discovered plaintext serials into secure strings.")] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "", Justification = "Used to convert discovered plaintext serials into secure strings.")] param([SecureString]$Serial) $licenseFiles = Get-ChildItem "C:\ProgramData\Unity\Unity_*.ulf" -ErrorAction 'SilentlyContinue' @@ -1608,18 +1605,18 @@ function Get-UnityLicense # The first four bytes look like a count so skip that to pull out the serial string $licenseSerial = [String]::new($devBytes[4..($devBytes.Length - 1)]) - if( $Serial -and [System.Net.NetworkCredential]::new($null, $Serial).Password -ne $licenseSerial ) { continue; } + if ( $Serial -and [System.Net.NetworkCredential]::new($null, $Serial).Password -ne $licenseSerial ) { continue; } $license = $doc.root.License [PSCustomObject]@{ 'LicenseVersion' = $license.LicenseVersion.Value - 'Serial' = ConvertTo-SecureString $licenseSerial -AsPlainText -Force - 'UnityVersion' = [UnityVersion]$license.ClientProvidedVersion.Value - 'DisplaySerial' = $license.SerialMasked.Value + 'Serial' = ConvertTo-SecureString $licenseSerial -AsPlainText -Force + 'UnityVersion' = [UnityVersion]$license.ClientProvidedVersion.Value + 'DisplaySerial' = $license.SerialMasked.Value 'ActivationDate' = ConvertTo-DateTime $license.InitialActivationDate.Value - 'StartDate' = ConvertTo-DateTime $license.StartDate.Value - 'StopDate' = ConvertTo-DateTime $license.StopDate.Value - 'UpdateDate' = ConvertTo-DateTime $license.UpdateDate.Value + 'StartDate' = ConvertTo-DateTime $license.StartDate.Value + 'StopDate' = ConvertTo-DateTime $license.StopDate.Value + 'UpdateDate' = ConvertTo-DateTime $license.UpdateDate.Value } } } From 54d86331acd0249fb3b77acd87dc339da482846c Mon Sep 17 00:00:00 2001 From: StephenHodgson Date: Wed, 17 Apr 2019 02:26:33 -0700 Subject: [PATCH 33/67] merged dev branch --- UnitySetup/UnitySetup.psm1 | 229 ++++++++++++++++++------------------- 1 file changed, 113 insertions(+), 116 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 809359a..3fc64fb 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -19,7 +19,8 @@ enum UnitySetupComponent { Facebook = (1 -shl 11) Vuforia = (1 -shl 12) WebGL = (1 -shl 13) - Lumin = (1 -shl 14) + Mac_IL2CPP = (1 -shl 14) + Lumin = (1 -shl 15) All = (1 -shl 15) - 1 } @@ -74,14 +75,14 @@ class UnitySetupInstance { $this.Components = [UnitySetupComponent]::Windows $playbackEnginePath = [io.path]::Combine("$Path", "Editor\Data\PlaybackEngines"); @{ - [UnitySetupComponent]::Documentation = , [io.path]::Combine("$Path", "Editor\Data\Documentation"); + [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"), + [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"); + [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"); } } ([OperatingSystem]::Linux) { @@ -93,10 +94,11 @@ class UnitySetupInstance { $this.Components = [UnitySetupComponent]::Mac $playbackEnginePath = [io.path]::Combine("$Path", "PlaybackEngines"); @{ - [UnitySetupComponent]::Documentation = , [io.path]::Combine("$Path", "Documentation"); + [UnitySetupComponent]::Documentation = , [io.path]::Combine("$Path", "Documentation"); [UnitySetupComponent]::StandardAssets = , [io.path]::Combine("$Path", "Standard Assets"); - [UnitySetupComponent]::Windows = , [io.path]::Combine("$playbackEnginePath", "WindowsStandaloneSupport"); - [UnitySetupComponent]::Linux = , [io.path]::Combine("$playbackEnginePath", "LinuxStandaloneSupport"); + [UnitySetupComponent]::Mac_IL2CPP = , [io.path]::Combine("$playbackEnginePath", "MacStandaloneSupport/Variations/macosx64_development_il2cpp"); + [UnitySetupComponent]::Windows = , [io.path]::Combine("$playbackEnginePath", "WindowsStandaloneSupport"); + [UnitySetupComponent]::Linux = , [io.path]::Combine("$playbackEnginePath", "LinuxStandaloneSupport"); } } } @@ -311,18 +313,19 @@ 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_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", + [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]::Vuforia = , "$targetSupport/UnitySetup-Vuforia-AR-Support-for-Editor-$Version.$installerExtension"; - [UnitySetupComponent]::WebGL = , "$targetSupport/UnitySetup-WebGL-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"; [UnitySetupComponent]::Windows_IL2CPP = , "$targetSupport/UnitySetup-Windows-IL2CPP-Support-for-Editor-$Version.$installerExtension"; [UnitySetupComponent]::Lumin = , "$targetSupport/UnitySetup-Lumin-Support-for-Editor-$Version.$installerExtension"; } @@ -368,8 +371,8 @@ function Find-UnitySetupInstaller { $patchPage = "https://unity3d.com/unity/qa/patch-releases?version=$($Version.Major).$($Version.Minor)" $searchPages += $patchPage - $webResult = Invoke-WebRequest $patchPage -UseBasicParsing - $searchPages += $webResult.Links | Where-Object { + $webResult = Invoke-WebRequest $patchPage -UseBasicParsing + $searchPages += $webResult.Links | Where-Object { $_.href -match "\/unity\/qa\/patch-releases\?version=$($Version.Major)\.$($Version.Minor)&page=(\d+)" -and $Matches[1] -gt 1 } | ForEach-Object { "https://unity3d.com$($_.href)" } } @@ -437,10 +440,10 @@ function Find-UnitySetupInstaller { } $result = New-Object UnitySetupInstaller -Property @{ 'ComponentType' = $_; - 'Version' = $Version; - 'DownloadUrl' = $endpoint; - 'Length' = $installerLength; - 'LastModified' = $lastModified; + 'Version' = $Version; + 'DownloadUrl' = $endpoint; + 'Length' = $installerLength; + 'LastModified' = $lastModified; } break @@ -543,13 +546,13 @@ function Select-UnitySetupInstaller { } filter Format-Bytes { - return "{0:N2} {1}" -f $( - if ($_ -lt 1kb) { $_, 'Bytes' } - elseif ($_ -lt 1mb) { ($_/1kb), 'KB' } - elseif ($_ -lt 1gb) { ($_/1mb), 'MB' } - elseif ($_ -lt 1tb) { ($_/1gb), 'GB' } - elseif ($_ -lt 1pb) { ($_/1tb), 'TB' } - else { ($_/1pb), 'PB' } + return "{0:N2} {1}" -f $( + if ($_ -lt 1kb) { $_, 'Bytes' } + elseif ($_ -lt 1mb) { ($_ / 1kb), 'KB' } + elseif ($_ -lt 1gb) { ($_ / 1mb), 'MB' } + elseif ($_ -lt 1tb) { ($_ / 1gb), 'GB' } + elseif ($_ -lt 1pb) { ($_ / 1tb), 'TB' } + else { ($_ / 1pb), 'PB' } ) } @@ -567,13 +570,13 @@ function Format-BitsPerSecond { } # Convert from bytes to bits $Bits = ($Bytes * 8) / $Seconds - return "{0:N2} {1}" -f $( - if ($Bits -lt 1kb) { $Bits, 'Bps' } - elseif ($Bits -lt 1mb) { ($Bits/1kb), 'Kbps' } - elseif ($Bits -lt 1gb) { ($Bits/1mb), 'Mbps' } - elseif ($Bits -lt 1tb) { ($Bits/1gb), 'Gbps' } - elseif ($Bits -lt 1pb) { ($Bits/1tb), 'Tbps' } - else { ($Bits/1pb), 'Pbps' } + return "{0:N2} {1}" -f $( + if ($Bits -lt 1kb) { $Bits, 'Bps' } + elseif ($Bits -lt 1mb) { ($Bits / 1kb), 'Kbps' } + elseif ($Bits -lt 1gb) { ($Bits / 1mb), 'Mbps' } + elseif ($Bits -lt 1tb) { ($Bits / 1gb), 'Gbps' } + elseif ($Bits -lt 1pb) { ($Bits / 1tb), 'Tbps' } + else { ($Bits / 1pb), 'Pbps' } ) } @@ -641,7 +644,7 @@ function Request-UnitySetupInstaller { $resource = New-Object UnitySetupResource -Property @{ 'ComponentType' = $_.ComponentType - 'Path' = $destination + 'Path' = $destination } $downloads += , $resource return @@ -658,15 +661,15 @@ function Request-UnitySetupInstaller { ++$downloadIndex $global:downloadData[$installerFileName] = New-Object PSObject -Property @{ installerFileName = $installerFileName - startTime = Get-Date - totalBytes = $_.Length - receivedBytes = 0 - isDownloaded = $false - destination = $destination - lastModified = $_.LastModified - componentType = $_.ComponentType - webClient = $webClient - downloadIndex = $downloadIndex + startTime = Get-Date + totalBytes = $_.Length + receivedBytes = 0 + isDownloaded = $false + destination = $destination + lastModified = $_.LastModified + componentType = $_.ComponentType + webClient = $webClient + downloadIndex = $downloadIndex } # Register to events for showing progress of file download. @@ -677,8 +680,7 @@ function Request-UnitySetupInstaller { $global:downloadData[$event.MessageData].isDownloaded = $true } | Out-Null - try - { + try { Write-Verbose "Downloading $($_.DownloadUrl) to $destination" $webClient.DownloadFileAsync($_.DownloadUrl, $destination) } @@ -713,17 +715,17 @@ function Request-UnitySetupInstaller { Unregister-Event -SourceIdentifier "$installerFileName-Completed" -Force Unregister-Event -SourceIdentifier "$installerFileName-Changed" -Force - + $data.webClient.Dispose() $data.webClient = $null # Re-writes the last modified time for ensuring downloads are cached properly. $downloadedFile = Get-Item $data.destination $downloadedFile.LastWriteTime = $data.lastModified - + $resource = New-Object UnitySetupResource -Property @{ 'ComponentType' = $data.componentType - 'Path' = $data.destination + 'Path' = $data.destination } $downloads += , $resource return @@ -732,16 +734,16 @@ function Request-UnitySetupInstaller { $elapsedTime = (Get-Date) - $data.startTime $progress = [int](($data.receivedBytes / [double]$data.totalBytes) * 100) - + $averageSpeed = $data.receivedBytes / $elapsedTime.TotalSeconds $secondsRemaining = ($data.totalBytes - $data.receivedBytes) / $averageSpeed - + if ([double]::IsInfinity($secondsRemaining)) { $averageSpeed = 0 # -1 for Write-Progress prevents seconds remaining from showing. $secondsRemaining = -1 } - + $downloadSpeed = Format-BitsPerSecond -Bytes $data.receivedBytes -Seconds $elapsedTime.TotalSeconds Write-Progress -Activity "Downloading $installerFileName | $downloadSpeed" ` @@ -792,10 +794,10 @@ function Install-UnitySetupPackage { switch ($currentOS) { ([OperatingSystem]::Windows) { $startProcessArgs = @{ - 'FilePath' = $Package.Path; + 'FilePath' = $Package.Path; 'ArgumentList' = @("/S", "/D=$Destination"); - 'PassThru' = $true; - 'Wait' = $true; + 'PassThru' = $true; + 'Wait' = $true; } } ([OperatingSystem]::Linux) { @@ -805,21 +807,21 @@ function Install-UnitySetupPackage { # Note that $Destination has to be a disk path. # sudo installer -package $Package.Path -target / $startProcessArgs = @{ - 'FilePath' = 'sudo'; + 'FilePath' = 'sudo'; 'ArgumentList' = @("installer", "-package", $Package.Path, "-target", $Destination); - 'PassThru' = $true; - 'Wait' = $true; + 'PassThru' = $true; + 'Wait' = $true; } } } - + Write-Verbose "$(Get-Date): Installing $($Package.ComponentType) to $Destination." $process = Start-Process @startProcessArgs if ( $process ) { if ( $process.ExitCode -ne 0) { Write-Error "$(Get-Date): Failed with exit code: $($process.ExitCode)" } - else { + else { Write-Verbose "$(Get-Date): Succeeded." } } @@ -923,7 +925,7 @@ function Install-UnitySetupInstance { $installPath += [io.path]::DirectorySeparatorChar } - # Creating sparse bundle to host installing Unity in other locations + # Creating sparse bundle to host installing Unity in other locations $unitySetupBundlePath = [io.path]::Combine($Cache, "UnitySetup.sparsebundle") if (-not (Test-Path $unitySetupBundlePath)) { Write-Verbose "Creating new sparse bundle disk image for installation." @@ -988,8 +990,7 @@ function Install-UnitySetupInstance { # Move the install from the sparse bundle disk to the install directory. if ($currentOS -eq [OperatingSystem]::Mac) { # rsync does not recursively create the directory path. - if (-not (Test-Path $installPath -PathType Container)) - { + if (-not (Test-Path $installPath -PathType Container)) { Write-Verbose "Creating directory $installPath." New-Item $installPath -ItemType Directory -ErrorAction Stop | Out-Null } @@ -1042,10 +1043,10 @@ function Uninstall-UnitySetupInstance { } $startProcessArgs = @{ - 'FilePath' = $uninstaller; - 'PassThru' = $true; - 'Wait' = $true; - 'ErrorAction' = 'Stop'; + 'FilePath' = $uninstaller; + 'PassThru' = $true; + 'Wait' = $true; + 'ErrorAction' = 'Stop'; 'ArgumentList' = @("/S"); } @@ -1189,10 +1190,10 @@ function Get-UnityProjectInstance { ) $args = @{ - 'Path' = $BasePath; - 'Filter' = 'ProjectSettings'; + 'Path' = $BasePath; + 'Filter' = 'ProjectSettings'; 'ErrorAction' = 'Ignore'; - 'Directory' = $true; + 'Directory' = $true; } if ( $Recurse ) { @@ -1312,7 +1313,7 @@ function Start-UnityEditor { [parameter(Mandatory = $false)] [string]$LogFile, [parameter(Mandatory = $false)] - [ValidateSet('StandaloneOSX', 'StandaloneWindows', 'iOS', 'Android', 'StandaloneLinux', 'StandaloneWindows64', 'WebGL', 'WSAPlayer', 'StandaloneLinux64', 'StandaloneLinuxUniversal', 'Tizen', 'PSP2', 'PS4', 'XBoxOne', 'N3DS', 'WiiU', 'tvOS', 'Switch', 'Lumin')] + [ValidateSet('StandaloneOSX', 'StandaloneWindows', 'iOS', 'Android', 'StandaloneLinux', 'StandaloneWindows64', 'WebGL', 'WSAPlayer', 'StandaloneLinux64', 'StandaloneLinuxUniversal', 'Tizen', 'PSP2', 'PS4', 'XBoxOne', 'N3DS', 'WiiU', 'tvOS', 'Switch')] [string]$BuildTarget, [parameter(Mandatory = $false)] [switch]$AcceptAPIUpdate, @@ -1417,7 +1418,7 @@ function Start-UnityEditor { if ( -not $PSBoundParameters.ContainsKey('BatchMode') ) { $BatchMode = $true } if ( -not $PSBoundParameters.ContainsKey('Quit') ) { $Quit = $true } } - if ( $AcceptAPIUpdate ) { + if ( $AcceptAPIUpdate ) { $sharedArgs += '-accept-apiupdate' if ( -not $PSBoundParameters.ContainsKey('BatchMode')) { $BatchMode = $true } } @@ -1480,7 +1481,7 @@ function Start-UnityEditor { ([OperatingSystem]::Windows) { $editor = Get-ChildItem "$($setupInstance.Path)" -Filter 'Unity.exe' -Recurse | Select-Object -First 1 -ExpandProperty FullName - + if ([string]::IsNullOrEmpty($editor)) { Write-Error "Could not find Unity.exe under setup instance path: $($setupInstance.Path)" continue @@ -1491,7 +1492,7 @@ function Start-UnityEditor { } ([OperatingSystem]::Mac) { $editor = [io.path]::Combine("$($setupInstance.Path)", "Unity.app/Contents/MacOS/Unity") - + if ([string]::IsNullOrEmpty($editor)) { Write-Error "Could not find Unity app under setup instance path: $($setupInstance.Path)" continue @@ -1503,24 +1504,11 @@ function Start-UnityEditor { $unityArgs = $sharedArgs | ForEach-Object { $_ } if ( $instanceArgs[$i] ) { $unityArgs += $instanceArgs[$i] } - $setProcessArgs = @{ - 'FilePath' = $editor; - 'PassThru' = $true; - 'ErrorAction' = 'Stop'; - 'RedirectStandardOutput' = New-TemporaryFile; - 'RedirectStandardError' = New-TemporaryFile; - } - - if ($Wait) { $setProcessArgs['Wait'] = $true } - - Write-Verbose "Redirecting standard output to $($setProcessArgs['RedirectStandardOutput'])" - Write-Verbose "Redirecting standard error to $($setProcessArgs['RedirectStandardError'])" - $actionString = "$editor $unityArgs" - if( $Credential ) { $actionString += " -password (hidden)"} - if( $Serial ) { $actionString += " -serial (hidden)"} + if ( $Credential ) { $actionString += " -password (hidden)"} + if ( $Serial ) { $actionString += " -serial (hidden)"} - if (-not $PSCmdlet.ShouldProcess($actionString, "Start-Process")) { + if (-not $PSCmdlet.ShouldProcess($actionString, "System.Diagnostics.Process.Start()")) { continue } @@ -1528,17 +1516,27 @@ function Start-UnityEditor { if ( $Credential ) { $unityArgs += '-password', $Credential.GetNetworkCredential().Password } if ( $Serial ) { $unityArgs += '-serial', [System.Net.NetworkCredential]::new($null, $Serial).Password } - if ($unityArgs -and $unityArgs.Length -gt 0) { - $setProcessArgs['ArgumentList'] = $unityArgs - } + # We've experienced issues with Start-Process -Wait and redirecting + # output so we're using the Process class directly now. + $process = New-Object System.Diagnostics.Process + $process.StartInfo.Filename = $editor + $process.StartInfo.Arguments = $unityArgs + $process.StartInfo.RedirectStandardOutput = $true + $process.StartInfo.RedirectStandardError = $true + $process.StartInfo.UseShellExecute = $false + $process.StartInfo.CreateNoWindow = $true + $process.StartInfo.WorkingDirectory = $PWD + $process.StartInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden + $process.Start() | Out-Null - $process = Start-Process @setProcessArgs if ( $Wait ) { + $process.WaitForExit() + if ( $LogFile -and (Test-Path $LogFile -Type Leaf) ) { # Note that Unity sometimes returns a success ExitCode despite the presence of errors, but we want # to make sure that we flag such errors. Write-UnityErrors $LogFile - + Write-Verbose "Writing $LogFile to Information stream Tagged as 'Logs'" Get-Content $LogFile | ForEach-Object { Write-Information -MessageData $_ -Tags 'Logs' } } @@ -1596,7 +1594,7 @@ function Get-IsUnityError { function ConvertTo-DateTime { param([string] $Text) - if( -not $text -or $text.Length -eq 0 ) { [DateTime]::MaxValue } + if ( -not $text -or $text.Length -eq 0 ) { [DateTime]::MaxValue } else { [DateTime]$Text } } @@ -1608,10 +1606,9 @@ function ConvertTo-DateTime { .EXAMPLE Get-UnityLicense #> -function Get-UnityLicense -{ +function Get-UnityLicense { [CmdletBinding()] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "", Justification="Used to convert discovered plaintext serials into secure strings.")] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "", Justification = "Used to convert discovered plaintext serials into secure strings.")] param([SecureString]$Serial) $licenseFiles = Get-ChildItem "C:\ProgramData\Unity\Unity_*.ulf" -ErrorAction 'SilentlyContinue' @@ -1622,18 +1619,18 @@ function Get-UnityLicense # The first four bytes look like a count so skip that to pull out the serial string $licenseSerial = [String]::new($devBytes[4..($devBytes.Length - 1)]) - if( $Serial -and [System.Net.NetworkCredential]::new($null, $Serial).Password -ne $licenseSerial ) { continue; } - + if ( $Serial -and [System.Net.NetworkCredential]::new($null, $Serial).Password -ne $licenseSerial ) { continue; } + $license = $doc.root.License [PSCustomObject]@{ 'LicenseVersion' = $license.LicenseVersion.Value - 'Serial' = ConvertTo-SecureString $licenseSerial -AsPlainText -Force - 'UnityVersion' = [UnityVersion]$license.ClientProvidedVersion.Value - 'DisplaySerial' = $license.SerialMasked.Value + 'Serial' = ConvertTo-SecureString $licenseSerial -AsPlainText -Force + 'UnityVersion' = [UnityVersion]$license.ClientProvidedVersion.Value + 'DisplaySerial' = $license.SerialMasked.Value 'ActivationDate' = ConvertTo-DateTime $license.InitialActivationDate.Value - 'StartDate' = ConvertTo-DateTime $license.StartDate.Value - 'StopDate' = ConvertTo-DateTime $license.StopDate.Value - 'UpdateDate' = ConvertTo-DateTime $license.UpdateDate.Value + 'StartDate' = ConvertTo-DateTime $license.StartDate.Value + 'StopDate' = ConvertTo-DateTime $license.StopDate.Value + 'UpdateDate' = ConvertTo-DateTime $license.UpdateDate.Value } } } @@ -1647,11 +1644,11 @@ function Get-UnityLicense $alias = Get-Alias -Name $_.Name -ErrorAction 'SilentlyContinue' if ( -not $alias ) { - Write-Verbose "Creating new alias $($_.Name) for $($_.Value)" - New-Alias @_ + Write-Verbose "Creating new alias $($_.Name) for $($_.Value)" + New-Alias @_ } elseif ( $alias.ModuleName -eq 'UnitySetup' ) { - Write-Verbose "Setting alias $($_.Name) to $($_.Value)" + Write-Verbose "Setting alias $($_.Name) to $($_.Value)" Set-Alias @_ } else { From 250ac3c98f27122e13acd24f9d0bb8f642da6908 Mon Sep 17 00:00:00 2001 From: StephenHodgson Date: Wed, 17 Apr 2019 02:30:31 -0700 Subject: [PATCH 34/67] just some whitespace changes --- UnitySetup/UnitySetup.psm1 | 56 +++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 4f83a9f..6688184 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -77,8 +77,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"); @@ -103,12 +103,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[$_] ) { @@ -368,8 +368,8 @@ function Find-UnitySetupInstaller { $patchPage = "https://unity3d.com/unity/qa/patch-releases?version=$($Version.Major).$($Version.Minor)" $searchPages += $patchPage - $webResult = Invoke-WebRequest $patchPage -UseBasicParsing - $searchPages += $webResult.Links | Where-Object { + $webResult = Invoke-WebRequest $patchPage -UseBasicParsing + $searchPages += $webResult.Links | Where-Object { $_.href -match "\/unity\/qa\/patch-releases\?version=$($Version.Major)\.$($Version.Minor)&page=(\d+)" -and $Matches[1] -gt 1 } | ForEach-Object { "https://unity3d.com$($_.href)" } } @@ -712,14 +712,14 @@ function Request-UnitySetupInstaller { Unregister-Event -SourceIdentifier "$installerFileName-Completed" -Force Unregister-Event -SourceIdentifier "$installerFileName-Changed" -Force - + $data.webClient.Dispose() $data.webClient = $null # Re-writes the last modified time for ensuring downloads are cached properly. $downloadedFile = Get-Item $data.destination $downloadedFile.LastWriteTime = $data.lastModified - + $resource = New-Object UnitySetupResource -Property @{ 'ComponentType' = $data.componentType 'Path' = $data.destination @@ -731,16 +731,16 @@ function Request-UnitySetupInstaller { $elapsedTime = (Get-Date) - $data.startTime $progress = [int](($data.receivedBytes / [double]$data.totalBytes) * 100) - + $averageSpeed = $data.receivedBytes / $elapsedTime.TotalSeconds $secondsRemaining = ($data.totalBytes - $data.receivedBytes) / $averageSpeed - + if ([double]::IsInfinity($secondsRemaining)) { $averageSpeed = 0 # -1 for Write-Progress prevents seconds remaining from showing. $secondsRemaining = -1 } - + $downloadSpeed = Format-BitsPerSecond -Bytes $data.receivedBytes -Seconds $elapsedTime.TotalSeconds Write-Progress -Activity "Downloading $installerFileName | $downloadSpeed" ` @@ -811,14 +811,14 @@ function Install-UnitySetupPackage { } } } - + Write-Verbose "$(Get-Date): Installing $($Package.ComponentType) to $Destination." $process = Start-Process @startProcessArgs if ( $process ) { if ( $process.ExitCode -ne 0) { Write-Error "$(Get-Date): Failed with exit code: $($process.ExitCode)" } - else { + else { Write-Verbose "$(Get-Date): Succeeded." } } @@ -922,7 +922,7 @@ function Install-UnitySetupInstance { $installPath += [io.path]::DirectorySeparatorChar } - # Creating sparse bundle to host installing Unity in other locations + # Creating sparse bundle to host installing Unity in other locations $unitySetupBundlePath = [io.path]::Combine($Cache, "UnitySetup.sparsebundle") if (-not (Test-Path $unitySetupBundlePath)) { Write-Verbose "Creating new sparse bundle disk image for installation." @@ -1415,7 +1415,7 @@ function Start-UnityEditor { if ( -not $PSBoundParameters.ContainsKey('BatchMode') ) { $BatchMode = $true } if ( -not $PSBoundParameters.ContainsKey('Quit') ) { $Quit = $true } } - if ( $AcceptAPIUpdate ) { + if ( $AcceptAPIUpdate ) { $sharedArgs += '-accept-apiupdate' if ( -not $PSBoundParameters.ContainsKey('BatchMode')) { $BatchMode = $true } } @@ -1478,7 +1478,7 @@ function Start-UnityEditor { ([OperatingSystem]::Windows) { $editor = Get-ChildItem "$($setupInstance.Path)" -Filter 'Unity.exe' -Recurse | Select-Object -First 1 -ExpandProperty FullName - + if ([string]::IsNullOrEmpty($editor)) { Write-Error "Could not find Unity.exe under setup instance path: $($setupInstance.Path)" continue @@ -1489,7 +1489,7 @@ function Start-UnityEditor { } ([OperatingSystem]::Mac) { $editor = [io.path]::Combine("$($setupInstance.Path)", "Unity.app/Contents/MacOS/Unity") - + if ([string]::IsNullOrEmpty($editor)) { Write-Error "Could not find Unity app under setup instance path: $($setupInstance.Path)" continue @@ -1513,7 +1513,7 @@ function Start-UnityEditor { if ( $Credential ) { $unityArgs += '-password', $Credential.GetNetworkCredential().Password } if ( $Serial ) { $unityArgs += '-serial', [System.Net.NetworkCredential]::new($null, $Serial).Password } - # We've experienced issues with Start-Process -Wait and redirecting + # We've experienced issues with Start-Process -Wait and redirecting # output so we're using the Process class directly now. $process = New-Object System.Diagnostics.Process $process.StartInfo.Filename = $editor @@ -1523,9 +1523,9 @@ function Start-UnityEditor { $process.StartInfo.UseShellExecute = $false $process.StartInfo.CreateNoWindow = $true $process.StartInfo.WorkingDirectory = $PWD - $process.StartInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden + $process.StartInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden $process.Start() | Out-Null - + if ( $Wait ) { $process.WaitForExit() @@ -1533,7 +1533,7 @@ function Start-UnityEditor { # Note that Unity sometimes returns a success ExitCode despite the presence of errors, but we want # to make sure that we flag such errors. Write-UnityErrors $LogFile - + Write-Verbose "Writing $LogFile to Information stream Tagged as 'Logs'" Get-Content $LogFile | ForEach-Object { Write-Information -MessageData $_ -Tags 'Logs' } } @@ -1617,7 +1617,7 @@ function Get-UnityLicense { # The first four bytes look like a count so skip that to pull out the serial string $licenseSerial = [String]::new($devBytes[4..($devBytes.Length - 1)]) if ( $Serial -and [System.Net.NetworkCredential]::new($null, $Serial).Password -ne $licenseSerial ) { continue; } - + $license = $doc.root.License [PSCustomObject]@{ 'LicenseVersion' = $license.LicenseVersion.Value @@ -1641,11 +1641,11 @@ function Get-UnityLicense { $alias = Get-Alias -Name $_.Name -ErrorAction 'SilentlyContinue' if ( -not $alias ) { - Write-Verbose "Creating new alias $($_.Name) for $($_.Value)" - New-Alias @_ + Write-Verbose "Creating new alias $($_.Name) for $($_.Value)" + New-Alias @_ } elseif ( $alias.ModuleName -eq 'UnitySetup' ) { - Write-Verbose "Setting alias $($_.Name) to $($_.Value)" + Write-Verbose "Setting alias $($_.Name) to $($_.Value)" Set-Alias @_ } else { From 89543d1e8f644b56b4b3dd228bed99af0687d0bf Mon Sep 17 00:00:00 2001 From: StephenHodgson Date: Wed, 17 Apr 2019 02:55:36 -0700 Subject: [PATCH 35/67] a bit more formatting --- UnitySetup/UnitySetup.psm1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 6688184..1657b64 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -311,16 +311,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"; From ae96311837f29c9021cfd58123f9347be0351ece Mon Sep 17 00:00:00 2001 From: StephenHodgson Date: Thu, 18 Apr 2019 20:19:44 -0700 Subject: [PATCH 36/67] adds both archive and beta pages for searching --- UnitySetup/UnitySetup.psm1 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 4f83a9f..13dddc5 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -360,10 +360,8 @@ function Find-UnitySetupInstaller { } # Every release type has a different pattern for finding installers - $searchPages = @() + $searchPages = @( "https://unity3d.com/get-unity/download/archive", "https://unity3d.com/unity/beta/unity$Version" ) switch ($Version.Release) { - 'f' { $searchPages += "https://unity3d.com/get-unity/download/archive" } - 'b' { $searchPages += "https://unity3d.com/unity/beta/unity$Version" } 'p' { $patchPage = "https://unity3d.com/unity/qa/patch-releases?version=$($Version.Major).$($Version.Minor)" $searchPages += $patchPage From 9d350e3d4ae94a6bf88d1bf2385567569d506cd9 Mon Sep 17 00:00:00 2001 From: StephenHodgson Date: Thu, 18 Apr 2019 20:25:41 -0700 Subject: [PATCH 37/67] added lumin back to the parameter list for build platform --- UnitySetup/UnitySetup.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 3fc64fb..1dd5098 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -1313,7 +1313,7 @@ function Start-UnityEditor { [parameter(Mandatory = $false)] [string]$LogFile, [parameter(Mandatory = $false)] - [ValidateSet('StandaloneOSX', 'StandaloneWindows', 'iOS', 'Android', 'StandaloneLinux', 'StandaloneWindows64', 'WebGL', 'WSAPlayer', 'StandaloneLinux64', 'StandaloneLinuxUniversal', 'Tizen', 'PSP2', 'PS4', 'XBoxOne', 'N3DS', 'WiiU', 'tvOS', 'Switch')] + [ValidateSet('StandaloneOSX', 'StandaloneWindows', 'iOS', 'Android', 'StandaloneLinux', 'StandaloneWindows64', 'WebGL', 'WSAPlayer', 'StandaloneLinux64', 'StandaloneLinuxUniversal', 'Tizen', 'PSP2', 'PS4', 'XBoxOne', 'N3DS', 'WiiU', 'tvOS', 'Switch', 'Lumin')] [string]$BuildTarget, [parameter(Mandatory = $false)] [switch]$AcceptAPIUpdate, From 780fd29f4f4b1caa71b1116c156b73d723f0e741 Mon Sep 17 00:00:00 2001 From: StephenHodgson Date: Thu, 18 Apr 2019 20:33:15 -0700 Subject: [PATCH 38/67] fixed spacing --- UnitySetup/UnitySetup.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 1dd5098..a0ab1b6 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -327,7 +327,7 @@ function Find-UnitySetupInstaller { [UnitySetupComponent]::Vuforia = , "$targetSupport/UnitySetup-Vuforia-AR-Support-for-Editor-$Version.$installerExtension"; [UnitySetupComponent]::WebGL = , "$targetSupport/UnitySetup-WebGL-Support-for-Editor-$Version.$installerExtension"; [UnitySetupComponent]::Windows_IL2CPP = , "$targetSupport/UnitySetup-Windows-IL2CPP-Support-for-Editor-$Version.$installerExtension"; - [UnitySetupComponent]::Lumin = , "$targetSupport/UnitySetup-Lumin-Support-for-Editor-$Version.$installerExtension"; + [UnitySetupComponent]::Lumin = , "$targetSupport/UnitySetup-Lumin-Support-for-Editor-$Version.$installerExtension"; } switch ($currentOS) { From 1edea460c080afab0c5692dab6dc3abe613af376 Mon Sep 17 00:00:00 2001 From: StephenHodgson Date: Thu, 18 Apr 2019 21:59:25 -0700 Subject: [PATCH 39/67] 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 317ebe96f9a84ee3cffe392cac2d6f20cb0e06d1 Mon Sep 17 00:00:00 2001 From: StephenHodgson Date: Thu, 18 Apr 2019 22:12:25 -0700 Subject: [PATCH 40/67] added alpha to regex search --- UnitySetup/UnitySetup.psm1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 13dddc5..f8c376e 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -162,7 +162,7 @@ class UnityVersion : System.IComparable { UnityVersion([string] $version) { $parts = $version.Split('-') - $parts[0] -match "(\d+)\.(\d+)\.(\d+)([fpb])(\d+)" | Out-Null + $parts[0] -match "(\d+)\.(\d+)\.(\d+)([fpba])(\d+)" | Out-Null if ( $Matches.Count -ne 6 ) { throw "Invalid unity version: $version" } $this.Major = [int]($Matches[1]); $this.Minor = [int]($Matches[2]); @@ -290,7 +290,7 @@ function Find-UnitySetupInstaller { $currentOS = Get-OperatingSystem switch ($currentOS) { ([OperatingSystem]::Windows) { - $unitySetupRegEx = "^(.+)\/([a-z0-9]+)\/Windows64EditorInstaller\/UnitySetup64-(\d+)\.(\d+)\.(\d+)([fpb])(\d+).exe$" + $unitySetupRegEx = "^(.+)\/([a-z0-9]+)\/Windows64EditorInstaller\/UnitySetup64-(\d+)\.(\d+)\.(\d+)([fpba])(\d+).exe$" $targetSupport = "TargetSupportInstaller" $installerExtension = "exe" } @@ -298,7 +298,7 @@ function Find-UnitySetupInstaller { throw "Find-UnitySetupInstaller has not been implemented on the Linux platform. Contributions welcomed!"; } ([OperatingSystem]::Mac) { - $unitySetupRegEx = "^(.+)\/([a-z0-9]+)\/MacEditorInstaller\/Unity-(\d+)\.(\d+)\.(\d+)([fpb])(\d+).pkg$" + $unitySetupRegEx = "^(.+)\/([a-z0-9]+)\/MacEditorInstaller\/Unity-(\d+)\.(\d+)\.(\d+)([fpba])(\d+).pkg$" $targetSupport = "MacEditorTargetInstaller" $installerExtension = "pkg" } @@ -399,7 +399,7 @@ function Find-UnitySetupInstaller { } else { # Regex needs to be reconfigured to parse builtin_shaders's url link - $unitySetupRegEx = "^(.+)\/([a-z0-9]+)\/builtin_shaders-(\d+)\.(\d+)\.(\d+)([fpb])(\d+).zip$" + $unitySetupRegEx = "^(.+)\/([a-z0-9]+)\/builtin_shaders-(\d+)\.(\d+)\.(\d+)([fpba])(\d+).zip$" } } From 460a8aab494d4eb13f0fa4801bae9e3457b0584f Mon Sep 17 00:00:00 2001 From: StephenHodgson Date: Thu, 18 Apr 2019 22:26:46 -0700 Subject: [PATCH 41/67] added switch cases back in --- UnitySetup/UnitySetup.psm1 | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index f8c376e..d9d8d58 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -360,14 +360,24 @@ function Find-UnitySetupInstaller { } # Every release type has a different pattern for finding installers - $searchPages = @( "https://unity3d.com/get-unity/download/archive", "https://unity3d.com/unity/beta/unity$Version" ) + $searchPages = @() switch ($Version.Release) { + 'a' { $searchPages += "https://unity3d.com/unity/beta/unity$Version" } + 'b' { $searchPages += "https://unity3d.com/unity/beta/unity$Version" } + 'f' { + $searchPages += "https://unity3d.com/get-unity/download/archive" + + # Just in case it's a release candidate search the beta as well. + if($Version.Revision -eq '0') { + $searchPages += "https://unity3d.com/unity/beta/unity$Version" + } + } 'p' { $patchPage = "https://unity3d.com/unity/qa/patch-releases?version=$($Version.Major).$($Version.Minor)" $searchPages += $patchPage - $webResult = Invoke-WebRequest $patchPage -UseBasicParsing - $searchPages += $webResult.Links | Where-Object { + $webResult = Invoke-WebRequest $patchPage -UseBasicParsing + $searchPages += $webResult.Links | Where-Object { $_.href -match "\/unity\/qa\/patch-releases\?version=$($Version.Major)\.$($Version.Minor)&page=(\d+)" -and $Matches[1] -gt 1 } | ForEach-Object { "https://unity3d.com$($_.href)" } } From 6f7c6dee91a9f0b4469ac1fb1382a5eff7f4298e Mon Sep 17 00:00:00 2001 From: Josh Wittner Date: Fri, 19 Apr 2019 17:04:35 -0700 Subject: [PATCH 42/67] More exhaustive searching. Fix for alpha search pages --- UnitySetup/UnitySetup.psm1 | 70 ++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 54d72b5..d44da0e 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -290,7 +290,6 @@ function Find-UnitySetupInstaller { $currentOS = Get-OperatingSystem switch ($currentOS) { ([OperatingSystem]::Windows) { - $unitySetupRegEx = "^(.+)\/([a-z0-9]+)\/Windows64EditorInstaller\/UnitySetup64-(\d+)\.(\d+)\.(\d+)([fpba])(\d+).exe$" $targetSupport = "TargetSupportInstaller" $installerExtension = "exe" } @@ -298,12 +297,13 @@ function Find-UnitySetupInstaller { throw "Find-UnitySetupInstaller has not been implemented on the Linux platform. Contributions welcomed!"; } ([OperatingSystem]::Mac) { - $unitySetupRegEx = "^(.+)\/([a-z0-9]+)\/MacEditorInstaller\/Unity-(\d+)\.(\d+)\.(\d+)([fpba])(\d+).pkg$" $targetSupport = "MacEditorTargetInstaller" $installerExtension = "pkg" } } + $unitySetupRegEx = "^(.+)\/([a-z0-9]+)\/(.+)\/(.+)-(\d+)\.(\d+)\.(\d+)([fpba])(\d+).$installerExtension$" + $knownBaseUrls = @( "https://download.unity3d.com/download_unity", "https://netstorage.unity3d.com/unity", @@ -312,7 +312,8 @@ function Find-UnitySetupInstaller { $installerTemplates = @{ [UnitySetupComponent]::UWP = "$targetSupport/UnitySetup-UWP-.NET-Support-for-Editor-$Version.$installerExtension", - "$targetSupport/UnitySetup-Metro-Support-for-Editor-$Version.$installerExtension"; + "$targetSupport/UnitySetup-Metro-Support-for-Editor-$Version.$installerExtension", + "$targetSupport/UnitySetup-Universal-Windows-Platform-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"; @@ -362,16 +363,22 @@ function Find-UnitySetupInstaller { # Every release type has a different pattern for finding installers $searchPages = @() switch ($Version.Release) { - 'a' { $searchPages += "https://unity3d.com/unity/beta/unity$Version" } - 'b' { $searchPages += "https://unity3d.com/unity/beta/unity$Version" } + 'a' { $searchPages += "https://unity3d.com/alpha/$($Version.Major).$($Version.Minor)" } + 'b' { + $searchPages += "https://unity3d.com/unity/beta/unity$Version", + "https://unity3d.com/unity/beta/$($Version.Major).$($Version.Minor)" + } 'f' { - $searchPages += "https://unity3d.com/get-unity/download/archive" - - # Just in case it's a release candidate search the beta as well. - if($Version.Revision -eq '0') { - $searchPages += "https://unity3d.com/unity/beta/unity$Version" - } + $searchPages += "https://unity3d.com/get-unity/download/archive", + "https://unity3d.com/unity/whats-new/$($Version.Major).$($Version.Minor).$($Version.Revision)" + + + # Just in case it's a release candidate search the beta as well. + if ($Version.Revision -eq '0') { + $searchPages += "https://unity3d.com/unity/beta/unity$Version" + $searchPages += "https://unity3d.com/unity/beta/$($Version.Major).$($Version.Minor)" } + } 'p' { $patchPage = "https://unity3d.com/unity/qa/patch-releases?version=$($Version.Major).$($Version.Minor)" $searchPages += $patchPage @@ -384,35 +391,32 @@ function Find-UnitySetupInstaller { } foreach ($page in $searchPages) { - $webResult = Invoke-WebRequest $page -UseBasicParsing - $prototypeLink = $webResult.Links | Select-Object -ExpandProperty href -ErrorAction SilentlyContinue | Where-Object { - $_ -match "$($installerTemplates[$setupComponent])$" - } - - if ($null -ne $prototypeLink) { break } - } - - if ($null -eq $prototypeLink) { - # Attempt to find Unity version and setup links based off builtin_shaders download. - Write-Verbose "Attempting version search with builtin_shaders fallback" - foreach ($page in $searchPages) { + try { $webResult = Invoke-WebRequest $page -UseBasicParsing $prototypeLink = $webResult.Links | Select-Object -ExpandProperty href -ErrorAction SilentlyContinue | Where-Object { - $_ -match "builtin_shaders-$($Version).zip$" - } + $link = $_ - if ($null -ne $prototypeLink) { break } - } + foreach ( $installer in $installerTemplates.Keys ) { + foreach ( $template in $installerTemplates[$installer] ) { + if ( $link -like "*$template*" ) { return $true } + } + } + + return $false + + } | Select-Object -First 1 - if ($null -eq $prototypeLink) { - throw "Could not find archives for Unity version $Version" + if ($null -ne $prototypeLink) { break } } - else { - # Regex needs to be reconfigured to parse builtin_shaders's url link - $unitySetupRegEx = "^(.+)\/([a-z0-9]+)\/builtin_shaders-(\d+)\.(\d+)\.(\d+)([fpba])(\d+).zip$" + catch { + Write-Verbose "$page failed: $($_.Exception.Message)" } } + if ($null -eq $prototypeLink) { + throw "Could not find archives for Unity version $Version" + } + $linkComponents = $prototypeLink -split $unitySetupRegEx -ne "" if ($knownBaseUrls -notcontains $linkComponents[0]) { @@ -454,7 +458,7 @@ function Find-UnitySetupInstaller { break } catch { - Write-Verbose "$endpoint failed: $_" + Write-Verbose "$endpoint failed: $($_.Exception.Message)" } } From 0ce94e8ce9f15e9981855c60fbeffa957776fcbd Mon Sep 17 00:00:00 2001 From: StephenHodgson Date: Sat, 20 Apr 2019 07:57:09 -0700 Subject: [PATCH 43/67] fixed some spacing --- UnitySetup/UnitySetup.psm1 | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index d44da0e..d9a3efa 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -312,8 +312,8 @@ function Find-UnitySetupInstaller { $installerTemplates = @{ [UnitySetupComponent]::UWP = "$targetSupport/UnitySetup-UWP-.NET-Support-for-Editor-$Version.$installerExtension", - "$targetSupport/UnitySetup-Metro-Support-for-Editor-$Version.$installerExtension", - "$targetSupport/UnitySetup-Universal-Windows-Platform-Support-for-Editor-$Version.$installerExtension"; + "$targetSupport/UnitySetup-Metro-Support-for-Editor-$Version.$installerExtension", + "$targetSupport/UnitySetup-Universal-Windows-Platform-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"; @@ -364,14 +364,13 @@ function Find-UnitySetupInstaller { $searchPages = @() switch ($Version.Release) { 'a' { $searchPages += "https://unity3d.com/alpha/$($Version.Major).$($Version.Minor)" } - 'b' { + 'b' { $searchPages += "https://unity3d.com/unity/beta/unity$Version", "https://unity3d.com/unity/beta/$($Version.Major).$($Version.Minor)" } 'f' { $searchPages += "https://unity3d.com/get-unity/download/archive", "https://unity3d.com/unity/whats-new/$($Version.Major).$($Version.Minor).$($Version.Revision)" - # Just in case it's a release candidate search the beta as well. if ($Version.Revision -eq '0') { From afbeec76ec835e8dd9a52dfe45ea2942280e6df6 Mon Sep 17 00:00:00 2001 From: StephenHodgson Date: Sat, 20 Apr 2019 08:02:20 -0700 Subject: [PATCH 44/67] updated search pages formatting for revisions --- UnitySetup/UnitySetup.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index d9a3efa..8568949 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -374,8 +374,8 @@ function Find-UnitySetupInstaller { # Just in case it's a release candidate search the beta as well. if ($Version.Revision -eq '0') { - $searchPages += "https://unity3d.com/unity/beta/unity$Version" - $searchPages += "https://unity3d.com/unity/beta/$($Version.Major).$($Version.Minor)" + $searchPages += "https://unity3d.com/unity/beta/unity$Version", + "https://unity3d.com/unity/beta/$($Version.Major).$($Version.Minor)" } } 'p' { From a9afbc3dc3dbfad4339e897e982a1465c0cbc011 Mon Sep 17 00:00:00 2001 From: StephenHodgson Date: Sat, 20 Apr 2019 10:07:07 -0700 Subject: [PATCH 45/67] 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 46/67] 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 47/67] 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 48/67] 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 49/67] 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 50/67] 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 51/67] 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 7ea64d4d9e29ba3120a61c76e4e637b1ff68a327 Mon Sep 17 00:00:00 2001 From: Josh Wittner Date: Mon, 22 Apr 2019 11:43:56 -0700 Subject: [PATCH 52/67] More discovered search paths, fixes 2019.1.0b9 --- UnitySetup/UnitySetup.psm1 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 8568949..495e5d9 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -366,16 +366,18 @@ function Find-UnitySetupInstaller { 'a' { $searchPages += "https://unity3d.com/alpha/$($Version.Major).$($Version.Minor)" } 'b' { $searchPages += "https://unity3d.com/unity/beta/unity$Version", - "https://unity3d.com/unity/beta/$($Version.Major).$($Version.Minor)" + "https://unity3d.com/unity/beta/$($Version.Major).$($Version.Minor)", + "https://unity3d.com/unity/beta/$Version" } 'f' { $searchPages += "https://unity3d.com/get-unity/download/archive", "https://unity3d.com/unity/whats-new/$($Version.Major).$($Version.Minor).$($Version.Revision)" - + # Just in case it's a release candidate search the beta as well. if ($Version.Revision -eq '0') { $searchPages += "https://unity3d.com/unity/beta/unity$Version", - "https://unity3d.com/unity/beta/$($Version.Major).$($Version.Minor)" + "https://unity3d.com/unity/beta/$($Version.Major).$($Version.Minor)", + "https://unity3d.com/unity/beta/$Version" } } 'p' { From e7ffdb4af0caee64ec177bb91095fda189691255 Mon Sep 17 00:00:00 2001 From: StephenHodgson Date: Mon, 22 Apr 2019 13:02:42 -0700 Subject: [PATCH 53/67] 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 54/67] 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 55/67] 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 56/67] 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 57/67] 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 58/67] 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 59/67] 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 60/67] 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 61/67] 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 62/67] 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 63/67] 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"; From d748ff70e0e230d2cd02e0a9bd42ce86ae8893dc Mon Sep 17 00:00:00 2001 From: Josh Wittner Date: Mon, 29 Apr 2019 15:31:48 -0700 Subject: [PATCH 64/67] Extract cross-platform editor discovery and use to cull paths for unity setup instances --- UnitySetup/UnitySetup.psd1 | 2 + UnitySetup/UnitySetup.psm1 | 84 ++++++++++++++++++++++++++------------ 2 files changed, 61 insertions(+), 25 deletions(-) diff --git a/UnitySetup/UnitySetup.psd1 b/UnitySetup/UnitySetup.psd1 index aca8d80..d823d65 100644 --- a/UnitySetup/UnitySetup.psd1 +++ b/UnitySetup/UnitySetup.psd1 @@ -84,6 +84,7 @@ 'Install-UnitySetupInstance', 'Select-UnitySetupInstance', 'Uninstall-UnitySetupInstance', + 'Get-UnityEditor', 'Start-UnityEditor', 'ConvertTo-UnitySetupComponent', 'Get-UnityLicense' @@ -100,6 +101,7 @@ 'gusi', 'gupi', 'susi', + 'gue', 'sue' ) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 9d92cac..2d3c933 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -232,6 +232,56 @@ function Get-OperatingSystem { } } +<# +.Synopsis + Get the Unity Editor application +.PARAMETER Path + Path of a UnitySetupInstance +.EXAMPLE + Get-UnityEditor -Path $unitySetupInstance.Path +#> +function Get-UnityEditor { + [CmdletBinding()] + param( + [ValidateScript( {Test-Path $_ -PathType Container} )] + [Parameter(Mandatory = $false, ValueFromPipeline = $true, Position = 0, ParameterSetName = "Path")] + [string[]]$Path = $PWD, + + [Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 0, ParameterSetName = "Instance")] + [ValidateNotNull()] + [UnitySetupInstance[]]$Instance + ) + + process { + + if ( $PSCmdlet.ParameterSetName -eq "Instance" ) { + $Path = $Instance.Path + } + + $currentOS = Get-OperatingSystem + foreach ($p in $Path) { + switch ($currentOS) { + ([OperatingSystem]::Windows) { + $editor = Get-ChildItem "$p" -Filter 'Unity.exe' -Recurse | + Select-Object -First 1 -ExpandProperty FullName + + Write-Output $editor + } + ([OperatingSystem]::Linux) { + throw "Get-UnityEditor has not been implemented on the Linux platform. Contributions welcomed!"; + } + ([OperatingSystem]::Mac) { + $editor = Join-Path "$p" "Unity.app/Contents/MacOS/Unity" + + if (Test-Path $editor) { + Write-Output (Resolve-Path $editor).Path + } + } + } + } + } +} + <# .Synopsis Help to create UnitySetupComponent @@ -1088,9 +1138,10 @@ function Get-UnitySetupInstance { } } - Get-ChildItem $BasePath -Directory | Where-Object { - Test-Path (Join-Path $_.FullName 'Editor\Unity.exe') -PathType Leaf - } | ForEach-Object { + + $BasePath | Where-Object { Test-Path $_ -PathType Container } | + Get-ChildItem -Directory | Where-Object { (Get-UnityEditor $_.FullName).Count -gt 0 } | + ForEach-Object { $path = $_.FullName try { Write-Verbose "Creating UnitySetupInstance for $path" @@ -1528,32 +1579,14 @@ function Start-UnityEditor { $setupInstances += , $setupInstance } - $currentOS = Get-OperatingSystem for ($i = 0; $i -lt $setupInstances.Length; $i++) { $setupInstance = $setupInstances[$i] - switch ($currentOS) { - ([OperatingSystem]::Windows) { - $editor = Get-ChildItem "$($setupInstance.Path)" -Filter 'Unity.exe' -Recurse | - Select-Object -First 1 -ExpandProperty FullName - - if ([string]::IsNullOrEmpty($editor)) { - Write-Error "Could not find Unity.exe under setup instance path: $($setupInstance.Path)" - continue - } - } - ([OperatingSystem]::Linux) { - throw "Start-UnityEditor has not been implemented on the Linux platform. Contributions welcomed!"; - } - ([OperatingSystem]::Mac) { - $editor = [io.path]::Combine("$($setupInstance.Path)", "Unity.app/Contents/MacOS/Unity") - - if ([string]::IsNullOrEmpty($editor)) { - Write-Error "Could not find Unity app under setup instance path: $($setupInstance.Path)" - continue - } - } + $editor = Get-UnityEditor "$($setupInstance.Path)" + if ( -not $editor ) { + Write-Error "Could not find Unity Editor under setup instance path: $($setupInstance.Path)" + continue } # clone the shared args list @@ -1695,6 +1728,7 @@ function Get-UnityLicense { @{ 'Name' = 'gusi'; 'Value' = 'Get-UnitySetupInstance' }, @{ 'Name' = 'gupi'; 'Value' = 'Get-UnityProjectInstance' }, @{ 'Name' = 'susi'; 'Value' = 'Select-UnitySetupInstance' }, + @{ 'Name' = 'gue'; 'Value' = 'Get-UnityEditor' } @{ 'Name' = 'sue'; 'Value' = 'Start-UnityEditor' } ) | ForEach-Object { From 9ed7023aa3c13ab6e7e94217f9c99acac481dcdf Mon Sep 17 00:00:00 2001 From: Robert Onulak Date: Wed, 1 May 2019 14:19:15 -0700 Subject: [PATCH 65/67] Corrects Request-UnitySetupInstaller Description - Updates `Request-UnitySetupInstaller` to have a proper description. --- UnitySetup/UnitySetup.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 5b4d260..7dc734f 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -634,7 +634,7 @@ function Format-BitsPerSecond { .Synopsis Download specified Unity installers. .DESCRIPTION - Filters a list of `UnitySetupInstaller` down to a specific version and/or specific components. + Downloads the given installers into the $Cache directory. .PARAMETER Installers List of installers that needs to be downloaded. .PARAMETER Cache From 2bbbff7f9d6d52736c872c9294820bbd75b1141f Mon Sep 17 00:00:00 2001 From: Josh Wittner Date: Thu, 2 May 2019 17:21:06 -0700 Subject: [PATCH 66/67] Look for expected unity.exe instead of searching recursively --- UnitySetup/UnitySetup.psm1 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 7dc734f..b93cf96 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -264,10 +264,11 @@ function Get-UnityEditor { foreach ($p in $Path) { switch ($currentOS) { ([OperatingSystem]::Windows) { - $editor = Get-ChildItem "$p" -Filter 'Unity.exe' -Recurse | - Select-Object -First 1 -ExpandProperty FullName - - Write-Output $editor + $editor = Join-Path "$p" 'Editor\Unity.exe' + + if (Test-Path $editor) { + Write-Output (Resolve-Path $editor).Path + } } ([OperatingSystem]::Linux) { throw "Get-UnityEditor has not been implemented on the Linux platform. Contributions welcomed!"; From c81c288f73f19391c8e3fa97a46ba7f604f95610 Mon Sep 17 00:00:00 2001 From: Josh Wittner Date: Thu, 2 May 2019 17:27:46 -0700 Subject: [PATCH 67/67] Fix for All flag and missing Lumin --- UnitySetup/UnitySetup.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 7dc734f..e739fa7 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -21,7 +21,7 @@ enum UnitySetupComponent { WebGL = (1 -shl 13) Mac_IL2CPP = (1 -shl 14) Lumin = (1 -shl 15) - All = (1 -shl 15) - 1 + All = (1 -shl 16) - 1 } [Flags()]