@@ -276,26 +276,20 @@ public static string ExtractStringFromDLL(string file, int number)
276276 private static readonly object _iconLock = new object ( ) ;
277277
278278 /// <summary>
279- /// Returns an icon when a thumbnail isn't available or if getIconOnly is true.
280- /// <br/>
281- /// Returns an icon overlay when getOverlay is true.
282- /// <br/>
283- /// Returns a boolean indicating if the icon/thumbnail is cached.
279+ /// Returns an icon if returnIconOnly is true, otherwise a thumbnail will be returned if available.
284280 /// </summary>
285281 /// <param name="path"></param>
286- /// <param name="thumbnailSize "></param>
282+ /// <param name="size "></param>
287283 /// <param name="isFolder"></param>
288- /// <param name="getIconOnly "></param>
284+ /// <param name="returnIconOnly "></param>
289285 /// <returns></returns>
290- public static ( byte [ ] ? icon , bool isIconCached ) GetIcon (
286+ public static byte [ ] ? GetIcon (
291287 string path ,
292- int thumbnailSize ,
288+ int size ,
293289 bool isFolder ,
294- bool getThumbnailOnly ,
295- bool getIconOnly )
290+ bool returnIconOnly )
296291 {
297292 byte [ ] ? iconData = null ;
298- bool isIconCached = false ;
299293
300294 try
301295 {
@@ -307,26 +301,22 @@ public static (byte[]? icon, bool isIconCached) GetIcon(
307301 {
308302 var flags = Shell32 . SIIGBF . SIIGBF_BIGGERSIZEOK ;
309303
310- if ( getIconOnly )
304+ if ( returnIconOnly )
311305 flags |= Shell32 . SIIGBF . SIIGBF_ICONONLY ;
312- else if ( getThumbnailOnly )
313- flags |= Shell32 . SIIGBF . SIIGBF_THUMBNAILONLY ;
314306
315- var hres = shellFactory . GetImage ( new SIZE ( thumbnailSize , thumbnailSize ) , flags , out var hbitmap ) ;
307+ var hres = shellFactory . GetImage ( new SIZE ( size , size ) , flags , out var hbitmap ) ;
316308 if ( hres == HRESULT . S_OK )
317309 {
318310 using var image = GetBitmapFromHBitmap ( hbitmap ) ;
319311 if ( image is not null )
320312 iconData = ( byte [ ] ? ) new ImageConverter ( ) . ConvertTo ( image , typeof ( byte [ ] ) ) ;
321-
322- isIconCached = true ;
323313 }
324314
325315 Marshal . ReleaseComObject ( shellFactory ) ;
326316 }
327317
328318 if ( iconData is not null )
329- return ( iconData , isIconCached ) ;
319+ return iconData ;
330320 else
331321 {
332322 var shfi = new Shell32 . SHFILEINFO ( ) ;
@@ -337,11 +327,11 @@ public static (byte[]? icon, bool isIconCached) GetIcon(
337327
338328 var ret = Shell32 . SHGetFileInfo ( path , isFolder ? FileAttributes . Directory : 0 , ref shfi , Shell32 . SHFILEINFO . Size , flags ) ;
339329 if ( ret == IntPtr . Zero )
340- return ( iconData , isIconCached ) ;
330+ return iconData ;
341331
342332 User32 . DestroyIcon ( shfi . hIcon ) ;
343333
344- var imageListSize = thumbnailSize switch
334+ var imageListSize = size switch
345335 {
346336 <= 16 => Shell32 . SHIL . SHIL_SMALL ,
347337 <= 32 => Shell32 . SHIL . SHIL_LARGE ,
@@ -352,7 +342,7 @@ public static (byte[]? icon, bool isIconCached) GetIcon(
352342 lock ( _iconLock )
353343 {
354344 if ( ! Shell32 . SHGetImageList ( imageListSize , typeof ( ComCtl32 . IImageList ) . GUID , out var imageListOut ) . Succeeded )
355- return ( iconData , isIconCached ) ;
345+ return iconData ;
356346
357347 var imageList = ( ComCtl32 . IImageList ) imageListOut ;
358348
@@ -375,14 +365,14 @@ public static (byte[]? icon, bool isIconCached) GetIcon(
375365 else if ( isFolder )
376366 {
377367 // Could not icon, load generic icon
378- var icons = ExtractSelectedIconsFromDLL ( Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . System ) , "imageres.dll" ) , new [ ] { 2 } , thumbnailSize ) ;
368+ var icons = ExtractSelectedIconsFromDLL ( Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . System ) , "imageres.dll" ) , new [ ] { 2 } , size ) ;
379369 var generic = icons . SingleOrDefault ( x => x . Index == 2 ) ;
380370 iconData = generic ? . IconData ;
381371 }
382372 else
383373 {
384374 // Could not icon, load generic icon
385- var icons = ExtractSelectedIconsFromDLL ( Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . System ) , "shell32.dll" ) , new [ ] { 1 } , thumbnailSize ) ;
375+ var icons = ExtractSelectedIconsFromDLL ( Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . System ) , "shell32.dll" ) , new [ ] { 1 } , size ) ;
386376 var generic = icons . SingleOrDefault ( x => x . Index == 1 ) ;
387377 iconData = generic ? . IconData ;
388378 }
@@ -391,7 +381,7 @@ public static (byte[]? icon, bool isIconCached) GetIcon(
391381 Marshal . ReleaseComObject ( imageList ) ;
392382 }
393383
394- return ( iconData , isIconCached ) ;
384+ return iconData ;
395385 }
396386 }
397387 finally
0 commit comments