Skip to content

Commit 35a6ade

Browse files
committed
Fallback icon
1 parent 4fa52cd commit 35a6ade

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Sources/Winget-AutoUpdate/WAU-Settings-GUI.ps1

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,21 @@ if (Test-Path $xamlConfigPath) {
13841384
$Script:WAU_INSTALL_INFO = Test-InstalledWAU -DisplayName "Winget-AutoUpdate"
13851385
$Script:WAU_VERSION = if ($Script:WAU_INSTALL_INFO.Count -ge 1) { $Script:WAU_INSTALL_INFO[0] } else { "Unknown" }
13861386
$Script:WAU_GUID = if ($Script:WAU_INSTALL_INFO.Count -ge 2) { $Script:WAU_INSTALL_INFO[1] } else { $null }
1387-
$Script:WAU_ICON = "${env:SystemRoot}\Installer\${Script:WAU_GUID}\icon.ico"
1387+
$wauIconPath = "${env:SystemRoot}\Installer\${Script:WAU_GUID}\icon.ico"
1388+
if (Test-Path $wauIconPath) {
1389+
$Script:WAU_ICON = $wauIconPath
1390+
} else {
1391+
# If missing, fallback and extract icon from PowerShell.exe and save as icon.ico in SYSTEM TEMP
1392+
$iconSource = "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe"
1393+
$systemTemp = [System.Environment]::GetEnvironmentVariable("TEMP", [System.EnvironmentVariableTarget]::Machine)
1394+
if (-not $systemTemp) { $systemTemp = "$env:SystemRoot\Temp" }
1395+
$iconDest = Join-Path $systemTemp "icon.ico"
1396+
$icon = [System.Drawing.Icon]::ExtractAssociatedIcon($iconSource)
1397+
$fs = [System.IO.File]::Open($iconDest, [System.IO.FileMode]::Create)
1398+
$icon.Save($fs)
1399+
$fs.Close()
1400+
$Script:WAU_ICON = $iconDest
1401+
}
13881402

13891403
#Pop "Starting..."
13901404
Start-PopUp "Gathering Data..."

0 commit comments

Comments
 (0)