-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathue-cleanup.ps1
138 lines (117 loc) · 5.02 KB
/
ue-cleanup.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
[CmdletBinding()] # Fail on unknown args
param (
[string]$src,
[switch]$nocloseeditor = $false,
[switch]$dryrun = $false,
[switch]$help = $false
)
function Print-Usage {
Write-Output "Steve's Unreal Project Cleanup Tool"
Write-Output " Clean up hot-reload DLLs & prune LFS to free space. Will close Unreal editor!"
Write-Output "Usage:"
Write-Output " ue-cleanup.ps1 [[-src:]sourcefolder] [Options]"
Write-Output " "
Write-Output " -src : Source folder (current folder if omitted)"
Write-Output " : (should be root of project)"
Write-Output " -nocloseeditor : Don't close Unreal editor (this will prevent DLL cleanup)"
Write-Output " -lfsprune : Call 'git lfs prune' to delete old LFS files as well"
Write-Output " -dryrun : Don't perform any actual actions, just report on what you would do"
Write-Output " -help : Print this help"
Write-Output " "
}
function Cleanup-DLLs($cleanupdir, $projname, $dryrun) {
if ($dryrun) {
Write-Output "Would clean up temporary DLLs/PDBs in $cleanupdir for $projname"
} else {
Write-Output "Cleaning up temporary DLLs/PDBs in $cleanupdir for $projname"
}
# Hot Reload files - UE4
$cleanupfiles = @(Get-ChildItem "$cleanupdir\UE4Editor-$projname-????.dll" | Select-Object -Expand Name)
$cleanupfiles += @(Get-ChildItem "$cleanupdir\UE4Editor-$projname-????.pdb" | Select-Object -Expand Name)
# Live Coding files - UE4
$cleanupfiles += @(Get-ChildItem "$cleanupdir\UE4Editor-$projname.exe.patch_*" | Select-Object -Expand Name)
$cleanupfiles += @(Get-ChildItem "$cleanupdir\UE4Editor-$projname.pdb.patch_*" | Select-Object -Expand Name)
# Hot Reload files - UE5
$cleanupfiles = @(Get-ChildItem "$cleanupdir\UnrealEditor-$projname-????.dll" | Select-Object -Expand Name)
$cleanupfiles += @(Get-ChildItem "$cleanupdir\UnrealEditor-$projname-????.pdb" | Select-Object -Expand Name)
# Live Coding files - UE5
$cleanupfiles += @(Get-ChildItem "$cleanupdir\UnrealEditor-$projname.exe.patch_*" | Select-Object -Expand Name)
$cleanupfiles += @(Get-ChildItem "$cleanupdir\UnrealEditor-$projname.pdb.patch_*" | Select-Object -Expand Name)
foreach ($cf in $cleanupfiles) {
if ($dryrun) {
Write-Output "Would have deleted $cleanupdir\$cf"
} else {
Write-Verbose "Deleting $cleanupdir\$cf"
Remove-Item "$cleanupdir\$cf" -Force
}
}
}
. $PSScriptRoot\inc\ueeditor.ps1
$ErrorActionPreference = "Stop"
if ($help) {
Print-Usage
Exit 0
}
$result = 0
try {
if ($src -ne ".") { Push-Location $src }
# Locate UE project file
$uprojfile = Get-ChildItem *.uproject | Select-Object -expand Name
if (-not $uprojfile) {
throw "No Unreal project file found in $(Get-Location)! Aborting."
}
if ($uprojfile -is [array]) {
throw "Multiple Unreal project files found in $(Get-Location)! Aborting."
}
# In PS 6.0+ we could use Split-Path -LeafBase but let's stick with built-in PS 5.1
$uprojname = [System.IO.Path]::GetFileNameWithoutExtension($uprojfile)
if ($dryrun) {
Write-Output "Would clean up $uprojname"
} else {
Write-Output "Cleaning up $uprojname"
}
# Close UE as early as possible
if (-not $nocloseeditor) {
# Check if UE is running, if so try to shut it gracefully
Close-UE-Editor $uprojname $dryrun
# Find all the modules in the project
$ujson = Get-Content $uprojfile | ConvertFrom-Json
foreach ($module in $ujson.Modules) {
# Because we know editor is closed, Hot Reload DLLs are OK to clean up
Cleanup-DLLs ".\Binaries\Win64" $module.Name $dryrun
}
# Also clean up SOURCE plugins, since they will be rebuilt
# This is not the same list as $ujson.Plugins, those are the binary ones
$plugins = Get-ChildItem -Path .\Plugins -Filter *.uplugin -Recurse -ErrorAction SilentlyContinue -Force
foreach ($pluginfile in $plugins) {
$pluginname = [System.IO.Path]::GetFileNameWithoutExtension($pluginfile.FullName)
if ($dryrun) {
Write-Output "Would clean up plugin $pluginname"
} else {
Write-Output "Cleaning up plugin $pluginname"
}
$pluginroot = Resolve-Path $pluginfile.DirectoryName -Relative
$pluginbinaries = Join-Path $pluginroot "Binaries\Win64"
Cleanup-DLLs $pluginbinaries $pluginname $dryrun
}
}
$isGit = Test-Path .git
if ($isGit) {
if ($lfsprune) {
if ($dryrun) {
Write-Output "Would have pruned LFS files"
git lfs prune --dry-run
} else {
Write-Output "Pruning Git LFS files"
git lfs prune
}
}
}
Write-Output "-- Cleanup finished OK --"
} catch {
Write-Output "ERROR: $($_.Exception.Message)"
$result = 9
} finally {
if ($src -ne ".") { Pop-Location }
}
Exit $result