mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-01-18 10:47:44 -06:00
Install flow rework
Sperated Winget and Chocolatey setps when installing software add skip them when not needed
This commit is contained in:
parent
6e201305c9
commit
5a98f63657
@ -36,19 +36,16 @@ Function Get-WinUtilCheckBoxes {
|
|||||||
$group = if ($CheckBox.Key.StartsWith("WPFInstall")) { "Install" }
|
$group = if ($CheckBox.Key.StartsWith("WPFInstall")) { "Install" }
|
||||||
elseif ($CheckBox.Key.StartsWith("WPFTweaks")) { "WPFTweaks" }
|
elseif ($CheckBox.Key.StartsWith("WPFTweaks")) { "WPFTweaks" }
|
||||||
elseif ($CheckBox.Key.StartsWith("WPFFeature")) { "WPFFeature" }
|
elseif ($CheckBox.Key.StartsWith("WPFFeature")) { "WPFFeature" }
|
||||||
|
|
||||||
if ($group) {
|
if ($group) {
|
||||||
if ($CheckBox.Value.IsChecked -eq $true) {
|
if ($CheckBox.Value.IsChecked -eq $true) {
|
||||||
$feature = switch ($group) {
|
$feature = switch ($group) {
|
||||||
"Install" {
|
"Install" {
|
||||||
# Get the winget value
|
# Get the winget value
|
||||||
$wingetValue = $sync.configs.applications.$($CheckBox.Name).winget
|
[PsCustomObject]@{
|
||||||
|
winget="$($sync.configs.applications.$($CheckBox.Name).winget)";
|
||||||
if (-not [string]::IsNullOrWhiteSpace($wingetValue) -and $wingetValue -ne "na") {
|
choco="$($sync.configs.applications.$($CheckBox.Name).choco)";
|
||||||
$wingetValue -split ";"
|
|
||||||
} else {
|
|
||||||
$sync.configs.applications.$($CheckBox.Name).choco
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
default {
|
default {
|
||||||
$CheckBox.Name
|
$CheckBox.Name
|
||||||
@ -72,6 +69,5 @@ Function Get-WinUtilCheckBoxes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $Output
|
return $Output
|
||||||
}
|
}
|
||||||
|
52
functions/private/Install-WinUtilProgramChoco.ps1
Normal file
52
functions/private/Install-WinUtilProgramChoco.ps1
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
function Install-WinUtilProgramChoco {
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Manages the provided programs using Chocolatey
|
||||||
|
|
||||||
|
.PARAMETER ProgramsToInstall
|
||||||
|
A list of programs to manage
|
||||||
|
|
||||||
|
.PARAMETER manage
|
||||||
|
The action to perform on the programs, can be either 'Installing' or 'Uninstalling'
|
||||||
|
|
||||||
|
.NOTES
|
||||||
|
The triple quotes are required any time you need a " in a normal script block.
|
||||||
|
#>
|
||||||
|
|
||||||
|
param(
|
||||||
|
$ProgramsToInstall,
|
||||||
|
$manage = "Installing"
|
||||||
|
)
|
||||||
|
|
||||||
|
$x = 0
|
||||||
|
$count = $ProgramsToInstall.Count
|
||||||
|
|
||||||
|
Write-Progress -Activity "$manage Applications" -Status "Starting" -PercentComplete 0
|
||||||
|
Write-Host "==========================================="
|
||||||
|
Write-Host "-- insstalling 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{
|
||||||
|
$chocoStatus = $(Start-Process -FilePath "choco" -ArgumentList "install $($Program.choco) -y" -Wait -PassThru).ExitCode
|
||||||
|
if($chocoStatus -eq 0){
|
||||||
|
Write-Host "$($Program.choco) installed successfully using Chocolatey."
|
||||||
|
continue
|
||||||
|
} else {
|
||||||
|
Write-Host "Failed to install $($Program.choco) using Chocolatey."
|
||||||
|
}
|
||||||
|
Write-Host "Failed to install $($Program.choco)."
|
||||||
|
} catch {
|
||||||
|
Write-Host "Failed to install $($Program.choco) due to an error: $_"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($manage -eq "Uninstalling"){
|
||||||
|
throw "not yet implemented";
|
||||||
|
}
|
||||||
|
$X++
|
||||||
|
}
|
||||||
|
Write-Progress -Activity "$manage Applications" -Status "Finished" -Completed
|
||||||
|
return;
|
||||||
|
}
|
@ -2,89 +2,86 @@ Function Install-WinUtilProgramWinget {
|
|||||||
|
|
||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Manages the provided programs using Winget
|
Manages the provided programs using Winget
|
||||||
|
|
||||||
.PARAMETER ProgramsToInstall
|
.PARAMETER ProgramsToInstall
|
||||||
A list of programs to manage
|
A list of programs to manage
|
||||||
|
|
||||||
.PARAMETER manage
|
.PARAMETER manage
|
||||||
The action to perform on the programs, can be either 'Installing' or 'Uninstalling'
|
The action to perform on the programs, can be either 'Installing' or 'Uninstalling'
|
||||||
|
|
||||||
.NOTES
|
.NOTES
|
||||||
The triple quotes are required any time you need a " in a normal script block.
|
The triple quotes are required any time you need a " in a normal script block.
|
||||||
#>
|
#>
|
||||||
|
|
||||||
param(
|
param(
|
||||||
$ProgramsToInstall,
|
$ProgramsToInstall,
|
||||||
$manage = "Installing"
|
$manage = "Installing"
|
||||||
)
|
)
|
||||||
|
|
||||||
$x = 0
|
$x = 0
|
||||||
$count = $($ProgramsToInstall -split ",").Count
|
$count = $ProgramsToInstall.Count
|
||||||
|
|
||||||
Write-Progress -Activity "$manage Applications" -Status "Starting" -PercentComplete 0
|
Write-Progress -Activity "$manage Applications" -Status "Starting" -PercentComplete 0
|
||||||
|
Write-Host "==========================================="
|
||||||
Foreach ($Program in $($ProgramsToInstall -split ",")){
|
Write-Host "-- installing winget packages ---"
|
||||||
|
Write-Host "==========================================="
|
||||||
Write-Progress -Activity "$manage Applications" -Status "$manage $Program $($x + 1) of $count" -PercentComplete $($x/$count*100)
|
Foreach ($Program in $ProgramsToInstall){
|
||||||
|
$failedPackages = @()
|
||||||
|
Write-Progress -Activity "$manage Applications" -Status "$manage $($Program.winget) $($x + 1) of $count" -PercentComplete $($x/$count*100)
|
||||||
if($manage -eq "Installing"){
|
if($manage -eq "Installing"){
|
||||||
# Install package via ID, if it fails try again with different scope and then with an unelevated prompt.
|
# Install package via ID, if it fails try again with different scope and then with an unelevated prompt.
|
||||||
# Since Install-WinGetPackage might not be directly available, we use winget install command as a workaround.
|
# Since Install-WinGetPackage might not be directly available, we use winget install command as a workaround.
|
||||||
# Winget, not all installers honor any of the following: System-wide, User Installs, or Unelevated Prompt OR Silent Install Mode.
|
# Winget, not all installers honor any of the following: System-wide, User Installs, or Unelevated Prompt OR Silent Install Mode.
|
||||||
# This is up to the individual package maintainers to enable these options. Aka. not as clean as Linux Package Managers.
|
# This is up to the individual package maintainers to enable these options. Aka. not as clean as Linux Package Managers.
|
||||||
|
Write-Host "Starting install of $($Program.winget) with winget."
|
||||||
try {
|
try {
|
||||||
$status = $(Start-Process -FilePath "winget" -ArgumentList "install --id $Program --silent --accept-source-agreements --accept-package-agreements" -Wait -PassThru).ExitCode
|
$status = $(Start-Process -FilePath "winget" -ArgumentList "install --id $($Program.winget) --silent --accept-source-agreements --accept-package-agreements" -Wait -PassThru).ExitCode
|
||||||
if($status -eq 0){
|
if($status -eq 0){
|
||||||
Write-Host "$Program installed successfully."
|
Write-Host "$($Program.winget) installed successfully."
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
Write-Host "Attempt with User scope"
|
Write-Host "Attempt with User scope"
|
||||||
$status = $(Start-Process -FilePath "winget" -ArgumentList "install --id $Program --scope user --silent --accept-source-agreements --accept-package-agreements" -Wait -PassThru).ExitCode
|
$status = $(Start-Process -FilePath "winget" -ArgumentList "install --id $($Program.winget) --scope user --silent --accept-source-agreements --accept-package-agreements" -Wait -PassThru).ExitCode
|
||||||
if($status -eq 0){
|
if($status -eq 0){
|
||||||
Write-Host "$Program installed successfully with User scope."
|
Write-Host "$($Program.winget) installed successfully with User scope."
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
Write-Host "Attempt with User prompt"
|
Write-Host "Attempt with User prompt"
|
||||||
$userChoice = [System.Windows.MessageBox]::Show("Do you want to attempt $Program installation with specific user credentials? Select 'Yes' to proceed or 'No' to skip.", "User Credential Prompt", [System.Windows.MessageBoxButton]::YesNo)
|
$userChoice = [System.Windows.MessageBox]::Show("Do you want to attempt $($Program.winget) installation with specific user credentials? Select 'Yes' to proceed or 'No' to skip.", "User Credential Prompt", [System.Windows.MessageBoxButton]::YesNo)
|
||||||
if ($userChoice -eq 'Yes') {
|
if ($userChoice -eq 'Yes') {
|
||||||
$getcreds = Get-Credential
|
$getcreds = Get-Credential
|
||||||
$process = Start-Process -FilePath "winget" -ArgumentList "install --id $Program --silent --accept-source-agreements --accept-package-agreements" -Credential $getcreds -PassThru
|
$process = Start-Process -FilePath "winget" -ArgumentList "install --id $($Program.winget) --silent --accept-source-agreements --accept-package-agreements" -Credential $getcreds -PassThru
|
||||||
Wait-Process -Id $process.Id
|
Wait-Process -Id $process.Id
|
||||||
$status = $process.ExitCode
|
$status = $process.ExitCode
|
||||||
} else {
|
} else {
|
||||||
Write-Host "Skipping installation with specific user credentials."
|
Write-Host "Skipping installation with specific user credentials."
|
||||||
}
|
}
|
||||||
if($status -eq 0){
|
if($status -eq 0){
|
||||||
Write-Host "$Program installed successfully with User prompt."
|
Write-Host "$($Program.winget) installed successfully with User prompt."
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
Write-Host "Attempting installation with Chocolatey as a fallback method"
|
} catch {
|
||||||
Install-WinUtilChoco
|
Write-Host "Failed to install $($Program.winget). With winget"
|
||||||
$status = $(Start-Process -FilePath "choco" -ArgumentList "install $Program -y" -Wait -PassThru).ExitCode
|
$failedPackages += $($Program.winget)
|
||||||
if($status -eq 0){
|
}
|
||||||
Write-Host "$Program installed successfully using Chocolatey."
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
Write-Host "Failed to install $Program. You need to install it manually... Sorry!"
|
|
||||||
} catch {
|
|
||||||
Write-Host "Failed to install $Program due to an error: $_"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if($manage -eq "Uninstalling"){
|
if($manage -eq "Uninstalling"){
|
||||||
# Uninstall package via ID using winget directly.
|
# Uninstall package via ID using winget directly.
|
||||||
try {
|
try {
|
||||||
$status = $(Start-Process -FilePath "winget" -ArgumentList "uninstall --id $Program --silent" -Wait -PassThru).ExitCode
|
$status = $(Start-Process -FilePath "winget" -ArgumentList "uninstall --id $($Program.winget) --silent" -Wait -PassThru).ExitCode
|
||||||
if($status -ne 0){
|
if($status -ne 0){
|
||||||
Write-Host "Failed to uninstall $Program."
|
Write-Host "Failed to uninstall $($Program.winget)."
|
||||||
} else {
|
} else {
|
||||||
Write-Host "$Program uninstalled successfully."
|
Write-Host "$($Program.winget) uninstalled successfully."
|
||||||
|
$failedPackages += $($Program.winget)
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
Write-Host "Failed to uninstall $Program due to an error: $_"
|
Write-Host "Failed to uninstall $($Program.winget) due to an error: $_"
|
||||||
|
$failedPackages += $($Program.winget)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$X++
|
$X++
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Progress -Activity "$manage Applications" -Status "Finished" -Completed
|
Write-Progress -Activity "$manage Applications" -Status "Finished" -Completed
|
||||||
|
return $failedPackages;
|
||||||
}
|
}
|
||||||
|
@ -12,23 +12,43 @@ function Invoke-WPFInstall {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
$WingetInstall = (Get-WinUtilCheckBoxes)["Install"]
|
$PackagesToInstall = (Get-WinUtilCheckBoxes)["Install"]
|
||||||
|
Write-Host $PackagesToInstall
|
||||||
if ($wingetinstall.Count -eq 0) {
|
if ($PackagesToInstall.Count -eq 0) {
|
||||||
$WarningMsg = "Please select the program(s) to install or upgrade"
|
$WarningMsg = "Please select the program(s) to install or upgrade"
|
||||||
[System.Windows.MessageBox]::Show($WarningMsg, $AppTitle, [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
|
[System.Windows.MessageBox]::Show($WarningMsg, $AppTitle, [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
Invoke-WPFRunspace -ArgumentList $WingetInstall -DebugPreference $DebugPreference -ScriptBlock {
|
Invoke-WPFRunspace -ArgumentList $PackagesToInstall -DebugPreference $DebugPreference -ScriptBlock {
|
||||||
param($WingetInstall, $DebugPreference)
|
param($PackagesToInstall, $DebugPreference)
|
||||||
|
$packagesWinget, $packagesChoco = {
|
||||||
|
$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 install"
|
||||||
|
} else {
|
||||||
|
$packagesWinget.add($package)
|
||||||
|
Write-Host "Queueing $($package.winget) for Winget install"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $packagesWinget, $packagesChoco
|
||||||
|
}.Invoke($PackagesToInstall)
|
||||||
|
|
||||||
try{
|
try{
|
||||||
$sync.ProcessRunning = $true
|
$sync.ProcessRunning = $true
|
||||||
|
$errorPackages = @()
|
||||||
Install-WinUtilWinget
|
if($packagesWinget.Count -gt 0){
|
||||||
Install-WinUtilProgramWinget -ProgramsToInstall $WingetInstall
|
Install-WinUtilWinget
|
||||||
|
$errorPackages += Install-WinUtilProgramWinget -ProgramsToInstall $packagesWinget
|
||||||
|
$errorPackages| ForEach-Object {if($_.choco -ne "na") {$packagesChoco += $_}}
|
||||||
|
}
|
||||||
|
if($packagesChoco.Count -gt 0){
|
||||||
|
Install-WinUtilChoco
|
||||||
|
Install-WinUtilProgramChoco -ProgramsToInstall $packagesChoco
|
||||||
|
}
|
||||||
Write-Host "==========================================="
|
Write-Host "==========================================="
|
||||||
Write-Host "-- Installs have finished ---"
|
Write-Host "-- Installs have finished ---"
|
||||||
Write-Host "==========================================="
|
Write-Host "==========================================="
|
||||||
|
Loading…
Reference in New Issue
Block a user