Files
devolutions--unigetui/scripts/generate-integrity-tree.ps1
wehub-resource-sync 643e9f9fcb
.NET Tests / test-codebase (push) Waiting to run
Translation Validation / validate-translations (push) Waiting to run
chore: import upstream snapshot with attribution
2026-07-13 13:01:52 +08:00

59 lines
1.6 KiB
PowerShell

#!/usr/bin/env pwsh
<#
.SYNOPSIS
Generates an IntegrityTree.json file containing SHA256 hashes of all files
in the specified directory. Used at build time; verified at runtime by
UniGetUI.Core.Tools.IntegrityTester.
.PARAMETER Path
The directory to scan (typically the publish/output directory).
.PARAMETER MinOutput
Suppress per-file progress output.
#>
[CmdletBinding()]
param(
[Parameter(Mandatory, Position = 0)]
[string] $Path,
[switch] $MinOutput
)
$ErrorActionPreference = 'Stop'
if (-not (Test-Path $Path -PathType Container)) {
throw "The directory '$Path' does not exist."
}
$Path = (Resolve-Path $Path).Path
$OutputFileName = 'IntegrityTree.json'
$ScriptName = [System.IO.Path]::GetFileName($PSCommandPath)
$integrityData = [ordered]@{}
Get-ChildItem $Path -Recurse -File | ForEach-Object {
$relativePath = $_.FullName.Substring($Path.Length).TrimStart('\', '/') -replace '\\', '/'
# Skip the output file itself
if ($relativePath -eq $OutputFileName) { return }
if (-not $MinOutput) {
Write-Host " - Computing SHA256 of $relativePath..."
}
$hash = (Get-FileHash $_.FullName -Algorithm SHA256).Hash.ToLower()
$integrityData[$relativePath] = $hash
}
# Sort keys for deterministic output
$sorted = [ordered]@{}
foreach ($key in ($integrityData.Keys | Sort-Object)) {
$sorted[$key] = $integrityData[$key]
}
$json = $sorted | ConvertTo-Json -Depth 1
Set-Content (Join-Path $Path $OutputFileName) $json -Encoding utf8NoBOM -NoNewline
Write-Host "Integrity tree was generated and saved to $Path/$OutputFileName"