|
1 | 1 | using System; |
2 | | -using System.Runtime.InteropServices; |
3 | 2 | using System.IO; |
| 3 | +using System.Runtime.InteropServices; |
4 | 4 | using System.Windows; |
5 | 5 | using System.Windows.Interop; |
6 | 6 | using System.Windows.Media.Imaging; |
| 7 | +using IniParser; |
7 | 8 | using Windows.Win32; |
8 | 9 | using Windows.Win32.Foundation; |
9 | | -using Windows.Win32.UI.Shell; |
10 | 10 | using Windows.Win32.Graphics.Gdi; |
| 11 | +using Windows.Win32.UI.Shell; |
11 | 12 |
|
12 | 13 | namespace Flow.Launcher.Infrastructure.Image |
13 | 14 | { |
@@ -35,9 +36,21 @@ public class WindowsThumbnailProvider |
35 | 36 |
|
36 | 37 | private static readonly HRESULT S_PATHNOTFOUND = (HRESULT)0x8004B205; |
37 | 38 |
|
| 39 | + private const string UrlExtension = ".url"; |
| 40 | + |
38 | 41 | public static BitmapSource GetThumbnail(string fileName, int width, int height, ThumbnailOptions options) |
39 | 42 | { |
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 | + } |
41 | 54 |
|
42 | 55 | try |
43 | 56 | { |
@@ -108,5 +121,30 @@ private static unsafe HBITMAP GetHBitmap(string fileName, int width, int height, |
108 | 121 |
|
109 | 122 | return hBitmap; |
110 | 123 | } |
| 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 | + } |
111 | 149 | } |
112 | 150 | } |
0 commit comments