Skip to content

Commit 9f60da9

Browse files
authored
Merge pull request #193 from jwittner/dev/supportUnity2019.2
Support local installs of 2019.2, formatting fixes.
2 parents 31a3618 + 6af6dfd commit 9f60da9

File tree

2 files changed

+62
-47
lines changed

2 files changed

+62
-47
lines changed

UnitySetup/UnitySetup.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
# Modules that must be imported into the global environment prior to importing this module
5656
RequiredModules = @(
57-
@{ModuleName = "powershell-yaml"; ModuleVersion = "0.3"; Guid = "6a75a662-7f53-425a-9777-ee61284407da"}
57+
@{ModuleName = "powershell-yaml"; ModuleVersion = "0.3"; Guid = "6a75a662-7f53-425a-9777-ee61284407da" }
5858
)
5959

6060
# Assemblies that must be loaded prior to importing this module

UnitySetup/UnitySetup.psm1

Lines changed: 61 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,16 @@ class UnityProjectInstance {
117117

118118
UnityProjectInstance([string]$path) {
119119
$versionFile = [io.path]::Combine($path, "ProjectSettings\ProjectVersion.txt")
120-
if (!(Test-Path $versionFile)) { throw "Path is not a Unity project: $path"}
120+
if (!(Test-Path $versionFile)) { throw "Path is not a Unity project: $path" }
121121

122122
$fileVersion = (Get-Content $versionFile -Raw | ConvertFrom-Yaml)['m_EditorVersion'];
123-
if (!$fileVersion) { throw "Project is missing a version in: $versionFile"}
123+
if (!$fileVersion) { throw "Project is missing a version in: $versionFile" }
124124

125125
$projectSettingsFile = [io.path]::Combine($path, "ProjectSettings\ProjectSettings.asset")
126-
if (!(Test-Path $projectSettingsFile)) { throw "Project is missing ProjectSettings.asset"}
126+
if (!(Test-Path $projectSettingsFile)) { throw "Project is missing ProjectSettings.asset" }
127127

128128
$prodName = ((Get-Content $projectSettingsFile -Raw | ConvertFrom-Yaml)['playerSettings'])['productName']
129-
if (!$prodName) { throw "ProjectSettings is missing productName"}
129+
if (!$prodName) { throw "ProjectSettings is missing productName" }
130130

131131
$this.Path = $path
132132
$this.Version = $fileVersion
@@ -144,7 +144,7 @@ class UnityVersion : System.IComparable {
144144

145145
[string] ToString() {
146146
$result = "$($this.Major).$($this.Minor).$($this.Revision)$($this.Release)$($this.Build)"
147-
if ( $this.Suffix ) { $result += "-$($this.Suffix)"}
147+
if ( $this.Suffix ) { $result += "-$($this.Suffix)" }
148148
return $result
149149
}
150150

@@ -166,7 +166,7 @@ class UnityVersion : System.IComparable {
166166

167167
[int] CompareTo([object]$obj) {
168168
if ($null -eq $obj) { return 1 }
169-
if ($obj -isnot [UnityVersion]) { throw "Object is not a UnityVersion"}
169+
if ($obj -isnot [UnityVersion]) { throw "Object is not a UnityVersion" }
170170

171171
return [UnityVersion]::Compare($this, $obj)
172172
}
@@ -245,7 +245,7 @@ function Get-OperatingSystem {
245245
function Get-UnityEditor {
246246
[CmdletBinding()]
247247
param(
248-
[ValidateScript( {Test-Path $_ -PathType Container} )]
248+
[ValidateScript( { Test-Path $_ -PathType Container } )]
249249
[Parameter(Mandatory = $false, ValueFromPipeline = $true, Position = 0, ParameterSetName = "Path")]
250250
[string[]]$Path = $PWD,
251251

@@ -426,27 +426,30 @@ function Find-UnitySetupInstaller {
426426
$searchPages += $patchPage
427427

428428
$webResult = Invoke-WebRequest $patchPage -UseBasicParsing
429-
$searchPages += $webResult.Links | Where-Object {
430-
$_.href -match "\/unity\/qa\/patch-releases\?version=$($Version.Major)\.$($Version.Minor)&page=(\d+)" -and $Matches[1] -gt 1
431-
} | ForEach-Object { "https://unity3d.com$($_.href)" }
429+
$searchPages += $webResult.Links |
430+
Where-Object { $_.href -match "\/unity\/qa\/patch-releases\?version=$($Version.Major)\.$($Version.Minor)&page=(\d+)" -and $Matches[1] -gt 1 } |
431+
ForEach-Object { "https://unity3d.com$($_.href)" }
432432
}
433433
}
434434

435435
foreach ($page in $searchPages) {
436436
try {
437437
$webResult = Invoke-WebRequest $page -UseBasicParsing
438-
$prototypeLink = $webResult.Links | Select-Object -ExpandProperty href -ErrorAction SilentlyContinue | Where-Object {
439-
$link = $_
440-
441-
foreach ( $installer in $installerTemplates.Keys ) {
442-
foreach ( $template in $installerTemplates[$installer] ) {
443-
if ( $link -like "*$template*" ) { return $true }
438+
$prototypeLink = $webResult.Links |
439+
Select-Object -ExpandProperty href -ErrorAction SilentlyContinue |
440+
Where-Object {
441+
$link = $_
442+
443+
foreach ( $installer in $installerTemplates.Keys ) {
444+
foreach ( $template in $installerTemplates[$installer] ) {
445+
if ( $link -like "*$template*" ) { return $true }
446+
}
444447
}
445-
}
446448

447-
return $false
449+
return $false
448450

449-
} | Select-Object -First 1
451+
} |
452+
Select-Object -First 1
450453

451454
if ($null -ne $prototypeLink) { break }
452455
}
@@ -465,10 +468,10 @@ function Find-UnitySetupInstaller {
465468
$knownBaseUrls = $linkComponents[0], $knownBaseUrls
466469
}
467470
else {
468-
$knownBaseUrls = $knownBaseUrls | Sort-Object -Property @{ Expression = {[math]::Abs(($_.CompareTo($linkComponents[0])))}; Ascending = $true}
471+
$knownBaseUrls = $knownBaseUrls | Sort-Object -Property @{ Expression = { [math]::Abs(($_.CompareTo($linkComponents[0]))) }; Ascending = $true }
469472
}
470473

471-
$installerTemplates.Keys | Where-Object { $Components -band $_ } | ForEach-Object {
474+
$installerTemplates.Keys | Where-Object { $Components -band $_ } | ForEach-Object {
472475
$templates = $installerTemplates.Item($_);
473476
$result = $null
474477
foreach ($template in $templates ) {
@@ -679,7 +682,7 @@ function Request-UnitySetupInstaller {
679682
$downloads = @()
680683

681684
try {
682-
$global:downloadData = [ordered]@{}
685+
$global:downloadData = [ordered]@{ }
683686
$downloadIndex = 1
684687

685688
$allInstallers | ForEach-Object {
@@ -934,7 +937,7 @@ function Install-UnitySetupInstance {
934937
$defaultInstallPath = $BasePath
935938
}
936939

937-
$versionInstallers = @{}
940+
$versionInstallers = @{ }
938941
}
939942
process {
940943
# Sort each installer received from the pipe into versions
@@ -1138,19 +1141,18 @@ function Get-UnitySetupInstance {
11381141
}
11391142
}
11401143

1141-
1142-
$BasePath | Where-Object { Test-Path $_ -PathType Container } |
1143-
Get-ChildItem -Directory | Where-Object { (Get-UnityEditor $_.FullName).Count -gt 0 } |
1144+
Get-ChildItem -Path $BasePath -Directory -ErrorAction Ignore |
1145+
Where-Object { (Get-UnityEditor $_.FullName).Count -gt 0 } |
11441146
ForEach-Object {
1145-
$path = $_.FullName
1146-
try {
1147-
Write-Verbose "Creating UnitySetupInstance for $path"
1148-
[UnitySetupInstance]::new($path)
1149-
}
1150-
catch {
1151-
Write-Warning "$_"
1147+
$path = $_.FullName
1148+
try {
1149+
Write-Verbose "Creating UnitySetupInstance for $path"
1150+
[UnitySetupInstance]::new($path)
1151+
}
1152+
catch {
1153+
Write-Warning "$_"
1154+
}
11521155
}
1153-
}
11541156
}
11551157

11561158
<#
@@ -1170,13 +1172,14 @@ function Get-UnitySetupInstanceVersion {
11701172
[CmdletBinding()]
11711173
param(
11721174
[ValidateNotNullOrEmpty()]
1173-
[ValidateScript( {Test-Path $_ -PathType Container})]
1175+
[ValidateScript( { Test-Path $_ -PathType Container })]
11741176
[Parameter(Mandatory = $true, Position = 0)]
11751177
[string]$Path
11761178
)
11771179

11781180
Write-Verbose "Attempting to find UnityVersion in $path"
11791181

1182+
# Try to look in the modules.json file for installer paths that contain version info
11801183
if ( Test-Path "$path\modules.json" -PathType Leaf ) {
11811184

11821185
Write-Verbose "Searching $path\modules.json for module versions"
@@ -1191,9 +1194,10 @@ function Get-UnitySetupInstanceVersion {
11911194
}
11921195
}
11931196

1197+
# No version found, start digging deeper
11941198
if ( Test-Path "$path\Editor" -PathType Container ) {
1195-
# We'll attempt to search for the version using the ivy.xml definitions for legacy editor compatibility.
1196-
1199+
1200+
# Search for the version using the ivy.xml definitions for legacy editor compatibility.
11971201
Write-Verbose "Looking for ivy.xml files under $path\Editor\"
11981202
$ivyFiles = Get-ChildItem -Path "$path\Editor\" -Filter 'ivy.xml' -Recurse -ErrorAction SilentlyContinue -Force -File
11991203
foreach ( $ivy in $ivyFiles) {
@@ -1203,11 +1207,22 @@ function Get-UnitySetupInstanceVersion {
12031207

12041208
[xml]$xmlDoc = Get-Content $ivy.FullName
12051209

1206-
[string]$version = $xmlDoc.'ivy-module'.info.unityVersion
1207-
if ( -not $version ) { continue; }
1210+
[string]$ivyVersion = $xmlDoc.'ivy-module'.info.unityVersion
1211+
if ( -not $ivyVersion ) { continue; }
1212+
1213+
Write-Verbose "`tFound version!"
1214+
return [UnityVersion]$ivyVersion
1215+
}
1216+
1217+
# Search through any header files which might define the unity version
1218+
Write-Verbose "Looking for .h files with UNITY_VERSION defined under $path\Editor\ "
1219+
$headerMatchInfo = Get-ChildItem -Path "$path\Editor\*.h" -Recurse -ErrorAction Ignore -Force -File |
1220+
Select-String -Pattern "UNITY_VERSION\s`"(\d+\.\d+\.\d+[fpba]\d+)`"" |
1221+
Select-Object -First 1
12081222

1223+
if ( $headerMatchInfo.Matches.Groups.Count -gt 1 ) {
12091224
Write-Verbose "`tFound version!"
1210-
return [UnityVersion]$version
1225+
return [UnityVersion]($headerMatchInfo.Matches.Groups[1].Value)
12111226
}
12121227
}
12131228
}
@@ -1309,11 +1324,11 @@ function Get-UnityProjectInstance {
13091324

13101325
Get-ChildItem @args |
13111326
ForEach-Object {
1312-
$path = [io.path]::Combine($_.FullName, "ProjectVersion.txt")
1313-
if ( Test-Path $path ) {
1314-
[UnityProjectInstance]::new((Join-Path $_.FullName "..\" | Convert-Path))
1327+
$path = [io.path]::Combine($_.FullName, "ProjectVersion.txt")
1328+
if ( Test-Path $path ) {
1329+
[UnityProjectInstance]::new((Join-Path $_.FullName "..\" | Convert-Path))
1330+
}
13151331
}
1316-
}
13171332
}
13181333

13191334
<#
@@ -1594,8 +1609,8 @@ function Start-UnityEditor {
15941609
if ( $instanceArgs[$i] ) { $unityArgs += $instanceArgs[$i] }
15951610

15961611
$actionString = "$editor $unityArgs"
1597-
if ( $Credential ) { $actionString += " -password (hidden)"}
1598-
if ( $Serial ) { $actionString += " -serial (hidden)"}
1612+
if ( $Credential ) { $actionString += " -password (hidden)" }
1613+
if ( $Serial ) { $actionString += " -serial (hidden)" }
15991614

16001615
if (-not $PSCmdlet.ShouldProcess($actionString, "System.Diagnostics.Process.Start()")) {
16011616
continue

0 commit comments

Comments
 (0)