-
Notifications
You must be signed in to change notification settings - Fork 0
/
Search-MissingPreallocatedKits.ps1
74 lines (61 loc) · 2.48 KB
/
Search-MissingPreallocatedKits.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
. .\Initialize-Script.ps1
$SearchPath = Join-Path @(Get-Location) -ChildPath "objects" -AdditionalChildPath "kits"
$VariantFilePaths = [System.IO.Directory]::GetFiles($searchPath, "variants.inc", "AllDirectories")
$MissingKits = @{}
function Search-MissingTemplates() {
foreach ($path in $VariantFilePaths) {
$factionDirectory = [System.IO.Path]::GetDirectoryName($path)
$variantFileText = Get-Content $path
$variants = [regex]::Matches($variantFileText, '(?s)("\w+"|else\b)(.*?)(?=else|$)')
foreach ($variant in $variants) {
Search-Kits -FactionPath $factionDirectory -VariantMatch $variant
}
}
}
function Search-Kits() {
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[string]$FactionPath,
[System.Text.RegularExpressions.Match]$VariantMatch
)
# Convert match groups to strings
$faction = [System.IO.Path]::GetFileName($FactionPath)
$variant = $VariantMatch.Groups[1].ToString()
$variant = (($variant -eq "else") ? $faction : $variant).Trim('"')
$kitFiles = $VariantMatch.Groups[2].ToString()
Write-Host "Checking $variant..."
# Initialize kit collections
$loadedKits = New-Object -TypeName System.Collections.Generic.HashSet[string]
$allocatedKits = New-Object -TypeName System.Collections.Generic.HashSet[string]
# Allocate kire from the variant runs and preloaded
$kits = [regex]::Matches($kitFiles, '(?<=run )[\w\/]+\.tweak')
foreach ($kit in $kits) {
$kitTweakFilePath = Join-Path -Path $FactionPath -ChildPath $kit.Value
$kitTweakFileText = Get-Content $kitTweakFilePath
try {
if ($kitTweakFilePath.Contains("preload")) {
$kitMatches = [regex]::Matches($kitTweakFileText, '(?<=ObjectTemplate\.setObjectTemplate \d )\w+')
foreach ($kitMatch in $kitMatches) {
[void]$allocatedKits.Add($kitMatch.Value)
}
}
else {
$kitMatches = [regex]::Matches($kitTweakFileText, '(?<=ObjectTemplate\.create Kit )\w+')
foreach ($kitMatch in $kitMatches) {
[void]$loadedKits.Add($kitMatch)
}
}
}
catch {
continue
}
}
$loadedKits.ExceptWith($allocatedKits)
if ($loadedKits.Count -gt 0) {
[void]$MissingKits.Add($variant, $loadedKits)
}
}
# Main program
Search-MissingTemplates
$MissingKits | Format-List -AutoSize