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/_Mods-Functions.ps1 b/Sources/Winget-AutoUpdate/mods/_Mods-Functions.ps1 index 01955c7d..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, @@ -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) { diff --git a/Sources/Winget-AutoUpdate/mods/_WAU-mods-postsys-template.ps1 b/Sources/Winget-AutoUpdate/mods/_WAU-mods-postsys-template.ps1 index df9dcd1d..b2668970 100644 --- a/Sources/Winget-AutoUpdate/mods/_WAU-mods-postsys-template.ps1 +++ b/Sources/Winget-AutoUpdate/mods/_WAU-mods-postsys-template.ps1 @@ -6,11 +6,21 @@ 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" +Write-ToLog "-> ...Mods (postsys) for WAU has nothing more to do!" "Green" 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" +# }