Skip to content
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
1edea46
Updated the UnitySetupInstance to search for the executable path and …
StephenHodgson Apr 19, 2019
6d48640
Merge branch 'develop' into dev-UnitySetupInstance
StephenHodgson Apr 19, 2019
a9afbc3
recursively search for legacy ivy.xml files, and then modules.json as…
StephenHodgson Apr 20, 2019
8c7fd7e
minor formatting changes
StephenHodgson Apr 20, 2019
869b396
even brackets need spaces
StephenHodgson Apr 20, 2019
48e4aab
cast strings to unity versions and check match for null array
StephenHodgson Apr 20, 2019
342a15a
search modules.json first as a recursive file search may be slower
StephenHodgson Apr 20, 2019
cfd1721
updated Get-UnitySetupInstance to use the same modules.json and ivy.x…
StephenHodgson Apr 20, 2019
183b28f
Filter out just the needed paths to get the setup instances
StephenHodgson Apr 20, 2019
e7ffdb4
PR feedback
StephenHodgson Apr 22, 2019
f9a98c2
check if version is valid
StephenHodgson Apr 22, 2019
b5e85bb
Don't use global match
StephenHodgson Apr 22, 2019
1cff3ea
Apply suggestions from code review
StephenHodgson Apr 23, 2019
531fdae
Simplified search paths
StephenHodgson Apr 23, 2019
64ac797
filtered out Unity Hub path and better version found
StephenHodgson Apr 23, 2019
51d8d94
finalized matching in modules
StephenHodgson Apr 23, 2019
700c481
Fix instance discovery, better error handling
jwittner Apr 23, 2019
ad69b80
Write output as it's built to better support pipelining
jwittner Apr 23, 2019
48a911e
reverted whitespace chagnes
StephenHodgson Apr 24, 2019
114e936
reverted more whitespace changes
StephenHodgson Apr 24, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 71 additions & 25 deletions UnitySetup/UnitySetup.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,11 @@ class UnitySetupInstance {
[string]$Path

UnitySetupInstance([string]$path) {

$currentOS = Get-OperatingSystem
$ivyPath = switch ($currentOS) {
([OperatingSystem]::Windows) { 'Editor\Data\UnityExtensions\Unity\Networking\ivy.xml' }
([OperatingSystem]::Linux) { throw "UnitySetupInstance has not been implemented on the Linux platform. Contributions welcomed!"; }
([OperatingSystem]::Mac) { 'Unity.app/Contents/UnityExtensions/Unity/Networking/ivy.xml' }
}

$ivyPath = [io.path]::Combine("$path", $ivyPath);
if (!(Test-Path $ivyPath)) { throw "Path is not a Unity setup: $path"}
[xml]$xmlDoc = Get-Content $ivyPath

if ( !($xmlDoc.'ivy-module'.info.unityVersion)) {
throw "Unity setup ivy is missing version: $ivyPath"
}

$this.Path = $path
$this.Version = $xmlDoc.'ivy-module'.info.unityVersion
$this.Version = Get-UnitySetupInstanceVersion -Path $path
if ( -not $this.Version ) { throw "Unable to find version for $path" }

$playbackEnginePath = $null
$componentTests = switch ($currentOS) {
Expand Down Expand Up @@ -884,8 +871,6 @@ function Install-UnitySetupInstance {
$defaultInstallPath = $BasePath
}

$unitySetupInstances = Get-UnitySetupInstance -BasePath $BasePath

$versionInstallers = @{}
}
process {
Expand Down Expand Up @@ -970,7 +955,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
}

Expand Down Expand Up @@ -1079,7 +1064,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!";
Expand All @@ -1088,16 +1072,78 @@ 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);
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 "$_"
}
}
}

<#
.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; }

Get-ChildItem $path -Recurse -ErrorAction Ignore |
ForEach-Object {
[UnitySetupInstance]::new((Join-Path $_.Directory "..\..\..\..\..\" | Convert-Path))
Write-Verbose "`tFound version!"
return [UnityVersion]$version
}
}
}
Expand Down