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,12 +32,25 @@ 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) {
if ($package.winget -eq "na") { switch ($Sync.DownloadEngine){
$packagesChoco.add($package) "Chocolatey"{
Write-Host "Queueing $($package.choco) for Chocolatey install" # TODO: Handle Upgrade if version is already installed
} else { $packagesChoco.add($package)
$null = $packagesWinget.add($($package.winget)) Write-Host "Queueing $($package.choco) for Chocolatey install"
Write-Host "Queueing $($package.winget) for Winget 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 return $packagesWinget, $packagesChoco

View File

@ -5,22 +5,36 @@ function Invoke-WPFInstallUpgrade {
Invokes the function that upgrades all installed programs using winget Invokes the function that upgrades all installed programs using winget
#> #>
if((Test-WinUtilPackageManager -winget) -eq "not-installed") { switch ($sync.DownloadEngine){
return "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() $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) {
if ($package.winget -eq "na") { switch ($Sync.DownloadEngine){
$packagesChoco.add($package) "Chocolatey"{
Write-Host "Queueing $($package.choco) for Chocolatey Uninstall" $packagesChoco.add($package)
} else { Write-Host "Queueing $($package.choco) for Chocolatey Uninstall"
$packagesWinget.add($($package.winget)) }
Write-Host "Queueing $($package.winget) for Winget 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 return $packagesWinget, $packagesChoco

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>