From 34bf3cfb812112003f97ab253d0854e3034c7bb3 Mon Sep 17 00:00:00 2001 From: "Mr.k" Date: Mon, 19 Aug 2024 21:12:20 +0300 Subject: [PATCH 01/12] Update documentation for 'Invoke-Preprocessing' Script Tool --- tools/Invoke-Preprocessing.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/Invoke-Preprocessing.ps1 b/tools/Invoke-Preprocessing.ps1 index c9692fc68f..22130d4feb 100644 --- a/tools/Invoke-Preprocessing.ps1 +++ b/tools/Invoke-Preprocessing.ps1 @@ -39,7 +39,7 @@ .EXAMPLE Invoke-Preprocessing -ThrowExceptionOnEmptyFilesList -WorkingDir "DRIVE:\Path\To\Folder\" -ExcludedFiles @('file.txt', '.\.git\', '*.png') -ProgressStatusMessage "Doing Preprocessing" - Same as Example No. 1, but will throw an exception when 'Invoke-Preprocessing' function doesn't find any files in 'WorkingDir' (not including 'ExcludedFiles' list). + Same as Example No. 1, but uses '-ThrowExceptionOnEmptyFilesList', which's an optional parameter that'll make 'Invoke-Preprocessing' throw an exception when no files are found in 'WorkingDir' (not including the ExcludedFiles, of course), useful when you want to double check your parameters & you're sure there's files to process in the 'WorkingDir'. .EXAMPLE Invoke-Preprocessing -Skip -WorkingDir "DRIVE:\Path\To\Folder\" -ExcludedFiles @('file.txt', '.\.git\', '*.png') -ProgressStatusMessage "Doing Preprocessing" From 3c634a5b8738936e0bfee360b9a2c23b7839ead2 Mon Sep 17 00:00:00 2001 From: "Mr.k" Date: Mon, 19 Aug 2024 21:20:14 +0300 Subject: [PATCH 02/12] Improve Compile Script a bit Deduplicating a lot of un-needed pre-fixes - Improve implementation for 'Invoke-Preprocessing' Script Tool --- Compile.ps1 | 41 +++++++++-------- functions/private/Get-TabXaml.ps1 | 2 +- tools/Invoke-Preprocessing.ps1 | 75 ++++++++++++++++++++++--------- 3 files changed, 78 insertions(+), 40 deletions(-) diff --git a/Compile.ps1 b/Compile.ps1 index f86fbce62e..2e42c4802e 100644 --- a/Compile.ps1 +++ b/Compile.ps1 @@ -7,6 +7,9 @@ $OFS = "`r`n" $scriptname = "winutil.ps1" $workingdir = $PSScriptRoot +Push-Location +Set-Location $workingdir + # Variable to sync between runspaces $sync = [Hashtable]::Synchronized(@{}) $sync.PSScriptRoot = $workingdir @@ -41,11 +44,11 @@ if (-NOT $SkipPreprocessing) { # Dot source the 'Invoke-Preprocessing' Function from 'tools/Invoke-Preprocessing.ps1' Script $preprocessingFilePath = ".\tools\Invoke-Preprocessing.ps1" - . "$(($workingdir -replace ('\\$', '')) + '\' + ($preprocessingFilePath -replace ('\.\\', '')))" + . $preprocessingFilePath $excludedFiles = @('.\.git\', '.\.gitignore', '.\.gitattributes', '.\.github\CODEOWNERS', '.\LICENSE', "$preprocessingFilePath", '*.png', '*.exe') $msg = "Pre-req: Code Formatting" - Invoke-Preprocessing -WorkingDir "$workingdir" -ExcludedFiles $excludedFiles -ProgressStatusMessage $msg + Invoke-Preprocessing -WorkingDir "$workingdir" -ExcludedFiles $excludedFiles -ProgressStatusMessage $msg -ThrowExceptionOnEmptyFilesList } # Create the script in memory. @@ -56,14 +59,14 @@ Update-Progress "Adding: Header" 5 $script_content.Add($header) Update-Progress "Adding: Version" 10 -$script_content.Add($(Get-Content "$workingdir\scripts\start.ps1").replace('#{replaceme}',"$(Get-Date -Format yy.MM.dd)")) +$script_content.Add($(Get-Content "scripts\start.ps1").replace('#{replaceme}',"$(Get-Date -Format yy.MM.dd)")) Update-Progress "Adding: Functions" 20 -Get-ChildItem "$workingdir\functions" -Recurse -File | ForEach-Object { +Get-ChildItem "functions" -Recurse -File | ForEach-Object { $script_content.Add($(Get-Content $psitem.FullName)) } Update-Progress "Adding: Config *.json" 40 -Get-ChildItem "$workingdir\config" | Where-Object {$psitem.extension -eq ".json"} | ForEach-Object { +Get-ChildItem "config" | Where-Object {$psitem.extension -eq ".json"} | ForEach-Object { $json = (Get-Content $psitem.FullName).replace("'","''") @@ -108,10 +111,10 @@ Get-ChildItem "$workingdir\config" | Where-Object {$psitem.extension -eq ".json" $script_content.Add($(Write-output "`$sync.configs.$($psitem.BaseName) = '$json' `| convertfrom-json" )) } -$xaml = (Get-Content "$workingdir\xaml\inputXML.xaml").replace("'","''") +$xaml = (Get-Content "xaml\inputXML.xaml").replace("'","''") # Dot-source the Get-TabXaml function -. "$workingdir\functions\private\Get-TabXaml.ps1" +. "functions\private\Get-TabXaml.ps1" Update-Progress "Building: Xaml " 75 $appXamlContent = Get-TabXaml "applications" 5 @@ -127,28 +130,27 @@ $xaml = $xaml -replace "{{InstallPanel_features}}", $featuresXamlContent $script_content.Add($(Write-output "`$inputXML = '$xaml'")) -$script_content.Add($(Get-Content "$workingdir\scripts\main.ps1")) +$script_content.Add($(Get-Content "scripts\main.ps1")) if ($Debug) { Update-Progress "Writing debug files" 95 - $appXamlContent | Out-File -FilePath "$workingdir\xaml\inputApp.xaml" -Encoding ascii - $tweaksXamlContent | Out-File -FilePath "$workingdir\xaml\inputTweaks.xaml" -Encoding ascii - $featuresXamlContent | Out-File -FilePath "$workingdir\xaml\inputFeatures.xaml" -Encoding ascii + $appXamlContent | Out-File -FilePath "xaml\inputApp.xaml" -Encoding ascii + $tweaksXamlContent | Out-File -FilePath "xaml\inputTweaks.xaml" -Encoding ascii + $featuresXamlContent | Out-File -FilePath "xaml\inputFeatures.xaml" -Encoding ascii } else { Update-Progress "Removing temporary files" 99 - Remove-Item "$workingdir\xaml\inputApp.xaml" -ErrorAction SilentlyContinue - Remove-Item "$workingdir\xaml\inputTweaks.xaml" -ErrorAction SilentlyContinue - Remove-Item "$workingdir\xaml\inputFeatures.xaml" -ErrorAction SilentlyContinue + Remove-Item "xaml\inputApp.xaml" -ErrorAction SilentlyContinue + Remove-Item "xaml\inputTweaks.xaml" -ErrorAction SilentlyContinue + Remove-Item "xaml\inputFeatures.xaml" -ErrorAction SilentlyContinue } -Set-Content -Path "$workingdir\$scriptname" -Value ($script_content -join "`r`n") -Encoding ascii +Set-Content -Path "$scriptname" -Value ($script_content -join "`r`n") -Encoding ascii Write-Progress -Activity "Compiling" -Completed Update-Progress -Activity "Validating" -StatusMessage "Checking winutil.ps1 Syntax" -Percent 0 try { $null = Get-Command -Syntax .\winutil.ps1 -} -catch { +} catch { Write-Warning "Syntax Validation for 'winutil.ps1' has failed" Write-Host "$($Error[0])" -ForegroundColor Red } @@ -156,9 +158,10 @@ Write-Progress -Activity "Validating" -Completed if ($run) { try { - Start-Process -FilePath "pwsh" -ArgumentList "$workingdir\$scriptname" + Start-Process -FilePath "pwsh" -ArgumentList "$scriptname" } catch { - Start-Process -FilePath "powershell" -ArgumentList "$workingdir\$scriptname" + Start-Process -FilePath "powershell" -ArgumentList "$scriptname" } } +Pop-Location diff --git a/functions/private/Get-TabXaml.ps1 b/functions/private/Get-TabXaml.ps1 index 5eef64176f..c58974f134 100644 --- a/functions/private/Get-TabXaml.ps1 +++ b/functions/private/Get-TabXaml.ps1 @@ -119,7 +119,7 @@ function Get-TabXaml { } # Dot-source the Get-WPFObjectName function - . "$($sync.PSScriptRoot)\functions\private\Get-WPFObjectName.ps1" + . "functions\private\Get-WPFObjectName.ps1" $categorycontent = $($category -replace '^.__', '') $categoryname = Get-WPFObjectName -type "Label" -name $categorycontent diff --git a/tools/Invoke-Preprocessing.ps1 b/tools/Invoke-Preprocessing.ps1 index 22130d4feb..092799d255 100644 --- a/tools/Invoke-Preprocessing.ps1 +++ b/tools/Invoke-Preprocessing.ps1 @@ -73,6 +73,18 @@ } $count = $ExcludedFiles.Count + + # Make sure there's a * at the end of folders in ExcludedFiles list + if ($count -gt 0) { + for ($i = 0; $i -lt $count; $i++) { + $excludedFile = $ExcludedFiles[$i] + $isFolder = ($excludedFile) -match '\\$' + if ($isFolder) { $ExcludedFiles[$i] = $excludedFile + '*' } + } + } + + # Validate the ExcludedFiles List before continuing on, + # that's if there's a list in the first place, and '-SkipExcludedFilesValidation' was not provided. if ((-NOT ($count -eq 0)) -AND (-NOT $SkipExcludedFilesValidation)) { for ($i = 0; $i -lt $count; $i++) { $excludedFile = $ExcludedFiles[$i] @@ -83,11 +95,49 @@ } $failedFilesList = $failedFilesList -replace (',\s*$', '') if (-NOT $failedFilesList -eq "") { - throw "[Invoke-Preprocessing] One or more File Paths & File Patterns were not found, you can use '-SkipExcludedFilesValidation' switch to skip this check, and the failed files are: $failedFilesList" + throw "[Invoke-Preprocessing] One or more File Paths and/or File Patterns were not found, you can use '-SkipExcludedFilesValidation' switch to skip this check, the failed to validate are: $failedFilesList" + } + } + + # Get Files List + [System.Collections.ArrayList]$files = Get-ChildItem $WorkingDir -Recurse -Exclude $ExcludedFiles -File + $numOfFiles = $files.Count + + # Only keep the 'FullName' Property for every entry in the list + for ($i = 0; $i -lt $numOfFiles; $i++) { + $file = $files[$i] + $files[$i] = $file.FullName + } + + # If a file(s) are found in Exclude List, + # Remove the file from files list. + for ($j = 0; $j -lt $excludedFiles.Count; $j++) { + # Prepare some variables + $excluded = $excludedFiles[$j] + $pathToFind = ($excluded) -replace ('^\.\\', '') + $pathToFind = $WorkingDir + '\' + $pathToFind + $index = -1 # reset index on every iteration + + # Handle paths with wildcards in a different implementation + $matches = ($pathToFind) -match '^.*?\*' + + if ($matches) { + $filesToCheck = Get-ChildItem -Recurse -Path "$pathToFind" -File + if ($filesToCheck) { + for ($k = 0; $k -lt $filesToCheck.Count; $k++) { + $fileToCheck = $filesToCheck[$k] + $index = $files.IndexOf("$fileToCheck") + if ($index -ge 0) { $files.RemoveAt($index) } + } + } + } else { + $index = $files.IndexOf("$pathToFind") + if ($index -ge 0) { $files.RemoveAt($index) } } } - $files = Get-ChildItem $WorkingDir -Recurse -Exclude $ExcludedFiles -File + # Make sure 'numOfFiles' is synced with the actual Number of Files found in '$files' + # This's done because previous may or may not edit the files list, so we should update it $numOfFiles = $files.Count if ($numOfFiles -eq 0) { @@ -99,26 +149,11 @@ } for ($i = 0; $i -lt $numOfFiles; $i++) { - $file = $files[$i] - - # If the file is in Exclude List, don't proceed to check/modify said file. - $fileIsExcluded = $False - for ($j = 0; $j -lt $excludedFiles.Count; $j++) { - $excluded = $excludedFiles[$j] - $strToCompare = ($excluded) -replace ('^\.\\', '') - if ($file.FullName.Contains("$strToCompare")) { - $fileIsExcluded = $True - break - } - } - - if ($fileIsExcluded) { - continue - } + $fullFileName = $files[$i] # TODO: # make more formatting rules, and document them in WinUtil Official Documentation - (Get-Content "$file").TrimEnd() ` + (Get-Content "$fullFileName").TrimEnd() ` -replace ('\t', ' ') ` -replace ('\)\s*\{', ') {') ` -replace ('(?if|for|foreach)\s*(?\([.*?]\))\s*\{', '${keyword} ${condition} {') ` @@ -130,7 +165,7 @@ -replace ('\}\s*Catch\s*(?(\[.*?\]\s*(\,)?\s*)+)\s*\{', '} catch ${exceptions} {') ` -replace ('\}\s*Catch\s*(?\[.*?\])\s*\{', '} catch ${exceptions} {') ` -replace ('(?\[.*?\])\s*(?\$.*?(,|\s*\)))', '${parameter_type}${str_after_type}') ` - | Set-Content "$file" + | Set-Content "$fullFileName" Write-Progress -Activity $ProgressActivity -Status "$ProgressStatusMessage - Finished $i out of $numOfFiles" -PercentComplete (($i/$numOfFiles)*100) } From b07cd88d109b313832b605c7d39f38ec608e9882 Mon Sep 17 00:00:00 2001 From: "Mr.k" Date: Mon, 19 Aug 2024 21:31:22 +0300 Subject: [PATCH 03/12] Fix RegEx in 'Invoke-Preprocessing' Script Tool --- tools/Invoke-Preprocessing.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/Invoke-Preprocessing.ps1 b/tools/Invoke-Preprocessing.ps1 index 092799d255..854584803a 100644 --- a/tools/Invoke-Preprocessing.ps1 +++ b/tools/Invoke-Preprocessing.ps1 @@ -164,7 +164,7 @@ -replace ('\}\s*Catch', '} catch') ` -replace ('\}\s*Catch\s*(?(\[.*?\]\s*(\,)?\s*)+)\s*\{', '} catch ${exceptions} {') ` -replace ('\}\s*Catch\s*(?\[.*?\])\s*\{', '} catch ${exceptions} {') ` - -replace ('(?\[.*?\])\s*(?\$.*?(,|\s*\)))', '${parameter_type}${str_after_type}') ` + -replace ('(?\[[^$]+\])\s*(?\$.*?)', '${parameter_type}${str_after_type}') ` | Set-Content "$fullFileName" Write-Progress -Activity $ProgressActivity -Status "$ProgressStatusMessage - Finished $i out of $numOfFiles" -PercentComplete (($i/$numOfFiles)*100) From 521b57be468c3591e688112582cf292978780f1a Mon Sep 17 00:00:00 2001 From: "Mr.k" Date: Mon, 19 Aug 2024 21:32:06 +0300 Subject: [PATCH 04/12] Result of Preprocessing --- .github/SECURITY.md | 2 +- .github/workflows/github-pages.yaml | 2 +- config/autounattend.xml | 2 +- scripts/main.ps1 | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/SECURITY.md b/.github/SECURITY.md index 6b43703354..be3f8839ed 100644 --- a/.github/SECURITY.md +++ b/.github/SECURITY.md @@ -1,5 +1,5 @@ # Security Policy -If you find a security issue please make post it in the issues tab. If you think it should be private you can email me at contact@christitus.com. +If you find a security issue please make post it in the issues tab. If you think it should be private you can email me at contact@christitus.com. For immediate response check out our discord server @ [![](https://dcbadge.limes.pink/api/server/https://discord.gg/RUbZUZyByQ?theme=default-inverted&style=for-the-badge)](https://discord.gg/RUbZUZyByQ) diff --git a/.github/workflows/github-pages.yaml b/.github/workflows/github-pages.yaml index b51697b85e..d6db1edc24 100644 --- a/.github/workflows/github-pages.yaml +++ b/.github/workflows/github-pages.yaml @@ -28,4 +28,4 @@ jobs: run: pip install -r .github/requirements.txt - name: Build & Deploy using 'mkdocs' - run: mkdocs gh-deploy --force -f .github/mkdocs.yml \ No newline at end of file + run: mkdocs gh-deploy --force -f .github/mkdocs.yml diff --git a/config/autounattend.xml b/config/autounattend.xml index c3a2f2138c..6a432641b9 100644 --- a/config/autounattend.xml +++ b/config/autounattend.xml @@ -293,7 +293,7 @@ param( - [xml] $Document + [xml]$Document ); $scriptsDir = 'C:\Windows\Setup\Scripts\'; diff --git a/scripts/main.ps1 b/scripts/main.ps1 index c1d476f43a..ac27fa12da 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -32,19 +32,19 @@ $sync.runspace.Open() # Create classes for different exceptions class WingetFailedInstall : Exception { - [string] $additionalData + [string]$additionalData WingetFailedInstall($Message) : base($Message) {} } class ChocoFailedInstall : Exception { - [string] $additionalData + [string]$additionalData ChocoFailedInstall($Message) : base($Message) {} } class GenericException : Exception { - [string] $additionalData + [string]$additionalData GenericException($Message) : base($Message) {} } From d81b5f0fb43790fe171d0f57f167e060459dd268 Mon Sep 17 00:00:00 2001 From: "Mr.k" Date: Wed, 21 Aug 2024 16:59:53 +0300 Subject: [PATCH 05/12] Update Replace Regex for Code Formatting in 'Invoke-Preprocessing' Script Tool --- tools/Invoke-Preprocessing.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/Invoke-Preprocessing.ps1 b/tools/Invoke-Preprocessing.ps1 index 854584803a..5267db5fa5 100644 --- a/tools/Invoke-Preprocessing.ps1 +++ b/tools/Invoke-Preprocessing.ps1 @@ -164,7 +164,7 @@ -replace ('\}\s*Catch', '} catch') ` -replace ('\}\s*Catch\s*(?(\[.*?\]\s*(\,)?\s*)+)\s*\{', '} catch ${exceptions} {') ` -replace ('\}\s*Catch\s*(?\[.*?\])\s*\{', '} catch ${exceptions} {') ` - -replace ('(?\[[^$]+\])\s*(?\$.*?)', '${parameter_type}${str_after_type}') ` + -replace ('(?\[[^$0-9]+\])\s*(?\$.*?)', '${parameter_type}${str_after_type}') ` | Set-Content "$fullFileName" Write-Progress -Activity $ProgressActivity -Status "$ProgressStatusMessage - Finished $i out of $numOfFiles" -PercentComplete (($i/$numOfFiles)*100) From 07e154459de7083171aa7f08973ff9afdf70ab0c Mon Sep 17 00:00:00 2001 From: "Mr.k" Date: Wed, 21 Aug 2024 17:00:06 +0300 Subject: [PATCH 06/12] Result of Preprocessing --- functions/private/Invoke-WinUtilMicroWin-Helper.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functions/private/Invoke-WinUtilMicroWin-Helper.ps1 b/functions/private/Invoke-WinUtilMicroWin-Helper.ps1 index b568b83928..1821965a30 100644 --- a/functions/private/Invoke-WinUtilMicroWin-Helper.ps1 +++ b/functions/private/Invoke-WinUtilMicroWin-Helper.ps1 @@ -248,8 +248,8 @@ function Remove-FileOrDirectory([string]$pathToDelete, [string]$mask = "", [swit function New-Unattend { param ( - [Parameter(Mandatory, Position = 0)] [string] $userName, - [Parameter(Position = 1)] [string] $userPassword + [Parameter(Mandatory, Position = 0)] [string]$userName, + [Parameter(Position = 1)] [string]$userPassword ) $unattend = @' From 674ab0308b71fd6c3215922268c6979f50425a11 Mon Sep 17 00:00:00 2001 From: "Mr.k" Date: Fri, 23 Aug 2024 00:28:39 +0300 Subject: [PATCH 07/12] Update Exclude Files List for Preprocessing in 'Compile.ps1' Script --- Compile.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Compile.ps1 b/Compile.ps1 index 2e42c4802e..380dc4ebd8 100644 --- a/Compile.ps1 +++ b/Compile.ps1 @@ -46,7 +46,7 @@ if (-NOT $SkipPreprocessing) { $preprocessingFilePath = ".\tools\Invoke-Preprocessing.ps1" . $preprocessingFilePath - $excludedFiles = @('.\.git\', '.\.gitignore', '.\.gitattributes', '.\.github\CODEOWNERS', '.\LICENSE', "$preprocessingFilePath", '*.png', '*.exe') + $excludedFiles = @('.\.git\', '.\.gitignore', '.\.gitattributes', '.\.github\CODEOWNERS', '.\.github\LICENSE', "$preprocessingFilePath", '*.png', '*.exe') $msg = "Pre-req: Code Formatting" Invoke-Preprocessing -WorkingDir "$workingdir" -ExcludedFiles $excludedFiles -ProgressStatusMessage $msg -ThrowExceptionOnEmptyFilesList } From 558c634b70dbf198ce77c331a20bca89bd7c8093 Mon Sep 17 00:00:00 2001 From: "Mr.k" Date: Fri, 23 Aug 2024 00:29:49 +0300 Subject: [PATCH 08/12] Remove Extra Whitespace in some place for 'Invoke-Preprocessing.ps1' Script Tool --- tools/Invoke-Preprocessing.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/Invoke-Preprocessing.ps1 b/tools/Invoke-Preprocessing.ps1 index 5267db5fa5..bc1dcc8b66 100644 --- a/tools/Invoke-Preprocessing.ps1 +++ b/tools/Invoke-Preprocessing.ps1 @@ -47,7 +47,7 @@ Same as Example No. 1, but uses '-SkipExcludedFilesValidation', which'll skip the validation step for 'ExcludedFiles' list. This can be useful when 'ExcludedFiles' list is generated from another function, or from unreliable source (you can't guarantee every item in list is a valid path), but you want to silently continue through the function. #> - param ( + param ( [Parameter(position=0)] [switch]$SkipExcludedFilesValidation, @@ -66,7 +66,7 @@ [Parameter(position=5)] [string]$ProgressActivity = "Preprocessing" - ) + ) if (-NOT (Test-Path -PathType Container -Path "$WorkingDir")) { throw "[Invoke-Preprocessing] Invalid Paramter Value for 'WorkingDir', passed value: '$WorkingDir'. Either the path is a File or Non-Existing/Invlid, please double check your code." From 895a95ccf67bf9e853d9019317b101c99439c709 Mon Sep 17 00:00:00 2001 From: "Mr.k" Date: Fri, 23 Aug 2024 00:30:24 +0300 Subject: [PATCH 09/12] Simplified and Improved the Exclude List Validation Step in 'Invoke-Preprocessing.ps1' Script Tool --- tools/Invoke-Preprocessing.ps1 | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/tools/Invoke-Preprocessing.ps1 b/tools/Invoke-Preprocessing.ps1 index bc1dcc8b66..96b919d197 100644 --- a/tools/Invoke-Preprocessing.ps1 +++ b/tools/Invoke-Preprocessing.ps1 @@ -75,22 +75,30 @@ $count = $ExcludedFiles.Count # Make sure there's a * at the end of folders in ExcludedFiles list - if ($count -gt 0) { - for ($i = 0; $i -lt $count; $i++) { - $excludedFile = $ExcludedFiles[$i] - $isFolder = ($excludedFile) -match '\\$' - if ($isFolder) { $ExcludedFiles[$i] = $excludedFile + '*' } - } + for ($i = 0; $i -lt $count; $i++) { + $excludedFile = $ExcludedFiles[$i] + $isFolder = ($excludedFile) -match '\\$' + if ($isFolder) { $ExcludedFiles[$i] = $excludedFile + '*' } } # Validate the ExcludedFiles List before continuing on, # that's if there's a list in the first place, and '-SkipExcludedFilesValidation' was not provided. - if ((-NOT ($count -eq 0)) -AND (-NOT $SkipExcludedFilesValidation)) { + if (-not $SkipExcludedFilesValidation) { for ($i = 0; $i -lt $count; $i++) { $excludedFile = $ExcludedFiles[$i] $filePath = "$(($WorkingDir -replace ('\\$', '')) + '\' + ($excludedFile -replace ('\.\\', '')))" - if (-NOT (Get-ChildItem -Recurse -Path "$filePath" -File)) { - $failedFilesList += "'$filePath', " + + # Handle paths with wildcards in a different implementation + $matches = ($filePath) -match '^.*?\*' + + if ($matches) { + if (-NOT (Get-ChildItem -Recurse -Path "$filePath" -File)) { + $failedFilesList += "'$filePath', " + } + } else { + if (-NOT (Test-Path -Path "$filePath")) { + $failedFilesList += "'$filePath', " + } } } $failedFilesList = $failedFilesList -replace (',\s*$', '') From d8b815e510b3139995251216cf85cb113ed0b23b Mon Sep 17 00:00:00 2001 From: "Mr.k" Date: Sat, 31 Aug 2024 09:55:18 +0300 Subject: [PATCH 10/12] Restore 'workingdir' variable when using '-Run' Parameter with 'Compile.ps1' Script --- Compile.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Compile.ps1 b/Compile.ps1 index 94acd778de..75998956b2 100644 --- a/Compile.ps1 +++ b/Compile.ps1 @@ -121,7 +121,7 @@ try { Write-Progress -Activity "Validating" -Completed if ($run) { - $script = "& '$scriptname' $Arguments" + $script = "& '$workingdir\$scriptname' $Arguments" $powershellcmd = if (Get-Command pwsh -ErrorAction SilentlyContinue) { "pwsh" } else { "powershell" } $processCmd = if (Get-Command wt.exe -ErrorAction SilentlyContinue) { "wt.exe" } else { $powershellcmd } From 848d81b96bc5e7a6a2176af9024f6d069f0383be Mon Sep 17 00:00:00 2001 From: "Mr.k" Date: Sat, 31 Aug 2024 09:55:27 +0300 Subject: [PATCH 11/12] Revert "Update Exclude Files List for Preprocessing in 'Compile.ps1' Script" This reverts commit 674ab0308b71fd6c3215922268c6979f50425a11. --- Compile.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Compile.ps1 b/Compile.ps1 index 75998956b2..c9d4355587 100644 --- a/Compile.ps1 +++ b/Compile.ps1 @@ -47,7 +47,7 @@ if (-NOT $SkipPreprocessing) { $preprocessingFilePath = ".\tools\Invoke-Preprocessing.ps1" . $preprocessingFilePath - $excludedFiles = @('.\.git\', '.\.gitignore', '.\.gitattributes', '.\.github\CODEOWNERS', '.\.github\LICENSE', "$preprocessingFilePath", '*.png', '*.exe') + $excludedFiles = @('.\.git\', '.\.gitignore', '.\.gitattributes', '.\.github\CODEOWNERS', '.\LICENSE', "$preprocessingFilePath", '*.png', '*.exe') $msg = "Pre-req: Code Formatting" Invoke-Preprocessing -WorkingDir "$workingdir" -ExcludedFiles $excludedFiles -ProgressStatusMessage $msg -ThrowExceptionOnEmptyFilesList } From 9027494f421b9cba85c8c3ea252a1747591321dd Mon Sep 17 00:00:00 2001 From: "Mr.k" Date: Sat, 31 Aug 2024 09:56:42 +0300 Subject: [PATCH 12/12] Result of Preprocessing --- .github/workflows/pre-release.yaml | 2 +- functions/private/Invoke-WinUtilGPU.ps1 | 2 +- functions/private/Invoke-WinUtilMicroWin-Helper.ps1 | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pre-release.yaml b/.github/workflows/pre-release.yaml index c8c0eda9a2..5d52e967c5 100644 --- a/.github/workflows/pre-release.yaml +++ b/.github/workflows/pre-release.yaml @@ -91,7 +91,7 @@ jobs: name: Pre-Release ${{ env.version }} body: | ${{ steps.generate_notes.outputs.body }} - + ![GitHub Downloads (specific asset, specific tag)](https://img.shields.io/github/downloads/ChrisTitusTech/winutil/${{ env.VERSION }}/winutil.ps1) append_body: false files: ./winutil.ps1 diff --git a/functions/private/Invoke-WinUtilGPU.ps1 b/functions/private/Invoke-WinUtilGPU.ps1 index 2bcbb01b00..6ec42d7afe 100644 --- a/functions/private/Invoke-WinUtilGPU.ps1 +++ b/functions/private/Invoke-WinUtilGPU.ps1 @@ -20,4 +20,4 @@ function Invoke-WinUtilGPU { } } return $true -} \ No newline at end of file +} diff --git a/functions/private/Invoke-WinUtilMicroWin-Helper.ps1 b/functions/private/Invoke-WinUtilMicroWin-Helper.ps1 index d1061d67f3..5590d501af 100644 --- a/functions/private/Invoke-WinUtilMicroWin-Helper.ps1 +++ b/functions/private/Invoke-WinUtilMicroWin-Helper.ps1 @@ -259,7 +259,7 @@ function New-Unattend { param ( [Parameter(Mandatory, Position = 0)] [string]$userName, - [Parameter(Position = 1)] [string] $userPassword + [Parameter(Position = 1)] [string]$userPassword ) $unattend = @'