-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathbuild.ps1
More file actions
57 lines (43 loc) · 1.75 KB
/
build.ps1
File metadata and controls
57 lines (43 loc) · 1.75 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
param (
[string]$SourceFolder,
[string]$PatchLetter,
[string]$OutputFolder
)
# Path to MPQEditor.exe
$MPQEditor = ".\Tools\MPQEditor.exe"
# Calculate the next power of 2
function Get-PowerOfTwo {
param ([int]$n)
$power = 1
while ($power -lt $n) { $power *= 2 }
return $power
}
# Check parameters
if (-not $SourceFolder -or -not $PatchLetter -or -not $OutputFolder) {
Write-Host "Usage: .\build.ps1 -SourceFolder 'D:\path\to\localizations' -PatchLetter '<4-9, A-Z>' -OutputFolder 'D:\path\to\output'"
exit
}
# Create Output Folder
if (!(Test-Path -Path $OutputFolder)) {
New-Item -ItemType Directory -Path $OutputFolder | Out-Null
}
Get-ChildItem -Path $SourceFolder -Directory | ForEach-Object {
$Locale = $_.Name # Name of the locale
$MPQFile = "$OutputFolder\patch-$Locale-$PatchLetter.MPQ"
$ScriptFile = "$OutputFolder\script-$Locale-$PatchLetter.txt"
$LocaleFolder = $_.FullName
$Files = Get-ChildItem -Path $LocaleFolder -Recurse -File
$FileCount = $Files.Count
$SlotCount = Get-PowerOfTwo -n $FileCount
$SlotCountInHex = ($SlotCount / 2).ToString("X")
"new `"$MPQFile`" 0x$SlotCountInHex" | Out-File -Encoding utf8 $ScriptFile
$Files | ForEach-Object {
$RelativePath = $_.FullName.Substring($LocaleFolder.Length + 1) -replace "\\", "\"
"add `"$MPQFile`" `"$($_.FullName)`" `"$RelativePath`" /auto /r"
Write-Host "Added file: $RelativePath"
} | Out-File -Encoding utf8 -Append $ScriptFile
"close `"$MPQFile`"" | Out-File -Encoding utf8 -Append $ScriptFile
Start-Process -NoNewWindow -Wait -FilePath $MPQEditor -ArgumentList "script `"$ScriptFile`""
Write-Host "Created MPQ: $MPQFile (Slots count: $SlotCount, Files count: $FileCount)"
}
Write-Host "Done!"