mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-01-15 17:30:37 -06:00
Change Logging, Fix interactivity and optimize uninstall
This commit is contained in:
parent
44c6ecc334
commit
d111244347
@ -41,31 +41,35 @@ function Install-WinUtilProgramChoco {
|
|||||||
$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
|
New-Item -ItemType File -Path $installOutputFilePath
|
||||||
$chocoInstallStatus = $(Start-Process -FilePath "choco" -ArgumentList "install $($Program.choco) -y" -Wait -PassThru -RedirectStandardOutput $installOutputFilePath -NoNewWindow).ExitCode
|
$chocoInstallStatus = $(Start-Process -FilePath "choco" -ArgumentList "install $($Program.choco) -y --log-file $($installOutputFilePath)" -Wait -PassThru).ExitCode
|
||||||
if (($chocoInstallStatus -eq 0) -AND (Test-Path -Path $installOutputFilePath)) {
|
if (($chocoInstallStatus -eq 0) -AND (Test-Path -Path $installOutputFilePath)) {
|
||||||
$keywordsFound = Get-Content -Path $installOutputFilePath | Where-Object { $_ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# 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) {
|
if ($tryUpgrade) {
|
||||||
$chocoUpdateStatus = $(Start-Process -FilePath "choco" -ArgumentList "upgrade $($Program.choco) -y" -Wait -PassThru -RedirectStandardOutput $installOutputFilePath -NoNewWindow).ExitCode
|
$chocoUpdateStatus = $(Start-Process -FilePath "choco" -ArgumentList "upgrade $($Program.choco) -y" -Wait -PassThru).ExitCode
|
||||||
if ($chocoUpdateStatus -eq 0) {
|
if ($chocoUpdateStatus -eq 0) {
|
||||||
Write-Host "$($Program.choco) was updated successfully using Chocolatey."
|
Write-Host "$($Program.choco) was updated successfully using Chocolatey."
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
Write-Host "Failed upgdate of $($Program.choco) using Chocolatey."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (($chocoInstallStatus -eq 0) -AND ($tryUpgrade -eq $false)) {
|
if (($chocoInstallStatus -eq 0) -AND ($tryUpgrade -eq $false)) {
|
||||||
Write-Host "$($Program.choco) installed successfully using Chocolatey."
|
Write-Host "$($Program.choco) installed successfully using Chocolatey."
|
||||||
$X++
|
$X++
|
||||||
$sync.form.Dispatcher.Invoke([action] { Set-WinUtilTaskbaritem -state "Normal" -value ($x / $count) })
|
$sync.form.Dispatcher.Invoke([action] { Set-WinUtilTaskbaritem -state "Normal" -value ($x / $count) })
|
||||||
continue
|
continue
|
||||||
} else {
|
}
|
||||||
Write-Host "Failed to install $($Program.choco) using Chocolatey, Chocolatey output:`n`n$(Get-Content -Path $installOutputFilePath)."
|
elseif (($chocoInstallStatus -ne 0) -AND ($tryUpgrade -eq $false)) {
|
||||||
|
Write-Host "Failed to install $($Program.choco) using Chocolatey"
|
||||||
$X++
|
$X++
|
||||||
$sync.form.Dispatcher.Invoke([action] { Set-WinUtilTaskbaritem -state "Error" -value ($x / $count) })
|
$sync.form.Dispatcher.Invoke([action] { Set-WinUtilTaskbaritem -state "Error" -value ($x / $count) })
|
||||||
}
|
}
|
||||||
} catch {
|
}
|
||||||
|
catch {
|
||||||
Write-Host "Failed to install $($Program.choco) due to an error: $_"
|
Write-Host "Failed to install $($Program.choco) due to an error: $_"
|
||||||
$X++
|
$X++
|
||||||
$sync.form.Dispatcher.Invoke([action] { Set-WinUtilTaskbaritem -state "Error" -value ($x / $count) })
|
$sync.form.Dispatcher.Invoke([action] { Set-WinUtilTaskbaritem -state "Error" -value ($x / $count) })
|
||||||
@ -73,22 +77,26 @@ function Install-WinUtilProgramChoco {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($manage -eq "Uninstalling") {
|
if ($manage -eq "Uninstalling") {
|
||||||
write-host "Starting uninstall of $($Program.choco) with Chocolatey."
|
Write-Host "Searching for Metapackages of of $($Program.choco) (.install or .portable)"
|
||||||
|
$chocoPackages = ((choco list | Select-String -Pattern "$($Program.choco)(\.install|\.portable){0,1}").Matches.Value) -join " "
|
||||||
|
Write-Host "Starting uninstall of $chocoPackages 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
|
New-Item -ItemType File -Path $uninstallOutputFilePath
|
||||||
$chocoUninstallStatus = $(Start-Process -FilePath "choco" -ArgumentList "uninstall $($Program.choco) -y" -Wait -PassThru -NoNewWindow).ExitCode
|
$chocoUninstallStatus = $(Start-Process -FilePath "choco" -ArgumentList "uninstall $chocoPackages -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."
|
||||||
$x++
|
$x++
|
||||||
$sync.form.Dispatcher.Invoke([action] { Set-WinUtilTaskbaritem -state "Normal" -value ($x / $count) })
|
$sync.form.Dispatcher.Invoke([action] { Set-WinUtilTaskbaritem -state "Normal" -value ($x / $count) })
|
||||||
continue
|
continue
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
Write-Host "Failed to uninstall $($Program.choco) using Chocolatey, Chocolatey output:`n`n$(Get-Content -Path $uninstallOutputFilePath)."
|
Write-Host "Failed to uninstall $($Program.choco) using Chocolatey, Chocolatey output:`n`n$(Get-Content -Path $uninstallOutputFilePath)."
|
||||||
$x++
|
$x++
|
||||||
$sync.form.Dispatcher.Invoke([action] { Set-WinUtilTaskbaritem -state "Error" -value ($x / $count) })
|
$sync.form.Dispatcher.Invoke([action] { Set-WinUtilTaskbaritem -state "Error" -value ($x / $count) })
|
||||||
}
|
}
|
||||||
} catch {
|
}
|
||||||
|
catch {
|
||||||
Write-Host "Failed to uninstall $($Program.choco) due to an error: $_"
|
Write-Host "Failed to uninstall $($Program.choco) due to an error: $_"
|
||||||
$x++
|
$x++
|
||||||
$sync.form.Dispatcher.Invoke([action] { Set-WinUtilTaskbaritem -state "Error" -value ($x / $count) })
|
$sync.form.Dispatcher.Invoke([action] { Set-WinUtilTaskbaritem -state "Error" -value ($x / $count) })
|
||||||
|
Loading…
Reference in New Issue
Block a user