From a22049ee300f215730f2e5b2ca2f8414a8eaa873 Mon Sep 17 00:00:00 2001 From: Dmitriy Vornychev Date: Fri, 23 Dec 2022 08:29:15 +0100 Subject: [PATCH 01/15] Support Get-UnitySetupInstance for Linux --- UnitySetup/UnitySetup.psm1 | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 4edaa6a..a22c00c 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -1,4 +1,4 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. Import-Module powershell-yaml -MinimumVersion '0.3' -ErrorAction Stop @@ -77,8 +77,15 @@ class UnitySetupInstance { } ([OperatingSystem]::Linux) { $this.Components = [UnitySetupComponent]::Linux - - throw "UnitySetupInstance has not been implemented on the Linux platform. Contributions welcomed!"; + $playbackEnginePath = [io.path]::Combine("$Path", "Data/PlaybackEngines"); + @{ + [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]::Windows = , [io.path]::Combine("$playbackEnginePath", "WindowsStandaloneSupport"); + [UnitySetupComponent]::Linux = , [io.path]::Combine("$playbackEnginePath", "LinuxStandaloneSupport/Variations/linux64_headless_development_mono"); + [UnitySetupComponent]::Linux_IL2CPP = , [io.path]::Combine("$playbackEnginePath", "LinuxStandaloneSupport/Variations/linux64_headless_development_il2cpp"); + } } ([OperatingSystem]::Mac) { $this.Components = [UnitySetupComponent]::Mac @@ -286,7 +293,11 @@ function Get-UnityEditor { } } ([OperatingSystem]::Linux) { - throw "Get-UnityEditor has not been implemented on the Linux platform. Contributions welcomed!"; + $editor = Join-Path "$p" 'Editor/Unity' + + if (Test-Path $editor) { + Write-Output (Resolve-Path $editor).Path + } } ([OperatingSystem]::Mac) { $editor = Join-Path "$p" "Unity.app/Contents/MacOS/Unity" @@ -1196,7 +1207,9 @@ function Get-UnitySetupInstance { } } ([OperatingSystem]::Linux) { - throw "Get-UnitySetupInstance has not been implemented on the Linux platform. Contributions welcomed!"; + if (-not $BasePath) { + $BasePath = @('~/Unity/Hub/Editor/*') + } } ([OperatingSystem]::Mac) { if (-not $BasePath) { From 3898d4a22a4b2a3a501599949fc3a226042933b9 Mon Sep 17 00:00:00 2001 From: Dmitriy Vornychev Date: Fri, 23 Dec 2022 08:29:15 +0100 Subject: [PATCH 02/15] Support Get-UnitySetupInstance for Linux --- UnitySetup/UnitySetup.psm1 | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 4edaa6a..30ae81d 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -77,8 +77,15 @@ class UnitySetupInstance { } ([OperatingSystem]::Linux) { $this.Components = [UnitySetupComponent]::Linux - - throw "UnitySetupInstance has not been implemented on the Linux platform. Contributions welcomed!"; + $playbackEnginePath = [io.path]::Combine("$Path", "Data/PlaybackEngines"); + @{ + [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]::Windows = , [io.path]::Combine("$playbackEnginePath", "WindowsStandaloneSupport"); + [UnitySetupComponent]::Linux = , [io.path]::Combine("$playbackEnginePath", "LinuxStandaloneSupport/Variations/linux64_headless_development_mono"); + [UnitySetupComponent]::Linux_IL2CPP = , [io.path]::Combine("$playbackEnginePath", "LinuxStandaloneSupport/Variations/linux64_headless_development_il2cpp"); + } } ([OperatingSystem]::Mac) { $this.Components = [UnitySetupComponent]::Mac @@ -286,7 +293,11 @@ function Get-UnityEditor { } } ([OperatingSystem]::Linux) { - throw "Get-UnityEditor has not been implemented on the Linux platform. Contributions welcomed!"; + $editor = Join-Path "$p" 'Editor/Unity' + + if (Test-Path $editor) { + Write-Output (Resolve-Path $editor).Path + } } ([OperatingSystem]::Mac) { $editor = Join-Path "$p" "Unity.app/Contents/MacOS/Unity" @@ -1196,7 +1207,9 @@ function Get-UnitySetupInstance { } } ([OperatingSystem]::Linux) { - throw "Get-UnitySetupInstance has not been implemented on the Linux platform. Contributions welcomed!"; + if (-not $BasePath) { + $BasePath = @('~/Unity/Hub/Editor/*') + } } ([OperatingSystem]::Mac) { if (-not $BasePath) { From 34e85d8799a03a7da88adba44448687f15525dfa Mon Sep 17 00:00:00 2001 From: Dmitriy Vornychev Date: Sat, 24 Dec 2022 00:29:22 +0100 Subject: [PATCH 03/15] Support Find-UnitySetupInstaller for Linux --- UnitySetup/UnitySetup.psd1 | 4 +-- UnitySetup/UnitySetup.psm1 | 64 +++++++++++++++++++++++++++++++++----- 2 files changed, 58 insertions(+), 10 deletions(-) diff --git a/UnitySetup/UnitySetup.psd1 b/UnitySetup/UnitySetup.psd1 index d62ef11..03afd04 100644 --- a/UnitySetup/UnitySetup.psd1 +++ b/UnitySetup/UnitySetup.psd1 @@ -54,7 +54,8 @@ # 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" }, + @{ModuleName = "PsIni"; ModuleVersion = "3.1.3"; Guid = "98e1dc0f-2f03-4ca1-98bb-fd7b4b6ac652" } ) # Assemblies that must be loaded prior to importing this module @@ -155,4 +156,3 @@ # DefaultCommandPrefix = '' } - diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index a22c00c..3096053 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -22,7 +22,10 @@ enum UnitySetupComponent { Mac_IL2CPP = (1 -shl 14) Lumin = (1 -shl 15) Linux_IL2CPP = (1 -shl 16) - All = (1 -shl 17) - 1 + Windows_Server = (1 -shl 17) + Linux_Server = (1 -shl 18) + Mac_Server = (1 -shl 19) + All = (1 -shl 20) - 1 } [Flags()] @@ -390,7 +393,9 @@ function Find-UnitySetupInstaller { $installerExtension = "exe" } ([OperatingSystem]::Linux) { - throw "Find-UnitySetupInstaller has not been implemented on the Linux platform. Contributions welcomed!"; + # This is default, but it seems some packages are used from Mac + $targetSupport = "LinuxEditorTargetInstaller" + $installerExtension = "" } ([OperatingSystem]::Mac) { $targetSupport = "MacEditorTargetInstaller" @@ -398,7 +403,9 @@ function Find-UnitySetupInstaller { } } - $unitySetupRegEx = "^(.+)\/([a-z0-9]+)\/(.+)\/(.+)-(\d+)\.(\d+)\.(\d+)([fpba])(\d+).$installerExtension$" + $hashRegEx = "([a-z0-9]+)" + $versionRegEx = "(\d+)\.(\d+)\.(\d+)([fpba])(\d+)" + $unitySetupRegEx = "^(.+)\/$hashRegEx\/(.+)\/(.+)-$versionRegEx.$installerExtension$" $knownBaseUrls = @( "https://download.unity3d.com/download_unity", @@ -406,6 +413,7 @@ function Find-UnitySetupInstaller { "https://beta.unity3d.com/download" ) + # For Linux this hashtable will be rewritten later $installerTemplates = @{ [UnitySetupComponent]::UWP = "$targetSupport/UnitySetup-UWP-.NET-Support-for-Editor-$Version.$installerExtension", "$targetSupport/UnitySetup-Metro-Support-for-Editor-$Version.$installerExtension", @@ -443,9 +451,7 @@ function Find-UnitySetupInstaller { } ([OperatingSystem]::Linux) { $setupComponent = [UnitySetupComponent]::Linux - # TODO: $installerTemplates[$setupComponent] = , "???/UnitySetup64-$Version.exe"; - - throw "Find-UnitySetupInstaller has not been implemented on the Linux platform. Contributions welcomed!"; + $installerTemplates[$setupComponent] = , "UnitySetup-$Version"; } ([OperatingSystem]::Mac) { $setupComponent = [UnitySetupComponent]::Mac @@ -526,10 +532,52 @@ function Find-UnitySetupInstaller { throw "Could not find archives for Unity version $Version" } - $linkComponents = $prototypeLink -split $unitySetupRegEx -ne "" + if ($currentOS -ne [OperatingSystem]::Linux) { + $linkComponents = $prototypeLink -split $unitySetupRegEx -ne "" + } + else { + # For Linux we should get list of available components with their target + Import-Module PsIni -MinimumVersion '3.1.3' -ErrorAction Stop + + $linkComponents = $prototypeLink -split "/$hashRegEx/" -ne "" + + $iniFileName = "unity-$Version-linux.ini" + $baseUrl = $linkComponents[0] + "/" + $linkComponents[1] + $iniLink = "$baseUrl/$iniFileName" + + $linuxIni = Invoke-WebRequest $iniLink -UseBasicParsing + + # PsIni can read only from files and from stdin + $localCachedIni = "/tmp/$iniFileName" + + Set-Content -Path $localCachedIni -Value $linuxIni + + $iniContent = Get-IniContent $localCachedIni + + # fill from scratch accessible targets using retrieved .ini + $installerTemplates = @{} + + foreach ($section in $iniContent.GetEnumerator()) { + $sectionName = $section.Name.Replace('-', "_") + $url = $iniContent[$section.Name].url + + Write-Verbose "Retrieved $url for $sectionName" + + switch ($sectionName) { + "Unity" { $component = [UnitySetupComponent]::Linux } + "Windows_Mono" { $component = [UnitySetupComponent]::Windows } + "Mac_Mono" { $component = [UnitySetupComponent]::Mac } + Default { $component = $sectionName } + } + + $installerTemplates[$component] = $url + } + } + + Write-Verbose "components: $linkComponents" if ($knownBaseUrls -notcontains $linkComponents[0]) { - $knownBaseUrls = $linkComponents[0], $knownBaseUrls + $knownBaseUrls = @($linkComponents[0]) + $knownBaseUrls } else { $knownBaseUrls = $knownBaseUrls | Sort-Object -Property @{ Expression = { [math]::Abs(($_.CompareTo($linkComponents[0]))) }; Ascending = $true } From b909d1b3560513fe4369540998dcddbf48822d7b Mon Sep 17 00:00:00 2001 From: Dmitriy Vornychev Date: Sat, 24 Dec 2022 00:38:09 +0100 Subject: [PATCH 04/15] Support Install-UnitySetupInstance for Linux --- UnitySetup/UnitySetup.psm1 | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 3096053..9362983 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -1,4 +1,4 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. Import-Module powershell-yaml -MinimumVersion '0.3' -ErrorAction Stop @@ -1033,17 +1033,14 @@ function Install-UnitySetupInstance { ) begin { $currentOS = Get-OperatingSystem - if ($currentOS -eq [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\Hub\Editor\" } ([OperatingSystem]::Linux) { - throw "Install-UnitySetupInstance has not been implemented on the Linux platform. Contributions welcomed!"; + "~/Unity/Hub/Editor/" } ([OperatingSystem]::Mac) { "/Applications/Unity/Hub/Editor/" From c422a1a453d0eb11b99c5685750962302ae78932 Mon Sep 17 00:00:00 2001 From: Dmitriy Vornychev Date: Sat, 24 Dec 2022 13:50:45 +0100 Subject: [PATCH 05/15] Download UnitySetup executable for Linux --- UnitySetup/UnitySetup.psm1 | 149 ++++++++++++++++++++++++++++++++----- 1 file changed, 130 insertions(+), 19 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 9362983..3e213ee 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -366,6 +366,10 @@ function ConvertTo-UnitySetupComponent { Manually specify the build hash, to select a private build. .PARAMETER Components What components would you like to search for? Defaults to All +.PARAMETER Cache + File path where installer and configuration for Linux will be downloaded to. + Preliminary installer and configuration download is necessary to retrieve actual paths of Unity components for Linux + and to allow subsequent components install. Defaults to ~/.unitysetup .EXAMPLE Find-UnitySetupInstaller -Version 2017.3.0f3 .EXAMPLE @@ -381,9 +385,27 @@ function Find-UnitySetupInstaller { [UnitySetupComponent] $Components = [UnitySetupComponent]::All, [parameter(Mandatory = $false)] - [string] $Hash = "" + [string] $Hash = "", + + [parameter(Mandatory = $false)] + [string]$Cache = [io.Path]::Combine("~", ".unitysetup") + + # , + # [parameter(Mandatory = $false)] + # [switch]$Verbose = $false ) + # 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 + $Components = ConvertTo-UnitySetupComponent -Component $Components -Version $Version $currentOS = Get-OperatingSystem @@ -451,6 +473,9 @@ function Find-UnitySetupInstaller { } ([OperatingSystem]::Linux) { $setupComponent = [UnitySetupComponent]::Linux + + # Note: This is the main installer small executable that is used to install all other components. + # It will be replaced later by Linux Editor component $installerTemplates[$setupComponent] = , "UnitySetup-$Version"; } ([OperatingSystem]::Mac) { @@ -541,16 +566,34 @@ function Find-UnitySetupInstaller { $linkComponents = $prototypeLink -split "/$hashRegEx/" -ne "" - $iniFileName = "unity-$Version-linux.ini" - $baseUrl = $linkComponents[0] + "/" + $linkComponents[1] - $iniLink = "$baseUrl/$iniFileName" + $unityPath = $linkComponents[0] + $unityHash = $linkComponents[1] + $unityVersion = $linkComponents[2] # simnilar to UnitySetup-2021.1.23f1 + + $baseUrl = "$unityPath/$unityHash" + + Write-Verbose "Ready to download installer from $baseUrl" + + # also download installer that will be used to install all other components + $installerName = $installerTemplates[[UnitySetupComponent]::Linux] + $installerUrl = "$baseUrl/$installerName" + $cachedInstallerBasePath = "$fullCachePath/Installers/Unity-$Version" + New-Item $cachedInstallerBasePath -ItemType Directory -Force | Out-Null - $linuxIni = Invoke-WebRequest $iniLink -UseBasicParsing + $localCachedInstaller = "$cachedInstallerBasePath/$installerName" + + Write-Verbose "Saving installer to $localCachedInstaller" + + Invoke-WebRequest $installerUrl -UseBasicParsing | Set-Content -Path $localCachedInstaller + + # Configuration file for installer + $iniFileName = "unity-$Version-linux.ini" + $iniUrl = "$baseUrl/$iniFileName" # PsIni can read only from files and from stdin - $localCachedIni = "/tmp/$iniFileName" - - Set-Content -Path $localCachedIni -Value $linuxIni + $localCachedIni = "$Cache/$iniFileName" + + Invoke-WebRequest $iniUrl -UseBasicParsing | Set-Content -Path $localCachedIni $iniContent = Get-IniContent $localCachedIni @@ -947,6 +990,19 @@ function Request-UnitySetupInstaller { } } +function StartProcessWithArgs($startProcessArgs) +{ + $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." + } + } +} + function Install-UnitySetupPackage { [CmdletBinding()] param( @@ -968,7 +1024,70 @@ function Install-UnitySetupPackage { } } ([OperatingSystem]::Linux) { - throw "Install-UnitySetupPackage has not been implemented on the Linux platform. Contributions welcomed!"; + + $VerbosePreference = "Continue" + + # TODO: assert that tar and 7z are installed + + Write-Verbose "Package path: $($Package.Path)" + Write-Verbose "Destination: $Destination" + + $isTarXz = $Package.Path -match ".*\.tar\.xz" + $isPkg = $Package.Path -match ".*\.pkg" + + if ($isTarXz) { + Write-Verbose ".tar.xz" + + $unpackedDir = $(Resolve-Path "$($Package.Path)") -replace '\.tar\.xz$','' + New-Item -ItemType Directory -Force "$unpackedDir" | Out-Null + + Write-Verbose "Unpack $($Package.Path) to $unpackedDir" + + $startProcessArgs = @{ + 'FilePath' = 'tar'; + 'ArgumentList' = @("xf", $Package.Path, "-C", "$unpackedDir", "-v"); + 'PassThru' = $true; + 'Wait' = $true; + } + + StartProcessWithArgs($startProcessArgs) + } + elseif ($isPkg) { + Write-Verbose ".pkg" + + $unpackedDir = $(Resolve-Path "$($Package.Path)") -replace '\.pkg$','' + New-Item -ItemType Directory -Force "$unpackedDir" | Out-Null + + Write-Verbose "Unpack $($Package.Path) to $unpackedDir" + + $startProcessArgs = @{ + 'FilePath' = '7z'; + 'ArgumentList' = @("x", $Package.Path, "-o$unpackedDir/", "-t*", "-y"); + 'PassThru' = $true; + 'Wait' = $true; + } + + StartProcessWithArgs($startProcessArgs) + } + else { + throw "$($Package.Path) has unsupported archive format" + } + + $pkgInfo = [xml](Get-Content ./TargetSupport.pkg.tmp/PackageInfo) + $targetName = basename $($pkgInfo.'pkg-info'.'install-location') + + Write-Verbose "targetName: $targetName" + + return + + $payloadPath = "$unpackedDir/TargetSupport.pkg.tmp/Payload" + # extract /TargetSupport.pkg.tmp/Payload to destination + $startProcessArgs = @{ + 'FilePath' = '7z'; + 'ArgumentList' = @("x", $Package.Path, "-o$unpackedDir", "-t*"); + 'PassThru' = $true; + 'Wait' = $true; + } } ([OperatingSystem]::Mac) { # Note that $Destination has to be a disk path. @@ -983,15 +1102,7 @@ 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 { - Write-Verbose "$(Get-Date): Succeeded." - } - } + StartProcessWithArgs($startProcessArgs) } <# @@ -1033,7 +1144,7 @@ function Install-UnitySetupInstance { ) begin { $currentOS = Get-OperatingSystem - + if ( -not $PSBoundParameters.ContainsKey('BasePath') ) { $defaultInstallPath = switch ($currentOS) { ([OperatingSystem]::Windows) { From 7b034afe4204a713bc40b907d58606a6ac38dc0f Mon Sep 17 00:00:00 2001 From: Dmitriy Vornychev Date: Sat, 24 Dec 2022 16:07:59 +0100 Subject: [PATCH 06/15] Support Install-UnitySetupPackage for Linux --- UnitySetup/UnitySetup.psm1 | 96 ++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 51 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 3e213ee..74aaf08 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -389,10 +389,6 @@ function Find-UnitySetupInstaller { [parameter(Mandatory = $false)] [string]$Cache = [io.Path]::Combine("~", ".unitysetup") - - # , - # [parameter(Mandatory = $false)] - # [switch]$Verbose = $false ) # Note that this has to happen before calculating the full path since @@ -584,16 +580,20 @@ function Find-UnitySetupInstaller { Write-Verbose "Saving installer to $localCachedInstaller" - Invoke-WebRequest $installerUrl -UseBasicParsing | Set-Content -Path $localCachedInstaller + Invoke-WebRequest $installerUrl -OutFile $localCachedInstaller + + chmod +x $localCachedInstaller # Configuration file for installer $iniFileName = "unity-$Version-linux.ini" $iniUrl = "$baseUrl/$iniFileName" # PsIni can read only from files and from stdin - $localCachedIni = "$Cache/$iniFileName" + $localCachedIni = "$cachedInstallerBasePath/$iniFileName" + + Invoke-WebRequest $iniUrl -UseBasicParsing -OutFile $localCachedIni - Invoke-WebRequest $iniUrl -UseBasicParsing | Set-Content -Path $localCachedIni + Write-Verbose $localCachedIni $iniContent = Get-IniContent $localCachedIni @@ -601,6 +601,7 @@ function Find-UnitySetupInstaller { $installerTemplates = @{} foreach ($section in $iniContent.GetEnumerator()) { + # replace "-" with "_" to match enum entries $sectionName = $section.Name.Replace('-', "_") $url = $iniContent[$section.Name].url @@ -1024,67 +1025,60 @@ function Install-UnitySetupPackage { } } ([OperatingSystem]::Linux) { - - $VerbosePreference = "Continue" + # Assume that UnitySetup in the same folder as package + $basePackagePath = [System.IO.Path]::GetDirectoryName($Package.Path) - # TODO: assert that tar and 7z are installed + $versionRegEx = "(\d+)\.(\d+)\.(\d+)([fpba])(\d+)" + if (-not ($Package.Path -match $versionRegEx)) { + throw "Can't determine Unity version from package" + } - Write-Verbose "Package path: $($Package.Path)" - Write-Verbose "Destination: $Destination" + $version = $Matches[0] - $isTarXz = $Package.Path -match ".*\.tar\.xz" - $isPkg = $Package.Path -match ".*\.pkg" + # installer is expected to be already donwloaded to the same location during Find-UnitySetupInstaller invocation + $installerName = "UnitySetup-$version" + $installerPath = "$basePackagePath/$installerName" - if ($isTarXz) { - Write-Verbose ".tar.xz" + if (-not (Test-Path $installerPath)) { + throw "Can't find Unity installer, expected at $installerPath" + } - $unpackedDir = $(Resolve-Path "$($Package.Path)") -replace '\.tar\.xz$','' - New-Item -ItemType Directory -Force "$unpackedDir" | Out-Null + Write-Verbose "Package path: $($Package.Path)" + Write-Verbose "Destination: $Destination" - Write-Verbose "Unpack $($Package.Path) to $unpackedDir" + Import-Module PsIni -MinimumVersion '3.1.3' -ErrorAction Stop - $startProcessArgs = @{ - 'FilePath' = 'tar'; - 'ArgumentList' = @("xf", $Package.Path, "-C", "$unpackedDir", "-v"); - 'PassThru' = $true; - 'Wait' = $true; - } + $iniFileName = "unity-$Version-linux.ini" + $iniPath = "$basePackagePath/$iniFileName" - StartProcessWithArgs($startProcessArgs) - } - elseif ($isPkg) { - Write-Verbose ".pkg" + $iniContent = Get-IniContent $iniPath - $unpackedDir = $(Resolve-Path "$($Package.Path)") -replace '\.pkg$','' - New-Item -ItemType Directory -Force "$unpackedDir" | Out-Null + $componentName = "" + foreach ($section in $iniContent.GetEnumerator()) { + $sectionName = $section.Name + $url = $iniContent[$section.Name].url # e.g. "LinuxEditorInstaller/Unity.tar.xz" - Write-Verbose "Unpack $($Package.Path) to $unpackedDir" + # this should match package name + $urlFileName = [System.IO.Path]::GetFileName($url) # e.g. "Unity.tar.xz" - $startProcessArgs = @{ - 'FilePath' = '7z'; - 'ArgumentList' = @("x", $Package.Path, "-o$unpackedDir/", "-t*", "-y"); - 'PassThru' = $true; - 'Wait' = $true; - } + Write-Verbose "Retrieved $url for $sectionName" - StartProcessWithArgs($startProcessArgs) - } - else { - throw "$($Package.Path) has unsupported archive format" + if ($Package.Path -like "*$urlFileName") { + $componentName = $sectionName + break + } } - $pkgInfo = [xml](Get-Content ./TargetSupport.pkg.tmp/PackageInfo) - $targetName = basename $($pkgInfo.'pkg-info'.'install-location') - - Write-Verbose "targetName: $targetName" + if (-not $componentName) { + throw "Could not determine proper component name for $($Package.Path)" + } - return + # Note: this way user will be asked for license confirmation. + # To bypass it, one should use "yes | " - $payloadPath = "$unpackedDir/TargetSupport.pkg.tmp/Payload" - # extract /TargetSupport.pkg.tmp/Payload to destination $startProcessArgs = @{ - 'FilePath' = '7z'; - 'ArgumentList' = @("x", $Package.Path, "-o$unpackedDir", "-t*"); + 'FilePath' = "$installerPath"; + 'ArgumentList' = @('-u', '-l', $Destination, '-d', $basePackagePath, '-c', $componentName); 'PassThru' = $true; 'Wait' = $true; } From eecc44f0a89bec45f3558da86855203343d908bf Mon Sep 17 00:00:00 2001 From: Dmitriy Vornychev Date: Sat, 24 Dec 2022 16:59:50 +0100 Subject: [PATCH 07/15] Fix paths for Linux components --- UnitySetup/UnitySetup.psm1 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 74aaf08..db3db13 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -80,14 +80,15 @@ class UnitySetupInstance { } ([OperatingSystem]::Linux) { $this.Components = [UnitySetupComponent]::Linux - $playbackEnginePath = [io.path]::Combine("$Path", "Data/PlaybackEngines"); + $playbackEnginePath = [io.path]::Combine("$Path", "Editor/Data/PlaybackEngines"); @{ [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 = , [io.path]::Combine("$playbackEnginePath", "MacStandaloneSupport/Variations/macos_x64_player_development_mono"); + [UnitySetupComponent]::Mac_IL2CPP = , [io.path]::Combine("$playbackEnginePath", "MacStandaloneSupport/Variations/macos_x64_player_development_il2cpp"); [UnitySetupComponent]::Windows = , [io.path]::Combine("$playbackEnginePath", "WindowsStandaloneSupport"); - [UnitySetupComponent]::Linux = , [io.path]::Combine("$playbackEnginePath", "LinuxStandaloneSupport/Variations/linux64_headless_development_mono"); - [UnitySetupComponent]::Linux_IL2CPP = , [io.path]::Combine("$playbackEnginePath", "LinuxStandaloneSupport/Variations/linux64_headless_development_il2cpp"); + [UnitySetupComponent]::Linux_IL2CPP = , [io.path]::Combine("$playbackEnginePath", "LinuxStandaloneSupport/Variations/linux64_player_development_il2cpp"); + [UnitySetupComponent]::Linux_Server = , [io.path]::Combine("$playbackEnginePath", "LinuxStandaloneSupport/Variations/linux64_server_development_mono"); } } ([OperatingSystem]::Mac) { @@ -113,6 +114,7 @@ class UnitySetupInstance { $componentTests[[UnitySetupComponent]::Vuforia] = , [io.path]::Combine("$playbackEnginePath", "VuforiaSupport"); $componentTests[[UnitySetupComponent]::WebGL] = , [io.path]::Combine("$playbackEnginePath", "WebGLSupport"); + Write-Verbose "path: $Path" $componentTests.Keys | ForEach-Object { foreach ( $test in $componentTests[$_] ) { if ( Test-Path -PathType Container -Path $test ) { From b7eca13fe1a5e8c557b1dd1a262135802c0f66c3 Mon Sep 17 00:00:00 2001 From: Dmitriy Vornychev Date: Wed, 11 Jan 2023 08:28:39 +0100 Subject: [PATCH 08/15] Common -PassThru and -Wait arguments In Install-UnitySetupPackage --- UnitySetup/UnitySetup.psm1 | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index db3db13..a911726 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -1,4 +1,4 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. Import-Module powershell-yaml -MinimumVersion '0.3' -ErrorAction Stop @@ -993,19 +993,6 @@ function Request-UnitySetupInstaller { } } -function StartProcessWithArgs($startProcessArgs) -{ - $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." - } - } -} - function Install-UnitySetupPackage { [CmdletBinding()] param( @@ -1022,8 +1009,6 @@ function Install-UnitySetupPackage { $startProcessArgs = @{ 'FilePath' = $Package.Path; 'ArgumentList' = @("/S", "/D=$Destination"); - 'PassThru' = $true; - 'Wait' = $true; } } ([OperatingSystem]::Linux) { @@ -1081,8 +1066,6 @@ function Install-UnitySetupPackage { $startProcessArgs = @{ 'FilePath' = "$installerPath"; 'ArgumentList' = @('-u', '-l', $Destination, '-d', $basePackagePath, '-c', $componentName); - 'PassThru' = $true; - 'Wait' = $true; } } ([OperatingSystem]::Mac) { @@ -1091,14 +1074,20 @@ function Install-UnitySetupPackage { $startProcessArgs = @{ 'FilePath' = 'sudo'; 'ArgumentList' = @("installer", "-package", $Package.Path, "-target", $Destination); - 'PassThru' = $true; - 'Wait' = $true; } } } Write-Verbose "$(Get-Date): Installing $($Package.ComponentType) to $Destination." - StartProcessWithArgs($startProcessArgs) + $process = Start-Process @startProcessArgs -PassThru -Wait + if ( $process ) { + if ( $process.ExitCode -ne 0) { + Write-Error "$(Get-Date): Failed with exit code: $($process.ExitCode)" + } + else { + Write-Verbose "$(Get-Date): Succeeded." + } + } } <# From 491d496dc9cad1f9306cedd8a5294f0ee607cc22 Mon Sep 17 00:00:00 2001 From: Dmitriy Vornychev Date: Wed, 11 Jan 2023 08:29:34 +0100 Subject: [PATCH 09/15] Minor fixes --- UnitySetup/UnitySetup.psm1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index a911726..0b75609 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -25,7 +25,7 @@ enum UnitySetupComponent { Windows_Server = (1 -shl 17) Linux_Server = (1 -shl 18) Mac_Server = (1 -shl 19) - All = (1 -shl 20) - 1 + All = 0xFFFFFFFF } [Flags()] @@ -114,7 +114,6 @@ class UnitySetupInstance { $componentTests[[UnitySetupComponent]::Vuforia] = , [io.path]::Combine("$playbackEnginePath", "VuforiaSupport"); $componentTests[[UnitySetupComponent]::WebGL] = , [io.path]::Combine("$playbackEnginePath", "WebGLSupport"); - Write-Verbose "path: $Path" $componentTests.Keys | ForEach-Object { foreach ( $test in $componentTests[$_] ) { if ( Test-Path -PathType Container -Path $test ) { From 3a05f5e8bebcdd3492d535f4c66ca90b424d225f Mon Sep 17 00:00:00 2001 From: Dmitriy Vornychev Date: Wed, 11 Jan 2023 08:44:37 +0100 Subject: [PATCH 10/15] Adapt Get-UnityLicense for Linux --- UnitySetup/UnitySetup.psm1 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 0b75609..f2c2d69 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -2202,7 +2202,14 @@ function Get-UnityLicense { [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' + switch (Get-OperatingSystem) { + Windows { $licensePaths = "C:\ProgramData\Unity\Unity_*.ulf" } + Linux { $licensePaths = "~/.local/share/unity3d/Unity/Unity_*.ulf" } + Mac { throw "Get-UnityLicense has not been implemented on the Mac platform. Contributions welcomed!" } + } + + $licenseFiles = Get-ChildItem $licensePaths -ErrorAction 'SilentlyContinue' + foreach ( $licenseFile in $licenseFiles ) { Write-Verbose "Discovered License File at $licenseFile" $doc = [xml](Get-Content "$licenseFile") From 5120a76168c059542fe070a995b40c30b81e60ed Mon Sep 17 00:00:00 2001 From: Dmitriy Vornychev Date: Wed, 11 Jan 2023 08:50:49 +0100 Subject: [PATCH 11/15] Minor imrpovement when reading "ProjectSettings.asset" --- UnitySetup/UnitySetup.psm1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index f2c2d69..ea76d90 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -140,8 +140,9 @@ class UnityProjectInstance { $projectSettingsFile = [io.path]::Combine($path, "ProjectSettings\ProjectSettings.asset") if (!(Test-Path $projectSettingsFile)) { throw "Project is missing ProjectSettings.asset" } - try { - $prodName = ((Get-Content $projectSettingsFile -Raw | ConvertFrom-Yaml)['playerSettings'])['productName'] + try { + # discard non-valid lines with empty keys before passing to ConvertFrom-Yaml + $prodName = (((Get-Content $projectSettingsFile -Raw) -replace '\n(\s)*:( \".*\")\n', "`n" | ConvertFrom-Yaml)['playerSettings'])['productName'] if (!$prodName) { throw "ProjectSettings is missing productName" } } catch { From e4ee3bf3bb1dea3ec2e67d3782fd59529a68a019 Mon Sep 17 00:00:00 2001 From: Dmitriy Vornychev Date: Wed, 11 Jan 2023 09:07:35 +0100 Subject: [PATCH 12/15] Replace [io.path]::Combine with Join-Path --- UnitySetup/UnitySetup.psm1 | 98 +++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index ea76d90..4d95fc1 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -1,4 +1,4 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. Import-Module powershell-yaml -MinimumVersion '0.3' -ErrorAction Stop @@ -64,55 +64,55 @@ class UnitySetupInstance { $componentTests = switch ($currentOS) { ([OperatingSystem]::Windows) { $this.Components = [UnitySetupComponent]::Windows - $playbackEnginePath = [io.path]::Combine("$Path", "Editor\Data\PlaybackEngines"); + $playbackEnginePath = Join-Path -Path "$Path" -ChildPath "Editor\Data\PlaybackEngines" -Resolve; @{ - [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"), - [io.path]::Combine("$playbackEnginePath", "windowsstandalonesupport\Variations\win32_player_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\Variations\linux64_headless_development_mono"); - [UnitySetupComponent]::Linux_IL2CPP = , [io.path]::Combine("$playbackEnginePath", "LinuxStandaloneSupport\Variations\linux64_headless_development_il2cpp"); - [UnitySetupComponent]::Mac = , [io.path]::Combine("$playbackEnginePath", "MacStandaloneSupport"); + [UnitySetupComponent]::Documentation = , (Join-Path -Path "$Path" -ChildPath "Editor\Data\Documentation" -Resolve); + [UnitySetupComponent]::StandardAssets = , (Join-Path -Path "$Path" -ChildPath "Editor\Standard Assets" -Resolve); + [UnitySetupComponent]::Windows_IL2CPP = , (Join-Path -Path "$playbackEnginePath" -ChildPath "windowsstandalonesupport\Variations\win32_development_il2cpp" -Resolve), + (Join-Path -Path "$playbackEnginePath" -ChildPath "windowsstandalonesupport\Variations\win32_player_development_il2cpp" -Resolve); + [UnitySetupComponent]::UWP = (Join-Path -Path "$playbackEnginePath" -ChildPath "MetroSupport\Templates\UWP_.NET_D3D" -Resolve), + (Join-Path -Path "$playbackEnginePath" -ChildPath "MetroSupport\Templates\UWP_D3D" -Resolve); + [UnitySetupComponent]::UWP_IL2CPP = , (Join-Path -Path "$playbackEnginePath" -ChildPath "MetroSupport\Templates\UWP_IL2CPP_D3D" -Resolve); + [UnitySetupComponent]::Linux = , (Join-Path -Path "$playbackEnginePath" -ChildPath "LinuxStandaloneSupport\Variations\linux64_headless_development_mono" -Resolve); + [UnitySetupComponent]::Linux_IL2CPP = , (Join-Path -Path "$playbackEnginePath" -ChildPath "LinuxStandaloneSupport\Variations\linux64_headless_development_il2cpp" -Resolve); + [UnitySetupComponent]::Mac = , (Join-Path -Path "$playbackEnginePath" -ChildPath "MacStandaloneSupport" -Resolve); } } ([OperatingSystem]::Linux) { $this.Components = [UnitySetupComponent]::Linux - $playbackEnginePath = [io.path]::Combine("$Path", "Editor/Data/PlaybackEngines"); + $playbackEnginePath = Join-Path -Path "$Path" -ChildPath "Editor/Data/PlaybackEngines" -Resolve; @{ - [UnitySetupComponent]::Documentation = , [io.path]::Combine("$Path", "Documentation"); - [UnitySetupComponent]::StandardAssets = , [io.path]::Combine("$Path", "Standard Assets"); - [UnitySetupComponent]::Mac = , [io.path]::Combine("$playbackEnginePath", "MacStandaloneSupport/Variations/macos_x64_player_development_mono"); - [UnitySetupComponent]::Mac_IL2CPP = , [io.path]::Combine("$playbackEnginePath", "MacStandaloneSupport/Variations/macos_x64_player_development_il2cpp"); - [UnitySetupComponent]::Windows = , [io.path]::Combine("$playbackEnginePath", "WindowsStandaloneSupport"); - [UnitySetupComponent]::Linux_IL2CPP = , [io.path]::Combine("$playbackEnginePath", "LinuxStandaloneSupport/Variations/linux64_player_development_il2cpp"); - [UnitySetupComponent]::Linux_Server = , [io.path]::Combine("$playbackEnginePath", "LinuxStandaloneSupport/Variations/linux64_server_development_mono"); + [UnitySetupComponent]::Documentation = , (Join-Path -Path "$Path" -ChildPath "Documentation" -Resolve); + [UnitySetupComponent]::StandardAssets = , (Join-Path -Path "$Path" -ChildPath "Standard Assets" -Resolve); + [UnitySetupComponent]::Mac = , (Join-Path -Path "$playbackEnginePath" -ChildPath "MacStandaloneSupport/Variations/macos_x64_player_development_mono" -Resolve); + [UnitySetupComponent]::Mac_IL2CPP = , (Join-Path -Path "$playbackEnginePath" -ChildPath "MacStandaloneSupport/Variations/macos_x64_player_development_il2cpp" -Resolve); + [UnitySetupComponent]::Windows = , (Join-Path -Path "$playbackEnginePath" -ChildPath "WindowsStandaloneSupport" -Resolve); + [UnitySetupComponent]::Linux_IL2CPP = , (Join-Path -Path "$playbackEnginePath" -ChildPath "LinuxStandaloneSupport/Variations/linux64_player_development_il2cpp" -Resolve); + [UnitySetupComponent]::Linux_Server = , (Join-Path -Path "$playbackEnginePath" -ChildPath "LinuxStandaloneSupport/Variations/linux64_server_development_mono" -Resolve); } } ([OperatingSystem]::Mac) { $this.Components = [UnitySetupComponent]::Mac - $playbackEnginePath = [io.path]::Combine("$Path", "PlaybackEngines"); + $playbackEnginePath = Join-Path -Path "$Path" -ChildPath "PlaybackEngines" -Resolve; @{ - [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]::Windows = , [io.path]::Combine("$playbackEnginePath", "WindowsStandaloneSupport"); - [UnitySetupComponent]::Linux = , [io.path]::Combine("$playbackEnginePath", "LinuxStandaloneSupport/Variations/linux64_headless_development_mono"); - [UnitySetupComponent]::Linux_IL2CPP = , [io.path]::Combine("$playbackEnginePath", "LinuxStandaloneSupport/Variations/linux64_headless_development_il2cpp"); + [UnitySetupComponent]::Documentation = , (Join-Path -Path "$Path" -ChildPath "Documentation" -Resolve); + [UnitySetupComponent]::StandardAssets = , (Join-Path -Path "$Path" -ChildPath "Standard Assets" -Resolve); + [UnitySetupComponent]::Mac_IL2CPP = , (Join-Path -Path "$playbackEnginePath" -ChildPath "MacStandaloneSupport/Variations/macosx64_development_il2cpp" -Resolve); + [UnitySetupComponent]::Windows = , (Join-Path -Path "$playbackEnginePath" -ChildPath "WindowsStandaloneSupport" -Resolve); + [UnitySetupComponent]::Linux = , (Join-Path -Path "$playbackEnginePath" -ChildPath "LinuxStandaloneSupport/Variations/linux64_headless_development_mono" -Resolve); + [UnitySetupComponent]::Linux_IL2CPP = , (Join-Path -Path "$playbackEnginePath" -ChildPath "LinuxStandaloneSupport/Variations/linux64_headless_development_il2cpp" -Resolve); } } } # 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"); - $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]::Lumin] = , (Join-Path -Path "$playbackEnginePath" -ChildPath "LuminSupport" -Resolve); + $componentTests[[UnitySetupComponent]::Android] = , (Join-Path -Path "$playbackEnginePath" -ChildPath "AndroidPlayer" -Resolve); + $componentTests[[UnitySetupComponent]::iOS] = , (Join-Path -Path "$playbackEnginePath" -ChildPath "iOSSupport" -Resolve); + $componentTests[[UnitySetupComponent]::AppleTV] = , (Join-Path -Path "$playbackEnginePath" -ChildPath "AppleTVSupport" -Resolve); + $componentTests[[UnitySetupComponent]::Facebook] = , (Join-Path -Path "$playbackEnginePath" -ChildPath "Facebook" -Resolve); + $componentTests[[UnitySetupComponent]::Vuforia] = , (Join-Path -Path "$playbackEnginePath" -ChildPath "VuforiaSupport" -Resolve); + $componentTests[[UnitySetupComponent]::WebGL] = , (Join-Path -Path "$playbackEnginePath" -ChildPath "WebGLSupport" -Resolve); $componentTests.Keys | ForEach-Object { foreach ( $test in $componentTests[$_] ) { @@ -131,13 +131,13 @@ class UnityProjectInstance { [string]$ProductName UnityProjectInstance([string]$path) { - $versionFile = [io.path]::Combine($path, "ProjectSettings\ProjectVersion.txt") + $versionFile = Join-Path -Path $path -ChildPath "ProjectSettings\ProjectVersion.txt" -Resolve 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" } - $projectSettingsFile = [io.path]::Combine($path, "ProjectSettings\ProjectSettings.asset") + $projectSettingsFile = Join-Path -Path $path -ChildPath "ProjectSettings\ProjectSettings.asset" -Resolve if (!(Test-Path $projectSettingsFile)) { throw "Project is missing ProjectSettings.asset" } try { @@ -390,7 +390,7 @@ function Find-UnitySetupInstaller { [string] $Hash = "", [parameter(Mandatory = $false)] - [string]$Cache = [io.Path]::Combine("~", ".unitysetup") + [string] $Cache = (Join-Path -Path "~" -ChildPath ".unitysetup" -Resolve) ) # Note that this has to happen before calculating the full path since @@ -819,7 +819,7 @@ function Request-UnitySetupInstaller { [UnitySetupInstaller[]] $Installers, [parameter(Mandatory = $false)] - [string]$Cache = [io.Path]::Combine("~", ".unitysetup") + [string] $Cache = (Join-Path -Path "~" -ChildPath ".unitysetup" -Resolve) ) begin { # Note that this has to happen before calculating the full path since @@ -850,7 +850,7 @@ function Request-UnitySetupInstaller { $allInstallers | ForEach-Object { $installerFileName = [io.Path]::GetFileName($_.DownloadUrl) - $destination = [io.Path]::Combine($fullCachePath, "Installers", "Unity-$($_.Version)", "$installerFileName") + $destination = Join-Path -Path $fullCachePath, "Installers", "Unity-$($_.Version)" -ChildPath "$installerFileName" -Resolve # Already downloaded? if ( Test-Path $destination ) { @@ -1119,13 +1119,13 @@ function Install-UnitySetupInstance { [UnitySetupInstaller[]] $Installers, [parameter(Mandatory = $false)] - [string]$BasePath, + [string] $BasePath, [parameter(Mandatory = $false)] - [string]$Destination, + [string] $Destination, [parameter(Mandatory = $false)] - [string]$Cache = [io.Path]::Combine("~", ".unitysetup") + [string] $Cache = (Join-Path -Path "~" -ChildPath ".unitysetup" -Resolve) ) begin { $currentOS = Get-OperatingSystem @@ -1166,16 +1166,16 @@ function Install-UnitySetupInstance { $installPath = $Destination } else { - $installPath = [io.path]::Combine($BasePath, $Destination) + $installPath = Join-Path -Path $BasePath -ChildPath $Destination -Resolve } } else { - $installPath = [io.path]::Combine($defaultInstallPath, $installVersion) + $installPath = Join-Path -Path $defaultInstallPath -ChildPath $installVersion -Resolve } if ($currentOS -eq [OperatingSystem]::Mac) { $volumeRoot = "/Volumes/UnitySetup/" - $volumeInstallPath = [io.path]::Combine($volumeRoot, "Applications/Unity/") + $volumeInstallPath = Join-Path -Path $volumeRoot -ChildPath "Applications/Unity/" -Resolve # Make sure the install path ends with a trailing slash. This # is required in some commands to treat as directory. @@ -1190,7 +1190,7 @@ function Install-UnitySetupInstance { } # Creating sparse bundle to host installing Unity in other locations - $unitySetupBundlePath = [io.path]::Combine($Cache, "UnitySetup.sparsebundle") + $unitySetupBundlePath = Join-Path -Path $Cache -ChildPath "UnitySetup.sparsebundle" -Resolve 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 @@ -1201,7 +1201,7 @@ function Install-UnitySetupInstance { # Previous version failed to remove. Cleaning up! if (Test-Path $volumeInstallPath) { Write-Verbose "Previous install did not clean up properly. Doing that now." - & sudo rm -Rf ([io.path]::Combine($volumeRoot, '*')) + & sudo rm -Rf (Join-Path -Path $volumeRoot -ChildPath '*' -Resolve) } # Copy installed version back to the sparse bundle disk for Unity component installs. @@ -1267,7 +1267,7 @@ function Install-UnitySetupInstance { Write-Verbose "Freeing sparse bundle disk space and unmounting." # Ensure the drive is cleaned up. - & sudo rm -Rf ([io.path]::Combine($volumeRoot, '*')) + & sudo rm -Rf (Join-Path -Path $volumeRoot -ChildPath '*' -Resolve) & hdiutil eject $volumeRoot # Free up disk space since deleting items in the volume send them to the trash @@ -1571,7 +1571,7 @@ function Get-UnityProjectInstance { Get-ChildItem @args | ForEach-Object { - $path = [io.path]::Combine($_.FullName, "ProjectVersion.txt") + $path = Join-Path -Path $_.FullName -ChildPath "ProjectVersion.txt" -Resolve if ( Test-Path $path ) { [UnityProjectInstance]::new((Join-Path $_.FullName "..\" | Convert-Path)) } From e3896064e5652ed0d6f84f8ebe8756d9f2ab5310 Mon Sep 17 00:00:00 2001 From: Dmitriy Vornychev Date: Wed, 11 Jan 2023 09:07:47 +0100 Subject: [PATCH 13/15] Bump version to 6.0 --- UnitySetup/UnitySetup.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitySetup/UnitySetup.psd1 b/UnitySetup/UnitySetup.psd1 index 03afd04..2dea38b 100644 --- a/UnitySetup/UnitySetup.psd1 +++ b/UnitySetup/UnitySetup.psd1 @@ -14,7 +14,7 @@ RootModule = 'UnitySetup' # Version number of this module. - ModuleVersion = '5.5' + ModuleVersion = '6.0' # Supported PSEditions # CompatiblePSEditions = @() From 2df1d33b866d26456bb2b430425418154e52a0fe Mon Sep 17 00:00:00 2001 From: Dmitriy Vornychev Date: Wed, 11 Jan 2023 09:47:23 +0100 Subject: [PATCH 14/15] Add PsIni to appveyor.yml --- appveyor.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index c2cd258..60b569f 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -16,6 +16,8 @@ install: Install-Module 'PowerShellGet' -Scope CurrentUser -Force -AllowClobber -Verbose Install-Module 'powershell-yaml' -Scope CurrentUser -Force -AllowClobber -Verbose + + Install-Module 'PsIni' -Scope CurrentUser -Force -AllowClobber -Verbose build_script: - ps: .\build.ps1 -Revision "$env:APPVEYOR_BUILD_NUMBER" -Suffix "$env:APPVEYOR_REPO_BRANCH" deploy_script: From 1da607b6cdee6239240400fbc931f4d98b8d5882 Mon Sep 17 00:00:00 2001 From: Dmitry Vornychev Date: Sat, 18 Mar 2023 13:02:39 +0100 Subject: [PATCH 15/15] Remove -Resolve and explicit Join-Path arg names --- UnitySetup/UnitySetup.psm1 | 92 +++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index 4d95fc1..4ee1429 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -64,55 +64,55 @@ class UnitySetupInstance { $componentTests = switch ($currentOS) { ([OperatingSystem]::Windows) { $this.Components = [UnitySetupComponent]::Windows - $playbackEnginePath = Join-Path -Path "$Path" -ChildPath "Editor\Data\PlaybackEngines" -Resolve; + $playbackEnginePath = Join-Path "$Path" "Editor\Data\PlaybackEngines"; @{ - [UnitySetupComponent]::Documentation = , (Join-Path -Path "$Path" -ChildPath "Editor\Data\Documentation" -Resolve); - [UnitySetupComponent]::StandardAssets = , (Join-Path -Path "$Path" -ChildPath "Editor\Standard Assets" -Resolve); - [UnitySetupComponent]::Windows_IL2CPP = , (Join-Path -Path "$playbackEnginePath" -ChildPath "windowsstandalonesupport\Variations\win32_development_il2cpp" -Resolve), - (Join-Path -Path "$playbackEnginePath" -ChildPath "windowsstandalonesupport\Variations\win32_player_development_il2cpp" -Resolve); - [UnitySetupComponent]::UWP = (Join-Path -Path "$playbackEnginePath" -ChildPath "MetroSupport\Templates\UWP_.NET_D3D" -Resolve), - (Join-Path -Path "$playbackEnginePath" -ChildPath "MetroSupport\Templates\UWP_D3D" -Resolve); - [UnitySetupComponent]::UWP_IL2CPP = , (Join-Path -Path "$playbackEnginePath" -ChildPath "MetroSupport\Templates\UWP_IL2CPP_D3D" -Resolve); - [UnitySetupComponent]::Linux = , (Join-Path -Path "$playbackEnginePath" -ChildPath "LinuxStandaloneSupport\Variations\linux64_headless_development_mono" -Resolve); - [UnitySetupComponent]::Linux_IL2CPP = , (Join-Path -Path "$playbackEnginePath" -ChildPath "LinuxStandaloneSupport\Variations\linux64_headless_development_il2cpp" -Resolve); - [UnitySetupComponent]::Mac = , (Join-Path -Path "$playbackEnginePath" -ChildPath "MacStandaloneSupport" -Resolve); + [UnitySetupComponent]::Documentation = , (Join-Path "$Path" "Editor\Data\Documentation"); + [UnitySetupComponent]::StandardAssets = , (Join-Path "$Path" "Editor\Standard Assets"); + [UnitySetupComponent]::Windows_IL2CPP = , (Join-Path "$playbackEnginePath" "windowsstandalonesupport\Variations\win32_development_il2cpp"), + (Join-Path "$playbackEnginePath" "windowsstandalonesupport\Variations\win32_player_development_il2cpp"); + [UnitySetupComponent]::UWP = (Join-Path "$playbackEnginePath" "MetroSupport\Templates\UWP_.NET_D3D"), + (Join-Path "$playbackEnginePath" "MetroSupport\Templates\UWP_D3D"); + [UnitySetupComponent]::UWP_IL2CPP = , (Join-Path "$playbackEnginePath" "MetroSupport\Templates\UWP_IL2CPP_D3D"); + [UnitySetupComponent]::Linux = , (Join-Path "$playbackEnginePath" "LinuxStandaloneSupport\Variations\linux64_headless_development_mono"); + [UnitySetupComponent]::Linux_IL2CPP = , (Join-Path "$playbackEnginePath" "LinuxStandaloneSupport\Variations\linux64_headless_development_il2cpp"); + [UnitySetupComponent]::Mac = , (Join-Path "$playbackEnginePath" "MacStandaloneSupport"); } } ([OperatingSystem]::Linux) { $this.Components = [UnitySetupComponent]::Linux - $playbackEnginePath = Join-Path -Path "$Path" -ChildPath "Editor/Data/PlaybackEngines" -Resolve; + $playbackEnginePath = Join-Path "$Path" "Editor/Data/PlaybackEngines"; @{ - [UnitySetupComponent]::Documentation = , (Join-Path -Path "$Path" -ChildPath "Documentation" -Resolve); - [UnitySetupComponent]::StandardAssets = , (Join-Path -Path "$Path" -ChildPath "Standard Assets" -Resolve); - [UnitySetupComponent]::Mac = , (Join-Path -Path "$playbackEnginePath" -ChildPath "MacStandaloneSupport/Variations/macos_x64_player_development_mono" -Resolve); - [UnitySetupComponent]::Mac_IL2CPP = , (Join-Path -Path "$playbackEnginePath" -ChildPath "MacStandaloneSupport/Variations/macos_x64_player_development_il2cpp" -Resolve); - [UnitySetupComponent]::Windows = , (Join-Path -Path "$playbackEnginePath" -ChildPath "WindowsStandaloneSupport" -Resolve); - [UnitySetupComponent]::Linux_IL2CPP = , (Join-Path -Path "$playbackEnginePath" -ChildPath "LinuxStandaloneSupport/Variations/linux64_player_development_il2cpp" -Resolve); - [UnitySetupComponent]::Linux_Server = , (Join-Path -Path "$playbackEnginePath" -ChildPath "LinuxStandaloneSupport/Variations/linux64_server_development_mono" -Resolve); + [UnitySetupComponent]::Documentation = , (Join-Path "$Path" "Documentation"); + [UnitySetupComponent]::StandardAssets = , (Join-Path "$Path" "Standard Assets"); + [UnitySetupComponent]::Mac = , (Join-Path "$playbackEnginePath" "MacStandaloneSupport/Variations/macos_x64_player_development_mono"); + [UnitySetupComponent]::Mac_IL2CPP = , (Join-Path "$playbackEnginePath" "MacStandaloneSupport/Variations/macos_x64_player_development_il2cpp"); + [UnitySetupComponent]::Windows = , (Join-Path "$playbackEnginePath" "WindowsStandaloneSupport"); + [UnitySetupComponent]::Linux_IL2CPP = , (Join-Path "$playbackEnginePath" "LinuxStandaloneSupport/Variations/linux64_player_development_il2cpp"); + [UnitySetupComponent]::Linux_Server = , (Join-Path "$playbackEnginePath" "LinuxStandaloneSupport/Variations/linux64_server_development_mono"); } } ([OperatingSystem]::Mac) { $this.Components = [UnitySetupComponent]::Mac - $playbackEnginePath = Join-Path -Path "$Path" -ChildPath "PlaybackEngines" -Resolve; + $playbackEnginePath = Join-Path "$Path" "PlaybackEngines"; @{ - [UnitySetupComponent]::Documentation = , (Join-Path -Path "$Path" -ChildPath "Documentation" -Resolve); - [UnitySetupComponent]::StandardAssets = , (Join-Path -Path "$Path" -ChildPath "Standard Assets" -Resolve); - [UnitySetupComponent]::Mac_IL2CPP = , (Join-Path -Path "$playbackEnginePath" -ChildPath "MacStandaloneSupport/Variations/macosx64_development_il2cpp" -Resolve); - [UnitySetupComponent]::Windows = , (Join-Path -Path "$playbackEnginePath" -ChildPath "WindowsStandaloneSupport" -Resolve); - [UnitySetupComponent]::Linux = , (Join-Path -Path "$playbackEnginePath" -ChildPath "LinuxStandaloneSupport/Variations/linux64_headless_development_mono" -Resolve); - [UnitySetupComponent]::Linux_IL2CPP = , (Join-Path -Path "$playbackEnginePath" -ChildPath "LinuxStandaloneSupport/Variations/linux64_headless_development_il2cpp" -Resolve); + [UnitySetupComponent]::Documentation = , (Join-Path "$Path" "Documentation"); + [UnitySetupComponent]::StandardAssets = , (Join-Path "$Path" "Standard Assets"); + [UnitySetupComponent]::Mac_IL2CPP = , (Join-Path "$playbackEnginePath" "MacStandaloneSupport/Variations/macosx64_development_il2cpp"); + [UnitySetupComponent]::Windows = , (Join-Path "$playbackEnginePath" "WindowsStandaloneSupport"); + [UnitySetupComponent]::Linux = , (Join-Path "$playbackEnginePath" "LinuxStandaloneSupport/Variations/linux64_headless_development_mono"); + [UnitySetupComponent]::Linux_IL2CPP = , (Join-Path "$playbackEnginePath" "LinuxStandaloneSupport/Variations/linux64_headless_development_il2cpp"); } } } # Common playback engines: - $componentTests[[UnitySetupComponent]::Lumin] = , (Join-Path -Path "$playbackEnginePath" -ChildPath "LuminSupport" -Resolve); - $componentTests[[UnitySetupComponent]::Android] = , (Join-Path -Path "$playbackEnginePath" -ChildPath "AndroidPlayer" -Resolve); - $componentTests[[UnitySetupComponent]::iOS] = , (Join-Path -Path "$playbackEnginePath" -ChildPath "iOSSupport" -Resolve); - $componentTests[[UnitySetupComponent]::AppleTV] = , (Join-Path -Path "$playbackEnginePath" -ChildPath "AppleTVSupport" -Resolve); - $componentTests[[UnitySetupComponent]::Facebook] = , (Join-Path -Path "$playbackEnginePath" -ChildPath "Facebook" -Resolve); - $componentTests[[UnitySetupComponent]::Vuforia] = , (Join-Path -Path "$playbackEnginePath" -ChildPath "VuforiaSupport" -Resolve); - $componentTests[[UnitySetupComponent]::WebGL] = , (Join-Path -Path "$playbackEnginePath" -ChildPath "WebGLSupport" -Resolve); + $componentTests[[UnitySetupComponent]::Lumin] = , (Join-Path "$playbackEnginePath" "LuminSupport"); + $componentTests[[UnitySetupComponent]::Android] = , (Join-Path "$playbackEnginePath" "AndroidPlayer"); + $componentTests[[UnitySetupComponent]::iOS] = , (Join-Path "$playbackEnginePath" "iOSSupport"); + $componentTests[[UnitySetupComponent]::AppleTV] = , (Join-Path "$playbackEnginePath" "AppleTVSupport"); + $componentTests[[UnitySetupComponent]::Facebook] = , (Join-Path "$playbackEnginePath" "Facebook"); + $componentTests[[UnitySetupComponent]::Vuforia] = , (Join-Path "$playbackEnginePath" "VuforiaSupport"); + $componentTests[[UnitySetupComponent]::WebGL] = , (Join-Path "$playbackEnginePath" "WebGLSupport"); $componentTests.Keys | ForEach-Object { foreach ( $test in $componentTests[$_] ) { @@ -131,13 +131,13 @@ class UnityProjectInstance { [string]$ProductName UnityProjectInstance([string]$path) { - $versionFile = Join-Path -Path $path -ChildPath "ProjectSettings\ProjectVersion.txt" -Resolve + $versionFile = Join-Path $path "ProjectSettings\ProjectVersion.txt" 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" } - $projectSettingsFile = Join-Path -Path $path -ChildPath "ProjectSettings\ProjectSettings.asset" -Resolve + $projectSettingsFile = Join-Path $path "ProjectSettings\ProjectSettings.asset" if (!(Test-Path $projectSettingsFile)) { throw "Project is missing ProjectSettings.asset" } try { @@ -390,7 +390,7 @@ function Find-UnitySetupInstaller { [string] $Hash = "", [parameter(Mandatory = $false)] - [string] $Cache = (Join-Path -Path "~" -ChildPath ".unitysetup" -Resolve) + [string] $Cache = (Join-Path "~" ".unitysetup") ) # Note that this has to happen before calculating the full path since @@ -819,7 +819,7 @@ function Request-UnitySetupInstaller { [UnitySetupInstaller[]] $Installers, [parameter(Mandatory = $false)] - [string] $Cache = (Join-Path -Path "~" -ChildPath ".unitysetup" -Resolve) + [string] $Cache = (Join-Path "~" ".unitysetup") ) begin { # Note that this has to happen before calculating the full path since @@ -850,7 +850,7 @@ function Request-UnitySetupInstaller { $allInstallers | ForEach-Object { $installerFileName = [io.Path]::GetFileName($_.DownloadUrl) - $destination = Join-Path -Path $fullCachePath, "Installers", "Unity-$($_.Version)" -ChildPath "$installerFileName" -Resolve + $destination = Join-Path $fullCachePath, "Installers", "Unity-$($_.Version)" -ChildPath "$installerFileName" # Already downloaded? if ( Test-Path $destination ) { @@ -1125,7 +1125,7 @@ function Install-UnitySetupInstance { [string] $Destination, [parameter(Mandatory = $false)] - [string] $Cache = (Join-Path -Path "~" -ChildPath ".unitysetup" -Resolve) + [string] $Cache = (Join-Path "~" ".unitysetup") ) begin { $currentOS = Get-OperatingSystem @@ -1166,16 +1166,16 @@ function Install-UnitySetupInstance { $installPath = $Destination } else { - $installPath = Join-Path -Path $BasePath -ChildPath $Destination -Resolve + $installPath = Join-Path $BasePath $Destination } } else { - $installPath = Join-Path -Path $defaultInstallPath -ChildPath $installVersion -Resolve + $installPath = Join-Path $defaultInstallPath $installVersion } if ($currentOS -eq [OperatingSystem]::Mac) { $volumeRoot = "/Volumes/UnitySetup/" - $volumeInstallPath = Join-Path -Path $volumeRoot -ChildPath "Applications/Unity/" -Resolve + $volumeInstallPath = Join-Path $volumeRoot "Applications/Unity/" # Make sure the install path ends with a trailing slash. This # is required in some commands to treat as directory. @@ -1190,7 +1190,7 @@ function Install-UnitySetupInstance { } # Creating sparse bundle to host installing Unity in other locations - $unitySetupBundlePath = Join-Path -Path $Cache -ChildPath "UnitySetup.sparsebundle" -Resolve + $unitySetupBundlePath = Join-Path $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 @@ -1201,7 +1201,7 @@ function Install-UnitySetupInstance { # Previous version failed to remove. Cleaning up! if (Test-Path $volumeInstallPath) { Write-Verbose "Previous install did not clean up properly. Doing that now." - & sudo rm -Rf (Join-Path -Path $volumeRoot -ChildPath '*' -Resolve) + & sudo rm -Rf (Join-Path $volumeRoot '*') } # Copy installed version back to the sparse bundle disk for Unity component installs. @@ -1267,7 +1267,7 @@ function Install-UnitySetupInstance { Write-Verbose "Freeing sparse bundle disk space and unmounting." # Ensure the drive is cleaned up. - & sudo rm -Rf (Join-Path -Path $volumeRoot -ChildPath '*' -Resolve) + & sudo rm -Rf (Join-Path $volumeRoot '*') & hdiutil eject $volumeRoot # Free up disk space since deleting items in the volume send them to the trash @@ -1571,7 +1571,7 @@ function Get-UnityProjectInstance { Get-ChildItem @args | ForEach-Object { - $path = Join-Path -Path $_.FullName -ChildPath "ProjectVersion.txt" -Resolve + $path = Join-Path $_.FullName "ProjectVersion.txt" if ( Test-Path $path ) { [UnityProjectInstance]::new((Join-Path $_.FullName "..\" | Convert-Path)) }