Skip to content

Commit

Permalink
Fix: Fixed issue where exe icons were sometimes small (#14700)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaira2 committed Feb 11, 2024
1 parent cb9412a commit fda8163
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/Files.App/Data/Items/DriveItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public int CompareTo(INavigationControlItem other)
public async Task LoadThumbnailAsync()
{
if (!string.IsNullOrEmpty(DeviceID) && !string.Equals(DeviceID, "network-folder"))
IconData ??= await FileThumbnailHelper.LoadIconWithoutOverlayAsync(DeviceID, Constants.DefaultIconSizes.Large, false, true);
IconData ??= await FileThumbnailHelper.LoadIconWithoutOverlayAsync(DeviceID, Constants.DefaultIconSizes.Large, false, false, true);

if (Root is not null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Data/Items/SidebarLibraryItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task<bool> CheckDefaultSaveFolderAccess()

public async Task LoadLibraryIconAsync()
{
IconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Path, Constants.DefaultIconSizes.Large, false, true);
IconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Path, Constants.DefaultIconSizes.Large, false, false, true);

if (IconData is not null)
Icon = await IconData.ToBitmapAsync();
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Data/Items/WidgetDriveCardItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public WidgetDriveCardItem(DriveItem item)

public async Task LoadCardThumbnailAsync()
{
thumbnailData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Item.Path, Constants.DefaultIconSizes.Jumbo, true, true);
thumbnailData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Item.Path, Constants.DefaultIconSizes.Jumbo, true, false, true);

// Thumbnail data is valid, set the item icon
if (thumbnailData is not null && thumbnailData.Length > 0)
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Data/Items/WidgetFolderCardItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public WidgetFolderCardItem(LocationItem item, string text, bool isPinned)

public async Task LoadCardThumbnailAsync()
{
_thumbnailData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Path, Constants.DefaultIconSizes.Jumbo, true, true);
_thumbnailData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Path, Constants.DefaultIconSizes.Jumbo, true, false, true);

if (_thumbnailData is not null && _thumbnailData.Length > 0)
Thumbnail = await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(() => _thumbnailData.ToBitmapAsync(), Microsoft.UI.Dispatching.DispatcherQueuePriority.Low);
Expand Down
11 changes: 6 additions & 5 deletions src/Files.App/Data/Models/ItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,8 @@ private async Task LoadItemThumbnailAsync(ListedItem item, uint thumbnailSize =
if (item.IsLibrary || item.PrimaryItemAttribute == StorageItemTypes.File || item.IsArchive)
{
var getIconOnly = UserSettingsService.FoldersSettingsService.ShowThumbnails == false;
var iconInfo = await FileThumbnailHelper.LoadIconAndOverlayAsync(item.ItemPath, thumbnailSize, false, getIconOnly);
var getThumbnailOnly = !item.IsExecutable && !getIconOnly;
var iconInfo = await FileThumbnailHelper.LoadIconAndOverlayAsync(item.ItemPath, thumbnailSize, false, getThumbnailOnly, getIconOnly);

if (!iconInfo.isIconCached)
{
Expand All @@ -965,7 +966,7 @@ private async Task LoadItemThumbnailAsync(ListedItem item, uint thumbnailSize =
var cancellationTokenSource = new CancellationTokenSource(3000);
while (!iconInfo.isIconCached)
{
iconInfo = await FileThumbnailHelper.LoadIconAndOverlayAsync(item.ItemPath, thumbnailSize, false, getIconOnly);
iconInfo = await FileThumbnailHelper.LoadIconAndOverlayAsync(item.ItemPath, thumbnailSize, false, getThumbnailOnly, getIconOnly);
cancellationTokenSource.Token.ThrowIfCancellationRequested();
await Task.Delay(500);
}
Expand All @@ -987,7 +988,7 @@ private async Task LoadItemThumbnailAsync(ListedItem item, uint thumbnailSize =
!item.IsExecutable
)
{
var fileIcon = await FileThumbnailHelper.LoadIconAndOverlayAsync(item.ItemPath, thumbnailSize, false, true);
var fileIcon = await FileThumbnailHelper.LoadIconAndOverlayAsync(item.ItemPath, thumbnailSize, false, false, true);
var bitmapImage = await fileIcon.IconData.ToBitmapAsync();
DefaultIcons.TryAdd(item.FileExtension.ToLowerInvariant(), bitmapImage);
}
Expand All @@ -1008,7 +1009,7 @@ private async Task LoadItemThumbnailAsync(ListedItem item, uint thumbnailSize =
else
{
var getIconOnly = UserSettingsService.FoldersSettingsService.ShowThumbnails == false || thumbnailSize < 80;
var iconInfo = await FileThumbnailHelper.LoadIconAndOverlayAsync(item.ItemPath, thumbnailSize, true, getIconOnly);
var iconInfo = await FileThumbnailHelper.LoadIconAndOverlayAsync(item.ItemPath, thumbnailSize, true, false, getIconOnly);

if (iconInfo.IconData is not null)
{
Expand Down Expand Up @@ -1287,7 +1288,7 @@ public async Task LoadGitPropertiesAsync(GitItem gitItem)
ImageSource? groupImage = null;
if (item.PrimaryItemAttribute != StorageItemTypes.Folder || item.IsArchive)
{
var headerIconInfo = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(item.ItemPath, Constants.DefaultIconSizes.ExtraLarge, false, true);
var headerIconInfo = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(item.ItemPath, Constants.DefaultIconSizes.ExtraLarge, false, false, true);

if (headerIconInfo is not null && !item.IsShortcut)
groupImage = await dispatcherQueue.EnqueueOrInvokeAsync(() => headerIconInfo.ToBitmapAsync(), Microsoft.UI.Dispatching.DispatcherQueuePriority.Low);
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Data/Models/SidebarPinnedModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public async Task<LocationItem> CreateLocationItemFromPathAsync(string path)

if (locationItem.IconData is null)
{
locationItem.IconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(path, 48u, false, true);
locationItem.IconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(path, 48u, false, false, true);

if (locationItem.IconData is not null)
locationItem.Icon = await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(() => locationItem.IconData.ToBitmapAsync());
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Utils/Cloud/CloudDrivesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static async Task UpdateDrivesAsync()
ShowProperties = true,
};

var iconData = provider.IconData ?? await FileThumbnailHelper.LoadIconWithoutOverlayAsync(provider.SyncFolder, Constants.DefaultIconSizes.Large, false, true);
var iconData = provider.IconData ?? await FileThumbnailHelper.LoadIconWithoutOverlayAsync(provider.SyncFolder, Constants.DefaultIconSizes.Large, false, false, true);
if (iconData is not null)
{
cloudProviderItem.IconData = iconData;
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Utils/RecentItem/RecentItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public RecentItem(ShellFileItem fileItem) : base()

public async Task LoadRecentItemIconAsync()
{
var iconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(RecentPath, Constants.DefaultIconSizes.Large, false, false);
var iconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(RecentPath, Constants.DefaultIconSizes.Large, false, false, false);
if (iconData is not null)
{
EmptyImgVis = false;
Expand Down
3 changes: 2 additions & 1 deletion src/Files.App/Utils/Shell/Win32API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ private class IconAndOverlayCacheEntry
string path,
int thumbnailSize,
bool isFolder,
bool getThumbnailOnly,
bool getIconOnly,
bool getOverlay = true,
bool onlyGetOverlay = false)
Expand Down Expand Up @@ -280,7 +281,7 @@ private class IconAndOverlayCacheEntry

if (getIconOnly)
flags |= Shell32.SIIGBF.SIIGBF_ICONONLY;
else if (!isFolder)
else if (getThumbnailOnly)
flags |= Shell32.SIIGBF.SIIGBF_THUMBNAILONLY;

var hres = shellFactory.GetImage(new SIZE(thumbnailSize, thumbnailSize), flags, out var hbitmap);
Expand Down
10 changes: 5 additions & 5 deletions src/Files.App/Utils/Storage/Helpers/FileThumbnailHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ namespace Files.App.Utils.Storage
{
public static class FileThumbnailHelper
{
public static Task<(byte[] IconData, byte[] OverlayData, bool isIconCached)> LoadIconAndOverlayAsync(string filePath, uint thumbnailSize, bool isFolder = false, bool getIconOnly = false)
=> Win32API.StartSTATask(() => Win32API.GetFileIconAndOverlay(filePath, (int)thumbnailSize, isFolder, getIconOnly));
public static Task<(byte[] IconData, byte[] OverlayData, bool isIconCached)> LoadIconAndOverlayAsync(string filePath, uint thumbnailSize, bool isFolder = false, bool getThumbnailOnly = false, bool getIconOnly = false)
=> Win32API.StartSTATask(() => Win32API.GetFileIconAndOverlay(filePath, (int)thumbnailSize, isFolder, getThumbnailOnly, getIconOnly));

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

public static async Task<byte[]> LoadIconFromStorageItemAsync(IStorageItem item, uint thumbnailSize, ThumbnailMode thumbnailMode, ThumbnailOptions thumbnailOptions)
Expand Down Expand Up @@ -54,7 +54,7 @@ public static async Task<byte[]> LoadIconFromPathAsync(string filePath, uint thu
}
}
}
return await LoadIconWithoutOverlayAsync(filePath, thumbnailSize, isFolder, false);
return await LoadIconWithoutOverlayAsync(filePath, thumbnailSize, isFolder, false, false);
}
}
}
4 changes: 2 additions & 2 deletions src/Files.App/ViewModels/Properties/Items/DriveProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ public async override Task GetSpecialPropertiesAsync()
}
else
{
ViewModel.IconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Drive.Path, 80, false, false);
ViewModel.IconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Drive.Path, 80, false, false, false);
}

ViewModel.IconData ??= await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Drive.DeviceID, 80, false, false); // For network shortcuts
ViewModel.IconData ??= await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Drive.DeviceID, 80, false, false, false); // For network shortcuts
}

if (diskRoot is null || diskRoot.Properties is null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public async override Task GetSpecialPropertiesAsync()
ViewModel.IsReadOnly = NativeFileOperationsHelper.HasFileAttribute(Library.ItemPath, System.IO.FileAttributes.ReadOnly);
ViewModel.IsHidden = NativeFileOperationsHelper.HasFileAttribute(Library.ItemPath, System.IO.FileAttributes.Hidden);

var fileIconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Library.ItemPath, 80, false, false);
var fileIconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Library.ItemPath, 80, false, false, false);
if (fileIconData is not null)
{
ViewModel.IconData = fileIconData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public virtual async Task LoadAsync()
public async virtual Task<List<FileProperty>> LoadPreviewAndDetailsAsync()
{
// Requesting sizes larger than 220 may result in a small thumbnail
var iconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Item.ItemPath, Constants.DefaultIconSizes.Jumbo, false, false);
var iconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Item.ItemPath, Constants.DefaultIconSizes.Jumbo, false, false, false);
if (iconData is not null)
await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(async () => FileImage = await iconData.ToBitmapAsync());
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private async Task LoadPreviewAndDetailsAsync()
var items = await Folder.GetItemsAsync();

// Requesting sizes larger than 220 may result in a thumbnail with a small folder
var iconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Item.ItemPath, Constants.DefaultIconSizes.Jumbo, true, false);
var iconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Item.ItemPath, Constants.DefaultIconSizes.Jumbo, true, false, false);
if (iconData is not null)
Thumbnail = await iconData.ToBitmapAsync();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override async Task LoadAsync()

private async Task LoadItemThumbnailAsync()
{
var iconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Item.ItemPath, Constants.DefaultIconSizes.Jumbo, false, false);
var iconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Item.ItemPath, Constants.DefaultIconSizes.Jumbo, false, false, false);
if (iconData is not null)
{
FileImage = await iconData.ToBitmapAsync();
Expand Down

0 comments on commit fda8163

Please sign in to comment.