Skip to content

Commit fda8163

Browse files
authored
Fix: Fixed issue where exe icons were sometimes small (#14700)
1 parent cb9412a commit fda8163

File tree

15 files changed

+26
-24
lines changed

15 files changed

+26
-24
lines changed

src/Files.App/Data/Items/DriveItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ public int CompareTo(INavigationControlItem other)
317317
public async Task LoadThumbnailAsync()
318318
{
319319
if (!string.IsNullOrEmpty(DeviceID) && !string.Equals(DeviceID, "network-folder"))
320-
IconData ??= await FileThumbnailHelper.LoadIconWithoutOverlayAsync(DeviceID, Constants.DefaultIconSizes.Large, false, true);
320+
IconData ??= await FileThumbnailHelper.LoadIconWithoutOverlayAsync(DeviceID, Constants.DefaultIconSizes.Large, false, false, true);
321321

322322
if (Root is not null)
323323
{

src/Files.App/Data/Items/SidebarLibraryItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public async Task<bool> CheckDefaultSaveFolderAccess()
4646

4747
public async Task LoadLibraryIconAsync()
4848
{
49-
IconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Path, Constants.DefaultIconSizes.Large, false, true);
49+
IconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Path, Constants.DefaultIconSizes.Large, false, false, true);
5050

5151
if (IconData is not null)
5252
Icon = await IconData.ToBitmapAsync();

src/Files.App/Data/Items/WidgetDriveCardItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public WidgetDriveCardItem(DriveItem item)
2626

2727
public async Task LoadCardThumbnailAsync()
2828
{
29-
thumbnailData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Item.Path, Constants.DefaultIconSizes.Jumbo, true, true);
29+
thumbnailData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Item.Path, Constants.DefaultIconSizes.Jumbo, true, false, true);
3030

3131
// Thumbnail data is valid, set the item icon
3232
if (thumbnailData is not null && thumbnailData.Length > 0)

src/Files.App/Data/Items/WidgetFolderCardItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public WidgetFolderCardItem(LocationItem item, string text, bool isPinned)
5050

5151
public async Task LoadCardThumbnailAsync()
5252
{
53-
_thumbnailData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Path, Constants.DefaultIconSizes.Jumbo, true, true);
53+
_thumbnailData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Path, Constants.DefaultIconSizes.Jumbo, true, false, true);
5454

5555
if (_thumbnailData is not null && _thumbnailData.Length > 0)
5656
Thumbnail = await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(() => _thumbnailData.ToBitmapAsync(), Microsoft.UI.Dispatching.DispatcherQueuePriority.Low);

src/Files.App/Data/Models/ItemViewModel.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,8 @@ private async Task LoadItemThumbnailAsync(ListedItem item, uint thumbnailSize =
948948
if (item.IsLibrary || item.PrimaryItemAttribute == StorageItemTypes.File || item.IsArchive)
949949
{
950950
var getIconOnly = UserSettingsService.FoldersSettingsService.ShowThumbnails == false;
951-
var iconInfo = await FileThumbnailHelper.LoadIconAndOverlayAsync(item.ItemPath, thumbnailSize, false, getIconOnly);
951+
var getThumbnailOnly = !item.IsExecutable && !getIconOnly;
952+
var iconInfo = await FileThumbnailHelper.LoadIconAndOverlayAsync(item.ItemPath, thumbnailSize, false, getThumbnailOnly, getIconOnly);
952953

953954
if (!iconInfo.isIconCached)
954955
{
@@ -965,7 +966,7 @@ await dispatcherQueue.EnqueueOrInvokeAsync(async () =>
965966
var cancellationTokenSource = new CancellationTokenSource(3000);
966967
while (!iconInfo.isIconCached)
967968
{
968-
iconInfo = await FileThumbnailHelper.LoadIconAndOverlayAsync(item.ItemPath, thumbnailSize, false, getIconOnly);
969+
iconInfo = await FileThumbnailHelper.LoadIconAndOverlayAsync(item.ItemPath, thumbnailSize, false, getThumbnailOnly, getIconOnly);
969970
cancellationTokenSource.Token.ThrowIfCancellationRequested();
970971
await Task.Delay(500);
971972
}
@@ -987,7 +988,7 @@ await dispatcherQueue.EnqueueOrInvokeAsync(async () =>
987988
!item.IsExecutable
988989
)
989990
{
990-
var fileIcon = await FileThumbnailHelper.LoadIconAndOverlayAsync(item.ItemPath, thumbnailSize, false, true);
991+
var fileIcon = await FileThumbnailHelper.LoadIconAndOverlayAsync(item.ItemPath, thumbnailSize, false, false, true);
991992
var bitmapImage = await fileIcon.IconData.ToBitmapAsync();
992993
DefaultIcons.TryAdd(item.FileExtension.ToLowerInvariant(), bitmapImage);
993994
}
@@ -1008,7 +1009,7 @@ await dispatcherQueue.EnqueueOrInvokeAsync(async () =>
10081009
else
10091010
{
10101011
var getIconOnly = UserSettingsService.FoldersSettingsService.ShowThumbnails == false || thumbnailSize < 80;
1011-
var iconInfo = await FileThumbnailHelper.LoadIconAndOverlayAsync(item.ItemPath, thumbnailSize, true, getIconOnly);
1012+
var iconInfo = await FileThumbnailHelper.LoadIconAndOverlayAsync(item.ItemPath, thumbnailSize, true, false, getIconOnly);
10121013

10131014
if (iconInfo.IconData is not null)
10141015
{
@@ -1287,7 +1288,7 @@ await SafetyExtensions.IgnoreExceptions(() =>
12871288
ImageSource? groupImage = null;
12881289
if (item.PrimaryItemAttribute != StorageItemTypes.Folder || item.IsArchive)
12891290
{
1290-
var headerIconInfo = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(item.ItemPath, Constants.DefaultIconSizes.ExtraLarge, false, true);
1291+
var headerIconInfo = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(item.ItemPath, Constants.DefaultIconSizes.ExtraLarge, false, false, true);
12911292

12921293
if (headerIconInfo is not null && !item.IsShortcut)
12931294
groupImage = await dispatcherQueue.EnqueueOrInvokeAsync(() => headerIconInfo.ToBitmapAsync(), Microsoft.UI.Dispatching.DispatcherQueuePriority.Low);

src/Files.App/Data/Models/SidebarPinnedModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public async Task<LocationItem> CreateLocationItemFromPathAsync(string path)
111111

112112
if (locationItem.IconData is null)
113113
{
114-
locationItem.IconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(path, 48u, false, true);
114+
locationItem.IconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(path, 48u, false, false, true);
115115

116116
if (locationItem.IconData is not null)
117117
locationItem.Icon = await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(() => locationItem.IconData.ToBitmapAsync());

src/Files.App/Utils/Cloud/CloudDrivesManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static async Task UpdateDrivesAsync()
6363
ShowProperties = true,
6464
};
6565

66-
var iconData = provider.IconData ?? await FileThumbnailHelper.LoadIconWithoutOverlayAsync(provider.SyncFolder, Constants.DefaultIconSizes.Large, false, true);
66+
var iconData = provider.IconData ?? await FileThumbnailHelper.LoadIconWithoutOverlayAsync(provider.SyncFolder, Constants.DefaultIconSizes.Large, false, false, true);
6767
if (iconData is not null)
6868
{
6969
cloudProviderItem.IconData = iconData;

src/Files.App/Utils/RecentItem/RecentItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public RecentItem(ShellFileItem fileItem) : base()
7575

7676
public async Task LoadRecentItemIconAsync()
7777
{
78-
var iconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(RecentPath, Constants.DefaultIconSizes.Large, false, false);
78+
var iconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(RecentPath, Constants.DefaultIconSizes.Large, false, false, false);
7979
if (iconData is not null)
8080
{
8181
EmptyImgVis = false;

src/Files.App/Utils/Shell/Win32API.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ public static (byte[]? icon, byte[]? overlay, bool isIconCached) GetFileIconAndO
246246
string path,
247247
int thumbnailSize,
248248
bool isFolder,
249+
bool getThumbnailOnly,
249250
bool getIconOnly,
250251
bool getOverlay = true,
251252
bool onlyGetOverlay = false)
@@ -280,7 +281,7 @@ public static (byte[]? icon, byte[]? overlay, bool isIconCached) GetFileIconAndO
280281

281282
if (getIconOnly)
282283
flags |= Shell32.SIIGBF.SIIGBF_ICONONLY;
283-
else if (!isFolder)
284+
else if (getThumbnailOnly)
284285
flags |= Shell32.SIIGBF.SIIGBF_THUMBNAILONLY;
285286

286287
var hres = shellFactory.GetImage(new SIZE(thumbnailSize, thumbnailSize), flags, out var hbitmap);

src/Files.App/Utils/Storage/Helpers/FileThumbnailHelper.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ namespace Files.App.Utils.Storage
99
{
1010
public static class FileThumbnailHelper
1111
{
12-
public static Task<(byte[] IconData, byte[] OverlayData, bool isIconCached)> LoadIconAndOverlayAsync(string filePath, uint thumbnailSize, bool isFolder = false, bool getIconOnly = false)
13-
=> Win32API.StartSTATask(() => Win32API.GetFileIconAndOverlay(filePath, (int)thumbnailSize, isFolder, getIconOnly));
12+
public static Task<(byte[] IconData, byte[] OverlayData, bool isIconCached)> LoadIconAndOverlayAsync(string filePath, uint thumbnailSize, bool isFolder = false, bool getThumbnailOnly = false, bool getIconOnly = false)
13+
=> Win32API.StartSTATask(() => Win32API.GetFileIconAndOverlay(filePath, (int)thumbnailSize, isFolder, getThumbnailOnly, getIconOnly));
1414

15-
public static async Task<byte[]> LoadIconWithoutOverlayAsync(string filePath, uint thumbnailSize, bool isFolder, bool getIconOnly)
15+
public static async Task<byte[]> LoadIconWithoutOverlayAsync(string filePath, uint thumbnailSize, bool isFolder, bool getThumbnailOnly, bool getIconOnly)
1616
{
17-
return (await Win32API.StartSTATask(() => Win32API.GetFileIconAndOverlay(filePath, (int)thumbnailSize, isFolder, getIconOnly))).icon;
17+
return (await Win32API.StartSTATask(() => Win32API.GetFileIconAndOverlay(filePath, (int)thumbnailSize, isFolder, getThumbnailOnly, getIconOnly))).icon;
1818
}
1919

2020
public static async Task<byte[]> LoadIconFromStorageItemAsync(IStorageItem item, uint thumbnailSize, ThumbnailMode thumbnailMode, ThumbnailOptions thumbnailOptions)
@@ -54,7 +54,7 @@ public static async Task<byte[]> LoadIconFromPathAsync(string filePath, uint thu
5454
}
5555
}
5656
}
57-
return await LoadIconWithoutOverlayAsync(filePath, thumbnailSize, isFolder, false);
57+
return await LoadIconWithoutOverlayAsync(filePath, thumbnailSize, isFolder, false, false);
5858
}
5959
}
6060
}

0 commit comments

Comments
 (0)