AutoSquirrel.IconHelper.IconReader.GetFileIcon C# (CSharp) Method

GetFileIcon() public static method

Returns an icon for a given file - indicated by the name parameter.
public static GetFileIcon ( string name, IconSize size, bool linkOverlay ) : Icon
name string Pathname for file.
size IconSize Large or small
linkOverlay bool Whether to include the link icon
return System.Drawing.Icon
            public static Icon GetFileIcon(string name, IconSize size, bool linkOverlay)
            {
                var shfi = new Shell32.Shfileinfo();
                var flags = Shell32.ShgfiIcon | Shell32.ShgfiUsefileattributes;
                if (linkOverlay) flags += Shell32.ShgfiLinkoverlay;
                /* Check the size specified for return. */
                if (IconSize.Small == size)
                    flags += Shell32.ShgfiSmallicon;
                else
                    flags += Shell32.ShgfiLargeicon;
                Shell32.SHGetFileInfo(name,
                    Shell32.FileAttributeNormal,
                    ref shfi,
                    (uint)Marshal.SizeOf(shfi),
                    flags);
                // Copy (clone) the returned icon to a new object, thus allowing us to clean-up properly
                var icon = (Icon)Icon.FromHandle(shfi.hIcon).Clone();
                User32.DestroyIcon(shfi.hIcon);     // Cleanup
                return icon;
            }
        }
IconHelper.IconReader