@@ -69,7 +69,7 @@ class UnityProjectInstance
6969 }
7070}
7171
72- class UnityVersion
72+ class UnityVersion : System.IComparable
7373{
7474 [int ] $Major ;
7575 [int ] $Minor ;
@@ -100,6 +100,14 @@ class UnityVersion
100100 }
101101 }
102102
103+ [int ] CompareTo([object ]$obj )
104+ {
105+ if ($null -eq $obj ) { return 1 }
106+ if ($obj -isnot [UnityVersion ]) { throw " Object is not a UnityVersion" }
107+
108+ return [UnityVersion ]::Compare($this , $obj )
109+ }
110+
103111 static [int ] Compare([UnityVersion ]$a , [UnityVersion ]$b )
104112 {
105113 if ($a.Major -lt $b.Major ) { return -1 }
@@ -182,10 +190,15 @@ function Find-UnitySetupInstaller
182190 ' f' { $searchPages += " https://unity3d.com/get-unity/download/archive" }
183191 ' b' { $searchPages += " https://unity3d.com/unity/beta/unity$Version " }
184192 ' p' {
185- $webResult = Invoke-WebRequest " https://unity3d.com/unity/qa/patch-releases?version=$ ( $Version.Major ) .$ ( $Version.Minor ) "
186- $searchPages += $webResult.Links | Where-Object { $_.href -match " \/unity\/qa\/patch-releases\?version=$ ( $Version.Major ) \.$ ( $Version.Minor ) &page=(\d+)" } | ForEach-Object {
187- " https://unity3d.com/unity/qa/patch-releases?version=$ ( $Version.Major ) .$ ( $Version.Minor ) &page=$ ( $Matches [1 ]) "
188- }
193+ $patchPage = " https://unity3d.com/unity/qa/patch-releases?version=$ ( $Version.Major ) .$ ( $Version.Minor ) "
194+ $searchPages += $patchPage
195+
196+ $webResult = Invoke-WebRequest $patchPage
197+ $searchPages += $webResult.Links | Where-Object {
198+ $_.href -match " \/unity\/qa\/patch-releases\?version=$ ( $Version.Major ) \.$ ( $Version.Minor ) &page=(\d+)" -and $Matches [1 ] -gt 1
199+ } | ForEach-Object {
200+ " https://unity3d.com/unity/qa/patch-releases?version=$ ( $Version.Major ) .$ ( $Version.Minor ) &page=$ ( $Matches [1 ]) "
201+ }
189202 }
190203 }
191204
@@ -196,7 +209,7 @@ function Find-UnitySetupInstaller
196209 $_ -match " $ ( $installerTemplates [[UnitySetupComponentType ]::Setup ]) $"
197210 }
198211
199- if ($null -eq $prototypeLink ) { break }
212+ if ($null -ne $prototypeLink ) { break }
200213 }
201214
202215 if ($null -eq $prototypeLink )
@@ -357,6 +370,51 @@ function Install-UnitySetupInstance
357370 }
358371}
359372
373+ <#
374+ . Synopsis
375+ Uninstall Unity Setup Instances
376+ . DESCRIPTION
377+ Uninstall the specified Unity Setup Instances
378+ . PARAMETER Instance
379+ What instances of UnitySetup should be uninstalled
380+ . EXAMPLE
381+ Get-UnitySetupInstance | Uninstall-UnitySetupInstance
382+ #>
383+ function Uninstall-UnitySetupInstance {
384+ [CmdletBinding (SupportsShouldProcess )]
385+ param (
386+ [parameter (Mandatory = $true , ValueFromPipeline = $true )]
387+ [UnitySetupInstance []] $Instances
388+ )
389+
390+ process {
391+ foreach ( $setupInstance in $Instances ) {
392+ $uninstaller = Get-ChildItem " $ ( $setupInstance.Path ) " - Filter ' Uninstall.exe' - Recurse |
393+ Select-Object - First 1 - ExpandProperty FullName
394+
395+ if ($null -eq $uninstaller ) {
396+ Write-Error " Could not find Uninstaller.exe under $ ( $setupInstance.Path ) "
397+ continue
398+ }
399+
400+ $startProcessArgs = @ {
401+ ' FilePath' = $uninstaller ;
402+ ' PassThru' = $true ;
403+ ' Wait' = $true ;
404+ ' ErrorAction' = ' Stop' ;
405+ ' ArgumentList' = @ (" /S" );
406+ }
407+
408+ if ( -not $PSCmdlet.ShouldProcess (" $uninstaller " , " Start-Process" )) { continue }
409+
410+ $process = Start-Process @startProcessArgs
411+ if ( $process.ExitCode -ne 0 ) {
412+ Write-Error " Uninstaller quit with non-zero exit code"
413+ }
414+ }
415+ }
416+ }
417+
360418<#
361419. Synopsis
362420 Get the Unity versions installed
@@ -554,6 +612,10 @@ function Start-UnityEditor
554612 [parameter (Mandatory = $false )]
555613 [string ]$ExecuteMethod ,
556614 [parameter (Mandatory = $false )]
615+ [string []]$ExportPackage ,
616+ [parameter (Mandatory = $false )]
617+ [string ]$CreateProject ,
618+ [parameter (Mandatory = $false )]
557619 [string ]$OutputPath ,
558620 [parameter (Mandatory = $false )]
559621 [string ]$LogFile ,
@@ -640,12 +702,14 @@ function Start-UnityEditor
640702 }
641703
642704 $sharedArgs = @ ()
705+ if ( $CreateProject ) { $sharedArgs += " -createProject" , $CreateProject }
643706 if ( $ExecuteMethod ) { $sharedArgs += " -executeMethod" , $ExecuteMethod }
644707 if ( $OutputPath ) { $sharedArgs += " -buildOutput" , $OutputPath }
645708 if ( $LogFile ) { $sharedArgs += " -logFile" , $LogFile }
646709 if ( $BuildTarget ) { $sharedArgs += " -buildTarget" , $BuildTarget }
647710 if ( $BatchMode ) { $sharedArgs += " -batchmode" }
648711 if ( $Quit ) { $sharedArgs += " -quit" }
712+ if ( $ExportPackage ) { $sharedArgs += " -exportPackage" , " $ExportPackage " }
649713
650714 $instanceArgs = @ ()
651715 foreach ( $p in $projectInstances ) {
@@ -689,7 +753,9 @@ function Start-UnityEditor
689753 continue
690754 }
691755
692- $unityArgs = $sharedArgs + $instanceArgs [$i ]
756+ # clone the shared args list
757+ $unityArgs = $sharedArgs | ForEach-Object { $_ }
758+ if ( $instanceArgs [$i ] ) { $unityArgs += $instanceArgs [$i ] }
693759 $setProcessArgs = @ {
694760 ' FilePath' = $editor ;
695761 ' PassThru' = $true ;
@@ -711,9 +777,9 @@ function Start-UnityEditor
711777 $process.WaitForExit ();
712778 if ( $process.ExitCode -ne 0 )
713779 {
714- if ( $LogFile )
780+ if ( $LogFile -and ( Test-Path $LogFile - Type Leaf) )
715781 {
716- Get-Content $LogFile | Write-Information
782+ Get-Content $LogFile | ForEach-Object { Write-Information - MessageData $_ - Tags ' Logs ' }
717783 }
718784
719785 Write-Error " Unity quit with non-zero exit code"
0 commit comments