Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for White List for WAU #8

Merged
merged 2 commits into from
Apr 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 44 additions & 3 deletions winget-install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@ To uninstall app. Works with AppIDs
.PARAMETER LogPath
Used to specify logpath. Default is same folder as Winget-Autoupdate project

.PARAMETER WAUWhiteList
Adds the app to the Winget-AutoUpdate White List. More info: https://github.com/Romanitho/Winget-AutoUpdate
If '-Uninstall' is used, it removes the app from WAU White List.

.EXAMPLE
.\winget-install.ps1 -AppIDs 7zip.7zip

.EXAMPLE
.\winget-install.ps1 -AppIDs 7zip.7zip -Uninstall

.EXAMPLE
.\winget-install.ps1 -AppIDs 7zip.7zip -WAUWhiteList

.EXAMPLE
.\winget-install.ps1 -AppIDs 7zip.7zip,notepad++.notepad++ -LogPath "C:\temp\logs"
#>
Expand All @@ -30,7 +37,8 @@ Used to specify logpath. Default is same folder as Winget-Autoupdate project
param(
[Parameter(Mandatory=$True,ParameterSetName="AppIDs")] [String[]] $AppIDs,
[Parameter(Mandatory=$False)] [Switch] $Uninstall,
[Parameter(Mandatory=$False)] [String] $LogPath = "$env:ProgramData\Winget-Install\logs"
[Parameter(Mandatory=$False)] [String] $LogPath = "$env:ProgramData\Winget-AutoUpdate\logs",
[Parameter(Mandatory=$False)] [Switch] $WAUWhiteList
)


Expand All @@ -45,7 +53,7 @@ function Init {

#Log file
$Script:LogFile = "$LogPath\install.log"
Write-Log "Log path is: $LogFile"
Write-Host "Log path is: $LogFile"

#Log Header
if ($Uninstall){
Expand Down Expand Up @@ -160,6 +168,31 @@ function Uninstall-App ($AppID){
}
}

#Function to Add app to WAU white list
function Add-WAUWhiteList ($AppID){
#Check if WAU default intall path exists
$WhiteList = "$env:ProgramData\Winget-AutoUpdate\included_apps.txt"
if (Test-Path $WhiteList){
Write-Log "Add $AppID to WAU included_apps.txt"
#Add App to "included_apps.txt"
Add-Content -path $WhiteList -Value "`n$AppID" -Force
#Remove duplicate and blank lines
$file = Get-Content $WhiteList | Select-Object -Unique | Where-Object {$_.trim() -ne ""} | Sort-Object
$file | Out-File $WhiteList
}
}

#Function to Remove app from WAU white list
function Remove-WAUWhiteList ($AppID){
#Check if WAU default intall path exists
$WhiteList = "$env:ProgramData\Winget-AutoUpdate\included_apps.txt"
if (Test-Path $WhiteList){
Write-Log "Remove $AppID to WAU included_apps.txt"
#Remove app from list
$file = Get-Content $WhiteList | Where-Object {$_ -notmatch "$AppID"}
$file | Out-File $WhiteList
}
}

<# MAIN #>

Expand All @@ -185,13 +218,21 @@ foreach ($AppID in $AppIDs){
#Install or Uninstall command
if ($Uninstall){
Uninstall-App $AppID
#Add to WAU White List if set
if ($WAUWhiteList){
Remove-WAUWhiteList $AppID
}
}
else{
Install-App $AppID
#Remove from WAU White List if set
if ($WAUWhiteList){
Add-WAUWhiteList $AppID
}
}
}
Start-Sleep 3
}

Write-Log "### END REQUEST ###" "Magenta"
Start-Sleep 3
Start-Sleep 3