From ddd852abc641b52f80c5522e301725026682c87f Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Thu, 8 Dec 2022 17:53:37 +0100 Subject: [PATCH 01/14] -override mods (.txt) too --- Winget-AutoUpdate/functions/Test-Mods.ps1 | 6 +++- Winget-AutoUpdate/functions/Test-ModsPath.ps1 | 10 +++---- Winget-AutoUpdate/functions/Update-App.ps1 | 29 ++++++++++++++----- 3 files changed, 31 insertions(+), 14 deletions(-) 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..6c5ea56 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" @@ -54,8 +60,15 @@ Function Update-App ($app) { #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" From 55f43d281e9a1cb2cfe502410a643f87d4080485 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Thu, 8 Dec 2022 18:27:45 +0100 Subject: [PATCH 02/14] Documented --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c38cff3..e5d88ee 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 +Another finess is the **AppID-override.txt** 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 as a native **winget --override** parameter when upgrading. + + ## 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. From 7134f53fcec475c33e54f0c7b1d1aa299b4e4099 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Fri, 9 Dec 2022 03:16:33 +0100 Subject: [PATCH 03/14] Text --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e5d88ee..c6a44ee 100644 --- a/README.md +++ b/README.md @@ -152,12 +152,12 @@ 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 -Another finess is the **AppID-override.txt** 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 as a native **winget --override** parameter when upgrading. +### Winget native parameters +Another finess is the **AppID** followed by the `-override` suffix as a text file 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. ## 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. From e386742200f5583f38cc69d6dfc79798e0dc72fb Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Fri, 9 Dec 2022 03:17:39 +0100 Subject: [PATCH 04/14] Linebreak --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c6a44ee..a1c7cb5 100644 --- a/README.md +++ b/README.md @@ -154,7 +154,7 @@ You can find more information on [Winget-Install Repo](https://github.com/Romani ### Winget native parameters Another finess is the **AppID** followed by the `-override` suffix as a text file you can place under the **mods** folder. -> Example: +> 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. From 34fbadb632330d0bbf2070e3e9c1a518ca4d802e Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Fri, 9 Dec 2022 16:01:40 +0100 Subject: [PATCH 05/14] Stressing text file --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a1c7cb5..9522e38 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,7 @@ 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 you can place under the **mods** folder. +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` From 3c30bfec0077e2f021745a7814449ae72c844ba4 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 11 Dec 2022 01:31:44 +0100 Subject: [PATCH 06/14] Winget Error Handling --- Winget-AutoUpdate/Winget-Upgrade.ps1 | 9 ++++++++- Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index cf79a12..116de25 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -84,7 +84,7 @@ if (Test-Network) { } else { Write-Log "List doesn't exist!" "Red" - Exit 0 + Exit 1 } } } @@ -125,6 +125,13 @@ 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 "An error occured, exiting..." "red" + Write-Log "$outdated" "red" + 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..b32e45c 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:$upgradeResult" } #Split winget output to lines From d6abb076c3f9781559de42fb12feb07a8da8f63f Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 11 Dec 2022 12:02:36 +0100 Subject: [PATCH 07/14] Small fixes --- Winget-AutoUpdate/Winget-Upgrade.ps1 | 2 +- Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 | 2 +- Winget-AutoUpdate/functions/Update-App.ps1 | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index 116de25..0be7404 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -126,7 +126,7 @@ if (Test-Network) { $outdated = Get-WingetOutdatedApps #If something is wrong with the winget source, exit - if (($outdated -like "Problem:*")) { + if ($outdated -like "Problem:*") { Write-Log "An error occured, exiting..." "red" Write-Log "$outdated" "red" Exit 1 diff --git a/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 b/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 index b32e45c..ae6aa50 100644 --- a/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 +++ b/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 @@ -13,7 +13,7 @@ function Get-WingetOutdatedApps { #Start Convertion of winget format to an array. Check if "-----" exists (Winget Error Handling) if (!($upgradeResult -match "-----")) { - return "Problem:$upgradeResult" + return "Problem:`n$upgradeResult" } #Split winget output to lines diff --git a/Winget-AutoUpdate/functions/Update-App.ps1 b/Winget-AutoUpdate/functions/Update-App.ps1 index 6c5ea56..11096a4 100644 --- a/Winget-AutoUpdate/functions/Update-App.ps1 +++ b/Winget-AutoUpdate/functions/Update-App.ps1 @@ -53,7 +53,7 @@ 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 } From 3a7694f9e2024b73072bb8616d0c51d30fe80594 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 11 Dec 2022 17:42:05 +0100 Subject: [PATCH 08/14] Old School Error Handling (by file) --- Winget-AutoUpdate/User-Run.ps1 | 10 ++++++++-- Winget-AutoUpdate/Winget-Upgrade.ps1 | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Winget-AutoUpdate/User-Run.ps1 b/Winget-AutoUpdate/User-Run.ps1 index 5ec50a8..36b6eae 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,14 @@ else { While (Test-WAUisRunning) { Start-Sleep 3 } + if (Test-Path "$WorkingDir\winget_error.txt") { + $MessageType = "error" + Remove-Item "$WorkingDir\winget_error.txt" -Force + } + 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 0be7404..5d867eb 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -108,6 +108,11 @@ if (Test-Network) { Write-Log "$DeletedMods Mods deleted (not externally managed) from local path: $($WAUConfig.InstallLocation)\mods" "Red" } } + + #Delete previous winget_error if exists and System + if (Test-Path "$WorkingDir\winget_error.txt") { + Remove-Item "$WorkingDir\winget_error.txt" -Force + } } #Get White or Black list @@ -129,6 +134,15 @@ if (Test-Network) { if ($outdated -like "Problem:*") { Write-Log "An error occured, exiting..." "red" Write-Log "$outdated" "red" + $path = "$WorkingDir\winget_error.txt" + New-Item "$path" -Value "$outdated" -Force + + #Setting file rights for everyone (so that it can be deleted by User-Run.ps1) + $rule= New-Object System.Security.AccessControl.FileSystemAccessRule ('Everyone', 'FullControl', 'Allow') + $acl = Get-ACL $path + $acl.SetAccessRule($rule) + Set-ACL -Path $path -AclObject $acl + Exit 1 } From 7c0c9dcb30ea63b63752fcb794ae9d9cdf144b0a Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 11 Dec 2022 18:40:06 +0100 Subject: [PATCH 09/14] Handling both System/User now --- Winget-AutoUpdate/User-Run.ps1 | 6 ++++++ Winget-AutoUpdate/Winget-Upgrade.ps1 | 25 ++++++++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Winget-AutoUpdate/User-Run.ps1 b/Winget-AutoUpdate/User-Run.ps1 index 36b6eae..8ec3ff2 100644 --- a/Winget-AutoUpdate/User-Run.ps1 +++ b/Winget-AutoUpdate/User-Run.ps1 @@ -81,10 +81,16 @@ else { While (Test-WAUisRunning) { Start-Sleep 3 } + + #Test if there was a winget error as System/User if (Test-Path "$WorkingDir\winget_error.txt") { $MessageType = "error" Remove-Item "$WorkingDir\winget_error.txt" -Force } + elseif (Test-Path "${env:TEMP}\winget_error.txt") { + $MessageType = "error" + Remove-Item "${env:TEMP}\winget_error.txt" -Force + } else { $MessageType = "success" } diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index 5d867eb..82400bc 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -108,11 +108,14 @@ if (Test-Network) { Write-Log "$DeletedMods Mods deleted (not externally managed) from local path: $($WAUConfig.InstallLocation)\mods" "Red" } } + } - #Delete previous winget_error if exists and System - if (Test-Path "$WorkingDir\winget_error.txt") { - Remove-Item "$WorkingDir\winget_error.txt" -Force - } + #Delete previous winget_error (if exists) as System/User + if ($IsSystem -and (Test-Path "$WorkingDir\winget_error.txt")) { + Remove-Item "$WorkingDir\winget_error.txt" -Force + } + elseif (!$IsSystem -and (Test-Path "${env:TEMP}\winget_error.txt")) { + Remove-Item "${env:TEMP}\winget_error.txt" -Force } #Get White or Black list @@ -130,14 +133,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:*") { + #If something is wrong with the winget source, exit as System/User + if ($IsSystem -and $outdated -like "Problem:*") { Write-Log "An error occured, exiting..." "red" Write-Log "$outdated" "red" $path = "$WorkingDir\winget_error.txt" New-Item "$path" -Value "$outdated" -Force - #Setting file rights for everyone (so that it can be deleted by User-Run.ps1) + #Setting file rights for everyone (so that it can be deleted by User in User-Run.ps1) $rule= New-Object System.Security.AccessControl.FileSystemAccessRule ('Everyone', 'FullControl', 'Allow') $acl = Get-ACL $path $acl.SetAccessRule($rule) @@ -145,6 +148,14 @@ if (Test-Network) { Exit 1 } + elseif (!$IsSystem -and $outdated -like "Problem:*") { + Write-Log "An error occured, exiting..." "red" + Write-Log "$outdated" "red" + $path = "${env:TEMP}\winget_error.txt" + New-Item "$path" -Value "$outdated" -Force + + Exit 1 + } #Log list of app to update foreach ($app in $outdated) { From 50b2d383c4f58271bcfe4e9192d8f1a953a47075 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 11 Dec 2022 22:22:22 +0100 Subject: [PATCH 10/14] ...and, missing list error too! --- Winget-AutoUpdate/User-Run.ps1 | 6 +++--- Winget-AutoUpdate/Winget-Upgrade.ps1 | 27 ++++++++++++++++++--------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/Winget-AutoUpdate/User-Run.ps1 b/Winget-AutoUpdate/User-Run.ps1 index 8ec3ff2..04661a4 100644 --- a/Winget-AutoUpdate/User-Run.ps1 +++ b/Winget-AutoUpdate/User-Run.ps1 @@ -82,10 +82,10 @@ else { Start-Sleep 3 } - #Test if there was a winget error as System/User - if (Test-Path "$WorkingDir\winget_error.txt") { + #Test if there was a list/winget error as System/User + if (Test-Path "$WorkingDir\*_error.txt") { $MessageType = "error" - Remove-Item "$WorkingDir\winget_error.txt" -Force + Remove-Item "$WorkingDir\*_error.txt" -Force } elseif (Test-Path "${env:TEMP}\winget_error.txt") { $MessageType = "error" diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index 82400bc..b0a5ccf 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -36,6 +36,14 @@ if ($IsSystem) { Add-ScopeMachine $SettingsPath } +#Delete previous list/winget_error (if they exist) as System/User +if ($IsSystem -and (Test-Path "$WorkingDir\*_error.txt")) { + Remove-Item "$WorkingDir\*_error.txt" -Force +} +elseif (!$IsSystem -and (Test-Path "${env:TEMP}\winget_error.txt")) { + Remove-Item "${env:TEMP}\winget_error.txt" -Force +} + #Get Notif Locale function $LocaleDisplayName = Get-NotifLocale Write-Log "Notification Level: $($WAUConfig.WAU_NotificationLevel). Notification Language: $LocaleDisplayName" "Cyan" @@ -83,7 +91,16 @@ if (Test-Network) { Write-Log "List is up to date." "Green" } else { - Write-Log "List doesn't exist!" "Red" + Write-Log "Critical: List doesn't exist, exiting..." "Red" + $path = "$WorkingDir\list_error.txt" + New-Item "$path" -Force + + #Setting file rights for everyone (so that it can be deleted by User in User-Run.ps1) + $rule= New-Object System.Security.AccessControl.FileSystemAccessRule ('Everyone', 'FullControl', 'Allow') + $acl = Get-ACL $path + $acl.SetAccessRule($rule) + Set-ACL -Path $path -AclObject $acl + Exit 1 } } @@ -110,14 +127,6 @@ if (Test-Network) { } } - #Delete previous winget_error (if exists) as System/User - if ($IsSystem -and (Test-Path "$WorkingDir\winget_error.txt")) { - Remove-Item "$WorkingDir\winget_error.txt" -Force - } - elseif (!$IsSystem -and (Test-Path "${env:TEMP}\winget_error.txt")) { - Remove-Item "${env:TEMP}\winget_error.txt" -Force - } - #Get White or Black list if ($WAUConfig.WAU_UseWhiteList -eq 1) { Write-Log "WAU uses White List config" From c49f6a084e24c1d925b1cb1d0b2726cd65eb9604 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Mon, 12 Dec 2022 01:28:38 +0100 Subject: [PATCH 11/14] Logic corrected! --- Winget-AutoUpdate/User-Run.ps1 | 7 +---- Winget-AutoUpdate/Winget-Upgrade.ps1 | 45 ++++++---------------------- 2 files changed, 10 insertions(+), 42 deletions(-) diff --git a/Winget-AutoUpdate/User-Run.ps1 b/Winget-AutoUpdate/User-Run.ps1 index 04661a4..c7c3583 100644 --- a/Winget-AutoUpdate/User-Run.ps1 +++ b/Winget-AutoUpdate/User-Run.ps1 @@ -82,14 +82,9 @@ else { Start-Sleep 3 } - #Test if there was a list/winget error as System/User + #Test if there was a list_/winget_error if (Test-Path "$WorkingDir\*_error.txt") { $MessageType = "error" - Remove-Item "$WorkingDir\*_error.txt" -Force - } - elseif (Test-Path "${env:TEMP}\winget_error.txt") { - $MessageType = "error" - Remove-Item "${env:TEMP}\winget_error.txt" -Force } else { $MessageType = "success" diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index b0a5ccf..7b9c9af 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -36,14 +36,6 @@ if ($IsSystem) { Add-ScopeMachine $SettingsPath } -#Delete previous list/winget_error (if they exist) as System/User -if ($IsSystem -and (Test-Path "$WorkingDir\*_error.txt")) { - Remove-Item "$WorkingDir\*_error.txt" -Force -} -elseif (!$IsSystem -and (Test-Path "${env:TEMP}\winget_error.txt")) { - Remove-Item "${env:TEMP}\winget_error.txt" -Force -} - #Get Notif Locale function $LocaleDisplayName = Get-NotifLocale Write-Log "Notification Level: $($WAUConfig.WAU_NotificationLevel). Notification Language: $LocaleDisplayName" "Cyan" @@ -79,6 +71,11 @@ if (Test-Network) { } } + #Delete previous list_/winget_error (if they exist) if System + if (Test-Path "$WorkingDir\*_error.txt") { + Remove-Item "$WorkingDir\*_error.txt" -Force + } + #Get External ListPath if System if ($WAUConfig.WAU_ListPath) { Write-Log "WAU uses External Lists from: $($WAUConfig.WAU_ListPath)" @@ -92,15 +89,7 @@ if (Test-Network) { } else { Write-Log "Critical: List doesn't exist, exiting..." "Red" - $path = "$WorkingDir\list_error.txt" - New-Item "$path" -Force - - #Setting file rights for everyone (so that it can be deleted by User in User-Run.ps1) - $rule= New-Object System.Security.AccessControl.FileSystemAccessRule ('Everyone', 'FullControl', 'Allow') - $acl = Get-ACL $path - $acl.SetAccessRule($rule) - Set-ACL -Path $path -AclObject $acl - + New-Item "$WorkingDir\list_error.txt" -Force Exit 1 } } @@ -142,27 +131,11 @@ if (Test-Network) { Write-Log "Checking application updates on Winget Repository..." "yellow" $outdated = Get-WingetOutdatedApps - #If something is wrong with the winget source, exit as System/User - if ($IsSystem -and $outdated -like "Problem:*") { + #If something is wrong with the winget source, exit + if ($outdated -like "Problem:*") { Write-Log "An error occured, exiting..." "red" Write-Log "$outdated" "red" - $path = "$WorkingDir\winget_error.txt" - New-Item "$path" -Value "$outdated" -Force - - #Setting file rights for everyone (so that it can be deleted by User in User-Run.ps1) - $rule= New-Object System.Security.AccessControl.FileSystemAccessRule ('Everyone', 'FullControl', 'Allow') - $acl = Get-ACL $path - $acl.SetAccessRule($rule) - Set-ACL -Path $path -AclObject $acl - - Exit 1 - } - elseif (!$IsSystem -and $outdated -like "Problem:*") { - Write-Log "An error occured, exiting..." "red" - Write-Log "$outdated" "red" - $path = "${env:TEMP}\winget_error.txt" - New-Item "$path" -Value "$outdated" -Force - + New-Item "$WorkingDir\winget_error.txt" -Value "$outdated" -Force Exit 1 } From 4e2c2b5c33cae42f11f86c5d326279dc26a51678 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Mon, 12 Dec 2022 02:18:08 +0100 Subject: [PATCH 12/14] Moved *_error.txt to logs --- Winget-AutoUpdate/User-Run.ps1 | 2 +- Winget-AutoUpdate/Winget-Upgrade.ps1 | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Winget-AutoUpdate/User-Run.ps1 b/Winget-AutoUpdate/User-Run.ps1 index c7c3583..0c79cfe 100644 --- a/Winget-AutoUpdate/User-Run.ps1 +++ b/Winget-AutoUpdate/User-Run.ps1 @@ -83,7 +83,7 @@ else { } #Test if there was a list_/winget_error - if (Test-Path "$WorkingDir\*_error.txt") { + if (Test-Path "$WorkingDir\logs\*_error.txt") { $MessageType = "error" } else { diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index 7b9c9af..3bd3094 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -72,8 +72,8 @@ if (Test-Network) { } #Delete previous list_/winget_error (if they exist) if System - if (Test-Path "$WorkingDir\*_error.txt") { - Remove-Item "$WorkingDir\*_error.txt" -Force + if (Test-Path "$WorkingDir\logs\*_error.txt") { + Remove-Item "$WorkingDir\logs\*_error.txt" -Force } #Get External ListPath if System @@ -89,7 +89,7 @@ if (Test-Network) { } else { Write-Log "Critical: List doesn't exist, exiting..." "Red" - New-Item "$WorkingDir\list_error.txt" -Force + New-Item "$WorkingDir\logs\list_error.txt" -Force Exit 1 } } @@ -135,7 +135,7 @@ if (Test-Network) { if ($outdated -like "Problem:*") { Write-Log "An error occured, exiting..." "red" Write-Log "$outdated" "red" - New-Item "$WorkingDir\winget_error.txt" -Value "$outdated" -Force + New-Item "$WorkingDir\logs\winget_error.txt" -Value "$outdated" -Force Exit 1 } From 369ae7bdd4def22d8f0dda6f381665344b2757f7 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Mon, 12 Dec 2022 02:52:46 +0100 Subject: [PATCH 13/14] Keyword: Critical... --- Winget-AutoUpdate/Winget-Upgrade.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index 3bd3094..e92c77c 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -133,7 +133,7 @@ if (Test-Network) { #If something is wrong with the winget source, exit if ($outdated -like "Problem:*") { - Write-Log "An error occured, exiting..." "red" + Write-Log "Critical: An error occured, exiting..." "red" Write-Log "$outdated" "red" New-Item "$WorkingDir\logs\winget_error.txt" -Value "$outdated" -Force Exit 1 From 221fe953f2c4d3535a56cf0c4b0b538c3bd1ce76 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Mon, 12 Dec 2022 03:13:51 +0100 Subject: [PATCH 14/14] Thanks to Nesovj... --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9522e38..8ce79a4 100644 --- a/README.md +++ b/README.md @@ -157,7 +157,7 @@ Another finess is the **AppID** followed by the `-override` suffix as a **text f > 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. +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.