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." 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 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
powershell choco feature enable -n allowGlobalConfirmation Start-Process -FilePath "powershell" -ArgumentList "choco feature enable -n allowGlobalConfirmation" -Wait -NoNewWindow
} catch { } catch {
Write-Host "===========================================" -Foregroundcolor Red Write-Host "===========================================" -Foregroundcolor Red

View File

@ -1,26 +1,33 @@
function Set-DownloadEngine { function Set-DownloadEngine {
$CheckBoxes = $sync.GetEnumerator() | Where-Object { $_.Value -is [System.Windows.Controls.CheckBox] } $CheckBoxes = $sync.GetEnumerator() | Where-Object { $_.Value -is [System.Windows.Controls.CheckBox] }
foreach ($CheckBox in $CheckBoxes) { foreach ($CheckBox in $CheckBoxes) {
if ($CheckBox.Key.StartsWith("WPFInstall")) { if ($CheckBox.Key.StartsWith("WPFInstall")) {
Switch ($sync.DownloadEngine) { Switch ($sync.DownloadEngine) {
"Winget" { "Winget" {
if ($($sync.configs.applications.$($CheckBox.Name).winget) -eq "na"){ if ($($sync.configs.applications.$($CheckBox.Name).winget) -eq "na"){
$CheckBox.Value.Visibility = "Collapsed" $CheckBox.Value.Visibility = "Collapsed"
$sync."$($CheckBox.Key)Link".Visibility = "Collapsed"
} }
else{ else{
$CheckBox.Value.Visibility = "Visible" $CheckBox.Value.Visibility = "Visible"
$sync."$($CheckBox.Key)Link".Visibility = "Visible"
} }
} }
"Chocolatey"{ "Chocolatey"{
if ($($sync.configs.applications.$($CheckBox.Name).chocolatey) -eq "na"){ if ($($sync.configs.applications.$($CheckBox.Name).chocolatey) -eq "na"){
$CheckBox.Value.Visibility = "Collapsed" $CheckBox.Value.Visibility = "Collapsed"
$sync."$($CheckBox.Key)Link".Visibility = "Collapsed"
} }
else { else {
$CheckBox.Value.Visibility = "Visible" $CheckBox.Value.Visibility = "Visible"
$sync."$($CheckBox.Key)Link".Visibility = "Visible"
} }
} }
default{ default{
$CheckBox.Value.Visibility = "Visible" $CheckBox.Value.Visibility = "Visible"
$sync."$($CheckBox.Key)Link".Visibility = "Visible"
} }
} }
} }

View File

@ -1,6 +1,6 @@
function Invoke-WPFGetInstalled { function Invoke-WPFGetInstalled {
<# <#
TODO: Add the Option to use Chocolatey as Engine
.SYNOPSIS .SYNOPSIS
Invokes the function that gets the checkboxes to check in a new runspace 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() $packagesWinget = [System.Collections.ArrayList]::new()
$packagesChoco = [System.Collections.Generic.List`1[System.Object]]::new() $packagesChoco = [System.Collections.Generic.List`1[System.Object]]::new()
foreach ($package in $PackagesToInstall) { 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") { if ($package.winget -eq "na") {
$packagesChoco.add($package) $packagesChoco.add($package)
Write-Host "Queueing $($package.choco) for Chocolatey install" Write-Host "Queueing $($package.choco) for Chocolatey install"
@ -40,6 +51,8 @@ function Invoke-WPFInstall {
Write-Host "Queueing $($package.winget) for Winget install" Write-Host "Queueing $($package.winget) for Winget install"
} }
} }
}
}
return $packagesWinget, $packagesChoco return $packagesWinget, $packagesChoco
}.Invoke($PackagesToInstall) }.Invoke($PackagesToInstall)

View File

@ -5,6 +5,18 @@ function Invoke-WPFInstallUpgrade {
Invokes the function that upgrades all installed programs using winget 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") { if((Test-WinUtilPackageManager -winget) -eq "not-installed") {
return return
} }
@ -23,4 +35,6 @@ function Invoke-WPFInstallUpgrade {
Write-Host "-- Updates started ---" Write-Host "-- Updates started ---"
Write-Host "-- You can close this window if desired ---" Write-Host "-- You can close this window if desired ---"
Write-Host "===========================================" Write-Host "==========================================="
}
}
} }

View File

@ -41,14 +41,26 @@ function Invoke-WPFUnInstall {
$packagesWinget = [System.Collections.Generic.List`1[System.Object]]::new() $packagesWinget = [System.Collections.Generic.List`1[System.Object]]::new()
$packagesChoco = [System.Collections.Generic.List`1[System.Object]]::new() $packagesChoco = [System.Collections.Generic.List`1[System.Object]]::new()
foreach ($package in $PackagesToInstall) { 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") { if ($package.winget -eq "na") {
$packagesChoco.add($package) $packagesChoco.add($package)
Write-Host "Queueing $($package.choco) for Chocolatey Uninstall" Write-Host "Queueing $($package.choco) for Chocolatey Uninstall"
} else { } else {
$packagesWinget.add($($package.winget)) $null = $packagesWinget.add($($package.winget))
Write-Host "Queueing $($package.winget) for Winget Uninstall" Write-Host "Queueing $($package.winget) for Winget Uninstall"
} }
} }
}
}
return $packagesWinget, $packagesChoco return $packagesWinget, $packagesChoco
}.Invoke($PackagesToInstall) }.Invoke($PackagesToInstall)
try { try {

View File

@ -793,10 +793,10 @@
<Button Name="WPFuninstall" Content=" Uninstall Selected" Margin="2"/> <Button Name="WPFuninstall" Content=" Uninstall Selected" Margin="2"/>
<Button Name="WPFGetInstalled" Content=" Get Installed" Margin="2"/> <Button Name="WPFGetInstalled" Content=" Get Installed" Margin="2"/>
<Button Name="WPFclearWinget" Content=" Clear Selection" 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="Auto" />
<ComboBoxItem Content="Winget"/> <ComboBoxItem Content="Winget" />
<ComboBoxItem Content="Chocolatey"/> <ComboBoxItem Content="Chocolatey" />
</ComboBox> </ComboBox>
</StackPanel> </StackPanel>