Compare commits

...

4 Commits

Author SHA1 Message Date
27792dc8a3 use Dispatcher.Invoke 2024-07-13 12:54:59 +02:00
790e0b22a5 add description feature 2024-07-12 16:40:45 +02:00
73973d7101 add function to manage taskbar item
changed from manually setting the taskbar overlay, progressvalue and progress state to setting them through a function
2024-07-12 08:00:32 +02:00
a86b07a826 Add Progress bar to some stuff
https://learn.microsoft.com/en-us/dotnet/api/system.windows.shell.taskbariteminfo?view=windowsdesktop-8.0
2024-07-09 00:52:24 +02:00
15 changed files with 6228 additions and 6041 deletions

View File

@ -13,16 +13,20 @@ function Install-WinUtilChoco {
if((Test-WinUtilPackageManager -choco) -eq "installed") { if((Test-WinUtilPackageManager -choco) -eq "installed") {
return return
} }
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" })
Write-Host "Seems Chocolatey is not installed, installing now." Write-Host "Seems Chocolatey is not installed, installing now."
Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) -ErrorAction Stop Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) -ErrorAction Stop
powershell choco feature enable -n allowGlobalConfirmation powershell choco feature enable -n allowGlobalConfirmation
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" })
} }
Catch { Catch {
Write-Host "===========================================" -Foregroundcolor Red Write-Host "===========================================" -Foregroundcolor Red
Write-Host "-- Chocolatey failed to install ---" -Foregroundcolor Red Write-Host "-- Chocolatey failed to install ---" -Foregroundcolor Red
Write-Host "===========================================" -Foregroundcolor Red Write-Host "===========================================" -Foregroundcolor Red
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" })
} }
} }

View File

@ -80,6 +80,7 @@ function Install-WinUtilProgramChoco {
} }
} }
$x++ $x++
# $sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value $using:x/$using:count })
} }
Write-Progress -Activity "$manage Applications" -Status "Finished" -Completed Write-Progress -Activity "$manage Applications" -Status "Finished" -Completed

View File

@ -97,6 +97,7 @@ Function Install-WinUtilProgramWinget {
} }
} }
$X++ $X++
# $sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value $using:x/$using:count })
} }
Write-Progress -Activity "$manage Applications" -Status "Finished" -Completed Write-Progress -Activity "$manage Applications" -Status "Finished" -Completed
return $failedPackages; return $failedPackages;

View File

@ -19,6 +19,8 @@ function Install-WinUtilWinget {
Write-Host "`nWinget is not Installed. Continuing with install.`r" -ForegroundColor Red Write-Host "`nWinget is not Installed. Continuing with install.`r" -ForegroundColor Red
} }
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" })
# Gets the computer's information # Gets the computer's information
if ($null -eq $sync.ComputerInfo){ if ($null -eq $sync.ComputerInfo){
$ComputerInfo = Get-ComputerInfo -ErrorAction Stop $ComputerInfo = Get-ComputerInfo -ErrorAction Stop
@ -63,4 +65,6 @@ function Install-WinUtilWinget {
throw [WingetFailedInstall]::new('Failed to install!') throw [WingetFailedInstall]::new('Failed to install!')
} }
} }
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" })
} }

View File

@ -10,6 +10,8 @@ function Invoke-WinUtilFeatureInstall {
$CheckBox $CheckBox
) )
# $sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value 1/$using:CheckBox.Count })
$CheckBox | ForEach-Object { $CheckBox | ForEach-Object {
if($sync.configs.feature.$psitem.feature){ if($sync.configs.feature.$psitem.feature){
Foreach( $feature in $sync.configs.feature.$psitem.feature ){ Foreach( $feature in $sync.configs.feature.$psitem.feature ){
@ -23,6 +25,7 @@ function Invoke-WinUtilFeatureInstall {
} }
else{ else{
Set-WinUtilTaskbaritem -state "Error"
Write-Warning "Unable to Install $feature due to unhandled exception" Write-Warning "Unable to Install $feature due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace Write-Warning $psitem.Exception.StackTrace
} }
@ -36,6 +39,7 @@ function Invoke-WinUtilFeatureInstall {
Write-Host "Running Script for $psitem" Write-Host "Running Script for $psitem"
Invoke-Command $scriptblock -ErrorAction stop Invoke-Command $scriptblock -ErrorAction stop
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" })
} }
Catch{ Catch{
if ($psitem.Exception.Message -like "*requires elevation*"){ if ($psitem.Exception.Message -like "*requires elevation*"){
@ -43,6 +47,7 @@ function Invoke-WinUtilFeatureInstall {
} }
else{ else{
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" })
Write-Warning "Unable to Install $feature due to unhandled exception" Write-Warning "Unable to Install $feature due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace Write-Warning $psitem.Exception.StackTrace
} }

View File

@ -0,0 +1,67 @@
<#
.SYNOPSIS
Modifies the Taskbaritem of the WPF Form
.PARAMETER state & value
Value can be between 0 and 1, 0 being no progress done yet and 1 being fully completed
State can be 'None' > No progress, 'Indeterminate' > Without value, 'Normal' > when using value, 'Error' > Red (when using value), 'Paused' > Yellow (when using value)
.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"
Set-WinUtilTaskbaritem -description "This is a description"
Set-WinUtilTaskbaritem -overlay "C:\path\to\icon.png"
#>
function Set-WinUtilTaskbaritem {
param (
[double]$value,
$state,
$overlay,
$description
)
if ($value) {
$sync["Form"].taskbarItemInfo.ProgressValue = $value
}
if ($state) {
$sync["Form"].taskbarItemInfo.ProgressState = $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 ($description) {
$sync["Form"].taskbarItemInfo.Description = $description
}
}

View File

@ -24,6 +24,7 @@ function Invoke-WPFGetInstalled {
param($checkbox, $DebugPreference) param($checkbox, $DebugPreference)
$sync.ProcessRunning = $true $sync.ProcessRunning = $true
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" })
if($checkbox -eq "winget"){ if($checkbox -eq "winget"){
Write-Host "Getting Installed Programs..." Write-Host "Getting Installed Programs..."
@ -42,5 +43,6 @@ function Invoke-WPFGetInstalled {
Write-Host "Done..." Write-Host "Done..."
$sync.ProcessRunning = $false $sync.ProcessRunning = $false
$sync.form.Dispatcher.Invoke([action] { Set-WinUtilTaskbaritem -state "None" })
} }
} }

View File

@ -16,6 +16,7 @@ function Invoke-WPFGetIso {
$sync.BusyText.Text="N Busy" $sync.BusyText.Text="N Busy"
Write-Host " _ __ __ _ " Write-Host " _ __ __ _ "
Write-Host " /\/\ (_) ___ _ __ ___ / / /\ \ \(_) _ __ " Write-Host " /\/\ (_) ___ _ __ ___ / / /\ \ \(_) _ __ "
Write-Host " / \ | | / __|| '__| / _ \ \ \/ \/ /| || '_ \ " Write-Host " / \ | | / __|| '__| / _ \ \ \/ \/ /| || '_ \ "
@ -88,6 +89,8 @@ function Invoke-WPFGetIso {
return return
} }
Set-WinUtilTaskbaritem -state "Indeterminate"
# Detect the file size of the ISO and compare it with the free space of the system drive # Detect the file size of the ISO and compare it with the free space of the system drive
$isoSize = (Get-Item -Path $filePath).Length $isoSize = (Get-Item -Path $filePath).Length
Write-Debug "Size of ISO file: $($isoSize) bytes" Write-Debug "Size of ISO file: $($isoSize) bytes"
@ -239,6 +242,7 @@ function Invoke-WPFGetIso {
$sync.BusyMessage.Visibility="Hidden" $sync.BusyMessage.Visibility="Hidden"
$sync.ProcessRunning = $false $sync.ProcessRunning = $false
Set-WinUtilTaskbaritem -state "None"
} }

View File

@ -20,8 +20,10 @@ function Invoke-WPFInstall {
return return
} }
Invoke-WPFRunspace -ArgumentList $PackagesToInstall -DebugPreference $DebugPreference -ScriptBlock { Invoke-WPFRunspace -ArgumentList $PackagesToInstall -DebugPreference $DebugPreference -ScriptBlock {
param($PackagesToInstall, $DebugPreference) param($PackagesToInstall, $DebugPreference)
# $sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value 1/$using:PackagesToInstall.Count })
$packagesWinget, $packagesChoco = { $packagesWinget, $packagesChoco = {
$packagesWinget = [System.Collections.Generic.List`1[System.Object]]::new() $packagesWinget = [System.Collections.Generic.List`1[System.Object]]::new()
$packagesChoco = [System.Collections.Generic.List`1[System.Object]]::new() $packagesChoco = [System.Collections.Generic.List`1[System.Object]]::new()
@ -52,11 +54,13 @@ function Invoke-WPFInstall {
Write-Host "===========================================" Write-Host "==========================================="
Write-Host "-- Installs have finished ---" Write-Host "-- Installs have finished ---"
Write-Host "===========================================" Write-Host "==========================================="
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" })
} }
Catch { Catch {
Write-Host "===========================================" Write-Host "==========================================="
Write-Host "Error: $_" Write-Host "Error: $_"
Write-Host "===========================================" Write-Host "==========================================="
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" })
} }
Start-Sleep -Seconds 5 Start-Sleep -Seconds 5
$sync.ProcessRunning = $False $sync.ProcessRunning = $False

View File

@ -4,6 +4,7 @@ function Invoke-WPFMicrowin {
Invoke MicroWin routines... Invoke MicroWin routines...
#> #>
if($sync.ProcessRunning) { if($sync.ProcessRunning) {
$msg = "GetIso process is currently running." $msg = "GetIso process is currently running."
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning) [System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
@ -42,6 +43,8 @@ public class PowerManagement {
return return
} }
Set-WinUtilTaskbaritem -state "Indeterminate"
Write-Host "Target ISO location: $($SaveDialog.FileName)" Write-Host "Target ISO location: $($SaveDialog.FileName)"
$index = $sync.MicrowinWindowsFlavors.SelectedValue.Split(":")[0].Trim() $index = $sync.MicrowinWindowsFlavors.SelectedValue.Split(":")[0].Trim()
@ -477,5 +480,6 @@ public class PowerManagement {
# Allow the machine to sleep again (optional) # Allow the machine to sleep again (optional)
[PowerManagement]::SetThreadExecutionState(0) [PowerManagement]::SetThreadExecutionState(0)
$sync.ProcessRunning = $false $sync.ProcessRunning = $false
Set-WinUtilTaskbaritem -state "None"
} }
} }

View File

@ -29,8 +29,10 @@ function Invoke-WPFUnInstall {
if($confirm -eq "No"){return} if($confirm -eq "No"){return}
Invoke-WPFRunspace -ArgumentList $PackagesToInstall -DebugPreference $DebugPreference -ScriptBlock { Invoke-WPFRunspace -ArgumentList $PackagesToInstall -DebugPreference $DebugPreference -ScriptBlock {
param($PackagesToInstall, $DebugPreference) param($PackagesToInstall, $DebugPreference)
# $sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value 1/$using:PackagesToInstall.Count })
$packagesWinget, $packagesChoco = { $packagesWinget, $packagesChoco = {
$packagesWinget = [System.Collections.Generic.List`1[System.Object]]::new() $packagesWinget = [System.Collections.Generic.List`1[System.Object]]::new()
$packagesChoco = [System.Collections.Generic.List`1[System.Object]]::new() $packagesChoco = [System.Collections.Generic.List`1[System.Object]]::new()
@ -66,11 +68,13 @@ function Invoke-WPFUnInstall {
Write-Host "===========================================" Write-Host "==========================================="
Write-Host "-- Uninstalls have finished ---" Write-Host "-- Uninstalls have finished ---"
Write-Host "===========================================" Write-Host "==========================================="
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" })
} }
Catch { Catch {
Write-Host "===========================================" Write-Host "==========================================="
Write-Host "Error: $_" Write-Host "Error: $_"
Write-Host "===========================================" Write-Host "==========================================="
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" })
} }
$sync.ProcessRunning = $False $sync.ProcessRunning = $False
} }

View File

@ -30,15 +30,18 @@ function Invoke-WPFtweaksbutton {
$sync.ProcessRunning = $true $sync.ProcessRunning = $true
# $sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value 1/$Tweaks.Count })
$cnt = 0 $cnt = 0
# Execute other selected tweaks # Execute other selected tweaks
foreach ($tweak in $Tweaks) { foreach ($tweak in $Tweaks) {
Write-Debug "This is a tweak to run $tweak count: $cnt" Write-Debug "This is a tweak to run $tweak count: $cnt"
Invoke-WinUtilTweaks $tweak Invoke-WinUtilTweaks $tweak
$cnt += 1 $cnt += 1
# $sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -value ($using:cnt/$using:Tweaks.Count)})
} }
$sync.ProcessRunning = $false $sync.ProcessRunning = $false
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" })
Write-Host "=================================" Write-Host "================================="
Write-Host "-- Tweaks are Finished ---" Write-Host "-- Tweaks are Finished ---"
Write-Host "=================================" Write-Host "================================="

View File

@ -24,12 +24,14 @@ function Invoke-WPFundoall {
param($Tweaks, $DebugPreference) param($Tweaks, $DebugPreference)
$sync.ProcessRunning = $true $sync.ProcessRunning = $true
# $sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value $using:Tweaks.Count })
Foreach ($tweak in $tweaks){ Foreach ($tweak in $tweaks){
Invoke-WinUtilTweaks $tweak -undo $true Invoke-WinUtilTweaks $tweak -undo $true
} }
$sync.ProcessRunning = $false $sync.ProcessRunning = $false
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" })
Write-Host "==================================" Write-Host "=================================="
Write-Host "--- Undo Tweaks are Finished ---" Write-Host "--- Undo Tweaks are Finished ---"
Write-Host "==================================" Write-Host "=================================="

View File

@ -153,6 +153,16 @@ Invoke-WPFRunspace -ScriptBlock {
# Print the logo # Print the logo
Invoke-WPFFormVariables 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
# Progress bar in taskbaritem > Set-WinUtilProgressbar
$sync["Form"].TaskbarItemInfo = New-Object System.Windows.Shell.TaskbarItemInfo
Set-WinUtilTaskbaritem -state "None"
# Set the titlebar # Set the titlebar
$sync["Form"].title = $sync["Form"].title + " " + $sync.version $sync["Form"].title = $sync["Form"].title + " " + $sync.version
# Set the commands that will run when the form is closed # Set the commands that will run when the form is closed
@ -287,37 +297,8 @@ Add-Type @"
} }
} }
# Using a TaskbarItem Overlay until someone figures out how to replace the icon correctly
# URL of the image
$imageUrl = "https://christitus.com/images/logo-full.png"
# Download the image
$imagePath = "$env:TEMP\logo-full.png"
Invoke-WebRequest -Uri $imageUrl -OutFile $imagePath
# Read the image file as a byte array
$imageBytes = [System.IO.File]::ReadAllBytes($imagePath)
# 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()
# Ensure TaskbarItemInfo is created if not already
if (-not $sync["Form"].TaskbarItemInfo) {
$sync["Form"].TaskbarItemInfo = New-Object System.Windows.Shell.TaskbarItemInfo
}
# Set the overlay icon for the taskbar # Set the overlay icon for the taskbar
$sync["Form"].TaskbarItemInfo.Overlay = $bitmap Set-WinUtilTaskbaritem -overlay $logoPath
$rect = New-Object RECT $rect = New-Object RECT
[Window]::GetWindowRect($windowHandle, [ref]$rect) [Window]::GetWindowRect($windowHandle, [ref]$rect)

12123
winutil.ps1

File diff suppressed because it is too large Load Diff