Skip to content

Commit a1b5941

Browse files
committed
Improve WindowsThumbnailProvider
1 parent 8e51096 commit a1b5941

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Flow.Launcher.Infrastructure/Image/ThumbnailReader.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Flow.Launcher.Infrastructure.Image
1313
{
1414
/// <summary>
15-
/// Subclass of <see cref="Windows.Win32.UI.Shell.SIIGBF"/>
15+
/// Subclass of <see cref="SIIGBF"/>
1616
/// </summary>
1717
[Flags]
1818
public enum ThumbnailOptions
@@ -33,6 +33,8 @@ public class WindowsThumbnailProvider
3333

3434
private static readonly HRESULT S_ExtractionFailed = (HRESULT)0x8004B200;
3535

36+
private static readonly HRESULT S_PATHNOTFOUND = (HRESULT)0x8004B205;
37+
3638
public static BitmapSource GetThumbnail(string fileName, int width, int height, ThumbnailOptions options)
3739
{
3840
HBITMAP hBitmap = GetHBitmap(Path.GetFullPath(fileName), width, height, options);
@@ -79,16 +81,22 @@ private static unsafe HBITMAP GetHBitmap(string fileName, int width, int height,
7981
{
8082
imageFactory.GetImage(size, (SIIGBF)options, &hBitmap);
8183
}
82-
catch (COMException ex) when (ex.HResult == S_ExtractionFailed && options == ThumbnailOptions.ThumbnailOnly)
84+
catch (COMException ex) when (options == ThumbnailOptions.ThumbnailOnly &&
85+
(ex.HResult == S_PATHNOTFOUND || ex.HResult == S_ExtractionFailed))
8386
{
84-
// Fallback to IconOnly if ThumbnailOnly fails
87+
// Fallback to IconOnly if extraction fails or files cannot be found
8588
imageFactory.GetImage(size, (SIIGBF)ThumbnailOptions.IconOnly, &hBitmap);
8689
}
8790
catch (FileNotFoundException) when (options == ThumbnailOptions.ThumbnailOnly)
8891
{
8992
// Fallback to IconOnly if files cannot be found
9093
imageFactory.GetImage(size, (SIIGBF)ThumbnailOptions.IconOnly, &hBitmap);
9194
}
95+
catch (System.Exception ex)
96+
{
97+
// Handle other exceptions
98+
throw new InvalidOperationException("Failed to get thumbnail", ex);
99+
}
92100
}
93101
finally
94102
{

0 commit comments

Comments
 (0)