12
12
namespace Flow . Launcher . Infrastructure . Image
13
13
{
14
14
/// <summary>
15
- /// Subclass of <see cref="Windows.Win32.UI.Shell. SIIGBF"/>
15
+ /// Subclass of <see cref="SIIGBF"/>
16
16
/// </summary>
17
17
[ Flags ]
18
18
public enum ThumbnailOptions
@@ -31,7 +31,9 @@ public class WindowsThumbnailProvider
31
31
32
32
private static readonly Guid GUID_IShellItem = typeof ( IShellItem ) . GUID ;
33
33
34
- private static readonly HRESULT S_ExtractionFailed = ( HRESULT ) 0x8004B200 ;
34
+ private static readonly HRESULT S_EXTRACTIONFAILED = ( HRESULT ) 0x8004B200 ;
35
+
36
+ private static readonly HRESULT S_PATHNOTFOUND = ( HRESULT ) 0x8004B205 ;
35
37
36
38
public static BitmapSource GetThumbnail ( string fileName , int width , int height , ThumbnailOptions options )
37
39
{
@@ -79,16 +81,22 @@ private static unsafe HBITMAP GetHBitmap(string fileName, int width, int height,
79
81
{
80
82
imageFactory . GetImage ( size , ( SIIGBF ) options , & hBitmap ) ;
81
83
}
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 ) )
83
86
{
84
- // Fallback to IconOnly if ThumbnailOnly fails
87
+ // Fallback to IconOnly if extraction fails or files cannot be found
85
88
imageFactory . GetImage ( size , ( SIIGBF ) ThumbnailOptions . IconOnly , & hBitmap ) ;
86
89
}
87
90
catch ( FileNotFoundException ) when ( options == ThumbnailOptions . ThumbnailOnly )
88
91
{
89
92
// Fallback to IconOnly if files cannot be found
90
93
imageFactory . GetImage ( size , ( SIIGBF ) ThumbnailOptions . IconOnly , & hBitmap ) ;
91
94
}
95
+ catch ( System . Exception ex )
96
+ {
97
+ // Handle other exceptions
98
+ throw new InvalidOperationException ( "Failed to get thumbnail" , ex ) ;
99
+ }
92
100
}
93
101
finally
94
102
{
0 commit comments