From 13d017c3dde029cfe6fa5616d67c40a2fc3c45e8 Mon Sep 17 00:00:00 2001 From: Josh Wittner Date: Wed, 25 Sep 2019 12:28:28 -0700 Subject: [PATCH 1/3] Search header files for UNITY_VERSION, support 2019.2 --- UnitySetup/UnitySetup.psm1 | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 95867bd..829c02b 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -1177,6 +1177,7 @@ function Get-UnitySetupInstanceVersion { Write-Verbose "Attempting to find UnityVersion in $path" + # Try to look in the modules.json file for installer paths that contain version info if ( Test-Path "$path\modules.json" -PathType Leaf ) { Write-Verbose "Searching $path\modules.json for module versions" @@ -1191,9 +1192,10 @@ function Get-UnitySetupInstanceVersion { } } + # No version found, start digging deeper if ( Test-Path "$path\Editor" -PathType Container ) { - # We'll attempt to search for the version using the ivy.xml definitions for legacy editor compatibility. - + + # 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) { @@ -1203,11 +1205,22 @@ function Get-UnitySetupInstanceVersion { [xml]$xmlDoc = Get-Content $ivy.FullName - [string]$version = $xmlDoc.'ivy-module'.info.unityVersion - if ( -not $version ) { continue; } + [string]$ivyVersion = $xmlDoc.'ivy-module'.info.unityVersion + if ( -not $ivyVersion ) { continue; } + + Write-Verbose "`tFound version!" + return [UnityVersion]$ivyVersion + } + + # Search through any header files which might define the unity version + Write-Verbose "Looking for .h files with UNITY_VERSION defined under $path\Editor\ " + $headerMatchInfo = Get-ChildItem -Path "$path\Editor\*.h" -Recurse -ErrorAction Ignore -Force -File | + Select-String -Pattern "UNITY_VERSION\s`"(\d+\.\d+\.\d+[fpba]\d+)`"" | + Select-Object -First 1 + if ( $headerMatchInfo.Matches.Groups.Count -gt 1 ) { Write-Verbose "`tFound version!" - return [UnityVersion]$version + return [UnityVersion]($headerMatchInfo.Matches.Groups[1].Value) } } } From 0f63e8e48257e018a5fc4a85c10b5849309f16ab Mon Sep 17 00:00:00 2001 From: Josh Wittner Date: Wed, 25 Sep 2019 12:48:44 -0700 Subject: [PATCH 2/3] Auto formatting --- UnitySetup/UnitySetup.psd1 | 2 +- UnitySetup/UnitySetup.psm1 | 63 ++++++++++++++++++++------------------ 2 files changed, 34 insertions(+), 31 deletions(-) diff --git a/UnitySetup/UnitySetup.psd1 b/UnitySetup/UnitySetup.psd1 index d823d65..d7a6d20 100644 --- a/UnitySetup/UnitySetup.psd1 +++ b/UnitySetup/UnitySetup.psd1 @@ -54,7 +54,7 @@ # Modules that must be imported into the global environment prior to importing this module RequiredModules = @( - @{ModuleName = "powershell-yaml"; ModuleVersion = "0.3"; Guid = "6a75a662-7f53-425a-9777-ee61284407da"} + @{ModuleName = "powershell-yaml"; ModuleVersion = "0.3"; Guid = "6a75a662-7f53-425a-9777-ee61284407da" } ) # Assemblies that must be loaded prior to importing this module diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 829c02b..bd49057 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -117,16 +117,16 @@ class UnityProjectInstance { UnityProjectInstance([string]$path) { $versionFile = [io.path]::Combine($path, "ProjectSettings\ProjectVersion.txt") - if (!(Test-Path $versionFile)) { throw "Path is not a Unity project: $path"} + if (!(Test-Path $versionFile)) { throw "Path is not a Unity project: $path" } $fileVersion = (Get-Content $versionFile -Raw | ConvertFrom-Yaml)['m_EditorVersion']; - if (!$fileVersion) { throw "Project is missing a version in: $versionFile"} + 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"} + 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"} + if (!$prodName) { throw "ProjectSettings is missing productName" } $this.Path = $path $this.Version = $fileVersion @@ -144,7 +144,7 @@ class UnityVersion : System.IComparable { [string] ToString() { $result = "$($this.Major).$($this.Minor).$($this.Revision)$($this.Release)$($this.Build)" - if ( $this.Suffix ) { $result += "-$($this.Suffix)"} + if ( $this.Suffix ) { $result += "-$($this.Suffix)" } return $result } @@ -166,7 +166,7 @@ class UnityVersion : System.IComparable { [int] CompareTo([object]$obj) { if ($null -eq $obj) { return 1 } - if ($obj -isnot [UnityVersion]) { throw "Object is not a UnityVersion"} + if ($obj -isnot [UnityVersion]) { throw "Object is not a UnityVersion" } return [UnityVersion]::Compare($this, $obj) } @@ -245,7 +245,7 @@ function Get-OperatingSystem { function Get-UnityEditor { [CmdletBinding()] param( - [ValidateScript( {Test-Path $_ -PathType Container} )] + [ValidateScript( { Test-Path $_ -PathType Container } )] [Parameter(Mandatory = $false, ValueFromPipeline = $true, Position = 0, ParameterSetName = "Path")] [string[]]$Path = $PWD, @@ -426,27 +426,30 @@ function Find-UnitySetupInstaller { $searchPages += $patchPage $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)" } + $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)" } } } foreach ($page in $searchPages) { try { $webResult = Invoke-WebRequest $page -UseBasicParsing - $prototypeLink = $webResult.Links | Select-Object -ExpandProperty href -ErrorAction SilentlyContinue | Where-Object { - $link = $_ - - foreach ( $installer in $installerTemplates.Keys ) { - foreach ( $template in $installerTemplates[$installer] ) { - if ( $link -like "*$template*" ) { return $true } + $prototypeLink = $webResult.Links | + Select-Object -ExpandProperty href -ErrorAction SilentlyContinue | + Where-Object { + $link = $_ + + foreach ( $installer in $installerTemplates.Keys ) { + foreach ( $template in $installerTemplates[$installer] ) { + if ( $link -like "*$template*" ) { return $true } + } } - } - return $false + return $false - } | Select-Object -First 1 + } | + Select-Object -First 1 if ($null -ne $prototypeLink) { break } } @@ -465,10 +468,10 @@ function Find-UnitySetupInstaller { $knownBaseUrls = $linkComponents[0], $knownBaseUrls } else { - $knownBaseUrls = $knownBaseUrls | Sort-Object -Property @{ Expression = {[math]::Abs(($_.CompareTo($linkComponents[0])))}; Ascending = $true} + $knownBaseUrls = $knownBaseUrls | Sort-Object -Property @{ Expression = { [math]::Abs(($_.CompareTo($linkComponents[0]))) }; Ascending = $true } } - $installerTemplates.Keys | Where-Object { $Components -band $_ } | ForEach-Object { + $installerTemplates.Keys | Where-Object { $Components -band $_ } | ForEach-Object { $templates = $installerTemplates.Item($_); $result = $null foreach ($template in $templates ) { @@ -679,7 +682,7 @@ function Request-UnitySetupInstaller { $downloads = @() try { - $global:downloadData = [ordered]@{} + $global:downloadData = [ordered]@{ } $downloadIndex = 1 $allInstallers | ForEach-Object { @@ -934,7 +937,7 @@ function Install-UnitySetupInstance { $defaultInstallPath = $BasePath } - $versionInstallers = @{} + $versionInstallers = @{ } } process { # Sort each installer received from the pipe into versions @@ -1170,7 +1173,7 @@ function Get-UnitySetupInstanceVersion { [CmdletBinding()] param( [ValidateNotNullOrEmpty()] - [ValidateScript( {Test-Path $_ -PathType Container})] + [ValidateScript( { Test-Path $_ -PathType Container })] [Parameter(Mandatory = $true, Position = 0)] [string]$Path ) @@ -1322,11 +1325,11 @@ function Get-UnityProjectInstance { Get-ChildItem @args | ForEach-Object { - $path = [io.path]::Combine($_.FullName, "ProjectVersion.txt") - if ( Test-Path $path ) { - [UnityProjectInstance]::new((Join-Path $_.FullName "..\" | Convert-Path)) + $path = [io.path]::Combine($_.FullName, "ProjectVersion.txt") + if ( Test-Path $path ) { + [UnityProjectInstance]::new((Join-Path $_.FullName "..\" | Convert-Path)) + } } - } } <# @@ -1607,8 +1610,8 @@ function Start-UnityEditor { if ( $instanceArgs[$i] ) { $unityArgs += $instanceArgs[$i] } $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, "System.Diagnostics.Process.Start()")) { continue From 6af6dfdbe7f30b48711b15b5300add0006f7e403 Mon Sep 17 00:00:00 2001 From: Josh Wittner Date: Wed, 25 Sep 2019 12:52:47 -0700 Subject: [PATCH 3/3] Simplify test and format --- UnitySetup/UnitySetup.psm1 | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index bd49057..a19d1ad 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -1141,19 +1141,18 @@ function Get-UnitySetupInstance { } } - - $BasePath | Where-Object { Test-Path $_ -PathType Container } | - Get-ChildItem -Directory | Where-Object { (Get-UnityEditor $_.FullName).Count -gt 0 } | + Get-ChildItem -Path $BasePath -Directory -ErrorAction Ignore | + Where-Object { (Get-UnityEditor $_.FullName).Count -gt 0 } | ForEach-Object { - $path = $_.FullName - try { - Write-Verbose "Creating UnitySetupInstance for $path" - [UnitySetupInstance]::new($path) - } - catch { - Write-Warning "$_" + $path = $_.FullName + try { + Write-Verbose "Creating UnitySetupInstance for $path" + [UnitySetupInstance]::new($path) + } + catch { + Write-Warning "$_" + } } - } } <#