Skip to content

Release/2.2 #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Feb 15, 2018
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
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
This PowerShell module contains tools for managing and automating your Unity installs and projects.

## Builds
[![Build status](https://ci.appveyor.com/api/projects/status/m7ykg9s8gw23fn6h?svg=true)](https://ci.appveyor.com/project/jwittner/unitysetup-powershell)

### Master
[![Build status](https://ci.appveyor.com/api/projects/status/m7ykg9s8gw23fn6h/branch/master?svg=true)](https://ci.appveyor.com/project/jwittner/unitysetup-powershell/branch/master)

The `master` branch is automatically built and deployed to the [PowerShell Gallery](https://www.powershellgallery.com/packages/UnitySetup).

### Develop
[![Build status](https://ci.appveyor.com/api/projects/status/m7ykg9s8gw23fn6h/branch/develop?svg=true)](https://ci.appveyor.com/project/jwittner/unitysetup-powershell/branch/develop)

The `develop` branch is automatically built and deployed as a prerelease module to the [PowerShell Gallery](https://www.powershellgallery.com/packages/UnitySetup).

## Installation

Expand Down
3 changes: 2 additions & 1 deletion UnitySetup/UnitySetup.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
RootModule = 'UnitySetup'

# Version number of this module.
ModuleVersion = '2.1'
ModuleVersion = '2.2'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down Expand Up @@ -79,6 +79,7 @@ FunctionsToExport = @(
'Get-UnitySetupInstance',
'Install-UnitySetupInstance',
'Select-UnitySetupInstance',
'Uninstall-UnitySetupInstance',
'Start-UnityEditor'
)
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
Expand Down
84 changes: 75 additions & 9 deletions UnitySetup/UnitySetup.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class UnityProjectInstance
}
}

class UnityVersion
class UnityVersion : System.IComparable
{
[int] $Major;
[int] $Minor;
Expand Down Expand Up @@ -100,6 +100,14 @@ class UnityVersion
}
}

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

return [UnityVersion]::Compare($this, $obj)
}

static [int] Compare([UnityVersion]$a, [UnityVersion]$b)
{
if($a.Major -lt $b.Major) { return -1 }
Expand Down Expand Up @@ -182,10 +190,15 @@ function Find-UnitySetupInstaller
'f' { $searchPages += "https://unity3d.com/get-unity/download/archive" }
'b' { $searchPages += "https://unity3d.com/unity/beta/unity$Version" }
'p' {
$webResult = Invoke-WebRequest "https://unity3d.com/unity/qa/patch-releases?version=$($Version.Major).$($Version.Minor)"
$searchPages += $webResult.Links | Where-Object { $_.href -match "\/unity\/qa\/patch-releases\?version=$($Version.Major)\.$($Version.Minor)&page=(\d+)" } | ForEach-Object {
"https://unity3d.com/unity/qa/patch-releases?version=$($Version.Major).$($Version.Minor)&page=$($Matches[1])"
}
$patchPage = "https://unity3d.com/unity/qa/patch-releases?version=$($Version.Major).$($Version.Minor)"
$searchPages += $patchPage

$webResult = Invoke-WebRequest $patchPage
$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/unity/qa/patch-releases?version=$($Version.Major).$($Version.Minor)&page=$($Matches[1])"
}
}
}

Expand All @@ -196,7 +209,7 @@ function Find-UnitySetupInstaller
$_ -match "$($installerTemplates[[UnitySetupComponentType]::Setup])$"
}

if($null -eq $prototypeLink) { break }
if($null -ne $prototypeLink) { break }
}

if($null -eq $prototypeLink)
Expand Down Expand Up @@ -357,6 +370,51 @@ function Install-UnitySetupInstance
}
}

<#
.Synopsis
Uninstall Unity Setup Instances
.DESCRIPTION
Uninstall the specified Unity Setup Instances
.PARAMETER Instance
What instances of UnitySetup should be uninstalled
.EXAMPLE
Get-UnitySetupInstance | Uninstall-UnitySetupInstance
#>
function Uninstall-UnitySetupInstance {
[CmdletBinding(SupportsShouldProcess)]
param(
[parameter(Mandatory = $true, ValueFromPipeline = $true)]
[UnitySetupInstance[]] $Instances
)

process {
foreach ( $setupInstance in $Instances ) {
$uninstaller = Get-ChildItem "$($setupInstance.Path)" -Filter 'Uninstall.exe' -Recurse |
Select-Object -First 1 -ExpandProperty FullName

if($null -eq $uninstaller) {
Write-Error "Could not find Uninstaller.exe under $($setupInstance.Path)"
continue
}

$startProcessArgs = @{
'FilePath' = $uninstaller;
'PassThru' = $true;
'Wait' = $true;
'ErrorAction' = 'Stop';
'ArgumentList' = @("/S");
}

if( -not $PSCmdlet.ShouldProcess("$uninstaller", "Start-Process")) { continue }

$process = Start-Process @startProcessArgs
if ( $process.ExitCode -ne 0 ) {
Write-Error "Uninstaller quit with non-zero exit code"
}
}
}
}

<#
.Synopsis
Get the Unity versions installed
Expand Down Expand Up @@ -554,6 +612,10 @@ function Start-UnityEditor
[parameter(Mandatory=$false)]
[string]$ExecuteMethod,
[parameter(Mandatory=$false)]
[string[]]$ExportPackage,
[parameter(Mandatory=$false)]
[string]$CreateProject,
[parameter(Mandatory=$false)]
[string]$OutputPath,
[parameter(Mandatory=$false)]
[string]$LogFile,
Expand Down Expand Up @@ -640,12 +702,14 @@ function Start-UnityEditor
}

$sharedArgs = @()
if( $CreateProject ) { $sharedArgs += "-createProject", $CreateProject }
if( $ExecuteMethod ) { $sharedArgs += "-executeMethod", $ExecuteMethod }
if( $OutputPath ) { $sharedArgs += "-buildOutput", $OutputPath }
if( $LogFile ) { $sharedArgs += "-logFile", $LogFile }
if( $BuildTarget ) { $sharedArgs += "-buildTarget", $BuildTarget }
if( $BatchMode ) { $sharedArgs += "-batchmode" }
if( $Quit ) { $sharedArgs += "-quit" }
if( $ExportPackage ) { $sharedArgs += "-exportPackage","$ExportPackage" }

$instanceArgs = @()
foreach( $p in $projectInstances ) {
Expand Down Expand Up @@ -689,7 +753,9 @@ function Start-UnityEditor
continue
}

$unityArgs = $sharedArgs + $instanceArgs[$i]
# clone the shared args list
$unityArgs = $sharedArgs | ForEach-Object { $_ }
if( $instanceArgs[$i] ) { $unityArgs += $instanceArgs[$i] }
$setProcessArgs = @{
'FilePath' = $editor;
'PassThru' = $true;
Expand All @@ -711,9 +777,9 @@ function Start-UnityEditor
$process.WaitForExit();
if( $process.ExitCode -ne 0 )
{
if( $LogFile )
if( $LogFile -and (Test-Path $LogFile -Type Leaf) )
{
Get-Content $LogFile | Write-Information
Get-Content $LogFile | ForEach-Object { Write-Information -MessageData $_ -Tags 'Logs' }
}

Write-Error "Unity quit with non-zero exit code"
Expand Down
9 changes: 4 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
version: '{build}'
pull_requests:
do_not_increment_build_number: true
branches:
only:
- master
- develop
environment:
NugetAPIKey:
secure: zvkaZiaBXVko+3ZzuSb7W6DTUJmHX98XgEhKs28SnGD+4TM3gzhPxVnNWSmBhXEx
Expand Down Expand Up @@ -37,4 +33,7 @@ for:
- master
build_script:
- ps: .\build.ps1 -Revision "$env:APPVEYOR_BUILD_NUMBER"

-
branches:
only:
- develop