Make Self Modification impossible for 'tools/Do-PreProcessing.ps1' Script - Make the workingdir same as sync.PSScriptRoot for consistency

This commit is contained in:
Mr.k 2024-07-26 05:36:58 +03:00
parent a57c6a8b40
commit 5f885087fe
No known key found for this signature in database
2 changed files with 6 additions and 4 deletions

View File

@ -9,7 +9,7 @@ $workingdir = $PSScriptRoot
# Variable to sync between runspaces # Variable to sync between runspaces
$sync = [Hashtable]::Synchronized(@{}) $sync = [Hashtable]::Synchronized(@{})
$sync.PSScriptRoot = $PSScriptRoot $sync.PSScriptRoot = $workingdir
$sync.configs = @{} $sync.configs = @{}
function Update-Progress { function Update-Progress {

View File

@ -7,9 +7,11 @@ function Do-PreProcessing {
[string]$ProgressActivity = "Pre-Processing" [string]$ProgressActivity = "Pre-Processing"
) )
$excludedFiles = @('git\', '.gitignore', '.gitattributes', '.github\CODEOWNERS', 'LICENSE', 'winutil.ps1', 'docs\changelog.md', '*.png', '*.jpg', '*.jpeg', '*.exe') # We could do Pre-processing on this script file, but by excluding it.. we could possible weird behavior,
# like future runs of this tool being different then previous ones, as the script has modified it self before one or more times.
$excludedFiles = @('git\', '.gitignore', '.gitattributes', '.github\CODEOWNERS', 'LICENSE', 'winutil.ps1', 'tools\Do-PreProcessing.ps1', 'docs\changelog.md', '*.png', '*.jpg', '*.jpeg', '*.exe')
$files = Get-ChildItem $workingdir -Recurse -Exclude $excludedFiles -Attributes !Directory $files = Get-ChildItem $sync.PSScriptRoot -Recurse -Exclude $excludedFiles -Attributes !Directory
$numOfFiles = $files.Count $numOfFiles = $files.Count
for ($i = 0; $i -lt $numOfFiles; $i++) { for ($i = 0; $i -lt $numOfFiles; $i++) {
@ -24,7 +26,7 @@ function Do-PreProcessing {
-replace ('try\{', 'try {') ` -replace ('try\{', 'try {') `
-replace ('try\r?\n\s*\{', 'try {') ` -replace ('try\r?\n\s*\{', 'try {') `
-replace ('}\r?\n\s*catch', '} catch') ` -replace ('}\r?\n\s*catch', '} catch') `
-replace ('\} catch', '} catch') ` -replace ('\} Catch', '} catch') `
| Set-Content "$file" | Set-Content "$file"
Write-Progress -Activity $ProgressActivity -Status "$ProgressStatusMessage - Finished $i out of $numOfFiles" -PercentComplete (($i/$numOfFiles)*100) Write-Progress -Activity $ProgressActivity -Status "$ProgressStatusMessage - Finished $i out of $numOfFiles" -PercentComplete (($i/$numOfFiles)*100)
} }