1212namespace 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
@@ -31,7 +31,9 @@ public class WindowsThumbnailProvider
3131
3232 private static readonly Guid GUID_IShellItem = typeof ( IShellItem ) . GUID ;
3333
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 ;
3537
3638 public static BitmapSource GetThumbnail ( string fileName , int width , int height , ThumbnailOptions options )
3739 {
@@ -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