From b32cae15b22b336564f1feb7246f6869c6d8e30a Mon Sep 17 00:00:00 2001 From: Princess Pi Date: Fri, 25 Sep 2026 15:20:47 -0600 Subject: [PATCH] waypoint debugging --- Windows-Scripts/checksum.ps1 | 48 +++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/Windows-Scripts/checksum.ps1 b/Windows-Scripts/checksum.ps1 index 2d7963c..35f5277 100644 --- a/Windows-Scripts/checksum.ps1 +++ b/Windows-Scripts/checksum.ps1 @@ -145,16 +145,16 @@ process { return } - # Added explicit semicolons here to prevent copy-paste line-break parsing errors $allItems = @(); $isWildcardGlobal =$false; $skipExtensions = @('.md5', '.sha1', '.sha256', '.sha384', '.sha512'); - foreach ($pathEntry in$FilePath) { - $isWildcard = ($pathEntry -match '\*') + # Delimiting collection in parentheses prevents space-stripping errors + foreach ($pathEntry in ($FilePath)) { + $isWildcard = ($pathEntry -match '\*'); if ($isWildcard) { $isWildcardGlobal =$true } - $resolvedItems = @() + $resolvedItems = @(); if ($Recursive) { $resolvedItems = Get-ChildItem -Path$pathEntry -Recurse -File -ErrorAction SilentlyContinue } else { @@ -170,12 +170,12 @@ process { continue } - $explicitFileFound = $false + $explicitFileFound = $false; if ((-not $isWildcard) -and (Test-Path -Path $pathEntry -PathType Leaf)) { $explicitFileFound = $true } - foreach ($item in $resolvedItems) { + foreach ($item in ($resolvedItems)) { if ($item.PSIsContainer) { continue } # Feature 1: Skip checksum extension files unless they were named explicitly @@ -197,11 +197,12 @@ process { Write-Verbose "Auto-detected algorithm: $Algorithm" } - $expectedHash = $Match.Trim().ToLower() + $expectedHash = $Match.Trim().ToLower(); - foreach ($item in $allItems) { + foreach ($item in ($allItems)) { $actualHash = (Get-FileHash -Path $item.FullName -Algorithm $Algorithm).Hash.ToLower() - $targetFile = Resolve-Path -Path $item.FullName -Relative + $targetFile = Resolve-Path -Path $item.FullName -Relative -ErrorAction SilentlyContinue + if (-not $targetFile) { $targetFile = $item.Name } if ($targetFile.StartsWith(".\")) { $targetFile = $targetFile.Substring(2) } if ($actualHash -eq $expectedHash) { @@ -215,7 +216,7 @@ process { } # --- VERIFICATION MODE (-c / -Check) --- elseif ($PSCmdlet.ParameterSetName -eq 'Verify') { - $checkFiles = @() + $checkFiles = @(); if ($Recursive) { # Find all files matching the name of $Check recursively $checkFileName = Split-Path $Check -Leaf @@ -231,13 +232,13 @@ process { return } - foreach ($cf in$checkFiles) { + foreach ($cf in ($checkFiles)) { $lines = Get-Content -Path$cf.FullName $baseDir =$cf.DirectoryName $fileAlgo =$Algorithm if ([string]::IsNullOrWhiteSpace($fileAlgo)) { - foreach ($line in$lines) { + foreach ($line in ($lines)) { if ([string]::IsNullOrWhiteSpace($line) -or$line.StartsWith("#")) { continue } if ($line -match '^([a-fA-F0-9]+)\s+') { $fileAlgo = Get-AlgorithmFromHashLength -HashString$Matches[1] @@ -248,7 +249,7 @@ process { if ([string]::IsNullOrWhiteSpace($fileAlgo)) {$fileAlgo = 'SHA256' } } - foreach ($line in$lines) { + foreach ($line in ($lines)) { if ([string]::IsNullOrWhiteSpace($line) -or$line.StartsWith("#")) { continue } if ($line -match '^([a-fA-F0-9]+)\s+[* ]?(.*)$') { @@ -260,7 +261,8 @@ process { if (Test-Path -Path $targetFullPath -PathType Leaf) {$actualHash = (Get-FileHash -Path $targetFullPath -Algorithm$fileAlgo).Hash.ToLower() - $displayPath = Resolve-Path -Path$targetFullPath -Relative + $displayPath = Resolve-Path -Path$targetFullPath -Relative -ErrorAction SilentlyContinue + if (-not $displayPath) { $displayPath =$targetFile } if ($displayPath.StartsWith(".\")) { $displayPath =$displayPath.Substring(2) } if ($actualHash -eq$expectedHash) { @@ -273,7 +275,7 @@ process { } else { # Format missing path nicely $displayPath =$targetFile - if ($baseDir -ne (Get-Location).Path) {$displayPath = Join-Path -Path (Resolve-Path -Path $baseDir -Relative) -ChildPath$targetFile + if ($baseDir -ne (Get-Location).Path) {$displayPath = Join-Path -Path (Resolve-Path -Path $baseDir -Relative -ErrorAction SilentlyContinue) -ChildPath$targetFile if ($displayPath.StartsWith(".\")) { $displayPath =$displayPath.Substring(2) } } Write-Host "${displayPath}: " -NoNewline @@ -299,7 +301,7 @@ process { if ($Recursive -and$isWildcardGlobal) { $groupedItems =$allItems | Group-Object DirectoryName - foreach ($group in$groupedItems) { + foreach ($group in ($groupedItems)) { $dirPath =$group.Name $filesInDir =$group.Group @@ -312,7 +314,7 @@ process { # Clear existing file before iterating $null = New-Item -Path$currentOutFile -ItemType File -Force - 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 # Localization relies purely on internal filenames $outputLine = "$hash$relativePath" @@ -323,7 +325,7 @@ process { } # Non-localized standard generation (Singular master file, or Per-file auto naming) else { - $singleOutFile =$null + $singleOutFile =$null; # Check for standard auto naming rules if ([string]::IsNullOrWhiteSpace($outFilename)) { @@ -338,9 +340,10 @@ process { $null = New-Item -Path$singleOutFile -ItemType File -Force } - 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 + $relativePath = Resolve-Path -Path$item.FullName -Relative -ErrorAction SilentlyContinue + if (-not $relativePath) { $relativePath =$item.Name } if ($relativePath.StartsWith(".\")) { $relativePath =$relativePath.Substring(2) } @@ -362,9 +365,10 @@ process { } # Standard fallback if no -o was invoked: Stream perfectly to console 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 + $relativePath = Resolve-Path -Path$item.FullName -Relative -ErrorAction SilentlyContinue + if (-not $relativePath) { $relativePath =$item.Name } if ($relativePath.StartsWith(".\")) { $relativePath =$relativePath.Substring(2) }