Repository navigation
Expand file tree
/
Copy pathbuild-loop.ps1
More file actions
131 lines (102 loc) · 3.76 KB
/
Copy pathbuild-loop.ps1
File metadata and controls
131 lines (102 loc) · 3.76 KB
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
$Project = "F:\GameDev\ADA\ADA.uproject"
$Engine = "F:\GameDev\UE_AngelScript\Engine"
$BuildBat = Join-Path $Engine "Build\BatchFiles\Build.bat"
$Editor = Join-Path $Engine "Binaries\Win64\UnrealEditor.exe"
$CloseTimeoutSeconds = 60
$ForceKillAfterTimeout = $true
function Get-ProjectEditorProcesses {
$escapedProject = [regex]::Escape($Project)
Get-CimInstance Win32_Process |
Where-Object {
$_.Name -eq "UnrealEditor.exe" -and
$_.CommandLine -match $escapedProject
} |
ForEach-Object {
Get-Process -Id $_.ProcessId -ErrorAction SilentlyContinue
}
}
function Close-ProjectEditor {
Write-Host "`nClosing Unreal Editor for this project gracefully..." -ForegroundColor Cyan
$procs = @(Get-ProjectEditorProcesses)
if ($procs.Count -eq 0) {
Write-Host "No matching Unreal Editor process found." -ForegroundColor DarkGray
return
}
foreach ($proc in $procs) {
Write-Host "Requesting close for UnrealEditor.exe PID $($proc.Id)..."
if ($proc.MainWindowHandle -ne 0) {
$null = $proc.CloseMainWindow()
}
else {
Write-Host "PID $($proc.Id) has no main window handle." -ForegroundColor Yellow
}
}
$deadline = (Get-Date).AddSeconds($CloseTimeoutSeconds)
while ((Get-Date) -lt $deadline) {
$stillRunning = @(Get-ProjectEditorProcesses)
if ($stillRunning.Count -eq 0) {
Write-Host "Unreal Editor closed cleanly." -ForegroundColor Green
Start-Sleep -Seconds 2
return
}
Write-Host "Waiting for Unreal Editor to exit cleanly... $($stillRunning.Count) process(es) still running."
Start-Sleep -Seconds 3
}
$stillRunning = @(Get-ProjectEditorProcesses)
if ($stillRunning.Count -eq 0) {
Write-Host "Unreal Editor closed cleanly." -ForegroundColor Green
Start-Sleep -Seconds 2
return
}
Write-Host "Unreal Editor did not close within $CloseTimeoutSeconds seconds." -ForegroundColor Yellow
if ($ForceKillAfterTimeout) {
foreach ($proc in $stillRunning) {
Write-Host "Force killing stuck UnrealEditor.exe PID $($proc.Id)..." -ForegroundColor Red
Stop-Process -Id $proc.Id -Force -ErrorAction SilentlyContinue
}
Start-Sleep -Seconds 2
}
else {
Write-Host "Force kill disabled. Close Unreal manually, then press Enter." -ForegroundColor Yellow
Read-Host
}
}
function Build-Project {
Write-Host "`nBuilding ADAEditor..." -ForegroundColor Cyan
$Args = @(
"ADAEditor",
"Win64",
"Development",
"-Project=`"$Project`"",
"-WaitMutex"
)
$Proc = Start-Process `
-FilePath $BuildBat `
-ArgumentList $Args `
-Wait `
-PassThru `
-NoNewWindow
return $Proc.ExitCode
}
function Start-ProjectEditor {
Write-Host "`nBuild succeeded. Starting project..." -ForegroundColor Green
Start-Process `
-FilePath $Editor `
-ArgumentList "`"$Project`""
}
while ($true) {
while ($true) {
Close-ProjectEditor
$ExitCode = Build-Project
if ($ExitCode -eq 0) {
Start-ProjectEditor
break
}
Write-Host "`nBuild failed with exit code $ExitCode." -ForegroundColor Red
Write-Host "Fix code, then press Enter to build again." -ForegroundColor Yellow
Read-Host
}
Write-Host "`nEditor started." -ForegroundColor Green
Write-Host "Press Enter to close editor gracefully and build again, or Ctrl+C to exit." -ForegroundColor Yellow
Read-Host
}