Extend Functionality

This commit is contained in:
Marterich 2024-08-20 23:41:17 +02:00
parent bd730b5418
commit ccd8dc89b0
7 changed files with 82 additions and 36 deletions

View File

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

View File

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

View File

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

View File

@ -32,6 +32,17 @@ function Invoke-WPFInstall {
$packagesWinget = [System.Collections.ArrayList]::new()
$packagesChoco = [System.Collections.Generic.List`1[System.Object]]::new()
foreach ($package in $PackagesToInstall) {
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"
@ -40,6 +51,8 @@ function Invoke-WPFInstall {
Write-Host "Queueing $($package.winget) for Winget install"
}
}
}
}
return $packagesWinget, $packagesChoco
}.Invoke($PackagesToInstall)

View File

@ -5,6 +5,18 @@ function Invoke-WPFInstallUpgrade {
Invokes the function that upgrades all installed programs using winget
#>
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
}
@ -24,3 +36,5 @@ function Invoke-WPFInstallUpgrade {
Write-Host "-- You can close this window if desired ---"
Write-Host "==========================================="
}
}
}

View File

@ -41,14 +41,26 @@ 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) {
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 {
$packagesWinget.add($($package.winget))
$null = $packagesWinget.add($($package.winget))
Write-Host "Queueing $($package.winget) for Winget Uninstall"
}
}
}
}
return $packagesWinget, $packagesChoco
}.Invoke($PackagesToInstall)
try {

View File

@ -793,7 +793,7 @@
<Button Name="WPFuninstall" Content=" Uninstall Selected" Margin="2"/>
<Button Name="WPFGetInstalled" Content=" Get Installed" Margin="2"/>
<Button Name="WPFclearWinget" Content=" Clear Selection" Margin="2"/>
<ComboBox Name="WPFselectDownloadEngine" SelectedIndex="0" Margin="2">
<ComboBox Name="WPFselectDownloadEngine" SelectedIndex="0" Margin="2" ToolTip="Select the Download Engine to be used to install Apps">
<ComboBoxItem Content="Auto" />
<ComboBoxItem Content="Winget" />
<ComboBoxItem Content="Chocolatey" />