mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-07-03 19:53:50 -05:00
Compare commits
4 Commits
main
...
27792dc8a3
Author | SHA1 | Date | |
---|---|---|---|
27792dc8a3 | |||
790e0b22a5 | |||
73973d7101 | |||
a86b07a826 |
@ -13,16 +13,20 @@ function Install-WinUtilChoco {
|
||||
if((Test-WinUtilPackageManager -choco) -eq "installed") {
|
||||
return
|
||||
}
|
||||
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" })
|
||||
|
||||
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
|
||||
powershell choco feature enable -n allowGlobalConfirmation
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" })
|
||||
|
||||
}
|
||||
Catch {
|
||||
Write-Host "===========================================" -Foregroundcolor Red
|
||||
Write-Host "-- Chocolatey failed to install ---" -Foregroundcolor Red
|
||||
Write-Host "===========================================" -Foregroundcolor Red
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" })
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -80,6 +80,7 @@ function Install-WinUtilProgramChoco {
|
||||
}
|
||||
}
|
||||
$x++
|
||||
# $sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value $using:x/$using:count })
|
||||
}
|
||||
Write-Progress -Activity "$manage Applications" -Status "Finished" -Completed
|
||||
|
||||
|
@ -97,6 +97,7 @@ Function Install-WinUtilProgramWinget {
|
||||
}
|
||||
}
|
||||
$X++
|
||||
# $sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value $using:x/$using:count })
|
||||
}
|
||||
Write-Progress -Activity "$manage Applications" -Status "Finished" -Completed
|
||||
return $failedPackages;
|
||||
|
@ -19,6 +19,8 @@ function Install-WinUtilWinget {
|
||||
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
|
||||
if ($null -eq $sync.ComputerInfo){
|
||||
$ComputerInfo = Get-ComputerInfo -ErrorAction Stop
|
||||
@ -63,4 +65,6 @@ function Install-WinUtilWinget {
|
||||
throw [WingetFailedInstall]::new('Failed to install!')
|
||||
}
|
||||
}
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" })
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ function Invoke-WinUtilFeatureInstall {
|
||||
$CheckBox
|
||||
)
|
||||
|
||||
# $sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value 1/$using:CheckBox.Count })
|
||||
|
||||
$CheckBox | ForEach-Object {
|
||||
if($sync.configs.feature.$psitem.feature){
|
||||
Foreach( $feature in $sync.configs.feature.$psitem.feature ){
|
||||
@ -23,6 +25,7 @@ function Invoke-WinUtilFeatureInstall {
|
||||
}
|
||||
|
||||
else{
|
||||
Set-WinUtilTaskbaritem -state "Error"
|
||||
Write-Warning "Unable to Install $feature due to unhandled exception"
|
||||
Write-Warning $psitem.Exception.StackTrace
|
||||
}
|
||||
@ -36,6 +39,7 @@ function Invoke-WinUtilFeatureInstall {
|
||||
|
||||
Write-Host "Running Script for $psitem"
|
||||
Invoke-Command $scriptblock -ErrorAction stop
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" })
|
||||
}
|
||||
Catch{
|
||||
if ($psitem.Exception.Message -like "*requires elevation*"){
|
||||
@ -43,6 +47,7 @@ function Invoke-WinUtilFeatureInstall {
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
67
functions/private/Set-WinUtilTaskbarItem.ps1
Normal file
67
functions/private/Set-WinUtilTaskbarItem.ps1
Normal 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
|
||||
}
|
||||
}
|
@ -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..."
|
||||
@ -42,5 +43,6 @@ function Invoke-WPFGetInstalled {
|
||||
|
||||
Write-Host "Done..."
|
||||
$sync.ProcessRunning = $false
|
||||
$sync.form.Dispatcher.Invoke([action] { Set-WinUtilTaskbaritem -state "None" })
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ function Invoke-WPFGetIso {
|
||||
$sync.BusyText.Text="N Busy"
|
||||
|
||||
|
||||
|
||||
Write-Host " _ __ __ _ "
|
||||
Write-Host " /\/\ (_) ___ _ __ ___ / / /\ \ \(_) _ __ "
|
||||
Write-Host " / \ | | / __|| '__| / _ \ \ \/ \/ /| || '_ \ "
|
||||
@ -88,6 +89,8 @@ function Invoke-WPFGetIso {
|
||||
return
|
||||
}
|
||||
|
||||
Set-WinUtilTaskbaritem -state "Indeterminate"
|
||||
|
||||
# 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"
|
||||
@ -239,6 +242,7 @@ function Invoke-WPFGetIso {
|
||||
|
||||
$sync.BusyMessage.Visibility="Hidden"
|
||||
$sync.ProcessRunning = $false
|
||||
Set-WinUtilTaskbaritem -state "None"
|
||||
}
|
||||
|
||||
|
||||
|
@ -20,8 +20,10 @@ function Invoke-WPFInstall {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Invoke-WPFRunspace -ArgumentList $PackagesToInstall -DebugPreference $DebugPreference -ScriptBlock {
|
||||
param($PackagesToInstall, $DebugPreference)
|
||||
# $sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value 1/$using:PackagesToInstall.Count })
|
||||
$packagesWinget, $packagesChoco = {
|
||||
$packagesWinget = [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 "-- Installs have finished ---"
|
||||
Write-Host "==========================================="
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" })
|
||||
}
|
||||
Catch {
|
||||
Write-Host "==========================================="
|
||||
Write-Host "Error: $_"
|
||||
Write-Host "==========================================="
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" })
|
||||
}
|
||||
Start-Sleep -Seconds 5
|
||||
$sync.ProcessRunning = $False
|
||||
|
@ -4,6 +4,7 @@ function Invoke-WPFMicrowin {
|
||||
Invoke MicroWin routines...
|
||||
#>
|
||||
|
||||
|
||||
if($sync.ProcessRunning) {
|
||||
$msg = "GetIso process is currently running."
|
||||
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
|
||||
@ -42,6 +43,8 @@ public class PowerManagement {
|
||||
return
|
||||
}
|
||||
|
||||
Set-WinUtilTaskbaritem -state "Indeterminate"
|
||||
|
||||
Write-Host "Target ISO location: $($SaveDialog.FileName)"
|
||||
|
||||
$index = $sync.MicrowinWindowsFlavors.SelectedValue.Split(":")[0].Trim()
|
||||
@ -477,5 +480,6 @@ public class PowerManagement {
|
||||
# Allow the machine to sleep again (optional)
|
||||
[PowerManagement]::SetThreadExecutionState(0)
|
||||
$sync.ProcessRunning = $false
|
||||
Set-WinUtilTaskbaritem -state "None"
|
||||
}
|
||||
}
|
@ -29,8 +29,10 @@ function Invoke-WPFUnInstall {
|
||||
|
||||
if($confirm -eq "No"){return}
|
||||
|
||||
|
||||
Invoke-WPFRunspace -ArgumentList $PackagesToInstall -DebugPreference $DebugPreference -ScriptBlock {
|
||||
param($PackagesToInstall, $DebugPreference)
|
||||
# $sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value 1/$using:PackagesToInstall.Count })
|
||||
$packagesWinget, $packagesChoco = {
|
||||
$packagesWinget = [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 "-- Uninstalls have finished ---"
|
||||
Write-Host "==========================================="
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" })
|
||||
}
|
||||
Catch {
|
||||
Write-Host "==========================================="
|
||||
Write-Host "Error: $_"
|
||||
Write-Host "==========================================="
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" })
|
||||
}
|
||||
$sync.ProcessRunning = $False
|
||||
}
|
||||
|
@ -30,15 +30,18 @@ function Invoke-WPFtweaksbutton {
|
||||
|
||||
$sync.ProcessRunning = $true
|
||||
|
||||
# $sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value 1/$Tweaks.Count })
|
||||
$cnt = 0
|
||||
# Execute other selected tweaks
|
||||
foreach ($tweak in $Tweaks) {
|
||||
Write-Debug "This is a tweak to run $tweak count: $cnt"
|
||||
Invoke-WinUtilTweaks $tweak
|
||||
$cnt += 1
|
||||
# $sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -value ($using:cnt/$using:Tweaks.Count)})
|
||||
}
|
||||
|
||||
$sync.ProcessRunning = $false
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" })
|
||||
Write-Host "================================="
|
||||
Write-Host "-- Tweaks are Finished ---"
|
||||
Write-Host "================================="
|
||||
|
@ -24,12 +24,14 @@ function Invoke-WPFundoall {
|
||||
param($Tweaks, $DebugPreference)
|
||||
|
||||
$sync.ProcessRunning = $true
|
||||
# $sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value $using:Tweaks.Count })
|
||||
|
||||
Foreach ($tweak in $tweaks){
|
||||
Invoke-WinUtilTweaks $tweak -undo $true
|
||||
}
|
||||
|
||||
$sync.ProcessRunning = $false
|
||||
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" })
|
||||
Write-Host "=================================="
|
||||
Write-Host "--- Undo Tweaks are Finished ---"
|
||||
Write-Host "=================================="
|
||||
|
@ -153,6 +153,16 @@ 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
|
||||
|
||||
# Progress bar in taskbaritem > Set-WinUtilProgressbar
|
||||
$sync["Form"].TaskbarItemInfo = New-Object System.Windows.Shell.TaskbarItemInfo
|
||||
Set-WinUtilTaskbaritem -state "None"
|
||||
|
||||
# Set the titlebar
|
||||
$sync["Form"].title = $sync["Form"].title + " " + $sync.version
|
||||
# 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
|
||||
$sync["Form"].TaskbarItemInfo.Overlay = $bitmap
|
||||
|
||||
Set-WinUtilTaskbaritem -overlay $logoPath
|
||||
|
||||
$rect = New-Object RECT
|
||||
[Window]::GetWindowRect($windowHandle, [ref]$rect)
|
||||
|
12123
winutil.ps1
12123
winutil.ps1
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user