-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
275 lines (243 loc) · 8.58 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
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<#
.SYNOPSIS
Creates FOMOD installer and Generates BBCODE version of Readme
.DESCRIPTION
Creates FOMOD installer and Generates BBCODE version of Readme
.PARAMETER ConfigFile
The path to the buildConfig.json used to build this mod
.NOTES
Copyright 2021 Mark E. Kraus
#>
[CmdletBinding()]
param (
[Parameter(
Position=0,
ValueFromPipelineByPropertyName=$true)]
[ValidateNotNullOrEmpty()]
[string]
$ConfigFile =
$(
if (![string]::IsNullOrWhitespace($PSScriptRoot)) {
Join-Path $PSScriptRoot "buildConfig.json"
}
else {
Join-Path $pwd.Path "buildConfig.json"
}
)
)
$StartTime = [datetime]::UtcNow
Write-Host ("Build started {0} UTC" -f $StartTime)
Write-Host " "
$BasePath = Split-Path $ConfigFile
Push-Location $BasePath
$FomodBasePath = Join-Path $BasePath "fomod"
$FomodInfoFile = Join-Path $FomodBasePath "info.xml"
$FomodModuleConfigFile = Join-Path $FomodBasePath "ModuleConfig.xml"
$Config = Get-Content -Path $ConfigFile | ConvertFrom-Json -Depth 10
$ModInfo = $Config.ModInfo
if([string]::IsNullOrWhiteSpace($Config.'$schema')) {
Write-Error "config file is missing '`$schema'"
exit 1
}
$Schema = (Invoke-WebRequest $Config.'$schema').Content
$SchemaIsValid = Get-Content -Path $ConfigFile -Raw | Test-Json -Schema $Schema
if(!$SchemaIsValid) {
Write-Error "Invalid JSON Schema."
exit 1
}
$FuzExtractorPath = Join-Path $Config.UnfuzerPath "Fuz_extractor.exe"
$XWmaEncodePath = Join-Path $Config.UnfuzerPath "xWMAEncode.exe"
$XWmaEncodeCmd = Get-Command $XWmaEncodePath
$Plugin = $Config.Plugin
$PluginPath = Join-Path $BasePath $Plugin
$BsaName = $Plugin -replace '\.esp$', '.bsa'
$ZipName = $Plugin -replace '\.esp$', '.zip'
$VoiceBasePath = Join-Path $BasePath 'Sound' 'Voice',$Plugin
Write-Host @"
BasePath: $BasePath
FomodBasePath: $FomodBasePath
FomodInfoFile: $FomodInfoFile
FomodModuleConfigFile: $FomodModuleConfigFile
VoiceBasePath: $VoiceBasePath
FuzExtractorPath: $FuzExtractorPath
XWmaEncodePath: $XWmaEncodePath
PluginPath: $PluginPath
BsaName: $BsaName
ZipName: $ZipName
"@
if (Test-Path $ZipName) {
Write-Host "Deleting $ZipName"
Remove-Item -Force $ZipName
}
$PluginXmlTemplate = @'
<plugin name="{0}">
<description>{1}</description>
<image path="{2}" />
<files>
<file source="{3}" destination="{3}" priority="0" />
<file source="{4}" destination="{4}" priority="0" />
</files>
<typeDescriptor>
<type name="Optional"/>
</typeDescriptor>
</plugin>
'@
$PluginPartXml = ""
$PluginPartXml = $PluginPartXml + ($PluginXmlTemplate -f @(
$Plugin
$ModInfo.Description
$ModInfo.Logo
$Plugin
$BsaName
))
$ScriptSourceXmlTemplate = @'
<file source="{0}" destination="{0}" priority="0" />
'@
$ScriptsXmlPart=""
$PapyrusScripts = Get-ChildItem -Recurse *.psc
foreach ($papyrusScript in $PapyrusScripts) {
$relPath = [Io.Path]::GetRelativePath($BasePath, $papyrusScript.FullName)
$ScriptsXmlPart += $ScriptSourceXmlTemplate -f $relPath
}
$InfoXml = @'
<fomod>
<Name>{0}</Name>
<Author>{1}</Author>
<Version>{2}</Version>
<Website>{3}</Website>
<Description>{4}</Description>
<Groups>
<element>{5}</element>
</Groups>
</fomod>
'@ -f @(
$ModInfo.Name
$ModInfo.Author
$ModInfo.Version
$ModInfo.Website
$ModInfo.Description
$ModInfo.Category
)
$Null = New-Item -ItemType Directory -Path $FomodBasePath -Force
$InfoXml | Set-Content -Encoding utf8NoBOM -Path $FomodInfoFile
$ModuleConfigXML = @'
<!-- Created with build.ps1 by Mark E. Kraus -->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://qconsulting.ca/fo3/ModConfig5.0.xsd">
<moduleName>{0}</moduleName>
<installSteps order="Explicit">
<installStep name="Install">
<optionalFileGroups order="Explicit">
<group name="Main" type="SelectExactlyOne">
<plugins order="Explicit">{1}
</plugins>
</group>
<group name="Install Script Sources?" type="SelectExactlyOne">
<plugins order="Explicit">
<plugin name="No (Default)">
<description>Skips installing script sources.</description>
<image path="{2}" />
<files></files>
<typeDescriptor>
<type name="Optional"/>
</typeDescriptor>
</plugin>
<plugin name="Yes (For Mod Developers)">
<description>Installs script sources.</description>
<image path="{2}" />
<files>{3}
</files>
<typeDescriptor>
<type name="Optional"/>
</typeDescriptor>
</plugin>
</plugins>
</group>
</optionalFileGroups>
</installStep>
</installSteps>
</config>
'@ -f @(
$ModInfo.Name
$PluginPartXml
$ModInfo.Logo
$ScriptsXmlPart
)
Write-Host @'
Converting Fuzzing Voice and Lip Files...
'@
if(Test-Path $VoiceBasePath) {
Push-Location $VoiceBasePath
foreach ($WavFile in (Get-ChildItem -Recurse -Filter '*.wav')) {
Push-Location $WavFile.Directory
Write-Host ([Io.Path]::GetRelativePath($VoiceBasePath, $WavFile))
$XWmaFile = $WavFile.BaseName + '.xwm'
$LipFile = $WavFile.BaseName + '.lip'
$FuzFile = $WavFile.BaseName + '.fuz'
$HashFile = $WavFile.BaseName + '.hash'
$currentHash = (Get-FileHash $WavFile -Algorithm SHA256).Hash
if ((Test-Path $HashFile) -and (Test-Path $FuzFile)) {
$oldHash = Get-Content $HashFile -TotalCount 1
if ($currentHash -eq $oldHash) {
Write-Host "No change. Skipping..."
Pop-Location
continue
}
}
else {
$currentHash | Set-Content -Path $HashFile -Encoding utf8BOM -NoNewline
}
& $XWmaEncodeCmd $WavFile $XWmaFile
if (Test-Path $LipFile) {
& $FuzExtractorPath -i $FuzFile $XWmaFile /l
# Remove-Item $LipFile -Force
} else {
& $FuzExtractorPath -i $FuzFile $XWmaFile
}
# Remove-Item $WavFile -Force
Remove-Item $XWmaFile -Force
Pop-Location
}
Pop-Location
}
$ModuleConfigXML | Set-Content -Encoding utf8NoBOM -Path $FomodModuleConfigFile
# Get-ChildItem -Recurse $VoiceBasePath
$bbcode = [System.Text.StringBuilder]::New()
$inList = $false
Copy-Item ".\README.md" "README.txt"
foreach ($Line in (Get-Content "README.md")) {
if ($Line -match '^#[^#]') {
$Line = $Line -replace '^# ','[size=6]'
$Line = $Line + '[/size]'
}
elseif ($Line -match '^##[^#]') {
$Line = $Line -replace '^## ','[size=5]'
$Line = $Line + '[/size]'
}
elseif ($Line -match '^#') {
$Line = $Line -replace '^#* ','[size=4]'
$Line = $Line + '[/size]'
}
if ($inList -and $Line -notmatch '^\* ') {
$inList = $false
$null = $bbcode.AppendLine('[/list]')
}
if (!$inList -and $Line -match '^\* ') {
$inList = $true
$null = $bbcode.AppendLine('[list]')
}
if($inList -and $Line -match '^\* ') {
$Line = $Line -replace '^\* ', '[*]'
}
$Line = $Line -replace '!\[[^)]*\)'
$Line = $Line -replace '\[([^\]]*)\]\(([^)]*)\)', '[url=$2]$1[/url]'
$Line = $Line -replace '`([^`]*)`', '[font=Courier New]$1[/font]'
$null = $bbcode.AppendLine($Line)
}
$bbcode.ToString() | Set-Content -Encoding utf8NoBOM README.bbcode -NoNewline
Pop-Location
$EndTime = [datetime]::UtcNow
$Elapsed = ($EndTime - $StartTime).TotalSeconds
Write-Host @"
Build ended $EndTime UTC
$Elapsed (s)
"@