Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion UnitySetup/UnitySetup.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
107 changes: 61 additions & 46 deletions UnitySetup/UnitySetup.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand All @@ -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)
}
Expand Down Expand Up @@ -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,

Expand Down Expand Up @@ -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 }
}
Expand All @@ -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 ) {
Expand Down Expand Up @@ -679,7 +682,7 @@ function Request-UnitySetupInstaller {
$downloads = @()

try {
$global:downloadData = [ordered]@{}
$global:downloadData = [ordered]@{ }
$downloadIndex = 1

$allInstallers | ForEach-Object {
Expand Down Expand Up @@ -934,7 +937,7 @@ function Install-UnitySetupInstance {
$defaultInstallPath = $BasePath
}

$versionInstallers = @{}
$versionInstallers = @{ }
}
process {
# Sort each installer received from the pipe into versions
Expand Down Expand Up @@ -1138,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 "$_"
}
}
}
}

<#
Expand All @@ -1170,13 +1172,14 @@ function Get-UnitySetupInstanceVersion {
[CmdletBinding()]
param(
[ValidateNotNullOrEmpty()]
[ValidateScript( {Test-Path $_ -PathType Container})]
[ValidateScript( { Test-Path $_ -PathType Container })]
[Parameter(Mandatory = $true, Position = 0)]
[string]$Path
)

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"
Expand All @@ -1191,9 +1194,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) {
Expand All @@ -1203,11 +1207,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)
}
}
}
Expand Down Expand Up @@ -1309,11 +1324,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))
}
}
}
}

<#
Expand Down Expand Up @@ -1594,8 +1609,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
Expand Down