From c490cbff1a3adab478a425e089dd63cf79c7b779 Mon Sep 17 00:00:00 2001 From: MyDrift Date: Mon, 15 Jul 2024 12:08:58 +0200 Subject: [PATCH] rework assets directory & its usage --- functions/private/Set-WinUtilTaskbarItem.ps1 | 4 +-- functions/public/Invoke-WPFShortcut.ps1 | 7 ++--- scripts/main.ps1 | 33 +++++++++++++------- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/functions/private/Set-WinUtilTaskbarItem.ps1 b/functions/private/Set-WinUtilTaskbarItem.ps1 index 8b0cfa6a..9e3f05a9 100644 --- a/functions/private/Set-WinUtilTaskbarItem.ps1 +++ b/functions/private/Set-WinUtilTaskbarItem.ps1 @@ -57,10 +57,10 @@ function Set-WinUtilTaskbaritem { if ($overlay) { switch ($overlay) { 'logo' { - $sync["Form"].taskbarItemInfo.Overlay = (ConvertTo-Bitmap -image "$env:LOCALAPPDATA\winutil\cttlogo.png") + $sync["Form"].taskbarItemInfo.Overlay = (ConvertTo-Bitmap -image $winutildir["logo.png"]) } 'checkmark' { - $sync["Form"].taskbarItemInfo.Overlay = (ConvertTo-Bitmap -image "$env:LOCALAPPDATA\winutil\cttcheckmark.png") + $sync["Form"].taskbarItemInfo.Overlay = (ConvertTo-Bitmap -image $winutildir["checkmark.png"]) } default { if (Test-Path $overlay) { diff --git a/functions/public/Invoke-WPFShortcut.ps1 b/functions/public/Invoke-WPFShortcut.ps1 index 5f88035a..9979caba 100644 --- a/functions/public/Invoke-WPFShortcut.ps1 +++ b/functions/public/Invoke-WPFShortcut.ps1 @@ -17,8 +17,7 @@ function Invoke-WPFShortcut { [bool]$RunAsAdmin = $false ) - # Preper the Shortcut Fields and add an a Custom Icon if it's available at "$env:TEMP\cttlogo.png", else don't add a Custom Icon. - $iconPath = $null + # Preper the Shortcut Fields and add an a Custom Icon if it's available, else don't add a Custom Icon. Switch ($ShortcutToAdd) { "WinUtil" { $SourceExe = "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe" @@ -48,8 +47,8 @@ function Invoke-WPFShortcut { $Shortcut = $WshShell.CreateShortcut($FileBrowser.FileName) $Shortcut.TargetPath = $SourceExe $Shortcut.Arguments = $ArgumentsToSourceExe - if (Test-Path -Path $ctticologo) { - $shortcut.IconLocation = $ctticologo + if (Test-Path -Path $winutildir["logo.ico"]) { + $shortcut.IconLocation = $winutildir["logo.ico"] } # Save the Shortcut to disk diff --git a/scripts/main.ps1 b/scripts/main.ps1 index a85ac22c..a4e2b7f0 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -430,22 +430,33 @@ $sync["SearchBar"].Add_TextChanged({ $label.Visibility = "Collapsed"} }) -$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 -} +# Initialize the hashtable +$winutildir = @{} -$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 +# Set the path for the winutil directory +$winutildir["path"] = "$env:LOCALAPPDATA\winutil" +if (-NOT (Test-Path -Path $winutildir["path"])) { + New-Item -Path $winutildir["path"] -ItemType Directory } -ConvertTo-Icon -bitmapPath $cttpnglogo -iconPath $ctticologo +# Set the path for the logo and checkmark images +$winutildir["logo.png"] = "$env:LOCALAPPDATA\winutil\cttlogo.png" +$winutildir["logo.ico"] = "$env:LOCALAPPDATA\winutil\cttlogo.ico" +if (-NOT (Test-Path -Path $winutildir["logo.png"])) { + Invoke-WebRequest -Uri "https://christitus.com/images/logo-full.png" -OutFile $winutildir["logo.png"] +} + +if (-NOT (Test-Path -Path $winutildir["logo.ico"])) { + ConvertTo-Icon -bitmapPath $winutildir["logo.png"] -iconPath $winutildir["logo.ico"] +} +$winutildir["checkmark.png"] = "$env:LOCALAPPDATA\winutil\cttcheckmark.png" +if (-NOT (Test-Path -Path $winutildir["checkmark.png"])) { + Invoke-WebRequest -Uri "https://christitus.com/images/checkmark.png" -OutFile $winutildir["checkmark.png"] +} Set-WinUtilTaskbaritem -overlay "logo" | Out-Null -$sync["Form"].icon = $cttpnglogo + +$sync["Form"].icon = $winutildir["logo.png"] $sync["Form"].Add_Activated({ Set-WinUtilTaskbaritem -overlay "logo"