Skip to content

Commit

Permalink
Refactored Get-Associated-Icon function to handle file path errors (#…
Browse files Browse the repository at this point in the history
…1096)

* Refactored Get-Associated-Icon function to handle file path errors

* Just do nothing when icon extraction failed

---------

Co-authored-by: Oliver Schwendener <[email protected]>
  • Loading branch information
Enubia and oliverschwendener authored May 11, 2024
1 parent 40c9b14 commit 8b6962c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/main/Core/ImageGenerator/Windows/powershellScripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ function Get-Associated-Icon {
$InFilePath = Get-Shortcut-Target -ShortcutFilePath $InFilePath
}
$Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($InFilePath)
# ExtractAssociatedIcon will crash if the file path contains special characters
# e.g. "Über iTunes" will crash the script and thus no search results are shown
try {
$Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($InFilePath)
if ($Icon -ne $null) {
$Icon.ToBitmap().Save($OutFilePath, [System.Drawing.Imaging.ImageFormat]::Png)
if ($null -ne $Icon) {
$Icon.ToBitmap().Save($OutFilePath, [System.Drawing.Imaging.ImageFormat]::Png)
}
} catch {
# Do nothing and continue
}
}`;

0 comments on commit 8b6962c

Please sign in to comment.