mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 23:38:37 +00:00
41 lines
2.7 KiB
PowerShell
41 lines
2.7 KiB
PowerShell
# Carves every .rpf in the game folder into <Out>\<archive path with _>, smallest first (research tool; the
|
|
# build itself doesn't need it). Skips archives that already have an index.json. Summary: <Out>\coverage.json
|
|
param([Parameter(Mandatory)][string]$Game, [Parameter(Mandatory)][string]$Out)
|
|
$root = Split-Path $PSScriptRoot -Parent
|
|
$tool = Join-Path $root "tools\rpf9_carve.py"
|
|
# -Game may be relative or end in a separator; archive names are cut from a separator-ended prefix.
|
|
$Game = (Resolve-Path -LiteralPath $Game).ProviderPath
|
|
# Resolve-Path preserves 8.3 short components (e.g. RUNNER~1), while Get-ChildItem emits canonical
|
|
# FullName paths. Deriving the prefix from Resolve-Path then cuts the wrong number of characters and
|
|
# re-carves already-caved archives; use the canonical form for both sides of the Substring.
|
|
$prefix = (Get-Item -LiteralPath $Game).FullName.TrimEnd('\') + '\'
|
|
$destinations = [System.Collections.Generic.Dictionary[string, string]]::new([StringComparer]::OrdinalIgnoreCase)
|
|
# Validate every destination before accepting any cached index or starting a carve.
|
|
$archives = foreach ($f in Get-ChildItem -LiteralPath $Game -Recurse -Filter *.rpf | Sort-Object Length) {
|
|
$rel = $f.FullName.Substring($prefix.Length)
|
|
$name = [IO.Path]::GetFileNameWithoutExtension(($rel -replace "[\\/]", "_"))
|
|
if ($destinations.ContainsKey($name)) {
|
|
throw ("Archives '{0}' and '{1}' both map to '{2}'." -f $destinations[$name], $rel, $name)
|
|
}
|
|
$destinations.Add($name, $rel)
|
|
[pscustomobject]@{ file = $f; relative = $rel; destination = Join-Path $Out $name }
|
|
}
|
|
|
|
$rows = @()
|
|
foreach ($archive in $archives) {
|
|
$f = $archive.file
|
|
$rel = $archive.relative
|
|
$dest = $archive.destination
|
|
if (-not (Test-Path -LiteralPath (Join-Path $dest "index.json"))) {
|
|
Write-Host ("{0:HH:mm:ss} carving {1} ({2:N1} GiB)" -f (Get-Date), $rel, ($f.Length / 1GB))
|
|
python -I $tool $f.FullName $dest | Select-Object -Last 1
|
|
if ($LASTEXITCODE -ne 0) { throw "Carving $rel failed (exit $LASTEXITCODE)" }
|
|
}
|
|
$s = (Get-Content -LiteralPath (Join-Path $dest "index.json") -Raw | ConvertFrom-Json).summary
|
|
$rows += [pscustomobject]@{ archive = $rel; files = $s.files; bink2 = $s.bink2_files; span = $s.span
|
|
readable = [math]::Round(($s.compressed_bytes) / $s.span, 4)
|
|
unread = [math]::Round($s.unread_bytes / $s.span, 4); inflated = $s.inflated_bytes }
|
|
}
|
|
$rows | ConvertTo-Json | Set-Content -Encoding utf8 -LiteralPath (Join-Path $Out "coverage.json")
|
|
$rows | Format-Table archive, files, bink2, @{n = "GiB"; e = { [math]::Round($_.span / 1GB, 2) } }, readable, unread -AutoSize | Out-String -Width 200
|