-
Notifications
You must be signed in to change notification settings - Fork 7
/
UEngine.ps1
executable file
·182 lines (142 loc) · 4.86 KB
/
UEngine.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/env pwsh
#
# UEngine.ps1
#
# UEngine.ps1 allows you to select an Engine Build based on the Registry.
# If you have only 1 custom engine, it uses that as the default. Otherwise
# you can select different engines based on their names.
#
# -List will show you the list of builds
# -NewName will allow you to rename the registry keys
# -Help for more info
#
# Epic's Registry Build List:
# HKEY_CURRENT_USER\Software\Epic Games\Unreal Engine\Builds
#
[CmdletBinding()]
param(
[Parameter()]$Name,
[Parameter()]$NewName,
[Parameter()]$UProject,
[switch]$Help,
[switch]$List,
[switch]$NoDefault,
[switch]$Start
)
# Make sure the powershell version is good, or throw an exception
& $PSScriptRoot/PSVersionCheck.ps1
# Import the UE helper module
Import-Module -Name $PSScriptRoot/Modules/UE.psm1
$BuildsRegistryKey = "HKEY_CURRENT_USER\Software\Epic Games\Unreal Engine\Builds"
# TODO this only works on Win64! Need to upgrade this for other dev platforms
$PlatformSpecificEditorPath = "Engine/Binaries/Win64/UnrealEditor.exe"
function Usage
{
$ScriptName = $MyInvocation.MyCommand.Name
Write-Host @"
############################################################
##
## Usage for ${ScriptName}:
##
& $ScriptName -Debug
Use the -Debug flag at any time to see more detailed debug info.
& $ScriptName -List
Return a list of currently registered engines as objects like:
{Name="foo", Root="C:\Root\"}
& $ScriptName Name
Return the Named engine, returns null if no such Name.
& $ScriptName Name -NewName MyEngine
Change the name of the "Name" engine to "MyEngine".
Return the build with the updated name.
Note that for random GUID names, you need to enclose it in quotes, like:
$ScriptName "{Random-GUID-here}" -NewName MyEngine
& $ScriptName -NoDefault
Explicitly disable use of a default Name.
Mainly useful for debugging.
"@
exit 1
}
if ($Help)
{
& Usage
}
################################################################################
## Main
################################################################################
# If they just want to see a list, show it
if ($List)
{
$BuildList =& UE_ListCustomEngines
if (!$BuildList.Count)
{
Write-Error ("There are no custom Unreal Engine Builds in the Registry. " +
"You need to run UnrealVersionSelector.exe in your Custom Engine Directory. " +
"Example: D:/UE_5.1/Engine/Binaries/Win64/UnrealVersionSelector-Win64-Shipping.exe")
}
return $BuildList
}
################################################################################
## Resolve Project
# If $UProject is set, resolve it
if ($UProject)
{
Write-Debug "Loading explicitly named UProject `"$UProject`""
$UProject =& $PSScriptRoot/UProject.ps1 -Path:$UProject
}
# If they didn't supply an explicit name, but they did supply a $UProject,
# then use the EngineAssociation from the $UProject
if (!$Name)
{
if (!$UProject)
{
try
{
# No $UProject was named, so load the default UProject
# We don't care about errors here, if there is no active project, that's fine
Write-Debug "Loading implicitly active UProject based on current directory"
$UProject =& $PSScriptRoot/UProject.ps1 2> $null
}
catch
{
$UProject = $null
Write-Debug "Not in an active UProject directory, cannot auto-select Engine by UProject"
}
}
if (!$UProject)
{
Write-Error "No -Name provided and no UProject found in the current directory `"$(Get-Location)`""
throw "Invalid Usage. See -Help for more info."
}
$Name = $UProject.EngineAssociation # Might be ""
Write-Debug "Loading Engine based on UProject `"$($UProject._UProjectFile)`" EngineAssociation `"$Name`""
$UEngine =& UE_GetEngineByAssociation -UProjectFile $UProject._UProjectFile -EngineAssociation $UProject.EngineAssociation
if ($UEngine)
{
# In case the UProject.EngineAssociation was "", get the real name of the UEngine we loaded
$Name = $UEngine.Name
}
}
else
{
Write-Debug "Loading Engine based on explicit name `"$Name`""
$UEngine =& UE_SelectCustomEngine -Name $Name
}
################################################################################
## Get/Set the current $UEngine
if ($UEngine)
{
Write-Debug "Selected UEngine: $($UEngine.Name) = $($UEngine.Root)"
# If they want to change the name, do so
if ($NewName)
{
Write-Debug "Renaming Engine `"$($UEngine.Name)`" to `"$NewName`""
# Try to change the name and reload the engine from the new name
$UEngine =& UE_RenameCustomEngine -OldName $UEngine.Name -NewName $NewName
}
}
elseif ($Name)
{
# User asked for a specific name that does not exist
Write-Error "No Such Engine Name: $Name"
}
return $UEngine