Skip to content

Commit

Permalink
Taskbaritem > Progressbar / Overlay icon / description / asset mgmt (#…
Browse files Browse the repository at this point in the history
…2309)

* Add Progress bar to some stuff

https://learn.microsoft.com/en-us/dotnet/api/system.windows.shell.taskbariteminfo?view=windowsdesktop-8.0

* add function to manage taskbar item

changed from manually setting the taskbar overlay, progressvalue and progress state to setting them through a function

* add description feature

* use Dispatcher.Invoke

* restructure, fix, additions

* fix merge conflicts

* add check to progresses

* remove progress from wiget & choco install

* fix

* polish

* fix

* Update functions/private/Set-WinUtilTaskbarItem.ps1

Co-authored-by: Mr.k <[email protected]>

* fix syntax

* Update functions/private/Set-WinUtilTaskbarItem.ps1

Co-authored-by: Mr.k <[email protected]>

* rework

- add overlay presets
- rework image saving & converting
- removed popup after uninstalling applications

* fix description of function

* undo winutil

* remove check.png

* Update functions/private/Set-WinUtilTaskbarItem.ps1

Co-authored-by: Mr.k <[email protected]>

* Update functions/private/Set-WinUtilTaskbarItem.ps1

Co-authored-by: Mr.k <[email protected]>

* rework assets directory & its usage

* fixes

- ability to set no overlay added
- added relative path to winutildir

* hotfix

* last fixes

* add comment

* remove trailing whitespaces

THX to Mr.K :)

* renamed checkmark & added warning

* last fixes

remove bitmap
remove unneeded "| out-null"

* hotfix for new commit

---------

Co-authored-by: Mr.k <[email protected]>
  • Loading branch information
MyDrift-user and og-mrk authored Jul 25, 2024
1 parent 84a84fd commit 1032d3d
Show file tree
Hide file tree
Showing 16 changed files with 225 additions and 52 deletions.
13 changes: 12 additions & 1 deletion functions/private/Install-WinUtilProgramChoco.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,18 @@ function Install-WinUtilProgramChoco {
}
if(($chocoInstallStatus -eq 0) -AND ($tryUpgrade -eq $false)){
Write-Host "$($Program.choco) installed successfully using Chocolatey."
$X++
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value ($x/$count) })
continue
} else {
Write-Host "Failed to install $($Program.choco) using Chocolatey, Chocolatey output:`n`n$(Get-Content -Path $installOutputFilePath)."
$X++
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" -value ($x/$count) })
}
} catch {
Write-Host "Failed to install $($Program.choco) due to an error: $_"
$X++
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" -value ($x/$count) })
}
}

Expand All @@ -71,15 +77,20 @@ function Install-WinUtilProgramChoco {
$chocoUninstallStatus = $(Start-Process -FilePath "choco" -ArgumentList "uninstall $($Program.choco) -y" -Wait -PassThru).ExitCode
if($chocoUninstallStatus -eq 0){
Write-Host "$($Program.choco) uninstalled successfully using Chocolatey."
$x++
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value ($x/$count) })
continue
} else {
Write-Host "Failed to uninstall $($Program.choco) using Chocolatey, Chocolatey output:`n`n$(Get-Content -Path $uninstallOutputFilePath)."
$x++
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" -value ($x/$count) })
}
} catch {
Write-Host "Failed to uninstall $($Program.choco) due to an error: $_"
$x++
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" -value ($x/$count) })
}
}
$x++
}
Write-Progress -Activity "$manage Applications" -Status "Finished" -Completed

Expand Down
10 changes: 10 additions & 0 deletions functions/private/Install-WinUtilProgramWinget.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,24 @@ Function Install-WinUtilProgramWinget {
$status = $(Start-Process -FilePath "winget" -ArgumentList "install --id $($Program.winget) --silent --accept-source-agreements --accept-package-agreements" -Wait -PassThru -NoNewWindow).ExitCode
if($status -eq 0) {
Write-Host "$($Program.winget) installed successfully."
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -value ($x/$count) })
continue
}
if ($status -eq -1978335189) {
Write-Host "$($Program.winget) No applicable update found"
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -value ($x/$count) })
continue
}
Write-Host "Attempt with User scope"
$status = $(Start-Process -FilePath "winget" -ArgumentList "install --id $($Program.winget) --scope user --silent --accept-source-agreements --accept-package-agreements" -Wait -PassThru -NoNewWindow).ExitCode
if($status -eq 0) {
Write-Host "$($Program.winget) installed successfully with User scope."
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -value ($x/$count) })
continue
}
if ($status -eq -1978335189) {
Write-Host "$($Program.winget) No applicable update found"
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -value ($x/$count) })
continue
}
Write-Host "Attempt with User prompt"
Expand All @@ -71,15 +75,18 @@ Function Install-WinUtilProgramWinget {
}
if($status -eq 0) {
Write-Host "$($Program.winget) installed successfully with User prompt."
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -value ($x/$count) })
continue
}
if ($status -eq -1978335189) {
Write-Host "$($Program.winget) No applicable update found"
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -value ($x/$count) })
continue
}
} catch {
Write-Host "Failed to install $($Program.winget). With winget"
$failedPackages += $Program
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" -value ($x/$count) })
}
}
elseif($manage -eq "Uninstalling") {
Expand All @@ -88,14 +95,17 @@ Function Install-WinUtilProgramWinget {
$status = $(Start-Process -FilePath "winget" -ArgumentList "uninstall --id $($Program.winget) --silent" -Wait -PassThru -NoNewWindow).ExitCode
if($status -ne 0) {
Write-Host "Failed to uninstall $($Program.winget)."
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" })
} else {
Write-Host "$($Program.winget) uninstalled successfully."
$failedPackages += $Program
}
} catch {
Write-Host "Failed to uninstall $($Program.winget) due to an error: $_"
$failedPackages += $Program
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" })
}
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -value ($x/$count) })
}
else {
throw "[Install-WinUtilProgramWinget] Invalid Value for Parameter 'manage', Provided Value is: $manage"
Expand Down
2 changes: 2 additions & 0 deletions functions/private/Install-WinUtilWinget.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function Install-WinUtilWinget {
Write-Host "`nWinget is not Installed. Continuing with install.`r" -ForegroundColor Red
}


# Gets the computer's information
if ($null -eq $sync.ComputerInfo){
$ComputerInfo = Get-ComputerInfo -ErrorAction Stop
Expand Down Expand Up @@ -63,4 +64,5 @@ function Install-WinUtilWinget {
throw [WingetFailedInstall]::new('Failed to install!')
}
}

}
8 changes: 8 additions & 0 deletions functions/private/Invoke-WinUtilFeatureInstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ function Invoke-WinUtilFeatureInstall {
$CheckBox
)

$x = 0

$CheckBox | ForEach-Object {
if($sync.configs.feature.$psitem.feature){
Foreach( $feature in $sync.configs.feature.$psitem.feature ){
Expand All @@ -20,9 +22,11 @@ function Invoke-WinUtilFeatureInstall {
Catch{
if ($psitem.Exception.Message -like "*requires elevation*"){
Write-Warning "Unable to Install $feature due to permissions. Are you running as admin?"
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" })
}

else{

Write-Warning "Unable to Install $feature due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace
}
Expand All @@ -40,14 +44,18 @@ function Invoke-WinUtilFeatureInstall {
Catch{
if ($psitem.Exception.Message -like "*requires elevation*"){
Write-Warning "Unable to Install $feature due to permissions. Are you running as admin?"
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" })
}

else{
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" })
Write-Warning "Unable to Install $feature due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace
}
}
}
}
$X++
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -value ($x/$CheckBox.Count) })
}
}
86 changes: 86 additions & 0 deletions functions/private/Set-WinUtilTaskbarItem.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
function Set-WinUtilTaskbaritem {
<#
.SYNOPSIS
Modifies the Taskbaritem of the WPF Form
.PARAMETER value
Value can be between 0 and 1, 0 being no progress done yet and 1 being fully completed
Value does not affect item without setting the state to 'Normal', 'Error' or 'Paused'
Set-WinUtilTaskbaritem -value 0.5
.PARAMETER state
State can be 'None' > No progress, 'Indeterminate' > inf. loading gray, 'Normal' > Gray, 'Error' > Red, 'Paused' > Yellow
no value needed:
- Set-WinUtilTaskbaritem -state "None"
- Set-WinUtilTaskbaritem -state "Indeterminate"
value needed:
- Set-WinUtilTaskbaritem -state "Error"
- Set-WinUtilTaskbaritem -state "Normal"
- Set-WinUtilTaskbaritem -state "Paused"
.PARAMETER overlay
Overlay icon to display on the taskbar item, there are the presets 'None', 'logo' and 'checkmark' or you can specify a path/link to an image file.
CTT logo preset:
- Set-WinUtilTaskbaritem -overlay "logo"
Checkmark preset:
- Set-WinUtilTaskbaritem -overlay "checkmark"
Warning preset:
- Set-WinUtilTaskbaritem -overlay "warning"
No overlay:
- Set-WinUtilTaskbaritem -overlay "None"
Custom icon (needs to be supported by WPF):
- Set-WinUtilTaskbaritem -overlay "C:\path\to\icon.png"
.PARAMETER description
Description to display on the taskbar item preview
Set-WinUtilTaskbaritem -description "This is a description"
#>
param (
[string]$state,
[double]$value,
[string]$overlay,
[string]$description
)

if ($value) {
$sync["Form"].taskbarItemInfo.ProgressValue = $value
}

if ($state) {
switch ($state) {
'None' { $sync["Form"].taskbarItemInfo.ProgressState = "None" }
'Indeterminate' { $sync["Form"].taskbarItemInfo.ProgressState = "Indeterminate" }
'Normal' { $sync["Form"].taskbarItemInfo.ProgressState = "Normal" }
'Error' { $sync["Form"].taskbarItemInfo.ProgressState = "Error" }
'Paused' { $sync["Form"].taskbarItemInfo.ProgressState = "Paused" }
default { throw "[Set-WinUtilTaskbarItem] Invalid state" }
}
}

if ($overlay) {
switch ($overlay) {
'logo' {
$sync["Form"].taskbarItemInfo.Overlay = "$env:LOCALAPPDATA\winutil\cttlogo.png"
}
'checkmark' {
$sync["Form"].taskbarItemInfo.Overlay = "$env:LOCALAPPDATA\winutil\checkmark.png"
}
'warning' {
$sync["Form"].taskbarItemInfo.Overlay = "$env:LOCALAPPDATA\winutil\warning.png"
}
'None' {
$sync["Form"].taskbarItemInfo.Overlay = $null
}
default {
if (Test-Path $overlay) {
$sync["Form"].taskbarItemInfo.Overlay = $overlay
}
}
}
}

if ($description) {
$sync["Form"].taskbarItemInfo.Description = $description
}
}
8 changes: 7 additions & 1 deletion functions/public/Invoke-WPFFeatureInstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ function Invoke-WPFFeatureInstall {

Invoke-WPFRunspace -ArgumentList $Features -DebugPreference $DebugPreference -ScriptBlock {
param($Features, $DebugPreference)

$sync.ProcessRunning = $true
if ($Features.count -eq 1){
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" -value 0.01 -overlay "logo" })
} else {
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value 0.01 -overlay "logo" })
}

Invoke-WinUtilFeatureInstall $Features

$sync.ProcessRunning = $false
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" -overlay "checkmark" })

Write-Host "==================================="
Write-Host "--- Features are Installed ---"
Write-Host "--- A Reboot may be required ---"
Expand Down
2 changes: 2 additions & 0 deletions functions/public/Invoke-WPFGetInstalled.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function Invoke-WPFGetInstalled {
param($checkbox, $DebugPreference)

$sync.ProcessRunning = $true
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" })

if($checkbox -eq "winget"){
Write-Host "Getting Installed Programs..."
Expand All @@ -42,5 +43,6 @@ function Invoke-WPFGetInstalled {

Write-Host "Done..."
$sync.ProcessRunning = $false
$sync.form.Dispatcher.Invoke([action] { Set-WinUtilTaskbaritem -state "None" })
}
}
7 changes: 7 additions & 0 deletions functions/public/Invoke-WPFGetIso.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function Invoke-WPFGetIso {
$sync.BusyText.Text="N Busy"



Write-Host " _ __ __ _ "
Write-Host " /\/\ (_) ___ _ __ ___ / / /\ \ \(_) _ __ "
Write-Host " / \ | | / __|| '__| / _ \ \ \/ \/ /| || '_ \ "
Expand Down Expand Up @@ -88,6 +89,8 @@ function Invoke-WPFGetIso {
return
}

Set-WinUtilTaskbaritem -state "Indeterminate" -overlay "logo"

# Detect the file size of the ISO and compare it with the free space of the system drive
$isoSize = (Get-Item -Path $filePath).Length
Write-Debug "Size of ISO file: $($isoSize) bytes"
Expand All @@ -104,6 +107,7 @@ function Invoke-WPFGetIso {
{
# It's critical and we can't continue. Output an error
Write-Host "You don't have enough space for this operation. You need at least $([Math]::Round(($isoSize / ([Math]::Pow(1024, 2))) * 2, 2)) MB of free space to copy the ISO files to a temp directory and to be able to perform additional operations."
Set-WinUtilTaskbaritem -state "Error" -value 1 -overlay "warning"
return
}
else
Expand All @@ -122,6 +126,7 @@ function Invoke-WPFGetIso {
Write-Error "Failed to mount the image. Error: $($_.Exception.Message)"
Write-Error "This is NOT winutil's problem, your ISO might be corrupt, or there is a problem on the system"
Write-Error "Please refer to this wiki for more details https://github.com/ChrisTitusTech/winutil/blob/main/wiki/Error-in-Winutil-MicroWin-during-ISO-mounting%2Cmd"
Set-WinUtilTaskbaritem -state "Error" -value 1 -overlay "warning"
return
}
# storing off values in hidden fields for further steps
Expand Down Expand Up @@ -199,6 +204,7 @@ function Invoke-WPFGetIso {
$msg = "Neither install.wim nor install.esd exist in the image, this could happen if you use unofficial Windows images. Please don't use shady images from the internet, use only official images. Here are instructions how to download ISO images if the Microsoft website is not showing the link to download and ISO. https://www.techrepublic.com/article/how-to-download-a-windows-10-iso-file-without-using-the-media-creation-tool/"
Write-Host $msg
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error)
Set-WinUtilTaskbaritem -state "Error" -value 1 -overlay "warning"
throw
}
elseif ((-not (Test-Path -Path $wimFile -PathType Leaf)) -and (Test-Path -Path $wimFile.Replace(".wim", ".esd").Trim() -PathType Leaf))
Expand Down Expand Up @@ -239,6 +245,7 @@ function Invoke-WPFGetIso {

$sync.BusyMessage.Visibility="Hidden"
$sync.ProcessRunning = $false
Set-WinUtilTaskbaritem -state "None" -overlay "checkmark"
}


9 changes: 8 additions & 1 deletion functions/public/Invoke-WPFInstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ function Invoke-WPFInstall {
return
}


Invoke-WPFRunspace -ArgumentList $PackagesToInstall -DebugPreference $DebugPreference -ScriptBlock {
param($PackagesToInstall, $DebugPreference)
if ($PackagesToInstall.count -eq 1){
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" -value 0.01 -overlay "logo" })
} else {
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value 0.01 -overlay "logo" })
}
$packagesWinget, $packagesChoco = {
$packagesWinget = [System.Collections.Generic.List`1[System.Object]]::new()
$packagesChoco = [System.Collections.Generic.List`1[System.Object]]::new()
Expand Down Expand Up @@ -52,13 +58,14 @@ function Invoke-WPFInstall {
Write-Host "==========================================="
Write-Host "-- Installs have finished ---"
Write-Host "==========================================="
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" -overlay "checkmark" })
}
Catch {
Write-Host "==========================================="
Write-Host "Error: $_"
Write-Host "==========================================="
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" -overlay "warning" })
}
Start-Sleep -Seconds 5
$sync.ProcessRunning = $False
}
}
2 changes: 2 additions & 0 deletions functions/public/Invoke-WPFInstallUpgrade.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ function Invoke-WPFInstallUpgrade {
return
}

# Set-WinUtilTaskbaritem -state "Indeterminate"

Update-WinUtilProgramWinget

Write-Host "==========================================="
Expand Down
Loading

0 comments on commit 1032d3d

Please sign in to comment.