22# Licensed under the MIT License.
33Import-Module powershell- yaml - Force - ErrorAction Stop
44
5+ [Flags ()]
6+ enum UnitySetupComponentType
7+ {
8+ Setup = (1 -shl 0 )
9+ Documentation = (1 -shl 1 )
10+ StandardAssets = (1 -shl 2 )
11+ ExampleProject = (1 -shl 3 )
12+ Metro = (1 -shl 4 )
13+ UWP_IL2CPP = (1 -shl 5 )
14+ Android = (1 -shl 6 )
15+ iOS = (1 -shl 7 )
16+ AppleTV = (1 -shl 8 )
17+ Facebook = (1 -shl 9 )
18+ Linux = (1 -shl 10 )
19+ Mac = (1 -shl 11 )
20+ Vuforia = (1 -shl 12 )
21+ WebGL = (1 -shl 13 )
22+ Windows_IL2CPP = (1 -shl 14 )
23+ All = (-1 )
24+ }
25+
526class UnitySetupInstaller
627{
728 [UnitySetupComponentType ] $ComponentType
@@ -228,6 +249,7 @@ function Find-UnitySetupInstaller
228249function Install-UnitySetupInstance
229250{
230251 [CmdletBinding ()]
252+ [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute (' PSAvoidUsingWriteHost' , ' ' , Scope= ' Function' )]
231253 param (
232254 [parameter (ValueFromPipeline = $true )]
233255 [UnitySetupInstaller []] $Installers ,
@@ -236,7 +258,11 @@ function Install-UnitySetupInstance
236258 [string ]$Destination ,
237259
238260 [parameter (Mandatory = $false )]
239- [string ]$Cache = [io.Path ]::Combine($env: USERPROFILE , " .unitysetup" )
261+ [string ]$Cache = [io.Path ]::Combine($env: USERPROFILE , " .unitysetup" ),
262+
263+ [parameter (Mandatory = $false )]
264+ [ValidateSet (' Open' , ' RunAs' )]
265+ [string ]$Verb
240266 )
241267
242268 process
@@ -299,10 +325,19 @@ function Install-UnitySetupInstance
299325 $installer = $localInstallers [$i ]
300326 $destination = $localDestinations [$i ]
301327
302- $args = @ (" /S" , " /D=$ ( $localDestinations [$i ]) " )
328+ $startProcessArgs = @ {
329+ ' FilePath' = $installer ;
330+ ' ArgumentList' = @ (" /S" , " /D=$ ( $localDestinations [$i ]) " );
331+ ' PassThru' = $true ;
332+ }
333+
334+ if ($Verb )
335+ {
336+ $startProcessArgs [' Verb' ] = $Verb
337+ }
303338
304339 $spinnerIndex = 0
305- $process = Start-Process - FilePath $installer - ArgumentList $args - PassThru
340+ $process = Start-Process @startProcessArgs
306341 while (! $process.HasExited )
307342 {
308343 Write-Host " `r Installing $installer to $destination - $ ( $spins [$spinnerIndex ++ % $spins.Length ]) " - NoNewline
@@ -496,7 +531,7 @@ function Get-UnityProjectInstance
496531#>
497532function Start-UnityEditor
498533{
499- [CmdletBinding (DefaultParameterSetName = " Context" )]
534+ [CmdletBinding (SupportsShouldProcess , DefaultParameterSetName = " Context" )]
500535 param (
501536 [parameter (Mandatory = $false , ValueFromPipeline = $true , ParameterSetName = ' Projects' )]
502537 [parameter (Mandatory = $true , ValueFromPipeline = $true , ParameterSetName = ' ProjectsLatest' )]
@@ -665,7 +700,11 @@ function Start-UnityEditor
665700 $setProcessArgs [' ArgumentList' ] = $unityArgs
666701 }
667702
668- Write-Verbose " Starting $editor $unityArgs "
703+ if (-not $PSCmdlet.ShouldProcess (" $editor $unityArgs " , " Start-Process" ))
704+ {
705+ continue
706+ }
707+
669708 $process = Start-Process @setProcessArgs
670709 if ( $Wait )
671710 {
0 commit comments