waypoit debuguing

This commit is contained in:
2026-09-25 15:50:28 -06:00
parent 757f1775ff
commit e5435d124e
+23 -48
View File
@@ -5,24 +5,19 @@ param(
[Parameter(Position = 0, ParameterSetName = 'Match', ValueFromPipeline = $true)]
[string[]]$FilePath,
# Output file switch (-o / --out) - auto generates file based on rules
# Output file (-o / --outfile / -OutFile)
[Parameter(Mandatory = $false, ParameterSetName = 'Generate')]
[Alias('o', 'out', 'SaveToFile')]
[switch]$SaveToFile,
# Custom Output file name (-f / --outfile)
[Parameter(Mandatory = $false, ParameterSetName = 'Generate')]
[Alias('f', 'outfile')]
[Alias('o')]
[string]$OutFile,
# File containing checksums to verify (-c / --check)
[Parameter(Mandatory = $false, ParameterSetName = 'Verify')]
[Alias('c', 'check')]
[Alias('c')]
[string]$Check,
# Direct checksum hash string to match against (-m / --match)
[Parameter(Mandatory = $true, ParameterSetName = 'Match')]
[Alias('m', 'match')]
[Alias('m')]
[string]$Match,
# Hashing algorithm to use (Defaults to SHA256)
@@ -33,12 +28,12 @@ param(
# Recursive flag (-r / --recursive)
[Parameter(Mandatory = $false)]
[Alias('r', 'recursive')]
[Alias('r')]
[switch]$Recursive,
# Help flag (-h / --help)
[Parameter(Mandatory = $false)]
[Alias('h', 'help')]
[Alias('h')]
[switch]$Help
)
@@ -49,7 +44,7 @@ NAME
checksum - Compute and verify message digests / file checksums
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 -Check <string> [-Algorithm <string>] [-r]
.\checksum.ps1 -Help
@@ -57,22 +52,19 @@ SYNOPSIS
DESCRIPTION
Computes or verifies checksums using cryptographic hash algorithms (SHA256, SHA512, SHA1, MD5, SHA384).
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.
PARAMETERS
-FilePath <string[]>
Specifies the target file(s) or wildcard pattern (*).
-o, --out, -SaveToFile <switch>
-o, --outfile, -OutFile <string>
Enables auto-saving checksum results to file(s).
- If input contains a wildcard (*), writes to 'checksums.<algo>'.
- If an explicit file is given, writes to '<filename>.<algo>'.
- If passed with an argument (e.g. -o custom.txt), writes to 'custom.txt'.
- 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.
-f, --outfile, -OutFile <string>
Specifies an explicit destination filename for saving checksum output.
-c, --check, -Check <string>
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.
@@ -95,17 +87,17 @@ EXAMPLES
1. Compute SHA256 for a single file:
.\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 * --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 --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:
.\checksum.ps1 myfile.bin --match 406653a68bd3538975656831f33f031b
'@
@@ -308,7 +300,9 @@ process {
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 ($Recursive -and$isWildcardGlobal) {
@@ -318,7 +312,7 @@ process {
$dirPath =$group.Name;
$filesInDir =$group.Group;
if ([string]::IsNullOrWhiteSpace($OutFile)) {
if ($isAutoFile) {
$currentOutFile = Join-Path -Path ($dirPath) -ChildPath "checksums.$($Algorithm.ToLower())";
} else {
$currentOutFile = Join-Path -Path ($dirPath) -ChildPath ($OutFile);
@@ -337,16 +331,12 @@ process {
};
}
else {
$singleOutFile =$null;
if ([string]::IsNullOrWhiteSpace($OutFile)) {
if ($isWildcardGlobal) {$singleOutFile = "checksums.$($Algorithm.ToLower())";
}
if ($isAutoFile) {$singleOutFile = "checksums.$($Algorithm.ToLower())";
} else {
$singleOutFile =$OutFile;
};
if ($singleOutFile) {$linesToWrite = @();
$linesToWrite = @();
foreach ($item in ($allItems)) {$hash = (Get-FileHash -Path ($item.FullName) -Algorithm ($Algorithm)).Hash.ToLower();
$relativePath = Resolve-Path -Path ($item.FullName) -Relative -ErrorAction 'SilentlyContinue';
@@ -361,21 +351,6 @@ process {
};
Set-Content -Path ($singleOutFile) -Value$linesToWrite -Encoding utf8;
} else {
foreach ($item in ($allItems)) {$hash = (Get-FileHash -Path ($item.FullName) -Algorithm ($Algorithm)).Hash.ToLower();
$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;
};
};
};
}
else {