mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-01-17 18:27:42 -06:00
Fix fallback bug and merge choco uninstall rework
- fixed return from wrong return from winget install Install-WinUtilProgramWinget - syntax/wording cleenup in Install-WinUtilProgramWinget - fix bugs in ty802/winutil#1 after merge
This commit is contained in:
parent
782fca962e
commit
532c7c85d5
@ -17,7 +17,7 @@ function Install-WinUtilProgramChoco {
|
|||||||
[Parameter(Mandatory, Position=0)]
|
[Parameter(Mandatory, Position=0)]
|
||||||
[PsCustomObject]$ProgramsToInstall,
|
[PsCustomObject]$ProgramsToInstall,
|
||||||
|
|
||||||
[Parameter(Mandatory, Position=1)]
|
[Parameter(Position=1)]
|
||||||
[String]$manage = "Installing"
|
[String]$manage = "Installing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ function Install-WinUtilProgramChoco {
|
|||||||
|
|
||||||
Write-Progress -Activity "$manage Applications" -Status "Starting" -PercentComplete 0
|
Write-Progress -Activity "$manage Applications" -Status "Starting" -PercentComplete 0
|
||||||
Write-Host "==========================================="
|
Write-Host "==========================================="
|
||||||
Write-Host "-- insstalling Chocolatey pacakages ---"
|
Write-Host "-- Configuring Chocolatey pacakages ---"
|
||||||
Write-Host "==========================================="
|
Write-Host "==========================================="
|
||||||
Foreach ($Program in $ProgramsToInstall){
|
Foreach ($Program in $ProgramsToInstall){
|
||||||
Write-Progress -Activity "$manage Applications" -Status "$manage $($Program.choco) $($x + 1) of $count" -PercentComplete $($x/$count*100)
|
Write-Progress -Activity "$manage Applications" -Status "$manage $($Program.choco) $($x + 1) of $count" -PercentComplete $($x/$count*100)
|
||||||
@ -40,9 +40,10 @@ function Install-WinUtilProgramChoco {
|
|||||||
try{
|
try{
|
||||||
$tryUpgrade = $false
|
$tryUpgrade = $false
|
||||||
$installOutputFilePath = "$env:TEMP\Install-WinUtilProgramChoco.install-command.output.txt"
|
$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).ExitCode
|
||||||
if(($chocoInstallStatus -eq 0) -AND (Test-Path -Path $outputFilePath)) {
|
if(($chocoInstallStatus -eq 0) -AND (Test-Path -Path $installOutputFilePath)) {
|
||||||
$keywordsFound = Get-Content -Path $outputFilePath | Where {$_ -match "reinstall" -OR $_ -match "already installed"}
|
$keywordsFound = Get-Content -Path $installOutputFilePath | Where-Object {$_ -match "reinstall" -OR $_ -match "already installed"}
|
||||||
if ($keywordsFound) {
|
if ($keywordsFound) {
|
||||||
$tryUpgrade = $true
|
$tryUpgrade = $true
|
||||||
}
|
}
|
||||||
@ -66,6 +67,7 @@ function Install-WinUtilProgramChoco {
|
|||||||
write-host "Starting uninstall of $($Program.choco) with Chocolatey."
|
write-host "Starting uninstall of $($Program.choco) with Chocolatey."
|
||||||
try{
|
try{
|
||||||
$uninstallOutputFilePath = "$env:TEMP\Install-WinUtilProgramChoco.uninstall-command.output.txt"
|
$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).ExitCode
|
||||||
if($chocoUninstallStatus -eq 0){
|
if($chocoUninstallStatus -eq 0){
|
||||||
Write-Host "$($Program.choco) uninstalled successfully using Chocolatey."
|
Write-Host "$($Program.choco) uninstalled successfully using Chocolatey."
|
||||||
@ -82,8 +84,8 @@ function Install-WinUtilProgramChoco {
|
|||||||
Write-Progress -Activity "$manage Applications" -Status "Finished" -Completed
|
Write-Progress -Activity "$manage Applications" -Status "Finished" -Completed
|
||||||
|
|
||||||
# Cleanup leftovers files
|
# Cleanup leftovers files
|
||||||
Remove-Item -Path $installOutputFilePath
|
if(Test-Path -Path $installOutputFilePath){ Remove-Item -Path $installOutputFilePath }
|
||||||
Remove-Item -Path $uninstallOutputFilePath
|
if(Test-Path -Path $installOutputFilePath){ Remove-Item -Path $uninstallOutputFilePath }
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -15,15 +15,18 @@ Function Install-WinUtilProgramWinget {
|
|||||||
#>
|
#>
|
||||||
|
|
||||||
param(
|
param(
|
||||||
$ProgramsToInstall,
|
[Parameter(Mandatory, Position=0)]
|
||||||
$manage = "Installing"
|
[PsCustomObject]$ProgramsToInstall,
|
||||||
|
|
||||||
|
[Parameter(Position=1)]
|
||||||
|
[String]$manage = "Installing"
|
||||||
)
|
)
|
||||||
$x = 0
|
$x = 0
|
||||||
$count = $ProgramsToInstall.Count
|
$count = $ProgramsToInstall.Count
|
||||||
|
|
||||||
Write-Progress -Activity "$manage Applications" -Status "Starting" -PercentComplete 0
|
Write-Progress -Activity "$manage Applications" -Status "Starting" -PercentComplete 0
|
||||||
Write-Host "==========================================="
|
Write-Host "==========================================="
|
||||||
Write-Host "-- installing winget packages ---"
|
Write-Host "-- Configuring winget packages ---"
|
||||||
Write-Host "==========================================="
|
Write-Host "==========================================="
|
||||||
Foreach ($Program in $ProgramsToInstall){
|
Foreach ($Program in $ProgramsToInstall){
|
||||||
$failedPackages = @()
|
$failedPackages = @()
|
||||||
@ -60,9 +63,11 @@ Function Install-WinUtilProgramWinget {
|
|||||||
Write-Host "$($Program.winget) installed successfully with User prompt."
|
Write-Host "$($Program.winget) installed successfully with User prompt."
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
Write-Host "Failed to install $($Program.winget). With winget"
|
||||||
|
$failedPackages += $Program
|
||||||
} catch {
|
} catch {
|
||||||
Write-Host "Failed to install $($Program.winget). With winget"
|
Write-Host "Failed to install $($Program.winget). With winget"
|
||||||
$failedPackages += $($Program.winget)
|
$failedPackages += $Program
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($manage -eq "Uninstalling"){
|
if($manage -eq "Uninstalling"){
|
||||||
@ -73,11 +78,11 @@ Function Install-WinUtilProgramWinget {
|
|||||||
Write-Host "Failed to uninstall $($Program.winget)."
|
Write-Host "Failed to uninstall $($Program.winget)."
|
||||||
} else {
|
} else {
|
||||||
Write-Host "$($Program.winget) uninstalled successfully."
|
Write-Host "$($Program.winget) uninstalled successfully."
|
||||||
$failedPackages += $($Program.winget)
|
$failedPackages += $Program
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
Write-Host "Failed to uninstall $($Program.winget) due to an error: $_"
|
Write-Host "Failed to uninstall $($Program.winget) due to an error: $_"
|
||||||
$failedPackages += $($Program.winget)
|
$failedPackages += $Program
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$X++
|
$X++
|
||||||
|
@ -50,10 +50,10 @@ function Invoke-WPFUnInstall {
|
|||||||
|
|
||||||
# Install all selected programs in new window
|
# Install all selected programs in new window
|
||||||
if($packagesWinget.Count -gt 0){
|
if($packagesWinget.Count -gt 0){
|
||||||
Install-WinUtilProgramWinget -ProgramsToInstall $PackagesToInstall -Manage "Uninstalling"
|
Install-WinUtilProgramWinget -ProgramsToInstall $packagesWinget -Manage "Uninstalling"
|
||||||
}
|
}
|
||||||
if($packagesChoco.Count -gt 0){
|
if($packagesChoco.Count -gt 0){
|
||||||
Install-WinUtilProgramChoco -ProgramsToInstall $PackagesToInstall -Manage "Uninstalling"
|
Install-WinUtilProgramChoco -ProgramsToInstall $packagesChoco -Manage "Uninstalling"
|
||||||
}
|
}
|
||||||
|
|
||||||
$ButtonType = [System.Windows.MessageBoxButton]::OK
|
$ButtonType = [System.Windows.MessageBoxButton]::OK
|
||||||
@ -69,7 +69,7 @@ function Invoke-WPFUnInstall {
|
|||||||
}
|
}
|
||||||
Catch {
|
Catch {
|
||||||
Write-Host "==========================================="
|
Write-Host "==========================================="
|
||||||
Write-Host "-- Winget failed to install ---"
|
Write-Host "Error: $_"
|
||||||
Write-Host "==========================================="
|
Write-Host "==========================================="
|
||||||
}
|
}
|
||||||
$sync.ProcessRunning = $False
|
$sync.ProcessRunning = $False
|
||||||
|
Loading…
Reference in New Issue
Block a user