-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
131 lines (121 loc) · 3.31 KB
/
build.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
param ([string]$Argument)
[console]::BackgroundColor = 'Black'
Clear-Host
$root = "E:/Program Files/Steam/steamapps/common/GarrysMod"
$addons = "$root/garrysmod/addons"
$addons_test = "$addons/test"
$addons_private = "$addons/private"
$gmad = "$root/bin/win64/gmad.exe"
$build = "./.build"
############
# Function #
############
function Write-Message {
param(
[string]$Object,
[string]$Color = 'Green',
[string]$Header = 'INFO',
[switch]$NoNewline = $false
)
Write-Host -NoNewline -ForegroundColor $Color "$Header "
if ($NoNewline) {
Write-Host $Object -NoNewline
} else {
Write-Host $Object
}
}
function Show-Prompt {
Write-Host 'What do you want to build?'
Write-Host '[1] Dark Mode'
Write-Host '[2] Fix Map'
Write-Host '[3] Kill Feed'
Write-Host '[4] Lua Menu'
Write-Host '[5] Private Reserve'
Write-Host '[6] SC Resistance Turrets'
Write-Host '[7] SC Tools'
Write-Host '[8] SC Weapons'
$choice = Read-Host 'Choice'
switch ($choice.ToUpper()) {
"1" { return 'Dark Mode' }
"2" { return 'Fix Map' }
"3" { return 'Kill Feed' }
"4" { return 'Lua Menu' }
"5" { return 'Private Reserve' }
"6" { return 'SC Resistance Turrets' }
"7" { return 'SC Tools' }
"8" { return 'SC Weapons' }
default { return $null }
}
}
function Copy-Recursive {
param([string]$src, [string]$dst)
if (-Not (Test-Path -Path $src)) {
Write-Message "Source directory does not exist: $src" -Color Red -Header ERROR
return
}
if (-Not (Test-Path -Path $dst)) {
New-Item -Path $dst -ItemType Directory | Out-Null
}
Copy-Item -Recurse -Force -Path "$src\*" -Destination $dst | Out-Null
Write-Message "Copied contents of '$src' to '$dst'"
}
function New-GMA {
param([string]$dir, [string]$dst = $addons_test)
$lower = ($dir -replace '[\s\t]', '_').ToLower() -replace '[^a-z0-9_]', ''
if (-Not (Test-Path -Path $dst)) {
New-Item -Path $dst -ItemType Directory | Out-Null
}
if (-Not (Test-Path -Path $build)) {
New-Item -Path $build -ItemType Directory | Out-Null
}
$gmaName = "$build/$lower.gma"
$cmd = "create -folder `"$dir`" -out `"$gmaName`""
$proc = Start-Process -NoNewWindow -Wait -FilePath $gmad -ArgumentList $cmd -PassThru
if ($proc.ExitCode -eq 0) {
Copy-Item -Force -Path $gmaName -Destination $dst
Write-Message "Copied '$gmaName' to '$dst'"
} else {
Write-Message 'Failed to compile GMA' -Color Red -Header ERROR
}
}
########
# Body #
########
if (-Not (Test-Path -Path $root)) {
Write-Message 'GMod is not installed.' -Color Red -Header ERROR
[void][System.Console]::ReadKey($false)
exit 1
}
if ([string]::IsNullOrEmpty($Argument)) {
$target = Show-Prompt
} else {
$target = Resolve-Target $Argument
}
Write-Host "target: $target"
if ($null -eq $target) {
Write-Message 'Invalid choice or argument!' -Color Red -Header ERROR
[void][System.Console]::ReadKey($false)
exit 1
}
switch ($target) {
'Dark Mode' {
Copy-Recursive 'Dark Mode' "$addons/DarkMode"
}
'Fix Map' {
New-GMA 'Fix Map'
}
'Kill Feed' {
New-GMA 'Kill Feed' $addons_private
}
'Lua Menu' {
Copy-Recursive 'Lua Menu' "$root/garrysmod"
}
'Private Reserve' {
New-GMA 'Private Reserve' $addons_private
}
default {
New-GMA $target
}
}
Write-Host 'Press any key to continue...'
[void][System.Console]::ReadKey($false)