From 932760cbdf7bd35e7d5e0f119c14757409a275fd Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 12 Apr 2025 17:50:03 +0200 Subject: [PATCH 1/6] Counter in Remove-ModsLnk --- Sources/Winget-AutoUpdate/mods/_Mods-Functions.ps1 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Sources/Winget-AutoUpdate/mods/_Mods-Functions.ps1 b/Sources/Winget-AutoUpdate/mods/_Mods-Functions.ps1 index 01955c7d..637a8049 100644 --- a/Sources/Winget-AutoUpdate/mods/_Mods-Functions.ps1 +++ b/Sources/Winget-AutoUpdate/mods/_Mods-Functions.ps1 @@ -141,10 +141,15 @@ Function Process-installedSoftware() { } function Remove-ModsLnk ($Lnk) { + $removedCount = 0 foreach ($link in $Lnk) { - Remove-Item -Path "${env:Public}\Desktop\$link.lnk" -Force -ErrorAction SilentlyContinue | Out-Null + $linkPath = "${env:Public}\Desktop\$link.lnk" + if (Test-Path $linkPath) { + Remove-Item -Path $linkPath -Force -ErrorAction SilentlyContinue | Out-Null + $removedCount++ + } } - Return + Return $removedCount } function Add-ModsReg ($AddKey, $AddValue, $AddTypeData, $AddType) { From dc219081ae8581bdc61b2a69432606b5728be812 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 12 Apr 2025 17:58:02 +0200 Subject: [PATCH 2/6] Approved Verbs --- Sources/Winget-AutoUpdate/mods/_Mods-Functions.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Winget-AutoUpdate/mods/_Mods-Functions.ps1 b/Sources/Winget-AutoUpdate/mods/_Mods-Functions.ps1 index 637a8049..3fab2a7c 100644 --- a/Sources/Winget-AutoUpdate/mods/_Mods-Functions.ps1 +++ b/Sources/Winget-AutoUpdate/mods/_Mods-Functions.ps1 @@ -56,17 +56,17 @@ function Uninstall-WingetID ($WingetIDUninst) { function Uninstall-ModsApp ($AppUninst, $AllVersions) { foreach ($app in $AppUninst) { # we start from scanning the x64 node in registry, if something was found, then we set x64=TRUE - [bool]$app_was_x64 = Process-installedSoftware -app $app -x64 $true; + [bool]$app_was_x64 = Get-InstalledSoftware -app $app -x64 $true; # if nothing was found in x64 node, then we repeat that action in x86 node if (!$app_was_x64) { - Process-installedSoftware -app $app | Out-Null; + Get-InstalledSoftware -app $app | Out-Null; } } Return } -Function Process-installedSoftware() { +Function Get-InstalledSoftware() { [OutputType([Bool])] Param( [parameter(Mandatory = $true)] [string]$app, From d22f3957e195f28ffc27dbed9197a90823e21b05 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 12 Apr 2025 19:38:14 +0200 Subject: [PATCH 3/6] Added functions and examples in _WAU-mods-postsys-template --- .../mods/_WAU-mods-postsys-template.ps1 | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Sources/Winget-AutoUpdate/mods/_WAU-mods-postsys-template.ps1 b/Sources/Winget-AutoUpdate/mods/_WAU-mods-postsys-template.ps1 index df9dcd1d..3cd3b2da 100644 --- a/Sources/Winget-AutoUpdate/mods/_WAU-mods-postsys-template.ps1 +++ b/Sources/Winget-AutoUpdate/mods/_WAU-mods-postsys-template.ps1 @@ -6,11 +6,20 @@ Make sure your Functions have unique names! #> <# FUNCTIONS #> - +. $PSScriptRoot\_Mods-Functions.ps1 <# ARRAYS/VARIABLES #> +#Example: +#Beginning of Desktop Link Name to Remove - optional wildcard (*) after, without .lnk, multiple: "lnk1","lnk2" +#The function Remove-ModsLnk returns the number of removed links. +#$Lnk = @("Acrobat Read*","Bitwarden","calibre*") <# MAIN #> +#Example: +# if ($Lnk) { +# $removedCount = Remove-ModsLnk $Lnk +# Write-ToLog "-> Removed $($removedCount) Public Desktop Links!" "Green" +# } Write-ToLog "...nothing to do!" "Green" From 02806ad9fafd31ce3790b28f33e04de9932cb047 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 12 Apr 2025 19:41:03 +0200 Subject: [PATCH 4/6] Added better log output for Mods (postsys) for WAU --- Sources/Winget-AutoUpdate/mods/_WAU-mods-postsys-template.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Winget-AutoUpdate/mods/_WAU-mods-postsys-template.ps1 b/Sources/Winget-AutoUpdate/mods/_WAU-mods-postsys-template.ps1 index 3cd3b2da..ad1be36e 100644 --- a/Sources/Winget-AutoUpdate/mods/_WAU-mods-postsys-template.ps1 +++ b/Sources/Winget-AutoUpdate/mods/_WAU-mods-postsys-template.ps1 @@ -22,4 +22,4 @@ Make sure your Functions have unique names! # Write-ToLog "-> Removed $($removedCount) Public Desktop Links!" "Green" # } -Write-ToLog "...nothing to do!" "Green" +Write-ToLog "-> ...Mods (postsys) for WAU has nothing more to do!" "Green" From fc3ab19d067d0c6e46b6fd614d011f8637562023 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 12 Apr 2025 19:46:45 +0200 Subject: [PATCH 5/6] Line comment spaces --- .../mods/_WAU-mods-postsys-template.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/Winget-AutoUpdate/mods/_WAU-mods-postsys-template.ps1 b/Sources/Winget-AutoUpdate/mods/_WAU-mods-postsys-template.ps1 index ad1be36e..4455228a 100644 --- a/Sources/Winget-AutoUpdate/mods/_WAU-mods-postsys-template.ps1 +++ b/Sources/Winget-AutoUpdate/mods/_WAU-mods-postsys-template.ps1 @@ -9,14 +9,14 @@ Make sure your Functions have unique names! . $PSScriptRoot\_Mods-Functions.ps1 <# ARRAYS/VARIABLES #> -#Example: -#Beginning of Desktop Link Name to Remove - optional wildcard (*) after, without .lnk, multiple: "lnk1","lnk2" -#The function Remove-ModsLnk returns the number of removed links. -#$Lnk = @("Acrobat Read*","Bitwarden","calibre*") +# Example: +# Beginning of Desktop Link Name to Remove - optional wildcard (*) after, without .lnk, multiple: "lnk1","lnk2" +# The function Remove-ModsLnk returns the number of removed links. +# $Lnk = @("Acrobat Read*","Bitwarden","calibre*") <# MAIN #> -#Example: +# Example: # if ($Lnk) { # $removedCount = Remove-ModsLnk $Lnk # Write-ToLog "-> Removed $($removedCount) Public Desktop Links!" "Green" From f594401cece538c1ca59780adbcc715a8c494199 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 13 Apr 2025 06:30:09 +0200 Subject: [PATCH 6/6] Template changes --- .../mods/_AppID-template.ps1 | 16 +++++++++-- .../mods/_WAU-mods-postsys-template.ps1 | 1 + .../mods/_WAU-mods-template.ps1 | 1 + .../mods/_WAU-notinstalled-template.ps1 | 28 ++++++++++--------- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/Sources/Winget-AutoUpdate/mods/_AppID-template.ps1 b/Sources/Winget-AutoUpdate/mods/_AppID-template.ps1 index b7fa5f2f..8318ed3c 100644 --- a/Sources/Winget-AutoUpdate/mods/_AppID-template.ps1 +++ b/Sources/Winget-AutoUpdate/mods/_AppID-template.ps1 @@ -1,3 +1,16 @@ +<# A mods template for apps +Possible use cases: +"$Mods\AppID-preinstall.ps1" +"$Mods\AppID-install.ps1" +"$Mods\AppID-upgrade.ps1" +"$Mods\AppID-installed.ps1" +"$Mods\AppID-notinstalled.ps1" +#> + +<# FUNCTIONS #> +. $PSScriptRoot\_Mods-Functions.ps1 + + <# ARRAYS/VARIABLES #> #App to Run (as SYSTEM) #$RunWait = $False if it shouldn't be waited for completion. Example: @@ -82,8 +95,6 @@ $GrantPath = @("") $RunUser = "" $User = $True -<# FUNCTIONS #> -. $PSScriptRoot\_Mods-Functions.ps1 <# MAIN #> if ($RunSystem) { @@ -135,4 +146,5 @@ if ($RunUser) { Invoke-ModsApp $RunUser "" "" $User } + <# EXTRAS #> diff --git a/Sources/Winget-AutoUpdate/mods/_WAU-mods-postsys-template.ps1 b/Sources/Winget-AutoUpdate/mods/_WAU-mods-postsys-template.ps1 index 4455228a..b2668970 100644 --- a/Sources/Winget-AutoUpdate/mods/_WAU-mods-postsys-template.ps1 +++ b/Sources/Winget-AutoUpdate/mods/_WAU-mods-postsys-template.ps1 @@ -8,6 +8,7 @@ Make sure your Functions have unique names! <# FUNCTIONS #> . $PSScriptRoot\_Mods-Functions.ps1 + <# ARRAYS/VARIABLES #> # Example: # Beginning of Desktop Link Name to Remove - optional wildcard (*) after, without .lnk, multiple: "lnk1","lnk2" diff --git a/Sources/Winget-AutoUpdate/mods/_WAU-mods-template.ps1 b/Sources/Winget-AutoUpdate/mods/_WAU-mods-template.ps1 index 5de6d0d4..c85e6707 100644 --- a/Sources/Winget-AutoUpdate/mods/_WAU-mods-template.ps1 +++ b/Sources/Winget-AutoUpdate/mods/_WAU-mods-template.ps1 @@ -7,6 +7,7 @@ Exit 1 to Re-run WAU from this script (beware of loops)! #> <# FUNCTIONS #> +. $PSScriptRoot\_Mods-Functions.ps1 <# ARRAYS/VARIABLES #> diff --git a/Sources/Winget-AutoUpdate/mods/_WAU-notinstalled-template.ps1 b/Sources/Winget-AutoUpdate/mods/_WAU-notinstalled-template.ps1 index 9f552299..4812121d 100644 --- a/Sources/Winget-AutoUpdate/mods/_WAU-notinstalled-template.ps1 +++ b/Sources/Winget-AutoUpdate/mods/_WAU-notinstalled-template.ps1 @@ -10,20 +10,22 @@ This all-purpose mod will be overridden by any specific: <# FUNCTIONS #> . $PSScriptRoot\_Mods-Functions.ps1 + <# ARRAYS/VARIABLES #> <# MAIN #> -if ($($app.Id) -eq "Microsoft.SQLServerManagementStudio") { - if ($ConfirmInstall -eq $false) { - try { - Write-ToLog "...successfully done something" "Green" - } - catch { - Write-ToLog "...failed to do something" "Red" - } - } -} -else { - Write-ToLog "...nothing defined for $($app.Id)" "Yellow" -} +# Example: +# if ($($app.Id) -eq "Microsoft.SQLServerManagementStudio") { +# if ($ConfirmInstall -eq $false) { +# try { +# Write-ToLog "...successfully done something" "Green" +# } +# catch { +# Write-ToLog "...failed to do something" "Red" +# } +# } +# } +# else { +# Write-ToLog "...nothing defined for $($app.Id)" "Yellow" +# }