mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-01-15 17:30:37 -06:00
Compare commits
7 Commits
cd35c74896
...
e7e742044b
Author | SHA1 | Date | |
---|---|---|---|
|
e7e742044b | ||
|
87c43ec87f | ||
|
b2dd522a90 | ||
|
000317a139 | ||
|
4a22f7a60f | ||
|
5889b36773 | ||
|
c2c2e5ea71 |
Binary file not shown.
Before Width: | Height: | Size: 42 KiB |
@ -4,27 +4,39 @@ function Set-WinUtilTaskbaritem {
|
||||
.SYNOPSIS
|
||||
Modifies the Taskbaritem of the WPF Form
|
||||
|
||||
.PARAMETER state
|
||||
State can be 'None' > No progress, 'Indeterminate' > Without value, 'Normal' > when using value, 'Error' > Red (when using value), 'Paused' > Yellow (when using value)
|
||||
.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
|
||||
|
||||
.EXAMPLE
|
||||
Set-WinUtilTaskbaritem -value 0.5 -state "Normal"
|
||||
Set-WinUtilTaskbaritem -state "Error"
|
||||
Set-WinUtilTaskbaritem -state "Indeterminate"
|
||||
Overlay icon to display on the taskbar item, there are the presets '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"
|
||||
Custom icon:
|
||||
- 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"
|
||||
Set-WinUtilTaskbaritem -overlay "C:\path\to\icon.png"
|
||||
|
||||
#>
|
||||
param (
|
||||
[string]$state,
|
||||
[double]$value,
|
||||
$state,
|
||||
$overlay,
|
||||
$description
|
||||
[string]$overlay,
|
||||
[string]$description
|
||||
)
|
||||
|
||||
if ($value) {
|
||||
@ -33,37 +45,29 @@ function Set-WinUtilTaskbaritem {
|
||||
|
||||
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 { $sync["Form"].taskbarItemInfo.ProgressState = "None" }
|
||||
default { throw "[Set-WinUtilTaskbarItem] Invalid state" }
|
||||
}
|
||||
}
|
||||
|
||||
if ($overlay -and (Test-Path $overlay)) {
|
||||
# Read the image file as a byte array
|
||||
$imageBytes = [System.IO.File]::ReadAllBytes($overlay)
|
||||
|
||||
# Convert the byte array to a Base64 string
|
||||
[System.Convert]::ToBase64String($imageBytes)
|
||||
|
||||
# Load the image file as a bitmap
|
||||
$bitmap = [System.Drawing.Bitmap]::new($overlay)
|
||||
|
||||
# Create a streaming image by streaming the bitmap to a memory stream
|
||||
$memoryStream = [System.IO.MemoryStream]::new()
|
||||
$bitmap.Save($memoryStream, [System.Drawing.Imaging.ImageFormat]::Png)
|
||||
$memoryStream.Position = 0
|
||||
|
||||
# Create a bitmap image from the memory stream
|
||||
$bitmapImage = [System.Windows.Media.Imaging.BitmapImage]::new()
|
||||
$bitmapImage.BeginInit()
|
||||
$bitmapImage.StreamSource = $memoryStream
|
||||
$bitmapImage.EndInit()
|
||||
$bitmapImage.Freeze()
|
||||
|
||||
$sync["Form"].taskbarItemInfo.Overlay = $bitmapImage
|
||||
if ($overlay) {
|
||||
switch ($overlay) {
|
||||
'logo' {
|
||||
$sync["Form"].taskbarItemInfo.Overlay = (ConvertTo-Bitmap -image "$env:LOCALAPPDATA\winutil\cttlogo.png")
|
||||
}
|
||||
'checkmark' {
|
||||
$sync["Form"].taskbarItemInfo.Overlay = (ConvertTo-Bitmap -image "$env:LOCALAPPDATA\winutil\cttcheckmark.png")
|
||||
}
|
||||
default {
|
||||
if (Test-Path $overlay) {
|
||||
$sync["Form"].taskbarItemInfo.Overlay = (ConvertTo-Bitmap -image $overlay)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($description) {
|
||||
|
31
functions/private/convertTo-Bitmap.ps1
Normal file
31
functions/private/convertTo-Bitmap.ps1
Normal file
@ -0,0 +1,31 @@
|
||||
function ConvertTo-Bitmap {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Converts an image file to a Bitmap object
|
||||
|
||||
.PARAMETER image
|
||||
The path to the image file to convert
|
||||
|
||||
.EXAMPLE
|
||||
ConvertTo-Bitmap -image "C:\path\to\image.png"
|
||||
#>
|
||||
param (
|
||||
$image
|
||||
)
|
||||
|
||||
# Read the image file as a byte array
|
||||
$imageBytes = [System.IO.File]::ReadAllBytes($image)
|
||||
|
||||
# Convert the byte array to a Base64 string
|
||||
$base64String = [System.Convert]::ToBase64String($imageBytes)
|
||||
|
||||
# Create a streaming image by streaming the base64 string to a bitmap streamsource
|
||||
$bitmap = New-Object System.Windows.Media.Imaging.BitmapImage
|
||||
$bitmap.BeginInit()
|
||||
$bitmap.StreamSource = [System.IO.MemoryStream][System.Convert]::FromBase64String($base64String)
|
||||
$bitmap.EndInit()
|
||||
$bitmap.Freeze()
|
||||
|
||||
# Return the bitmap object
|
||||
return $bitmap
|
||||
}
|
@ -18,15 +18,15 @@ function Invoke-WPFFeatureInstall {
|
||||
param($Features, $DebugPreference)
|
||||
$sync.ProcessRunning = $true
|
||||
if ($Features.count -eq 1){
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" -value 0.01 })
|
||||
$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 })
|
||||
$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 "$env:TEMP\cttcheck.png" })
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" -overlay "checkmark" })
|
||||
|
||||
Write-Host "==================================="
|
||||
Write-Host "--- Features are Installed ---"
|
||||
|
@ -89,7 +89,7 @@ function Invoke-WPFGetIso {
|
||||
return
|
||||
}
|
||||
|
||||
Set-WinUtilTaskbaritem -state "Indeterminate"
|
||||
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
|
||||
@ -245,7 +245,7 @@ function Invoke-WPFGetIso {
|
||||
|
||||
$sync.BusyMessage.Visibility="Hidden"
|
||||
$sync.ProcessRunning = $false
|
||||
Set-WinUtilTaskbaritem -state "None"
|
||||
Set-WinUtilTaskbaritem -state "None" -overlay "checkmark"
|
||||
}
|
||||
|
||||
|
||||
|
@ -24,9 +24,9 @@ function Invoke-WPFInstall {
|
||||
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 })
|
||||
$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 })
|
||||
$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()
|
||||
@ -58,7 +58,7 @@ function Invoke-WPFInstall {
|
||||
Write-Host "==========================================="
|
||||
Write-Host "-- Installs have finished ---"
|
||||
Write-Host "==========================================="
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" -overlay "$env:TEMP\cttcheck.png" })
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" -overlay "checkmark" })
|
||||
}
|
||||
Catch {
|
||||
Write-Host "==========================================="
|
||||
@ -66,7 +66,6 @@ function Invoke-WPFInstall {
|
||||
Write-Host "==========================================="
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" })
|
||||
}
|
||||
Start-Sleep -Seconds 5
|
||||
$sync.ProcessRunning = $False
|
||||
}
|
||||
}
|
||||
|
@ -40,10 +40,11 @@ public class PowerManagement {
|
||||
|
||||
if ($SaveDialog.FileName -eq "") {
|
||||
Write-Host "No file name for the target image was specified"
|
||||
Set-WinUtilTaskbaritem -state "Error" -value 1
|
||||
return
|
||||
}
|
||||
|
||||
Set-WinUtilTaskbaritem -state "Indeterminate"
|
||||
Set-WinUtilTaskbaritem -state "Indeterminate" -overlay "logo"
|
||||
|
||||
Write-Host "Target ISO location: $($SaveDialog.FileName)"
|
||||
|
||||
@ -474,7 +475,7 @@ public class PowerManagement {
|
||||
#$msg = "Done. ISO image is located here: $env:temp\microwin.iso"
|
||||
$msg = "Done. ISO image is located here: $($SaveDialog.FileName)"
|
||||
Write-Host $msg
|
||||
Set-WinUtilTaskbaritem -state "None"
|
||||
Set-WinUtilTaskbaritem -state "None" -overlay "checkmark"
|
||||
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Information)
|
||||
} else {
|
||||
Write-Host "ISO creation failed. The "$($mountDir)" directory has not been removed."
|
||||
@ -487,6 +488,5 @@ public class PowerManagement {
|
||||
# Allow the machine to sleep again (optional)
|
||||
[PowerManagement]::SetThreadExecutionState(0)
|
||||
$sync.ProcessRunning = $false
|
||||
Set-WinUtilTaskbaritem -state "None"
|
||||
}
|
||||
}
|
@ -27,12 +27,6 @@ function Invoke-WPFShortcut {
|
||||
$ArgumentsToSourceExe = "$powershell '$IRM'"
|
||||
$DestinationName = "WinUtil.lnk"
|
||||
|
||||
Invoke-WebRequest -Uri "https://christitus.com/images/logo-full.png" -OutFile "$env:TEMP\cttlogo.png"
|
||||
|
||||
if (Test-Path -Path "$env:TEMP\cttlogo.png") {
|
||||
$iconPath = "$env:LOCALAPPDATA\winutil\cttlogo.ico"
|
||||
ConvertTo-Icon -bitmapPath "$env:TEMP\cttlogo.png" -iconPath $iconPath
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,8 +48,8 @@ function Invoke-WPFShortcut {
|
||||
$Shortcut = $WshShell.CreateShortcut($FileBrowser.FileName)
|
||||
$Shortcut.TargetPath = $SourceExe
|
||||
$Shortcut.Arguments = $ArgumentsToSourceExe
|
||||
if ($iconPath -ne $null) {
|
||||
$shortcut.IconLocation = $iconPath
|
||||
if (Test-Path -Path $ctticologo) {
|
||||
$shortcut.IconLocation = $ctticologo
|
||||
}
|
||||
|
||||
# Save the Shortcut to disk
|
||||
|
@ -33,9 +33,9 @@ function Invoke-WPFUnInstall {
|
||||
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 })
|
||||
$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 })
|
||||
$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()
|
||||
@ -67,7 +67,7 @@ function Invoke-WPFUnInstall {
|
||||
Write-Host "==========================================="
|
||||
Write-Host "-- Uninstalls have finished ---"
|
||||
Write-Host "==========================================="
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" -overlay "$env:TEMP\cttcheck.png" })
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" -overlay "checkmark" })
|
||||
}
|
||||
Catch {
|
||||
Write-Host "==========================================="
|
||||
@ -77,9 +77,5 @@ function Invoke-WPFUnInstall {
|
||||
}
|
||||
$sync.ProcessRunning = $False
|
||||
|
||||
$ButtonType = [System.Windows.MessageBoxButton]::OK
|
||||
$MessageboxTitle = "Uninstalls are Finished "
|
||||
$Messageboxbody = ("Done")
|
||||
$MessageIcon = [System.Windows.MessageBoxImage]::Information
|
||||
}
|
||||
}
|
||||
|
@ -31,9 +31,9 @@ function Invoke-WPFtweaksbutton {
|
||||
$sync.ProcessRunning = $true
|
||||
|
||||
if ($Tweaks.count -eq 1){
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" -value 0.01 })
|
||||
$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 })
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value 0.01 -overlay "logo" })
|
||||
}
|
||||
$cnt = 0
|
||||
# Execute other selected tweaks
|
||||
@ -45,7 +45,7 @@ function Invoke-WPFtweaksbutton {
|
||||
}
|
||||
|
||||
$sync.ProcessRunning = $false
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" -overlay "$env:TEMP\cttcheck.png" })
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" -overlay "checkmark" })
|
||||
Write-Host "================================="
|
||||
Write-Host "-- Tweaks are Finished ---"
|
||||
Write-Host "================================="
|
||||
|
@ -25,9 +25,9 @@ function Invoke-WPFundoall {
|
||||
|
||||
$sync.ProcessRunning = $true
|
||||
if ($Tweaks.count -eq 1){
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" -value 0.01 })
|
||||
$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 })
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value 0.01 -overlay "logo" })
|
||||
}
|
||||
$cnt = 0
|
||||
|
||||
@ -38,7 +38,7 @@ function Invoke-WPFundoall {
|
||||
}
|
||||
|
||||
$sync.ProcessRunning = $false
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" -overlay "$env:TEMP\cttcheck.png" })
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" -overlay "checkmark" })
|
||||
Write-Host "=================================="
|
||||
Write-Host "--- Undo Tweaks are Finished ---"
|
||||
Write-Host "=================================="
|
||||
|
@ -154,19 +154,6 @@ Invoke-WPFRunspace -ScriptBlock {
|
||||
# Print the logo
|
||||
Invoke-WPFFormVariables
|
||||
|
||||
# download the logo
|
||||
$logoUrl = "https://christitus.com/images/logo-full.png"
|
||||
# Download the image
|
||||
$logoPath = "$env:TEMP\cttlogo.png"
|
||||
Invoke-WebRequest -Uri $logoUrl -OutFile $logoPath
|
||||
|
||||
# download the check
|
||||
$CheckUrl = "https://raw.githubusercontent.com/ChrisTitusTech/winutil/main/docs/assets/check.png"
|
||||
|
||||
# Download the image
|
||||
$CheckPath = "$env:TEMP\cttcheck.png"
|
||||
Invoke-WebRequest -Uri $CheckUrl -OutFile $CheckPath
|
||||
|
||||
# Progress bar in taskbaritem > Set-WinUtilProgressbar
|
||||
$sync["Form"].TaskbarItemInfo = New-Object System.Windows.Shell.TaskbarItemInfo
|
||||
Set-WinUtilTaskbaritem -state "None"
|
||||
@ -305,9 +292,6 @@ Add-Type @"
|
||||
}
|
||||
}
|
||||
|
||||
# Set the overlay icon for the taskbar
|
||||
Set-WinUtilTaskbaritem -overlay $logoPath
|
||||
|
||||
$rect = New-Object RECT
|
||||
[Window]::GetWindowRect($windowHandle, [ref]$rect)
|
||||
$width = $rect.Right - $rect.Left
|
||||
@ -446,8 +430,25 @@ $sync["SearchBar"].Add_TextChanged({
|
||||
$label.Visibility = "Collapsed"}
|
||||
})
|
||||
|
||||
$sync["Form"].Add_Activated({
|
||||
Set-WinUtilTaskbaritem -overlay $logoPath -state "None"
|
||||
$cttpnglogo = "$env:LOCALAPPDATA\winutil\cttlogo.png"
|
||||
$ctticologo = "$env:LOCALAPPDATA\winutil\cttlogo.ico"
|
||||
if (-NOT (Test-Path -Path $cttpnglogo) -or -NOT (Test-Path -Path $ctticologo)) {
|
||||
Invoke-WebRequest -Uri "https://christitus.com/images/logo-full.png" -OutFile $cttpnglogo
|
||||
}
|
||||
|
||||
$cttpngcheckmark = "$env:LOCALAPPDATA\winutil\cttcheckmark.png"
|
||||
$ctticocheckmark = "$env:LOCALAPPDATA\winutil\cttcheckmark.ico"
|
||||
if (-NOT (Test-Path -Path $cttpngcheckmark) -or -NOT (Test-Path -Path $ctticocheckmark)) {
|
||||
Invoke-WebRequest -Uri "https://christitus.com/images/checkmark.png" -OutFile $cttpngcheckmark
|
||||
}
|
||||
|
||||
ConvertTo-Icon -bitmapPath $cttpnglogo -iconPath $ctticologo
|
||||
|
||||
Set-WinUtilTaskbaritem -overlay "logo" | Out-Null
|
||||
$sync["Form"].icon = $cttpnglogo
|
||||
|
||||
$sync["Form"].Add_Activated({
|
||||
Set-WinUtilTaskbaritem -overlay "logo"
|
||||
})
|
||||
|
||||
# Define event handler for button click
|
||||
|
Loading…
Reference in New Issue
Block a user