mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-01-15 09:20:36 -06:00
Switch to PreferChocolatey Checkbox
This commit is contained in:
parent
ccd8dc89b0
commit
a3ab1409e5
@ -29,19 +29,19 @@ function Install-WinUtilProgramChoco {
|
||||
throw "Private Function 'Install-WinUtilProgramChoco' expected Parameter 'ProgramsToInstall' to be of size 1 or greater, instead got $count,`nPlease double check your code and re-compile WinUtil."
|
||||
}
|
||||
|
||||
Write-Progress -Activity "$manage Applications" -Status "Starting" -PercentComplete 0
|
||||
|
||||
Write-Host "==========================================="
|
||||
Write-Host "-- Configuring Chocolatey pacakages ---"
|
||||
Write-Host "==========================================="
|
||||
Foreach ($Program in $ProgramsToInstall) {
|
||||
Write-Progress -Activity "$manage Applications" -Status "$manage $($Program.choco) $($x + 1) of $count" -PercentComplete $($x/$count*100)
|
||||
|
||||
if($manage -eq "Installing") {
|
||||
write-host "Starting install of $($Program.choco) with Chocolatey."
|
||||
try {
|
||||
$tryUpgrade = $false
|
||||
$installOutputFilePath = "$env:TEMP\Install-WinUtilProgramChoco.install-command.output.txt"
|
||||
New-Item -ItemType File -Path $installOutputFilePath
|
||||
$chocoInstallStatus = $(Start-Process -FilePath "choco" -ArgumentList "install $($Program.choco) -y" -Wait -PassThru -RedirectStandardOutput $installOutputFilePath).ExitCode
|
||||
$chocoInstallStatus = $(Start-Process -FilePath "choco" -ArgumentList "install $($Program.choco) -y" -Wait -PassThru -RedirectStandardOutput $installOutputFilePath -NoNewWindow).ExitCode
|
||||
if(($chocoInstallStatus -eq 0) -AND (Test-Path -Path $installOutputFilePath)) {
|
||||
$keywordsFound = Get-Content -Path $installOutputFilePath | Where-Object {$_ -match "reinstall" -OR $_ -match "already installed"}
|
||||
if ($keywordsFound) {
|
||||
@ -50,7 +50,10 @@ function Install-WinUtilProgramChoco {
|
||||
}
|
||||
# TODO: Implement the Upgrade part using 'choco upgrade' command, this will make choco consistent with WinGet, as WinGet tries to Upgrade when you use the install command.
|
||||
if ($tryUpgrade) {
|
||||
throw "Automatic Upgrade for Choco isn't implemented yet, a feature to make it consistent with WinGet, the install command using choco simply failed because $($Program.choco) is already installed."
|
||||
$chocoUpdateStatus = $(Start-Process -FilePath "choco" -ArgumentList "upgrade $($Program.choco) -y" -Wait -PassThru -RedirectStandardOutput $installOutputFilePath -NoNewWindow).ExitCode
|
||||
if ($chocoUpdateStatus -eq 0) {
|
||||
Write-Host "$($Program.choco) was updated successfully using Chocolatey."
|
||||
}
|
||||
}
|
||||
if(($chocoInstallStatus -eq 0) -AND ($tryUpgrade -eq $false)) {
|
||||
Write-Host "$($Program.choco) installed successfully using Chocolatey."
|
||||
@ -74,7 +77,7 @@ function Install-WinUtilProgramChoco {
|
||||
try {
|
||||
$uninstallOutputFilePath = "$env:TEMP\Install-WinUtilProgramChoco.uninstall-command.output.txt"
|
||||
New-Item -ItemType File -Path $uninstallOutputFilePath
|
||||
$chocoUninstallStatus = $(Start-Process -FilePath "choco" -ArgumentList "uninstall $($Program.choco) -y" -Wait -PassThru).ExitCode
|
||||
$chocoUninstallStatus = $(Start-Process -FilePath "choco" -ArgumentList "uninstall $($Program.choco) -y" -Wait -PassThru -NoNewWindow).ExitCode
|
||||
if($chocoUninstallStatus -eq 0) {
|
||||
Write-Host "$($Program.choco) uninstalled successfully using Chocolatey."
|
||||
$x++
|
||||
@ -92,7 +95,6 @@ function Install-WinUtilProgramChoco {
|
||||
}
|
||||
}
|
||||
}
|
||||
Write-Progress -Activity "$manage Applications" -Status "Finished" -Completed
|
||||
|
||||
# Cleanup leftovers files
|
||||
if(Test-Path -Path $installOutputFilePath) { Remove-Item -Path $installOutputFilePath }
|
||||
|
@ -1,35 +0,0 @@
|
||||
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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -19,7 +19,9 @@ function Invoke-WPFGetInstalled {
|
||||
if(((Test-WinUtilPackageManager -winget) -eq "not-installed") -and $checkbox -eq "winget") {
|
||||
return
|
||||
}
|
||||
|
||||
if ($sync.WPFpreferChocolatey.IsChecked) {
|
||||
Write-Host "The Function `"Get Installed`" is only supported for Winget at the moment" -ForegroundColor Red
|
||||
}
|
||||
Invoke-WPFRunspace -ArgumentList $checkbox -DebugPreference $DebugPreference -ScriptBlock {
|
||||
param($checkbox, $DebugPreference)
|
||||
|
||||
|
@ -19,10 +19,9 @@ function Invoke-WPFInstall {
|
||||
[System.Windows.MessageBox]::Show($WarningMsg, $AppTitle, [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Invoke-WPFRunspace -ArgumentList $PackagesToInstall -DebugPreference $DebugPreference -ScriptBlock {
|
||||
param($PackagesToInstall, $DebugPreference)
|
||||
$ChocoPreference = $($sync.WPFpreferChocolatey.IsChecked)
|
||||
Invoke-WPFRunspace -ArgumentList $PackagesToInstall,$ChocoPreference -DebugPreference $DebugPreference -ScriptBlock {
|
||||
param($PackagesToInstall, $ChocoPreference, $DebugPreference)
|
||||
if ($PackagesToInstall.count -eq 1) {
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" -value 0.01 -overlay "logo" })
|
||||
} else {
|
||||
@ -31,18 +30,20 @@ function Invoke-WPFInstall {
|
||||
$packagesWinget, $packagesChoco = {
|
||||
$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))
|
||||
if ($ChocoPreference) {
|
||||
Write-Host "Prefer Choco"
|
||||
if ($package.choco -eq "na") {
|
||||
$packagesWinget.add($package.winget)
|
||||
Write-Host "Queueing $($package.winget) for Winget install"
|
||||
} else {
|
||||
$null = $packagesChoco.add($package)
|
||||
Write-Host "Queueing $($package) for Chocolatey install"
|
||||
}
|
||||
default {
|
||||
}
|
||||
else {
|
||||
Write-Host "Prefer Winget"
|
||||
if ($package.winget -eq "na") {
|
||||
$packagesChoco.add($package)
|
||||
Write-Host "Queueing $($package.choco) for Chocolatey install"
|
||||
@ -52,7 +53,7 @@ function Invoke-WPFInstall {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $packagesWinget, $packagesChoco
|
||||
}.Invoke($PackagesToInstall)
|
||||
|
||||
|
@ -2,11 +2,10 @@ function Invoke-WPFInstallUpgrade {
|
||||
<#
|
||||
|
||||
.SYNOPSIS
|
||||
Invokes the function that upgrades all installed programs using winget
|
||||
Invokes the function that upgrades all installed programs
|
||||
|
||||
#>
|
||||
switch ($sync.DownloadEngine){
|
||||
"Chocolatey"{
|
||||
if ($sync.WPFpreferChocolatey.IsChecked) {
|
||||
Install-WinUtilChoco
|
||||
$chocoUpgradeStatus = (Start-Process "choco" -ArgumentList "upgrade all -y" -Wait -PassThru -NoNewWindow).ExitCode
|
||||
if ($chocoUpgradeStatus -eq 0) {
|
||||
@ -16,7 +15,7 @@ function Invoke-WPFInstallUpgrade {
|
||||
Write-Host "Error Occured. Return Code: $chocoUpgradeStatus"
|
||||
}
|
||||
}
|
||||
default{
|
||||
else{
|
||||
if((Test-WinUtilPackageManager -winget) -eq "not-installed") {
|
||||
return
|
||||
}
|
||||
@ -27,8 +26,6 @@ function Invoke-WPFInstallUpgrade {
|
||||
return
|
||||
}
|
||||
|
||||
# Set-WinUtilTaskbaritem -state "Indeterminate"
|
||||
|
||||
Update-WinUtilProgramWinget
|
||||
|
||||
Write-Host "==========================================="
|
||||
@ -37,4 +34,3 @@ function Invoke-WPFInstallUpgrade {
|
||||
Write-Host "==========================================="
|
||||
}
|
||||
}
|
||||
}
|
@ -30,7 +30,9 @@ function Invoke-WPFRunspace {
|
||||
|
||||
# Add Scriptblock and Arguments to runspace
|
||||
$script:powershell.AddScript($ScriptBlock)
|
||||
$script:powershell.AddArgument($ArgumentList)
|
||||
foreach ($Argument in $ArgumentList) {
|
||||
$script:powershell.AddArgument($Argument)
|
||||
}
|
||||
$script:powershell.AddArgument($DebugPreference) # Pass DebugPreference to the script block
|
||||
$script:powershell.RunspacePool = $sync.runspace
|
||||
|
||||
|
@ -28,10 +28,10 @@ function Invoke-WPFUnInstall {
|
||||
$confirm = [System.Windows.MessageBox]::Show($Messageboxbody, $MessageboxTitle, $ButtonType, $MessageIcon)
|
||||
|
||||
if($confirm -eq "No") {return}
|
||||
$ChocoPreference = $($sync.WPFpreferChocolatey.IsChecked)
|
||||
|
||||
|
||||
Invoke-WPFRunspace -ArgumentList $PackagesToInstall -DebugPreference $DebugPreference -ScriptBlock {
|
||||
param($PackagesToInstall, $DebugPreference)
|
||||
Invoke-WPFRunspace -ArgumentList $PackagesToInstall, $ChocoPreference -DebugPreference $DebugPreference -ScriptBlock {
|
||||
param($PackagesToInstall, $ChocoPreference, $DebugPreference)
|
||||
if ($PackagesToInstall.count -eq 1) {
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" -value 0.01 -overlay "logo" })
|
||||
} else {
|
||||
@ -41,16 +41,17 @@ 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"{
|
||||
if ($ChocoPreference) {
|
||||
if ($packagesChoco.choco -eq "na") {
|
||||
$null = $packagesWinget.add($package.winget)
|
||||
Write-Host "Queueing $($package.winget) for Winget Uninstall"
|
||||
}
|
||||
else {
|
||||
$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 {
|
||||
else {
|
||||
if ($package.winget -eq "na") {
|
||||
$packagesChoco.add($package)
|
||||
Write-Host "Queueing $($package.choco) for Chocolatey Uninstall"
|
||||
@ -60,7 +61,6 @@ function Invoke-WPFUnInstall {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $packagesWinget, $packagesChoco
|
||||
}.Invoke($PackagesToInstall)
|
||||
try {
|
||||
|
@ -87,19 +87,6 @@ try {
|
||||
|
||||
$xaml.SelectNodes("//*[@Name]") | ForEach-Object {$sync["$("$($psitem.Name)")"] = $sync["Form"].FindName($psitem.Name)}
|
||||
|
||||
#Initialize Download Engine
|
||||
$selectedItem = $sync.WPFselectDownloadEngine.SelectedItem
|
||||
$selectedText = $selectedItem.Content
|
||||
$sync.DownloadEngine = $selectedText
|
||||
Set-DownloadEngine
|
||||
|
||||
$sync.WPFselectDownloadEngine.Add_SelectionChanged({
|
||||
$selectedItem = $sync.WPFselectDownloadEngine.SelectedItem
|
||||
$selectedText = $selectedItem.Content
|
||||
$sync.DownloadEngine = $selectedText
|
||||
Set-DownloadEngine
|
||||
})
|
||||
|
||||
$sync.keys | ForEach-Object {
|
||||
if($sync.$psitem) {
|
||||
if($($sync["$psitem"].GetType() | Select-Object -ExpandProperty Name) -eq "CheckBox" `
|
||||
|
@ -793,11 +793,9 @@
|
||||
<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" ToolTip="Select the Download Engine to be used to install Apps">
|
||||
<ComboBoxItem Content="Auto" />
|
||||
<ComboBoxItem Content="Winget" />
|
||||
<ComboBoxItem Content="Chocolatey" />
|
||||
</ComboBox>
|
||||
<CheckBox Name="WPFpreferChocolatey" VerticalAlignment="Center" VerticalContentAlignment="Center">
|
||||
<TextBlock Text="Prefer Chocolatey" ToolTip="Prefers Chocolatey as Download Engine instead of Winget" VerticalAlignment="Center" />
|
||||
</CheckBox>
|
||||
</StackPanel>
|
||||
|
||||
<ScrollViewer x:Name="scrollViewer" Grid.Row="1" Grid.Column="0" Padding="-1" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"
|
||||
|
Loading…
Reference in New Issue
Block a user