waypoit debuguing

This commit is contained in:
2026-09-25 15:50:28 -06:00
parent 757f1775ff
commit e5435d124e
+34 -59
View File
@@ -5,24 +5,19 @@ param(
[Parameter(Position = 0, ParameterSetName = 'Match', ValueFromPipeline = $true)] [Parameter(Position = 0, ParameterSetName = 'Match', ValueFromPipeline = $true)]
[string[]]$FilePath, [string[]]$FilePath,
# Output file switch (-o / --out) - auto generates file based on rules # Output file (-o / --outfile / -OutFile)
[Parameter(Mandatory = $false, ParameterSetName = 'Generate')] [Parameter(Mandatory = $false, ParameterSetName = 'Generate')]
[Alias('o', 'out', 'SaveToFile')] [Alias('o')]
[switch]$SaveToFile,
# Custom Output file name (-f / --outfile)
[Parameter(Mandatory = $false, ParameterSetName = 'Generate')]
[Alias('f', 'outfile')]
[string]$OutFile, [string]$OutFile,
# File containing checksums to verify (-c / --check) # File containing checksums to verify (-c / --check)
[Parameter(Mandatory = $false, ParameterSetName = 'Verify')] [Parameter(Mandatory = $false, ParameterSetName = 'Verify')]
[Alias('c', 'check')] [Alias('c')]
[string]$Check, [string]$Check,
# Direct checksum hash string to match against (-m / --match) # Direct checksum hash string to match against (-m / --match)
[Parameter(Mandatory = $true, ParameterSetName = 'Match')] [Parameter(Mandatory = $true, ParameterSetName = 'Match')]
[Alias('m', 'match')] [Alias('m')]
[string]$Match, [string]$Match,
# Hashing algorithm to use (Defaults to SHA256) # Hashing algorithm to use (Defaults to SHA256)
@@ -33,12 +28,12 @@ param(
# Recursive flag (-r / --recursive) # Recursive flag (-r / --recursive)
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
[Alias('r', 'recursive')] [Alias('r')]
[switch]$Recursive, [switch]$Recursive,
# Help flag (-h / --help) # Help flag (-h / --help)
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
[Alias('h', 'help')] [Alias('h')]
[switch]$Help [switch]$Help
) )
@@ -49,7 +44,7 @@ NAME
checksum - Compute and verify message digests / file checksums checksum - Compute and verify message digests / file checksums
SYNOPSIS SYNOPSIS
.\checksum.ps1 [-FilePath] <string[]> [-o] [-OutFile <string>] [-Algorithm <string>] [-r] .\checksum.ps1 [-FilePath] <string[]> [-o [<string>]] [-Algorithm <string>] [-r]
.\checksum.ps1 [-FilePath] <string[]> -Match <string> [-Algorithm <string>] [-r] .\checksum.ps1 [-FilePath] <string[]> -Match <string> [-Algorithm <string>] [-r]
.\checksum.ps1 -Check <string> [-Algorithm <string>] [-r] .\checksum.ps1 -Check <string> [-Algorithm <string>] [-r]
.\checksum.ps1 -Help .\checksum.ps1 -Help
@@ -57,22 +52,19 @@ SYNOPSIS
DESCRIPTION DESCRIPTION
Computes or verifies checksums using cryptographic hash algorithms (SHA256, SHA512, SHA1, MD5, SHA384). Computes or verifies checksums using cryptographic hash algorithms (SHA256, SHA512, SHA1, MD5, SHA384).
Outputs hash values in standard GNU coreutils format (<hash> <filename>). Outputs hash values in standard GNU coreutils format (<hash> <filename>).
Supports both single-dash (-o, -c, -r) and double-dash (--out, --check, --recursive) GNU-style flags. Supports both single-dash (-o, -c, -r) and double-dash (--outfile, --check, --recursive) GNU-style flags.
Ignores checksum metadata files (.md5, .sha1, .sha256, .sha384, .sha512) during wildcards unless passed explicitly. Ignores checksum metadata files (.md5, .sha1, .sha256, .sha384, .sha512) during wildcards unless passed explicitly.
PARAMETERS PARAMETERS
-FilePath <string[]> -FilePath <string[]>
Specifies the target file(s) or wildcard pattern (*). Specifies the target file(s) or wildcard pattern (*).
-o, --out, -SaveToFile <switch> -o, --outfile, -OutFile <string>
Enables auto-saving checksum results to file(s). Enables auto-saving checksum results to file(s).
- If input contains a wildcard (*), writes to 'checksums.<algo>'. - If passed with an argument (e.g. -o custom.txt), writes to 'custom.txt'.
- If an explicit file is given, writes to '<filename>.<algo>'. - If passed with NO argument (or empty string ""), automatically outputs to 'checksums.<algo>'.
When combined with -r and *, recursively auto-generates checksum files per directory. When combined with -r and *, recursively auto-generates checksum files per directory.
-f, --outfile, -OutFile <string>
Specifies an explicit destination filename for saving checksum output.
-c, --check, -Check <string> -c, --check, -Check <string>
Reads hashes from a specified checksum file and verifies target files on disk. Reads hashes from a specified checksum file and verifies target files on disk.
If -r is specified, recursively looks for and validates checksum files by name across subdirectories. If -r is specified, recursively looks for and validates checksum files by name across subdirectories.
@@ -95,17 +87,17 @@ EXAMPLES
1. Compute SHA256 for a single file: 1. Compute SHA256 for a single file:
.\checksum.ps1 myfile.iso .\checksum.ps1 myfile.iso
2. Compute SHA512 checksums recursively and auto-save: 2. Compute SHA512 checksums recursively and auto-save (prompts for filename, hit Enter for auto):
.\checksum.ps1 * -r -o -a SHA512 .\checksum.ps1 * -r -o -a SHA512
.\checksum.ps1 * --recursive --out --algo SHA512 .\checksum.ps1 * --recursive --outfile "" --algo SHA512
3. Verify checksums against a verification file: 3. Compute SHA256 checksums and save to custom file:
.\checksum.ps1 * -o my_hashes.txt
4. Verify checksums against a verification file:
.\checksum.ps1 -c checksums.sha256 .\checksum.ps1 -c checksums.sha256
.\checksum.ps1 --check checksums.sha256 .\checksum.ps1 --check checksums.sha256
4. Recursively verify checksum files across subdirectories:
.\checksum.ps1 --check checksums.sha256 --recursive
5. Compare file directly against an expected hash string: 5. Compare file directly against an expected hash string:
.\checksum.ps1 myfile.bin --match 406653a68bd3538975656831f33f031b .\checksum.ps1 myfile.bin --match 406653a68bd3538975656831f33f031b
'@ '@
@@ -308,7 +300,9 @@ process {
if ([string]::IsNullOrWhiteSpace($Algorithm)) {$Algorithm = 'SHA256'; if ([string]::IsNullOrWhiteSpace($Algorithm)) {$Algorithm = 'SHA256';
}; };
$wantOutFile = $SaveToFile.IsPresent -or (-not [string]::IsNullOrWhiteSpace($OutFile)); # Detect if the parameter was used AT ALL, even if they hit Enter at the prompt (resulting in empty string)
$wantOutFile =$PSBoundParameters.ContainsKey('OutFile');
$isAutoFile = [string]::IsNullOrWhiteSpace($OutFile);
if ($wantOutFile) { if ($wantOutFile) {
if ($Recursive -and$isWildcardGlobal) { if ($Recursive -and$isWildcardGlobal) {
@@ -318,7 +312,7 @@ process {
$dirPath =$group.Name; $dirPath =$group.Name;
$filesInDir =$group.Group; $filesInDir =$group.Group;
if ([string]::IsNullOrWhiteSpace($OutFile)) { if ($isAutoFile) {
$currentOutFile = Join-Path -Path ($dirPath) -ChildPath "checksums.$($Algorithm.ToLower())"; $currentOutFile = Join-Path -Path ($dirPath) -ChildPath "checksums.$($Algorithm.ToLower())";
} else { } else {
$currentOutFile = Join-Path -Path ($dirPath) -ChildPath ($OutFile); $currentOutFile = Join-Path -Path ($dirPath) -ChildPath ($OutFile);
@@ -337,45 +331,26 @@ process {
}; };
} }
else { else {
$singleOutFile =$null; if ($isAutoFile) {$singleOutFile = "checksums.$($Algorithm.ToLower())";
if ([string]::IsNullOrWhiteSpace($OutFile)) {
if ($isWildcardGlobal) {$singleOutFile = "checksums.$($Algorithm.ToLower())";
}
} else { } else {
$singleOutFile =$OutFile; $singleOutFile =$OutFile;
}; };
if ($singleOutFile) {$linesToWrite = @(); $linesToWrite = @();
foreach ($item in ($allItems)) {$hash = (Get-FileHash -Path ($item.FullName) -Algorithm ($Algorithm)).Hash.ToLower(); foreach ($item in ($allItems)) {$hash = (Get-FileHash -Path ($item.FullName) -Algorithm ($Algorithm)).Hash.ToLower();
$relativePath = Resolve-Path -Path ($item.FullName) -Relative -ErrorAction 'SilentlyContinue'; $relativePath = Resolve-Path -Path ($item.FullName) -Relative -ErrorAction 'SilentlyContinue';
if (-not $relativePath) { $relativePath =$item.Name; }; if (-not $relativePath) { $relativePath =$item.Name; };
if ($relativePath.StartsWith(".\") -or $relativePath.StartsWith("./")) { if ($relativePath.StartsWith(".\") -or $relativePath.StartsWith("./")) {
$relativePath =$relativePath.Substring(2); $relativePath =$relativePath.Substring(2);
};
$outputLine = "${hash}${relativePath}";
$linesToWrite +=$outputLine;
Write-Output $outputLine;
}; };
Set-Content -Path ($singleOutFile) -Value$linesToWrite -Encoding utf8; $outputLine = "${hash}${relativePath}";
} else { $linesToWrite +=$outputLine;
foreach ($item in ($allItems)) {$hash = (Get-FileHash -Path ($item.FullName) -Algorithm ($Algorithm)).Hash.ToLower(); Write-Output $outputLine;
$relativePath = Resolve-Path -Path ($item.FullName) -Relative -ErrorAction 'SilentlyContinue';
if (-not $relativePath) { $relativePath =$item.Name; };
if ($relativePath.StartsWith(".\") -or $relativePath.StartsWith("./")) {
$relativePath =$relativePath.Substring(2);
};
$outputLine = "${hash}${relativePath}";
$currentOutFile = "$($item.FullName).$($Algorithm.ToLower())";
Set-Content -Path ($currentOutFile) -Value$outputLine -Encoding utf8;
Write-Output $outputLine;
};
}; };
Set-Content -Path ($singleOutFile) -Value$linesToWrite -Encoding utf8;
}; };
} }
else { else {