diff --git a/Windows-Scripts/checksum.ps1 b/Windows-Scripts/checksum.ps1 index b6146da..c10ebee 100644 --- a/Windows-Scripts/checksum.ps1 +++ b/Windows-Scripts/checksum.ps1 @@ -52,6 +52,7 @@ param( begin { function Show-Help { @' + Princess Pi's Magical CHECKSUM! NAME @@ -123,74 +124,76 @@ EXAMPLES Princess Pi LOVES YOU!~ https://linktr.ee/princesspi3 + '@ }; function Write-ErrorWithHelp { param([string]$ErrorMessage); - Write-Error $ErrorMessage; - Write-Host ""; Show-Help; + Write-Host ""; + Write-Error $ErrorMessage; }; function Show-PrincessPiArt { $art = @' - =#= -- ##*+++++ *+ - -#=#- +# -*%%= ##++++++++++# ##*********# - #==#= *** %%++%% -++# #++++++++++++*+ *#***************# - #===#= %***+%++#*%%@+++++% #++++++++++++**+++#******++********# - ====+#%@*******###%=%++##++% #+++++++++++*++++++++#***====+****++# - =#=*==**#*#########%++#*+++@ *++++++++#+++++++++++#****==+******# - *#=====%####***%%++++#*+++**% ++++++++*+++++++++++++#************#******* - @****#==%####**#*+++++++#+++#**# #+++++++++++++++++++#####+*****************# - @****#######%**@+*%**#%+++++%##*** #+++++++++++++++++#+++++++#****+======*****+ - #****##%####@**%+*******@@+++@###**% #+++++++++++++*++++++++++****========****# - ****#####%%*%*%+***@@@%%@*+++@####** *+++++++++++++++++++++#****=======****# - %***####%%**+%%*++*@=##@@%@++++%###*** +++++*+++++++++++#+**************# - @%%%@@##%%#++++++++==**@@**+++%*###**% +++++++++++#*+++++#*********#### - %###%++++++++====**#++++%**##**% @% ++++#+++++++++++++**************# - %###%++++++++++++++++++%**%##**%@###@ %++++++++++++++++***=====******** - ###%%++++++++%++++++*%%%%###***##%##@ +++++++++++++##**************# - ###%%%%+++++##+++++++#*+%###***%%%##@ ++++++++++++++%********+############%@ + =#= -- ##*+++++ *+ + -#=#- +# -*%%= ##++++++++++# ##*********# + #==#= *** %%++%% -++# #++++++++++++*+ *#***************# + #===#= %***+%++#*%%@+++++% #++++++++++++**+++#******++********# + ====+#%@*******###%=%++##++% #+++++++++++*++++++++#***====+****++# + =#=*==**#*#########%++#*+++@ *++++++++#+++++++++++#****==+******# + *#=====%####***%%++++#*+++**% ++++++++*+++++++++++++#************#******* + @****#==%####**#*+++++++#+++#**# #+++++++++++++++++++#####+*****************# + @****#######%**@+*%**#%+++++%##*** #+++++++++++++++++#+++++#****+======*****+ + #****##%####@**%+*******@@+++@###**% #+++++++++++++*++++++++++****========****# + ****#####%%*%*%+***@@@%%@*+++@####** *+++++++++++++++++++++#****=======****# + %***####%%**+%%*++*@=##@@%@++++%###*** +++++*+++++++++++#+**************# + @%%%@@##%%#++++++++==**@@**+++%*###**% +++++++++++#*+++++#*********#### + %###%++++++++====**#++++%**##**% @% ++++#+++++++++++++**************# + %###%++++++++++++++++++%**%##**%@###@ %++++++++++++++++***=====******** + ###%%++++++++%++++++*%%%%###***##%##@ +++++++++++++##**************# + ###%%%%+++++##+++++++#*+%###***%%%##@ ++++++++++++++%********+############%@ @%%*@*%%%%###****+*%%****++%##***%##@@@ #+++++++++++++++*********###*****#########* - #%%###***#####%**++++##**%#@@#@ ##+++++++++*###%#+***+***##*************####### - @#%%####%%####%+++++++##*######%++++++++++++++#*+++++#%###%#######*********######% - ##%########@%@+++@###%*%#####@+++++++++++%**++++++++++%%%%%%########***==**###%##% - %#%###%###########@@%#%#@@##++++++++****++++********+++ %########**===*###%*# - #**##%####@@####%@######%*++++++++++++++++#++**+*#++++# ########******###% % - @#***# ###%@@##%#######@+++++++++++++++++++++%*++**++++# *########******##% @ - %*******% %##% =@#########++++++++++++++++++#++++*%++*#%#++# ########******##% - #@%@# %% *@#@@###*+++++++++++++++++++%+++##+++###++* ##*#####******##@ + #%%###***#####%**++++##**%#@@#@ ##+++++++++*###%#+***+***##*************####### + @#%%####%%####%+++++++##*######%++++++++++++++#*+++++#%###%#######*********######% + ##%########@%@+++@###%*%#####@+++++++++++%**++++++++++%%%%%%########***==**###%##% + %#%###%###########@@%#%#@@##++++++++****++++********+++ %########**===*###%*# + #**##%####@@####%@######%*++++++++++++++++#++**+*#++++# ########******###% % + @#***# ###%@@##%#######@+++++++++++++++++++++%*++**++++# *########******##% @ + *******% %##% =@#########++++++++++++++++++#++++*%++*#%#++# ########******##% + #@%@# %% *@#@@###*+++++++++++++++++++%+++##+++###++* ##*#####******##@ **##%*++%++++++++++++++++++++++++++++++++% +#**#####******### - ##%#######*@***+#+++++++++++++++#***#++++++++++++ %**#####*******#% - *+++++++****##****++++++++##% #******#+++++++++++ %**#####*******#@ - #++++++++*******- ++++++++# *******#++++++++++# @**#####*******# - #@@+++++++******- *+++++++# #******#+++++++++* **####%**==+**@ - @@@@@+++ %+++++++# ******# %+++++++ %*###%***===**@ %= - @@@@@@@@@ #+++++++# =****** #++++++% *###%#***=+**% %** - @@@@@@@@@@ ++++++++# ******# #++++++# *##@%********% @*@ - @@+@@@++@@+ ++++++++# #******# #++++++# @## #*********@ #***# - @@+@@++@@@++ @@@++++++* @@@%**** #@@++++% +## %#****************% - @*@**@+++# @@@@+++++ @@@@@@**# @@@@+++# @# %#**************** - +#+++++# @@@@@@+++% @@@@@@@@# @@@@@@@++ @ %##************% - #+++** @@@@@@@@@@ @@@@@@@@@ @@@@@@@@@ %###********%* - @@@@@@@@@@+ @@@@@@@@@@ =@@@@@@@@@ %%#####%% - *@@@@@@@@@@ @+*@@@@@@@= @@++@@@@@@ - @++@@@@@@@@ #**@**@@@@@ *@@*#@@@@@@ -= - @%#@@@@@@@@ *#***@@@@@@ @+#+@++#@@@ - #+++@++@@@@@ **********# #+++++@+@@@@ - ##+#+++@@@@@@ ##****#### *+#+##+++@@%% - #+++++++++++# #++++++++++# - #########* + ##%#######*@***+#+++++++++++++++#***#++++++++++++ %**#####*******#% + *+++++$****##****++++++++##% #******#+++++++++++ %**#####*******#@ + #++++++++*******- ++++++++# *******#++++++++++# @**#####*******# + #@@+++++++******- *+++++++# #******#+++++++++* **####%**==+**@ + @@@@@+++ %+++++++# ******# %+++++++ %*###%***===**@ %= + @@@@@@@@@ #+++++++# =****** #++++++% *###%#***=+**% %** + @@@@@@@@@@ ++++++++# ******# #++++++# *##@%********% @*@ + @@+@@@++@@+ ++++++++# ******# #++++++# @## #*********@ #***# + @@+@@++@@@++ @@@++++++* @@@%**** #@@++++% +## %#****************% + @*@**@+++# @@@@+++++ @@@@@@**# @@@@++++# @# %#**************** + +#+++++# @@@@@@+++% @@@@@@@@# @@@@@@@++ @ %##************% + #+++** @@@@@@@@@@ @@@@@@@@@ @@@@@@@@@ %###********%* + @@@@@@@@@@+ @@@@@@@@@@ =@@@@@@@@@ %%#####%% + *@@@@@@@@@@ @+*@@@@@@@= @@++@@@@@@ + @++@@@@@@@@ #**@**@@@@@ *@@*#@@@@@@ -= + @%#@@@@@@@@ *#***@@@@@@ @+#+@++#@@@ + #+++@++@@@@@ **********# #+++++@+@@@@ + ##+#+++@@@@@@ ##****#### *+#+##+++@@%% + #+++++++++++# #++++++++++# + #########* - ____ ____ ____ _ _ ___ ____ ___ ___ ____ ____ -( _ \( _ \(_ _)( \( )/ __)( ___)/ __)/ __) ( _ \(_ _)/\/ - )___/ ) / _)(_ ) (( (__ )__) \__ \\__ \ )___/ _)(_ -(__) (_)\_)(____)(_)\_)\___)(____)(___/(___/ (__) (____) + ____ ____ ____ _ _ ___ ____ ___ ___ ____ ____ + ( _ \( _ \(_ _)( \( )/ __)( ___)/ __)/ __) ( _ \(_ _)/\/ + )___/ ) / _)(_ ) (( (__ )__) \__ \\__ \ )___/ _)(_ + (__) (_)\_)(____)(_)\_)\___)(____)(___/(___/ (__) (____) Princess Pi -https://linktr.ee/princesspi3 +https://linktr.ee/princesspi3 + '@ Write-Host $art -ForegroundColor Blue; }; @@ -338,9 +341,13 @@ process { } } -ThrottleLimit 16; + $showProgressMatch = $Recursive.IsPresent -or $isWildcardGlobal; + foreach ($res in $results) { $currentIndex.Value++; - Write-Progress -Activity "Matching Checksums ($Algorithm)" -Status "Processing file $($currentIndex.Value) of $totalFiles" -PercentComplete (($currentIndex.Value / $totalFiles) * 100); + if ($showProgressMatch -and $totalFiles -gt 0) { + 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; @@ -348,9 +355,11 @@ process { } else { Write-Host "$($res.TargetFile): " -NoNewline; Write-Host "FAILED" -ForegroundColor Red; - }; + } }; - Write-Progress -Activity "Matching Checksums ($Algorithm)" -Completed; + if ($showProgressMatch) { + Write-Progress -Activity "Matching Checksums ($Algorithm)" -Completed; + } } # --- VERIFICATION MODE (-c / -Check) --- elseif ($PSCmdlet.ParameterSetName -eq 'Verify') { @@ -454,7 +463,9 @@ process { foreach ($res in $verifyResults) { $currentIndex.Value++; - Write-Progress -Activity "Verifying Checksums ($fileAlgo)" -Status "Processing file $($currentIndex.Value) of $totalFiles" -PercentComplete (($currentIndex.Value / $totalFiles) * 100); + if ($totalFiles -gt 0) { + 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) { @@ -477,6 +488,9 @@ process { $wantCustomOut = $PSBoundParameters.ContainsKey('OutFile'); $wantAutoOut = $Save.IsPresent; + # Show progress if wildcard used anywhere in inputs or recursive flag set + $showProgressGen = $Recursive.IsPresent -or $isWildcardGlobal; + if ($wantCustomOut -or $wantAutoOut) { # Recursive wildcard auto-saves per directory if ($Recursive -and $isWildcardGlobal) { @@ -499,12 +513,16 @@ process { $parallelResults = Invoke-ParallelHashing -Items $filesInDir -Algorithm $Algorithm; foreach ($res in $parallelResults) { $currentIndex++; - Write-Progress -Activity "Computing Checksums ($Algorithm)" -Status "Directory: $(Split-Path $dirPath -Leaf) [$currentIndex/$totalFiles]" -PercentComplete (($currentIndex / $totalFiles) * 100); + if ($showProgressGen -and $totalFiles -gt 0) { + Write-Progress -Activity "Computing Checksums ($Algorithm)" -Status "Directory: $(Split-Path $dirPath -Leaf) [$currentIndex/$totalFiles]" -PercentComplete (($currentIndex / $totalFiles) * 100); + } $linesToWrite += $res.OutputLine; Write-Output $res.OutputLine; } - Write-Progress -Activity "Computing Checksums ($Algorithm)" -Completed; + if ($showProgressGen) { + Write-Progress -Activity "Computing Checksums ($Algorithm)" -Completed; + } Set-Content -Path ($currentOutFile) -Value $linesToWrite -Encoding utf8; }; @@ -525,12 +543,16 @@ process { $parallelResults = Invoke-ParallelHashing -Items $allItems -Algorithm $Algorithm; foreach ($res in $parallelResults) { $currentIndex++; - Write-Progress -Activity "Computing Checksums ($Algorithm)" -Status "Processing file $currentIndex of $totalFiles" -PercentComplete (($currentIndex / $totalFiles) * 100); + if ($showProgressGen -and $totalFiles -gt 0) { + Write-Progress -Activity "Computing Checksums ($Algorithm)" -Status "Processing file $currentIndex of $totalFiles" -PercentComplete (($currentIndex / $totalFiles) * 100); + } $linesToWrite += $res.OutputLine; Write-Output $res.OutputLine; } - Write-Progress -Activity "Computing Checksums ($Algorithm)" -Completed; + if ($showProgressGen) { + Write-Progress -Activity "Computing Checksums ($Algorithm)" -Completed; + } Set-Content -Path ($singleOutFile) -Value $linesToWrite -Encoding utf8; } @@ -542,12 +564,16 @@ process { $parallelResults = Invoke-ParallelHashing -Items $allItems -Algorithm $Algorithm; foreach ($res in $parallelResults) { $currentIndex++; - Write-Progress -Activity "Computing Checksums ($Algorithm)" -Status "Processing file $currentIndex of $totalFiles" -PercentComplete (($currentIndex / $totalFiles) * 100); + if ($showProgressGen -and $totalFiles -gt 0) { + Write-Progress -Activity "Computing Checksums ($Algorithm)" -Status "Processing file $currentIndex of $totalFiles" -PercentComplete (($currentIndex / $totalFiles) * 100); + } Write-Output $res.OutputLine; Set-Content -Path ($res.ItemOutFile) -Value $res.OutputLine -Encoding utf8; } - Write-Progress -Activity "Computing Checksums ($Algorithm)" -Completed; + if ($showProgressGen) { + Write-Progress -Activity "Computing Checksums ($Algorithm)" -Completed; + } }; }; } @@ -559,11 +585,15 @@ process { $parallelResults = Invoke-ParallelHashing -Items $allItems -Algorithm $Algorithm; foreach ($res in $parallelResults) { $currentIndex++; - Write-Progress -Activity "Computing Checksums ($Algorithm)" -Status "Processing file $currentIndex of $totalFiles" -PercentComplete (($currentIndex / $totalFiles) * 100); + if ($showProgressGen -and $totalFiles -gt 0) { + Write-Progress -Activity "Computing Checksums ($Algorithm)" -Status "Processing file $currentIndex of $totalFiles" -PercentComplete (($currentIndex / $totalFiles) * 100); + } Write-Output $res.OutputLine; } - Write-Progress -Activity "Computing Checksums ($Algorithm)" -Completed; + if ($showProgressGen) { + Write-Progress -Activity "Computing Checksums ($Algorithm)" -Completed; + } }; } }