Compare commits

..

2 Commits

Author SHA1 Message Date
MyDrift
2fab47dd13 last fixes
remove bitmap
remove unneeded "| out-null"
2024-07-16 20:57:47 +02:00
MyDrift
d9b085d316 renamed checkmark & added warning 2024-07-16 19:48:23 +02:00
6 changed files with 27 additions and 50 deletions

View File

@ -25,9 +25,11 @@ function Set-WinUtilTaskbaritem {
- Set-WinUtilTaskbaritem -overlay "logo"
Checkmark preset:
- Set-WinUtilTaskbaritem -overlay "checkmark"
Warning preset:
- Set-WinUtilTaskbaritem -overlay "warning"
No overlay:
- Set-WinUtilTaskbaritem -overlay "None"
Custom icon:
Custom icon (needs to be supported by WPF):
- Set-WinUtilTaskbaritem -overlay "C:\path\to\icon.png"
.PARAMETER description
@ -41,39 +43,6 @@ function Set-WinUtilTaskbaritem {
[string]$description
)
# TODO: Make a better solution for this function, accessing problem when calling Set-WinUtilTaskbaritem inside a runspace. Future me or other contributors, please fix this.
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 -imageFilePath "C:\path\to\image.png"
#>
param (
$imageFilePath
)
# Read the image file as a byte array
$imageBytes = [System.IO.File]::ReadAllBytes($imageFilePath)
# 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
}
if ($value) {
$sync["Form"].taskbarItemInfo.ProgressValue = $value
}
@ -92,17 +61,20 @@ function Set-WinUtilTaskbaritem {
if ($overlay) {
switch ($overlay) {
'logo' {
$sync["Form"].taskbarItemInfo.Overlay = (ConvertTo-Bitmap -imageFilePath "$env:LOCALAPPDATA\winutil\cttlogo.png")
$sync["Form"].taskbarItemInfo.Overlay = "$env:LOCALAPPDATA\winutil\cttlogo.png"
}
'checkmark' {
$sync["Form"].taskbarItemInfo.Overlay = (ConvertTo-Bitmap -imageFilePath "$env:LOCALAPPDATA\winutil\cttcheckmark.png"])
$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 = (ConvertTo-Bitmap -image $overlay)
$sync["Form"].taskbarItemInfo.Overlay = $overlay
}
}
}

View File

@ -107,7 +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
Set-WinUtilTaskbaritem -state "Error" -value 1 -overlay "warning"
return
}
else
@ -126,7 +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
Set-WinUtilTaskbaritem -state "Error" -value 1 -overlay "warning"
return
}
# storing off values in hidden fields for further steps
@ -204,7 +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
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))

View File

@ -64,7 +64,7 @@ function Invoke-WPFInstall {
Write-Host "==========================================="
Write-Host "Error: $_"
Write-Host "==========================================="
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" })
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" -overlay "warning" })
}
$sync.ProcessRunning = $False
}

View File

@ -40,7 +40,7 @@ public class PowerManagement {
if ($SaveDialog.FileName -eq "") {
Write-Host "No file name for the target image was specified"
Set-WinUtilTaskbaritem -state "Error" -value 1
Set-WinUtilTaskbaritem -state "Error" -value 1 -overlay "warning"
return
}
@ -78,7 +78,7 @@ public class PowerManagement {
$msg = "The export process has failed and MicroWin processing cannot continue"
Write-Host "Failed to export the image"
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error)
Set-WinUtilTaskbaritem -state "Error" -value 1
Set-WinUtilTaskbaritem -state "Error" -value 1 -overlay "warning"
return
}
}
@ -92,7 +92,7 @@ public class PowerManagement {
$dlg_msg = $msg + "`n`nIf you want more information, the version of the image selected is $($imgVersion)`n`nIf an image has been incorrectly marked as incompatible, report an issue to the developers."
Write-Host $msg
[System.Windows.MessageBox]::Show($dlg_msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Exclamation)
Set-WinUtilTaskbaritem -state "Error" -value 1
Set-WinUtilTaskbaritem -state "Error" -value 1 -overlay "warning"
return
}
@ -101,7 +101,7 @@ public class PowerManagement {
if (-not $mountDirExists -or -not $scratchDirExists)
{
Write-Error "Required directories '$mountDirExists' '$scratchDirExists' and do not exist."
Set-WinUtilTaskbaritem -state "Error" -value 1
Set-WinUtilTaskbaritem -state "Error" -value 1 -overlay "warning"
return
}
@ -116,7 +116,7 @@ public class PowerManagement {
else
{
Write-Host "Could not mount image. Exiting..."
Set-WinUtilTaskbaritem -state "Error" -value 1
Set-WinUtilTaskbaritem -state "Error" -value 1 -overlay "warning"
return
}
@ -386,7 +386,7 @@ public class PowerManagement {
if (-not (Test-Path -Path "$mountDir\sources\install.wim"))
{
Write-Error "Something went wrong and '$mountDir\sources\install.wim' doesn't exist. Please report this bug to the devs"
Set-WinUtilTaskbaritem -state "Error" -value 1
Set-WinUtilTaskbaritem -state "Error" -value 1 -overlay "warning"
return
}
Write-Host "Windows image completed. Continuing with boot.wim."

View File

@ -73,7 +73,7 @@ function Invoke-WPFUnInstall {
Write-Host "==========================================="
Write-Host "Error: $_"
Write-Host "==========================================="
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" })
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" -overlay "warning" })
}
$sync.ProcessRunning = $False

View File

@ -450,12 +450,17 @@ if (-NOT (Test-Path -Path $winutildir["logo.ico"])) {
ConvertTo-Icon -bitmapPath $winutildir["logo.png"] -iconPath $winutildir["logo.ico"]
}
$winutildir["checkmark.png"] = $winutildir["path"] + "cttcheckmark.png"
$winutildir["checkmark.png"] = $winutildir["path"] + "checkmark.png"
$winutildir["warning.png"] = $winutildir["path"] + "warning.png"
if (-NOT (Test-Path -Path $winutildir["checkmark.png"])) {
Invoke-WebRequest -Uri "https://christitus.com/images/checkmark.png" -OutFile $winutildir["checkmark.png"]
}
if (-NOT (Test-Path -Path $winutildir["warning.png"])) {
Invoke-WebRequest -Uri "https://christitus.com/images/warning.png" -OutFile $winutildir["warning.png"]
}
Set-WinUtilTaskbaritem -overlay "logo" | Out-Null
Set-WinUtilTaskbaritem -overlay "logo"
$sync["Form"].Add_Activated({
Set-WinUtilTaskbaritem -overlay "logo"