forked from XistGG/UnrealXistTools
-
Notifications
You must be signed in to change notification settings - Fork 1
/
UProjectClean.ps1
111 lines (89 loc) · 3.12 KB
/
UProjectClean.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
#
# UnrealProjectClean.ps1
#
# See: https://github.com/XistGG/UnrealXistTools/
#
# Clean an Unreal Project
#
# - Remove Binaries dirs
# - Remove Intermediate dirs
# - Remove DerivedDataCache dirs (only if -DDC switch)
# - Remove .idea directories (only if -Idea switch)
# - Remove *.sln files from the project root
# - Generate Project Files
#
[CmdletBinding()]
param(
[switch]$DryRun,
[switch]$Idea,
[switch]$DDC,
[Parameter()]$Path
)
# Determine which UProjectFile we will clean
$UProjectFile = & $PSScriptRoot\UProjectFile.ps1 -Path:$Path
if (!$UProjectFile)
{
throw "No UProjectFile selected for clean"
}
################################################################################
### Find Binaries + Intermediate + other temporary files
################################################################################
Write-Host "Scanning files & directories..."
# All directories at any depth named 'Binaries' or 'Intermediate'
# Include DerivedDataCache directories only if you set -DDC parameter
#
$TempDirs = Get-ChildItem -Path $UProjectFile.Directory -Directory -Recurse `
| Where-Object { `
($_.Name -ieq 'Binaries') `
-or ($_.Name -ieq 'Intermediate') `
-or (($_.Name -ieq 'DerivedDataCache') -and $DDC) `
-or (($_.Name -ieq '.idea') -and $Idea) `
}
# *.sln files in the root folder
$TempFiles = Get-ChildItem -Path $UProjectFile.Directory -File `
| Where-Object {$_.Extension -ieq '.sln'}
Write-Host ""
################################################################################
### DELETE Binaries + Intermediate + other temporary files
################################################################################
# If there is stuff to delete, then delete it
if (($TempDirs.count + $TempFiles.count) -gt 0)
{
Write-Host "Deleting generated data..."
foreach ($TempDir in $TempDirs)
{
# If the temp dir still exists, delete it
# (handles nested paths that were previously deleted this run)
if (Test-Path -Path $TempDir.FullName)
{
Write-Host "[-] $TempDir"
if (!$DryRun)
{
Remove-Item -Force -Recurse -Path $TempDir.FullName
}
}
}
foreach ($TempFile in $TempFiles)
{
# If the temp file still exists, delete it
# (handles nested paths that were previously deleted this run)
if (Test-Path -Path $TempFile.FullName)
{
Write-Host "[-] $TempFile"
if (!$DryRun)
{
Remove-Item -Force -Path $TempFile.FullName
}
}
}
Write-Host ""
}
################################################################################
### Generate Project Files
################################################################################
if ($DryRun)
{
Write-Warning "Exiting without generating project files due to -DryRun"
exit 151
}
. $PSScriptRoot\UnrealVersionSelector.ps1 -ProjectFiles $UProjectFile.FullName