diff --git a/README.md b/README.md index c38cff3..8ce79a4 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ Same process as new installation : download, unzip and run `install.bat`. ### Automatic Update A new Auto-Update process has been released from version 1.5.0. By default, WAU AutoUpdate is enabled. It will not overwrite the configurations, icons (if personalised), excluded_apps list,... -To disable WAU AutoUpdate, run the `winget-install-and-update.ps1` with `-DisableWAUAutoUpdate` parameter +To disable WAU AutoUpdate, run the `Winget-AutoUpdate-Install.ps1` with `-DisableWAUAutoUpdate` parameter ## Uninstall WAU Simply uninstall it from your programs: @@ -152,6 +152,13 @@ If you want to run a script that removes the shortcut from **%PUBLIC%\Desktop** You can find more information on [Winget-Install Repo](https://github.com/Romanitho/Winget-Install#custom-mods), as it's a related feature +### Winget native parameters +Another finess is the **AppID** followed by the `-override` suffix as a **text file** (.txt) that you can place under the **mods** folder. +> Example: +> **Canneverbe.CDBurnerXP-override.txt** with the content `ADDLOCAL=All REMOVE=Desktop_Shortcut /qn` + +This will use the content from the text file as a native **winget --override** parameter when upgrading (as proposed by [Nesovj](https://github.com/Nesovj) in [Mod for --override argument #244](https://github.com/Romanitho/Winget-AutoUpdate/discussions/244#discussion-4637666)). + ## Help In some cases, you need to "unblock" the `install.bat` file (Windows Defender SmartScreen). Right click, properties and unblock. Then, you'll be able to run it. diff --git a/Winget-AutoUpdate/User-Run.ps1 b/Winget-AutoUpdate/User-Run.ps1 index 5ec50a8..0c79cfe 100644 --- a/Winget-AutoUpdate/User-Run.ps1 +++ b/Winget-AutoUpdate/User-Run.ps1 @@ -49,7 +49,7 @@ $Balise = "Winget-AutoUpdate (WAU)" $UserRun = $True if ($Logs) { - if ((Test-Path "$WorkingDir\logs\updates.log")) { + if (Test-Path "$WorkingDir\logs\updates.log") { Invoke-Item "$WorkingDir\logs\updates.log" } else { @@ -81,8 +81,15 @@ else { While (Test-WAUisRunning) { Start-Sleep 3 } + + #Test if there was a list_/winget_error + if (Test-Path "$WorkingDir\logs\*_error.txt") { + $MessageType = "error" + } + else { + $MessageType = "success" + } $Message = $NotifLocale.local.outputs.output[9].message - $MessageType = "success" Start-NotifTask -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -ButtonDismiss } catch { diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index cf79a12..e92c77c 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -71,6 +71,11 @@ if (Test-Network) { } } + #Delete previous list_/winget_error (if they exist) if System + if (Test-Path "$WorkingDir\logs\*_error.txt") { + Remove-Item "$WorkingDir\logs\*_error.txt" -Force + } + #Get External ListPath if System if ($WAUConfig.WAU_ListPath) { Write-Log "WAU uses External Lists from: $($WAUConfig.WAU_ListPath)" @@ -83,8 +88,9 @@ if (Test-Network) { Write-Log "List is up to date." "Green" } else { - Write-Log "List doesn't exist!" "Red" - Exit 0 + Write-Log "Critical: List doesn't exist, exiting..." "Red" + New-Item "$WorkingDir\logs\list_error.txt" -Force + Exit 1 } } } @@ -125,6 +131,14 @@ if (Test-Network) { Write-Log "Checking application updates on Winget Repository..." "yellow" $outdated = Get-WingetOutdatedApps + #If something is wrong with the winget source, exit + if ($outdated -like "Problem:*") { + Write-Log "Critical: An error occured, exiting..." "red" + Write-Log "$outdated" "red" + New-Item "$WorkingDir\logs\winget_error.txt" -Value "$outdated" -Force + Exit 1 + } + #Log list of app to update foreach ($app in $outdated) { #List available updates diff --git a/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 b/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 index 4634cd2..ae6aa50 100644 --- a/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 +++ b/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 @@ -11,9 +11,9 @@ function Get-WingetOutdatedApps { #Get list of available upgrades on winget format $upgradeResult = & $Winget upgrade --source winget | Out-String - #Start Convertion of winget format to an array. Check if "-----" exists + #Start Convertion of winget format to an array. Check if "-----" exists (Winget Error Handling) if (!($upgradeResult -match "-----")) { - return + return "Problem:`n$upgradeResult" } #Split winget output to lines diff --git a/Winget-AutoUpdate/functions/Test-Mods.ps1 b/Winget-AutoUpdate/functions/Test-Mods.ps1 index 1496ea2..560df80 100644 --- a/Winget-AutoUpdate/functions/Test-Mods.ps1 +++ b/Winget-AutoUpdate/functions/Test-Mods.ps1 @@ -4,6 +4,7 @@ function Test-Mods ($app) { #Takes care of a null situation $ModsPreInstall = $null + $ModsOverride = $null $ModsUpgrade = $null $ModsInstall = $null $ModsInstalled = $null @@ -13,6 +14,9 @@ function Test-Mods ($app) { if (Test-Path "$Mods\$app-preinstall.ps1") { $ModsPreInstall = "$Mods\$app-preinstall.ps1" } + if (Test-Path "$Mods\$app-override.txt") { + $ModsOverride = Get-Content "$Mods\$app-override.txt" -Raw + } if (Test-Path "$Mods\$app-install.ps1") { $ModsInstall = "$Mods\$app-install.ps1" $ModsUpgrade = "$Mods\$app-install.ps1" @@ -25,6 +29,6 @@ function Test-Mods ($app) { } } - return $ModsPreInstall, $ModsUpgrade, $ModsInstall, $ModsInstalled + return $ModsPreInstall, $ModsOverride, $ModsUpgrade, $ModsInstall, $ModsInstalled } diff --git a/Winget-AutoUpdate/functions/Test-ModsPath.ps1 b/Winget-AutoUpdate/functions/Test-ModsPath.ps1 index 2ebc50d..7b3e91a 100644 --- a/Winget-AutoUpdate/functions/Test-ModsPath.ps1 +++ b/Winget-AutoUpdate/functions/Test-ModsPath.ps1 @@ -7,7 +7,7 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath) { $ExternalMods = "$ModsPath" #Get File Names Locally - $InternalModsNames = Get-ChildItem -Path $LocalMods -Name -Recurse -Include *.ps1 + $InternalModsNames = Get-ChildItem -Path $LocalMods -Name -Recurse -Include *.ps1, *.txt # If path is URL if ($ExternalMods -like "http*") { @@ -35,8 +35,8 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath) { #Loop through all links $WebResponse.Links | Select-Object -ExpandProperty href | ForEach-Object { - #Check for .ps1 in listing/HREF:s in an index page pointing to .ps1 - if ($_ -like "*.ps1") { + #Check for .ps1/.txt in listing/HREF:s in an index page pointing to .ps1/.txt + if (($_ -like "*.ps1") -or ($_ -like "*.txt")) { try { $dateExternalMod = "" $dateLocalMod ="" @@ -67,9 +67,9 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath) { } # If path is UNC or local else { - if (Test-Path -Path $ExternalMods"\*.ps1") { + if ((Test-Path -Path $ExternalMods"\*.ps1") -or (Test-Path -Path $ExternalMods"\*.txt")) { #Get File Names Externally - $ExternalModsNames = Get-ChildItem -Path $ExternalMods -Name -Recurse -Include *.ps1 + $ExternalModsNames = Get-ChildItem -Path $ExternalMods -Name -Recurse -Include *.ps1, *.txt #Delete Local Mods that don't exist Externally foreach ($Mod in $InternalModsNames){ If($Mod -notin $ExternalModsNames ){ diff --git a/Winget-AutoUpdate/functions/Update-App.ps1 b/Winget-AutoUpdate/functions/Update-App.ps1 index b316b94..11096a4 100644 --- a/Winget-AutoUpdate/functions/Update-App.ps1 +++ b/Winget-AutoUpdate/functions/Update-App.ps1 @@ -17,7 +17,10 @@ Function Update-App ($app) { Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Balise $Balise -Button1Action $ReleaseNoteURL -Button1Text $Button1Text #Check if mods exist for preinstall/install/upgrade - $ModsPreInstall, $ModsUpgrade, $ModsInstall, $ModsInstalled = Test-Mods $($app.Id) + $ModsPreInstall, $ModsOverride, $ModsUpgrade, $ModsInstall, $ModsInstalled = Test-Mods $($app.Id) + + #Winget upgrade + Write-Log "########## WINGET UPGRADE PROCESS STARTS FOR APPLICATION ID '$($App.Id)' ##########" "Gray" #If PreInstall script exist if ($ModsPreInstall) { @@ -25,12 +28,15 @@ Function Update-App ($app) { & "$ModsPreInstall" } - #Winget upgrade - Write-Log "########## WINGET UPGRADE PROCESS STARTS FOR APPLICATION ID '$($App.Id)' ##########" "Gray" - #Run Winget Upgrade command - Write-Log "-> Running: Winget upgrade --id $($app.Id) --accept-package-agreements --accept-source-agreements -h" - & $Winget upgrade --id $($app.Id) --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append + if ($ModsOverride) { + Write-Log "-> Running (overriding default): Winget upgrade --id $($app.Id) --accept-package-agreements --accept-source-agreements --override $ModsOverride" + & $Winget upgrade --id $($app.Id) --accept-package-agreements --accept-source-agreements --override $ModsOverride | Tee-Object -file $LogFile -Append + } + else { + Write-Log "-> Running: Winget upgrade --id $($app.Id) --accept-package-agreements --accept-source-agreements -h" + & $Winget upgrade --id $($app.Id) --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append + } if ($ModsUpgrade) { Write-Log "Modifications for $($app.Id) during upgrade are being applied..." "Yellow" @@ -47,15 +53,22 @@ Function Update-App ($app) { #Test for a Pending Reboot (Component Based Servicing/WindowsUpdate/CCM_ClientUtilities) $PendingReboot = Test-PendingReboot if ($PendingReboot -eq $true) { - Write-Log "-> A Pending Reboot lingers and probably prohibited $($app.Name) from upgrading...`n...an install for $($app.Name) is NOT executed!" "Red" + Write-Log "-> A Pending Reboot lingers and probably prohibited $($app.Name) from upgrading...`n-> ...an install for $($app.Name) is NOT executed!" "Red" $FailedToUpgrade = $true break } #If app failed to upgrade, run Install command Write-Log "-> An upgrade for $($app.Name) failed, now trying an install instead..." "Yellow" - Write-Log "-> Running: Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements -h" - & $Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append + + if ($ModsOverride) { + Write-Log "-> Running (overriding default): Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements --override $ModsOverride" + & $Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements --override $ModsOverride | Tee-Object -file $LogFile -Append + } + else { + Write-Log "-> Running: Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements -h" + & $Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append + } if ($ModsInstall) { Write-Log "Modifications for $($app.Id) during install are being applied..." "Yellow"