From ccd8dc89b02dc110b11ebc3f271a11ae47834c99 Mon Sep 17 00:00:00 2001 From: Marterich <47688561+Marterich@users.noreply.github.com> Date: Tue, 20 Aug 2024 23:41:17 +0200 Subject: [PATCH] Extend Functionality --- functions/private/Install-WinUtilChoco.ps1 | 4 +- functions/private/Set-DownloadEngine.ps1 | 7 +++ functions/public/Invoke-WPFGetInstalled.ps1 | 2 +- functions/public/Invoke-WPFInstall.ps1 | 25 +++++++--- functions/public/Invoke-WPFInstallUpgrade.ps1 | 50 ++++++++++++------- functions/public/Invoke-WPFUnInstall.ps1 | 24 ++++++--- xaml/inputXML.xaml | 6 +-- 7 files changed, 82 insertions(+), 36 deletions(-) diff --git a/functions/private/Install-WinUtilChoco.ps1 b/functions/private/Install-WinUtilChoco.ps1 index 37655b9c..254feba7 100644 --- a/functions/private/Install-WinUtilChoco.ps1 +++ b/functions/private/Install-WinUtilChoco.ps1 @@ -15,8 +15,8 @@ function Install-WinUtilChoco { } Write-Host "Seems Chocolatey is not installed, installing now." - Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) -ErrorAction Stop - powershell choco feature enable -n allowGlobalConfirmation + Start-Process -FilePath "powershell" -ArgumentList "Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) -ErrorAction Stop" -Wait -NoNewWindow + Start-Process -FilePath "powershell" -ArgumentList "choco feature enable -n allowGlobalConfirmation" -Wait -NoNewWindow } catch { Write-Host "===========================================" -Foregroundcolor Red diff --git a/functions/private/Set-DownloadEngine.ps1 b/functions/private/Set-DownloadEngine.ps1 index 1b293a5d..48e99424 100644 --- a/functions/private/Set-DownloadEngine.ps1 +++ b/functions/private/Set-DownloadEngine.ps1 @@ -1,26 +1,33 @@ function Set-DownloadEngine { $CheckBoxes = $sync.GetEnumerator() | Where-Object { $_.Value -is [System.Windows.Controls.CheckBox] } + foreach ($CheckBox in $CheckBoxes) { if ($CheckBox.Key.StartsWith("WPFInstall")) { Switch ($sync.DownloadEngine) { "Winget" { if ($($sync.configs.applications.$($CheckBox.Name).winget) -eq "na"){ $CheckBox.Value.Visibility = "Collapsed" + $sync."$($CheckBox.Key)Link".Visibility = "Collapsed" + } else{ $CheckBox.Value.Visibility = "Visible" + $sync."$($CheckBox.Key)Link".Visibility = "Visible" } } "Chocolatey"{ if ($($sync.configs.applications.$($CheckBox.Name).chocolatey) -eq "na"){ $CheckBox.Value.Visibility = "Collapsed" + $sync."$($CheckBox.Key)Link".Visibility = "Collapsed" } else { $CheckBox.Value.Visibility = "Visible" + $sync."$($CheckBox.Key)Link".Visibility = "Visible" } } default{ $CheckBox.Value.Visibility = "Visible" + $sync."$($CheckBox.Key)Link".Visibility = "Visible" } } } diff --git a/functions/public/Invoke-WPFGetInstalled.ps1 b/functions/public/Invoke-WPFGetInstalled.ps1 index 6f5a326a..9b31e483 100644 --- a/functions/public/Invoke-WPFGetInstalled.ps1 +++ b/functions/public/Invoke-WPFGetInstalled.ps1 @@ -1,6 +1,6 @@ function Invoke-WPFGetInstalled { <# - + TODO: Add the Option to use Chocolatey as Engine .SYNOPSIS Invokes the function that gets the checkboxes to check in a new runspace diff --git a/functions/public/Invoke-WPFInstall.ps1 b/functions/public/Invoke-WPFInstall.ps1 index 0d880c93..a1bf8b78 100644 --- a/functions/public/Invoke-WPFInstall.ps1 +++ b/functions/public/Invoke-WPFInstall.ps1 @@ -32,12 +32,25 @@ function Invoke-WPFInstall { $packagesWinget = [System.Collections.ArrayList]::new() $packagesChoco = [System.Collections.Generic.List`1[System.Object]]::new() foreach ($package in $PackagesToInstall) { - if ($package.winget -eq "na") { - $packagesChoco.add($package) - Write-Host "Queueing $($package.choco) for Chocolatey install" - } else { - $null = $packagesWinget.add($($package.winget)) - Write-Host "Queueing $($package.winget) for Winget install" + switch ($Sync.DownloadEngine){ + "Chocolatey"{ + # TODO: Handle Upgrade if version is already installed + $packagesChoco.add($package) + Write-Host "Queueing $($package.choco) for Chocolatey install" + } + "Winget" { + $null = $packagesWinget.add($($package.winget)) + Write-Host "Queueing $($package.winget) for Winget install" + } + default { + if ($package.winget -eq "na") { + $packagesChoco.add($package) + Write-Host "Queueing $($package.choco) for Chocolatey install" + } else { + $null = $packagesWinget.add($($package.winget)) + Write-Host "Queueing $($package.winget) for Winget install" + } + } } } return $packagesWinget, $packagesChoco diff --git a/functions/public/Invoke-WPFInstallUpgrade.ps1 b/functions/public/Invoke-WPFInstallUpgrade.ps1 index e30f5f1f..1d902c54 100644 --- a/functions/public/Invoke-WPFInstallUpgrade.ps1 +++ b/functions/public/Invoke-WPFInstallUpgrade.ps1 @@ -5,22 +5,36 @@ function Invoke-WPFInstallUpgrade { Invokes the function that upgrades all installed programs using winget #> - if((Test-WinUtilPackageManager -winget) -eq "not-installed") { - return + switch ($sync.DownloadEngine){ + "Chocolatey"{ + Install-WinUtilChoco + $chocoUpgradeStatus = (Start-Process "choco" -ArgumentList "upgrade all -y" -Wait -PassThru -NoNewWindow).ExitCode + if ($chocoUpgradeStatus -eq 0){ + Write-Host "Upgrade Successful" + } + else{ + Write-Host "Error Occured. Return Code: $chocoUpgradeStatus" + } + } + default{ + if((Test-WinUtilPackageManager -winget) -eq "not-installed") { + return + } + + if(Get-WinUtilInstallerProcess -Process $global:WinGetInstall) { + $msg = "[Invoke-WPFInstallUpgrade] Install process is currently running. Please check for a powershell window labeled 'Winget Install'" + [System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning) + return + } + + # Set-WinUtilTaskbaritem -state "Indeterminate" + + Update-WinUtilProgramWinget + + Write-Host "===========================================" + Write-Host "-- Updates started ---" + Write-Host "-- You can close this window if desired ---" + Write-Host "===========================================" + } } - - if(Get-WinUtilInstallerProcess -Process $global:WinGetInstall) { - $msg = "[Invoke-WPFInstallUpgrade] Install process is currently running. Please check for a powershell window labeled 'Winget Install'" - [System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning) - return - } - - # Set-WinUtilTaskbaritem -state "Indeterminate" - - Update-WinUtilProgramWinget - - Write-Host "===========================================" - Write-Host "-- Updates started ---" - Write-Host "-- You can close this window if desired ---" - Write-Host "===========================================" -} +} \ No newline at end of file diff --git a/functions/public/Invoke-WPFUnInstall.ps1 b/functions/public/Invoke-WPFUnInstall.ps1 index 19aec2d2..aeb38480 100644 --- a/functions/public/Invoke-WPFUnInstall.ps1 +++ b/functions/public/Invoke-WPFUnInstall.ps1 @@ -41,12 +41,24 @@ function Invoke-WPFUnInstall { $packagesWinget = [System.Collections.Generic.List`1[System.Object]]::new() $packagesChoco = [System.Collections.Generic.List`1[System.Object]]::new() foreach ($package in $PackagesToInstall) { - if ($package.winget -eq "na") { - $packagesChoco.add($package) - Write-Host "Queueing $($package.choco) for Chocolatey Uninstall" - } else { - $packagesWinget.add($($package.winget)) - Write-Host "Queueing $($package.winget) for Winget Uninstall" + switch ($Sync.DownloadEngine){ + "Chocolatey"{ + $packagesChoco.add($package) + Write-Host "Queueing $($package.choco) for Chocolatey Uninstall" + } + "Winget" { + $null = $packagesWinget.add($($package.winget)) + Write-Host "Queueing $($package.winget) for Winget Uninstall" + } + default { + if ($package.winget -eq "na") { + $packagesChoco.add($package) + Write-Host "Queueing $($package.choco) for Chocolatey Uninstall" + } else { + $null = $packagesWinget.add($($package.winget)) + Write-Host "Queueing $($package.winget) for Winget Uninstall" + } + } } } return $packagesWinget, $packagesChoco diff --git a/xaml/inputXML.xaml b/xaml/inputXML.xaml index 1370e2d4..db5c178e 100644 --- a/xaml/inputXML.xaml +++ b/xaml/inputXML.xaml @@ -793,10 +793,10 @@