From 7bd65e7d76c64d8ed479a2a78241e40e3d9210b8 Mon Sep 17 00:00:00 2001 From: Princess Pi Date: Fri, 25 Sep 2026 16:45:30 -0600 Subject: [PATCH] waypoit debuguing --- Windows-Scripts/checksum.ps1 | 210 +++++++++++++++++++++-------------- 1 file changed, 124 insertions(+), 86 deletions(-) diff --git a/Windows-Scripts/checksum.ps1 b/Windows-Scripts/checksum.ps1 index 2cd759a..b6146da 100644 --- a/Windows-Scripts/checksum.ps1 +++ b/Windows-Scripts/checksum.ps1 @@ -4,6 +4,7 @@ param( [Parameter(Position = 0, ParameterSetName = 'Generate', ValueFromPipeline = $true)] [Parameter(Position = 0, ParameterSetName = 'Match', ValueFromPipeline = $true)] [Parameter(Position = 0, ParameterSetName = 'PrincessPi', ValueFromPipeline = $false)] + [Alias('i', 'input', 'if', 'InputFile')] [string[]]$FilePath, # Custom output file (-f / -OutFile / -of) @@ -11,9 +12,9 @@ param( [Alias('f', 'of')] [string]$OutFile, - # Auto output file switch (-s / -Save) + # Auto output file switch (-s / -Save / -o) [Parameter(Mandatory = $false, ParameterSetName = 'Generate')] - [Alias('s')] + [Alias('s', 'o')] [switch]$Save, # File containing checksums to verify (-c / -Check) @@ -69,10 +70,10 @@ DESCRIPTION Ignores checksum metadata files (.md5, .sha1, .sha256, .sha384, .sha512) during wildcards unless passed explicitly. PARAMETERS - -FilePath + -FilePath, -i, -input, -if, -InputFile Specifies the target file(s) or wildcard pattern (*). - -s, -S, -Save + -s, -S, -Save, -o, -O Auto-saves checksum results. (Takes no arguments). - If input filename contains a wildcard (*), saves to 'checksums.'. - If input filename does NOT contain a wildcard, saves to '.'. @@ -120,7 +121,8 @@ EXAMPLES 5. Compare file directly against an expected hash string: .\checksum.ps1 myfile.bin -m 406653a68bd3538975656831f33f031b -Priness Pi LOVES YOU!~ +Princess Pi LOVES YOU!~ +https://linktr.ee/princesspi3 '@ }; @@ -133,61 +135,64 @@ Priness Pi LOVES YOU!~ function Show-PrincessPiArt { $art = @' - .. ..... - ....------.. - ..:--------.. ....... - ..----------.. ....---.. - ...---------=------::....:----:.. - ..-----=+**************=-----:... - .----+****************=-----... - .--=****************=-----=**+:::--:.... - .-#*********##**++=---====++**+-----:. - ..:==********#=.+@%-==++===++===++*=----... - .:=::******%%+-::=++====+==++====+**=--... - .+..+*****--@===-:-%--====-=+====+*#=:.. - .-.-****#=.#+===--=+===----======+*+.. - .::=:+****#@#+=====-**-----*+====++**:. - .. .=****=--======-..%-----%+==++***+-.. - ..=++***+-.----======..*-----#+==+***#%#+.. - .. .:-..---=====--------=-+==+**-@*. ............::::::.... - ..=:..--===+-:-------*%+==*+#%**=. .....:-------------------------:. - ..............-:..--===+-..:-------+==+==.:... ...:----------------------------::. - ......:----------::=:...--==+--:.:-------+==+=:.... ....--------------------------:..... - ..:::----------------=-::.:--===---:.:------=--:.... ...:---------------------------... - ..:------------------=--:..:--=+=--------::.:+-..... ...------------------------------.. - ...:-----------------:....----==-------:...=%*.......:::--------------------------------:.. - ...--------------:+......---------------:+%%#.----------------------------:.......-----:.. - .:----===-------:-.. .:--------------*%%%%=--------------========------:.......-------:... - ..-:.:------------....-.=---------=#%%%%##%------------=-----------------------------------.. - .:--:....:--------:##*=:.-------=#%%%%%%#%+-----------=-------------------------------------: - ..:-----------------::*%%#-------=###%%%%##=--------------------------------------:............ - ..:-------------------:.-#%%##+==+%%%%%%#%+------------------------...:::--------------::::::.. - ...:----------------------..-#%#%%%%%%%%*+#%=-------------------------=-:....:----------------:... - --------------------------:.-#%%%%%%%%+#@%%%--------------------------=++=-::---------------:... - ---------------------------...+%%%%%]%%%%#---------------------------------------------:.... - ............------.....----:....-#%%%%%%%*=------------------------------::+=---------....... - ..:-... ....-----.. ....-=-------------------------------------.=*+=....... - ..---:....:-----:.......:--------------------------:-------------==+=-...... - .:-------------..........:---------------------------..:-------------==.......... - ..-------------:... ...--------:...----------------....:-----------==-........... - ..:----==------:..-.... ..--------:...:---------------.....:----------=+-..... - ..------==+=++==-..+--:. .:--------.....-----------=*%=.. ..----------=+=...... - ....------------........:... ..:--------.....-------+#%%#@%.. ...----------=+=...... - ..---------===:............... .:----=+*#=. ..--+#**+%@@@#%+. ..:-:..=----=*=*=:..... - :............:=::+=:--:=.=-.::=... ..*@*-+%@@@:.....-@@#%@*#@@@#%:.. ..-:..---:-#**+-......... - .. ...::::....::-.:.::-.. ..*%:..*@@@*.. ..-%#%@@+%@@@@=.. ...::.=#=..-%*++=:... ... - ...... .......... ..**...*#=*%:. .--*#@%+#%@@@@+... ..*%@%+...+%+=*+=-... - ..*#:.-#+..+-. .--*#**%%*%@@%=.. ..-%@@*:..+@%=:+**+=:.. - ..*@#*%%=..==. .-*%@#%@##@@@#-. ...#@@%*-=%@@#:..-=++=- - .:#@*-:++..==. .=#%@%*@@*%*=+*:....:.+@*::+%@@@%=......-* - .-%+...=%##%-. .+@*@%*%@##*-:*+..:-==*@=..:#@+:=*:....... - .:*#:..:*@@@%:. .--%@*%@#*%*#=..-%-....:+#=-.:#%-.:+-....... - .+@#=.-*@@@@*.. ....-%@@@@@@=..+%*.. .--%--=+#%-.:*-. .... - .-=++++++++=... .:***+++==::::... .-%#=-*#%#**#-. + + =#= -- ##*+++++ *+ + -#=#- +# -*%%= ##++++++++++# ##*********# + #==#= *** %%++%% -++# #++++++++++++*+ *#***************# + #===#= %***+%++#*%%@+++++% #++++++++++++**+++#******++********# + ====+#%@*******###%=%++##++% #+++++++++++*++++++++#***====+****++# + =#=*==**#*#########%++#*+++@ *++++++++#+++++++++++#****==+******# + *#=====%####***%%++++#*+++**% ++++++++*+++++++++++++#************#******* + @****#==%####**#*+++++++#+++#**# #+++++++++++++++++++#####+*****************# + @****#######%**@+*%**#%+++++%##*** #+++++++++++++++++#+++++++#****+======*****+ + #****##%####@**%+*******@@+++@###**% #+++++++++++++*++++++++++****========****# + ****#####%%*%*%+***@@@%%@*+++@####** *+++++++++++++++++++++#****=======****# + %***####%%**+%%*++*@=##@@%@++++%###*** +++++*+++++++++++#+**************# + @%%%@@##%%#++++++++==**@@**+++%*###**% +++++++++++#*+++++#*********#### + %###%++++++++====**#++++%**##**% @% ++++#+++++++++++++**************# + %###%++++++++++++++++++%**%##**%@###@ %++++++++++++++++***=====******** + ###%%++++++++%++++++*%%%%###***##%##@ +++++++++++++##**************# + ###%%%%+++++##+++++++#*+%###***%%%##@ ++++++++++++++%********+############%@ + @%%*@*%%%%###****+*%%****++%##***%##@@@ #+++++++++++++++*********###*****#########* + #%%###***#####%**++++##**%#@@#@ ##+++++++++*###%#+***+***##*************####### + @#%%####%%####%+++++++##*######%++++++++++++++#*+++++#%###%#######*********######% + ##%########@%@+++@###%*%#####@+++++++++++%**++++++++++%%%%%%########***==**###%##% + %#%###%###########@@%#%#@@##++++++++****++++********+++ %########**===*###%*# + #**##%####@@####%@######%*++++++++++++++++#++**+*#++++# ########******###% % + @#***# ###%@@##%#######@+++++++++++++++++++++%*++**++++# *########******##% @ + %*******% %##% =@#########++++++++++++++++++#++++*%++*#%#++# ########******##% + #@%@# %% *@#@@###*+++++++++++++++++++%+++##+++###++* ##*#####******##@ + **##%*++%++++++++++++++++++++++++++++++++% +#**#####******### + ##%#######*@***+#+++++++++++++++#***#++++++++++++ %**#####*******#% + *+++++++****##****++++++++##% #******#+++++++++++ %**#####*******#@ + #++++++++*******- ++++++++# *******#++++++++++# @**#####*******# + #@@+++++++******- *+++++++# #******#+++++++++* **####%**==+**@ + @@@@@+++ %+++++++# ******# %+++++++ %*###%***===**@ %= + @@@@@@@@@ #+++++++# =****** #++++++% *###%#***=+**% %** + @@@@@@@@@@ ++++++++# ******# #++++++# *##@%********% @*@ + @@+@@@++@@+ ++++++++# #******# #++++++# @## #*********@ #***# + @@+@@++@@@++ @@@++++++* @@@%**** #@@++++% +## %#****************% + @*@**@+++# @@@@+++++ @@@@@@**# @@@@+++# @# %#**************** + +#+++++# @@@@@@+++% @@@@@@@@# @@@@@@@++ @ %##************% + #+++** @@@@@@@@@@ @@@@@@@@@ @@@@@@@@@ %###********%* + @@@@@@@@@@+ @@@@@@@@@@ =@@@@@@@@@ %%#####%% + *@@@@@@@@@@ @+*@@@@@@@= @@++@@@@@@ + @++@@@@@@@@ #**@**@@@@@ *@@*#@@@@@@ -= + @%#@@@@@@@@ *#***@@@@@@ @+#+@++#@@@ + #+++@++@@@@@ **********# #+++++@+@@@@ + ##+#+++@@@@@@ ##****#### *+#+##+++@@%% + #+++++++++++# #++++++++++# + #########* + + ____ ____ ____ _ _ ___ ____ ___ ___ ____ ____ +( _ \( _ \(_ _)( \( )/ __)( ___)/ __)/ __) ( _ \(_ _)/\/ + )___/ ) / _)(_ ) (( (__ )__) \__ \\__ \ )___/ _)(_ +(__) (_)\_)(____)(_)\_)\___)(____)(___/(___/ (__) (____) + Princess Pi -https://linktr.ee/princesspi3 +https://linktr.ee/princesspi3 '@ - Write-Host $art -ForegroundColor Magenta; + Write-Host $art -ForegroundColor Blue; }; function Get-AlgorithmFromHashLength { @@ -315,7 +320,7 @@ process { $expectedHash = $Match.Trim().ToLower(); $totalFiles = $allItems.Count; - $currentIndex = 0; + $currentIndex = [ref]0; $results = $allItems | ForEach-Object -Parallel { $item = $_ @@ -334,8 +339,8 @@ process { } -ThrottleLimit 16; foreach ($res in $results) { - $currentIndex++; - Write-Progress -Activity "Matching Checksums ($Algorithm)" -Status "Processing file $currentIndex of $totalFiles" -PercentComplete (($currentIndex / $totalFiles) * 100); + $currentIndex.Value++; + Write-Progress -Activity "Matching Checksums ($Algorithm)" -Status "Processing file $($currentIndex.Value) of $totalFiles" -PercentComplete (($currentIndex.Value / $totalFiles) * 100); if ($res.IsMatch) { Write-Host "$($res.TargetFile): " -NoNewline; @@ -385,6 +390,8 @@ process { if ([string]::IsNullOrWhiteSpace($fileAlgo)) { $fileAlgo = 'SHA256'; }; }; + # Parse verification items + $verifyItems = @(); foreach ($line in ($lines)) { if ([string]::IsNullOrWhiteSpace($line) -or $line.StartsWith("#")) { continue; }; @@ -402,32 +409,63 @@ process { 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(); - - $displayPath = Resolve-Path -Path ($targetFullPath) -Relative -ErrorAction 'SilentlyContinue'; - if (-not $displayPath) { $displayPath = $targetFile; }; - if ($displayPath.StartsWith(".\") -or $displayPath.StartsWith("./")) { $displayPath = $displayPath.Substring(2); }; - - if ($actualHash -eq $expectedHash) { - Write-Host "${displayPath}: " -NoNewline; - Write-Host "OK" -ForegroundColor Green; - } else { - Write-Host "${displayPath}: " -NoNewline; - Write-Host "FAILED" -ForegroundColor Red; - }; - } else { - $displayPath = $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); }; - }; - Write-Host "${displayPath}: " -NoNewline; - Write-Host "FAILED open or read" -ForegroundColor Red; + $verifyItems += [PSCustomObject]@{ + ExpectedHash = $expectedHash + TargetFile = $targetFile + TargetFullPath = $targetFullPath + BaseDir = $baseDir }; - }; - }; + } + } + + $totalFiles = $verifyItems.Count; + $currentIndex = [ref]0; + + # Run verification items in parallel + $verifyResults = $verifyItems | ForEach-Object -Parallel { + $item = $_ + $algo = $using:fileAlgo + + if (Test-Path -Path ($item.TargetFullPath) -PathType 'Leaf') { + $actualHash = (Get-FileHash -Path ($item.TargetFullPath) -Algorithm ($algo)).Hash.ToLower(); + + $displayPath = Resolve-Path -Path ($item.TargetFullPath) -Relative -ErrorAction 'SilentlyContinue'; + if (-not $displayPath) { $displayPath = $item.TargetFile; }; + if ($displayPath.StartsWith(".\") -or $displayPath.StartsWith("./")) { $displayPath = $displayPath.Substring(2); }; + + [PSCustomObject]@{ + DisplayPath = $displayPath + Status = if ($actualHash -eq $item.ExpectedHash) { "OK" } else { "FAILED" } + IsError = $false + } + } else { + $displayPath = $item.TargetFile; + if ($item.BaseDir -ne (Get-Location).Path) { + $displayPath = Join-Path -Path (Resolve-Path -Path ($item.BaseDir) -Relative -ErrorAction 'SilentlyContinue') -ChildPath ($item.TargetFile); + if ($displayPath.StartsWith(".\") -or $displayPath.StartsWith("./")) { $displayPath = $displayPath.Substring(2); }; + }; + [PSCustomObject]@{ + DisplayPath = $displayPath + Status = "FAILED open or read" + IsError = $true + } + } + } -ThrottleLimit 16; + + foreach ($res in $verifyResults) { + $currentIndex.Value++; + Write-Progress -Activity "Verifying Checksums ($fileAlgo)" -Status "Processing file $($currentIndex.Value) of $totalFiles" -PercentComplete (($currentIndex.Value / $totalFiles) * 100); + + Write-Host "$($res.DisplayPath): " -NoNewline; + if ($res.IsError) { + Write-Host "$($res.Status)" -ForegroundColor Red; + } elseif ($res.Status -eq "OK") { + Write-Host "OK" -ForegroundColor Green; + } else { + Write-Host "FAILED" -ForegroundColor Red; + } + } + Write-Progress -Activity "Verifying Checksums ($fileAlgo)" -Completed; }; } # --- GENERATION MODE ---