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

View File

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

View File

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

View File

@ -793,10 +793,10 @@
<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"/>
<ComboBoxItem Content="Winget" />
<ComboBoxItem Content="Chocolatey" />
</ComboBox>
</StackPanel>