Skip to content

Commit

Permalink
Code Quality: UseCurrentScale for properties window (#13301)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaira2 authored Sep 3, 2023
1 parent 103dcdf commit 010a8f1
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/Files.App/Services/ImagingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal sealed class ImagingService : IImageService
if (storable is not ILocatableStorable locatableStorable)
return null;

var iconData = await FileThumbnailHelper.LoadIconFromPathAsync(locatableStorable.Path, 24u, ThumbnailMode.ListView);
var iconData = await FileThumbnailHelper.LoadIconFromPathAsync(locatableStorable.Path, 24u, ThumbnailMode.ListView, ThumbnailOptions.ResizeThumbnail);
if (iconData is null)
return null;

Expand All @@ -30,7 +30,7 @@ internal sealed class ImagingService : IImageService

public async Task<IImageModel?> GetImageModelFromPathAsync(string filePath, uint thumbnailSize = 64)
{
if (await FileThumbnailHelper.LoadIconFromPathAsync(filePath, thumbnailSize, ThumbnailMode.ListView) is byte[] imageBuffer)
if (await FileThumbnailHelper.LoadIconFromPathAsync(filePath, thumbnailSize, ThumbnailMode.ListView, ThumbnailOptions.ResizeThumbnail) is byte[] imageBuffer)
return await GetImageModelFromDataAsync(imageBuffer);

return null;
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/UserControls/Widgets/DrivesWidget.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public async Task LoadCardThumbnailAsync()
{
// Try load thumbnail using ListView mode
if (thumbnailData is null || thumbnailData.Length == 0)
thumbnailData = await FileThumbnailHelper.LoadIconFromPathAsync(Item.Path, Convert.ToUInt32(Constants.Widgets.WidgetIconSize), Windows.Storage.FileProperties.ThumbnailMode.SingleItem);
thumbnailData = await FileThumbnailHelper.LoadIconFromPathAsync(Item.Path, Convert.ToUInt32(Constants.Widgets.WidgetIconSize), Windows.Storage.FileProperties.ThumbnailMode.SingleItem, Windows.Storage.FileProperties.ThumbnailOptions.ResizeThumbnail);

// Thumbnail is still null, use DriveItem icon (loaded using SingleItem mode)
if (thumbnailData is null || thumbnailData.Length == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public async Task LoadCardThumbnailAsync()
{
if (thumbnailData is null || thumbnailData.Length == 0)
{
thumbnailData = await FileThumbnailHelper.LoadIconFromPathAsync(Path, Convert.ToUInt32(Constants.Widgets.WidgetIconSize), Windows.Storage.FileProperties.ThumbnailMode.SingleItem);
thumbnailData = await FileThumbnailHelper.LoadIconFromPathAsync(Path, Convert.ToUInt32(Constants.Widgets.WidgetIconSize), Windows.Storage.FileProperties.ThumbnailMode.SingleItem, Windows.Storage.FileProperties.ThumbnailOptions.ResizeThumbnail);
}
if (thumbnailData is not null && thumbnailData.Length > 0)
{
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 @@ -76,7 +76,7 @@ public RecentItem(ShellFileItem fileItem) : base()

public async Task LoadRecentItemIcon()
{
var iconData = await FileThumbnailHelper.LoadIconFromPathAsync(RecentPath, 96u, ThumbnailMode.SingleItem);
var iconData = await FileThumbnailHelper.LoadIconFromPathAsync(RecentPath, 96u, ThumbnailMode.SingleItem, ThumbnailOptions.ResizeThumbnail);
if (iconData is null)
{
EmptyImgVis = true;
Expand Down
4 changes: 4 additions & 0 deletions src/Files.App/Utils/Shell/ContextMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ private void EnumMenuItems(HMENU hMenu, List<Win32ContextMenuItem> menuItemsResu

if (bitmap is not null)
{
// Make the icon background transparent
Color backgroundColor = bitmap.GetPixel(0, 0);
bitmap.MakeTransparent(backgroundColor);

byte[] bitmapData = (byte[])new ImageConverter().ConvertTo(bitmap, typeof(byte[]));
menuItem.Icon = bitmapData;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/Utils/Storage/Helpers/FileThumbnailHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ public static async Task<byte[]> LoadIconFromStorageItemAsync(IStorageItem item,
return null;
}

public static async Task<byte[]> LoadIconFromPathAsync(string filePath, uint thumbnailSize, ThumbnailMode thumbnailMode, bool isFolder = false)
public static async Task<byte[]> LoadIconFromPathAsync(string filePath, uint thumbnailSize, ThumbnailMode thumbnailMode, ThumbnailOptions thumbnailOptions, bool isFolder = false)
{
if (!FileExtensionHelpers.IsShortcutOrUrlFile(filePath))
{
var item = await StorageHelpers.ToStorageItem<IStorageItem>(filePath);
if (item is not null)
{
var iconData = await LoadIconFromStorageItemAsync(item, thumbnailSize, thumbnailMode, ThumbnailOptions.ResizeThumbnail);
var iconData = await LoadIconFromStorageItemAsync(item, thumbnailSize, thumbnailMode, thumbnailOptions);
if (iconData is not null)
{
return iconData;
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Utils/Storage/Search/FolderSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ private ListedItem GetListedItemAsync(string itemPath, WIN32_FIND_DATA findData)
}
if (listedItem is not null && MaxItemCount > 0) // Only load icon for searchbox suggestions
{
_ = FileThumbnailHelper.LoadIconFromPathAsync(listedItem.ItemPath, ThumbnailSize, ThumbnailMode.ListView, isFolder)
_ = FileThumbnailHelper.LoadIconFromPathAsync(listedItem.ItemPath, ThumbnailSize, ThumbnailMode.ListView, ThumbnailOptions.ResizeThumbnail, isFolder)
.ContinueWith((t) =>
{
if (t.IsCompletedSuccessfully && t.Result is not null)
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/ViewModels/MainPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public async Task UpdateTabInfo(TabItem tabItem, object navigationArg)

if (iconSource.ImageSource is null)
{
var iconData = await FileThumbnailHelper.LoadIconFromPathAsync(currentPath, 24u, Windows.Storage.FileProperties.ThumbnailMode.ListView, true);
var iconData = await FileThumbnailHelper.LoadIconFromPathAsync(currentPath, 24u, Windows.Storage.FileProperties.ThumbnailMode.ListView, Windows.Storage.FileProperties.ThumbnailOptions.ResizeThumbnail, true);
if (iconData is not null)
iconSource.ImageSource = await iconData.ToBitmapAsync();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public override async Task GetSpecialProperties()
ViewModel.ItemSizeOnDisk = NativeFileOperationsHelper.GetFileSizeOnDisk(Item.ItemPath)?.ToLongSizeString() ??
string.Empty;

var fileIconData = await FileThumbnailHelper.LoadIconFromPathAsync(Item.ItemPath, 80, Windows.Storage.FileProperties.ThumbnailMode.DocumentsView, false);
var fileIconData = await FileThumbnailHelper.LoadIconFromPathAsync(Item.ItemPath, 80, Windows.Storage.FileProperties.ThumbnailMode.DocumentsView, Windows.Storage.FileProperties.ThumbnailOptions.ResizeThumbnail, false);
if (fileIconData is not null)
{
ViewModel.IconData = fileIconData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public async override Task GetSpecialProperties()
ViewModel.IsHidden = NativeFileOperationsHelper.HasFileAttribute(
Item.ItemPath, System.IO.FileAttributes.Hidden);

var fileIconData = await FileThumbnailHelper.LoadIconFromPathAsync(Item.ItemPath, 80, Windows.Storage.FileProperties.ThumbnailMode.SingleItem, true);
var fileIconData = await FileThumbnailHelper.LoadIconFromPathAsync(Item.ItemPath, 80, Windows.Storage.FileProperties.ThumbnailMode.SingleItem, Windows.Storage.FileProperties.ThumbnailOptions.UseCurrentScale, true);
if (fileIconData is not null)
{
ViewModel.IconData = fileIconData;
Expand Down

0 comments on commit 010a8f1

Please sign in to comment.