WORKAN DEBUG

This commit is contained in:
2026-09-25 16:10:17 -06:00
parent 4fea9dbccc
commit 608e225833
+22 -13
View File
@@ -130,7 +130,7 @@ process {
$helpInPath = $false; $helpInPath = $false;
if ($FilePath) { if ($FilePath) {
foreach ($p in ($FilePath)) { foreach ($p in ($FilePath)) {
if ($p -match '^(?i)[-/]{1,2}(h\vert{}help\vert{}\?)$') { if ($p -match '^(?i)[-/]{1,2}(h|help|\?)$') {
$helpInPath = $true; $helpInPath = $true;
break; break;
} }
@@ -173,7 +173,7 @@ process {
}; };
if (-not $resolvedItems) { if (-not $resolvedItems) {
Write-Error "checksum: $($pathEntry)`: No such file or directory"; Write-Error "checksum: $($pathEntry): No such file or directory";
continue; continue;
}; };
@@ -232,7 +232,7 @@ process {
}; };
if (-not $checkFiles -or $checkFiles.Count -eq 0) { if (-not $checkFiles -or $checkFiles.Count -eq 0) {
Write-Error "checksum: $($Check)`: No such file or directory"; Write-Error "checksum: $($Check): No such file or directory";
return; return;
}; };
@@ -267,14 +267,16 @@ process {
$expectedHash = $Matches[1].ToLower(); $expectedHash = $Matches[1].ToLower();
$targetFile = $Matches[2].Trim().TrimStart('*'); $targetFile = $Matches[2].Trim().TrimStart('*');
} }
elseif ($line -match '^([a-fA-F0-9]{128}\vert{}[a-fA-F0-9]{96}\vert{}[a-fA-F0-9]{64}\vert{}[a-fA-F0-9]{40}\vert{}[a-fA-F0-9]{32})[* ]?(.*)$') { elseif ($line -match '^([a-fA-F0-9]{128}|[a-fA-F0-9]{96}|[a-fA-F0-9]{64}|[a-fA-F0-9]{40}|[a-fA-F0-9]{32})[* ]?(.*)$') {
$expectedHash = $Matches[1].ToLower(); $expectedHash = $Matches[1].ToLower();
$targetFile = $Matches[2].Trim().TrimStart('*'); $targetFile = $Matches[2].Trim().TrimStart('*');
}; };
if ($expectedHash -and $targetFile) {$targetFullPath = Join-Path -Path ($baseDir) -ChildPath ($targetFile); if ($expectedHash -and $targetFile) {
$targetFullPath = Join-Path -Path ($baseDir) -ChildPath ($targetFile);
if (Test-Path -Path ($targetFullPath) -PathType 'Leaf') {$actualHash = (Get-FileHash -Path ($targetFullPath) -Algorithm ($fileAlgo)).Hash.ToLower(); if (Test-Path -Path ($targetFullPath) -PathType 'Leaf') {
$actualHash = (Get-FileHash -Path ($targetFullPath) -Algorithm ($fileAlgo)).Hash.ToLower();
$displayPath = Resolve-Path -Path ($targetFullPath) -Relative -ErrorAction 'SilentlyContinue'; $displayPath = Resolve-Path -Path ($targetFullPath) -Relative -ErrorAction 'SilentlyContinue';
if (-not $displayPath) { $displayPath = $targetFile; }; if (-not $displayPath) { $displayPath = $targetFile; };
@@ -289,7 +291,8 @@ process {
}; };
} else { } else {
$displayPath = $targetFile; $displayPath = $targetFile;
if ($baseDir -ne (Get-Location).Path) {$displayPath = Join-Path -Path (Resolve-Path -Path ($baseDir) -Relative -ErrorAction 'SilentlyContinue') -ChildPath ($targetFile); if ($baseDir -ne (Get-Location).Path) {
$displayPath = Join-Path -Path (Resolve-Path -Path ($baseDir) -Relative -ErrorAction 'SilentlyContinue') -ChildPath ($targetFile);
if ($displayPath.StartsWith(".\") -or $displayPath.StartsWith("./")) { $displayPath = $displayPath.Substring(2); }; if ($displayPath.StartsWith(".\") -or $displayPath.StartsWith("./")) { $displayPath = $displayPath.Substring(2); };
}; };
Write-Host "${displayPath}: " -NoNewline; Write-Host "${displayPath}: " -NoNewline;
@@ -301,7 +304,8 @@ process {
} }
# --- GENERATION MODE --- # --- GENERATION MODE ---
else { else {
if ([string]::IsNullOrWhiteSpace($Algorithm)) {$Algorithm = 'SHA256'; if ([string]::IsNullOrWhiteSpace($Algorithm)) {
$Algorithm = 'SHA256';
}; };
$wantCustomOut = $PSBoundParameters.ContainsKey('OutFile'); $wantCustomOut = $PSBoundParameters.ContainsKey('OutFile');
@@ -316,13 +320,15 @@ process {
$dirPath = $group.Name; $dirPath = $group.Name;
$filesInDir = $group.Group; $filesInDir = $group.Group;
if ($wantCustomOut) {$currentOutFile = Join-Path -Path ($dirPath) -ChildPath ($OutFile); if ($wantCustomOut) {
$currentOutFile = Join-Path -Path ($dirPath) -ChildPath ($OutFile);
} else { } else {
$currentOutFile = Join-Path -Path ($dirPath) -ChildPath "checksums.$($Algorithm.ToLower())"; $currentOutFile = Join-Path -Path ($dirPath) -ChildPath "checksums.$($Algorithm.ToLower())";
}; };
$linesToWrite = @(); $linesToWrite = @();
foreach ($item in ($filesInDir)) {$hash = (Get-FileHash -Path ($item.FullName) -Algorithm ($Algorithm)).Hash.ToLower(); foreach ($item in ($filesInDir)) {
$hash = (Get-FileHash -Path ($item.FullName) -Algorithm ($Algorithm)).Hash.ToLower();
$relativePath = $item.Name; $relativePath = $item.Name;
$outputLine = "${hash} ${relativePath}"; $outputLine = "${hash} ${relativePath}";
@@ -343,7 +349,8 @@ process {
}; };
$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; };
@@ -360,7 +367,8 @@ process {
} }
# Auto file for explicit individual files (No wildcard) # Auto file for explicit individual files (No wildcard)
else { else {
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; };
@@ -380,7 +388,8 @@ process {
} }
# Standard console output (No save flags passed) # Standard console output (No save flags passed)
else { else {
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; };