Merge pull request #245 from KnifMelti/Override

Override mods done (+error handling)
pull/264/head
Romain 2022-12-15 21:12:45 +01:00 committed by GitHub
commit dbdfb1e09c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 67 additions and 22 deletions

View File

@ -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.

View File

@ -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
}
$Message = $NotifLocale.local.outputs.output[9].message
#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
Start-NotifTask -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -ButtonDismiss
}
catch {

View File

@ -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

View File

@ -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

View File

@ -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
}

View File

@ -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 ){

View File

@ -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
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"
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"