Skip to content

Commit 90c73e5

Browse files
committed
Support .url file icons
1 parent fbc88bb commit 90c73e5

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

Flow.Launcher.Infrastructure/Image/ThumbnailReader.cs

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
using System;
2-
using System.Runtime.InteropServices;
32
using System.IO;
3+
using System.Runtime.InteropServices;
44
using System.Windows;
55
using System.Windows.Interop;
66
using System.Windows.Media.Imaging;
7+
using IniParser;
78
using Windows.Win32;
89
using Windows.Win32.Foundation;
9-
using Windows.Win32.UI.Shell;
1010
using Windows.Win32.Graphics.Gdi;
11+
using Windows.Win32.UI.Shell;
1112

1213
namespace Flow.Launcher.Infrastructure.Image
1314
{
@@ -35,9 +36,21 @@ public class WindowsThumbnailProvider
3536

3637
private static readonly HRESULT S_PATHNOTFOUND = (HRESULT)0x8004B205;
3738

39+
private const string UrlExtension = ".url";
40+
3841
public static BitmapSource GetThumbnail(string fileName, int width, int height, ThumbnailOptions options)
3942
{
40-
HBITMAP hBitmap = GetHBitmap(Path.GetFullPath(fileName), width, height, options);
43+
HBITMAP hBitmap;
44+
45+
var extension = Path.GetExtension(fileName)?.ToLowerInvariant();
46+
if (extension is UrlExtension)
47+
{
48+
hBitmap = GetHBitmapForUrlFile(fileName, width, height, options);
49+
}
50+
else
51+
{
52+
hBitmap = GetHBitmap(Path.GetFullPath(fileName), width, height, options);
53+
}
4154

4255
try
4356
{
@@ -108,5 +121,30 @@ private static unsafe HBITMAP GetHBitmap(string fileName, int width, int height,
108121

109122
return hBitmap;
110123
}
124+
125+
private static unsafe HBITMAP GetHBitmapForUrlFile(string fileName, int width, int height, ThumbnailOptions options)
126+
{
127+
HBITMAP hBitmap;
128+
129+
try
130+
{
131+
var parser = new FileIniDataParser();
132+
var data = parser.ReadFile(fileName);
133+
var urlSection = data["InternetShortcut"];
134+
135+
var iconPath = urlSection?["IconFile"];
136+
if (string.IsNullOrEmpty(iconPath))
137+
{
138+
throw new FileNotFoundException();
139+
}
140+
hBitmap = GetHBitmap(Path.GetFullPath(iconPath), width, height, options);
141+
}
142+
catch
143+
{
144+
hBitmap = GetHBitmap(Path.GetFullPath(fileName), width, height, options);
145+
}
146+
147+
return hBitmap;
148+
}
111149
}
112150
}

0 commit comments

Comments
 (0)