Skip to content

feat: Don't convert primary thumbnail to byte array #6104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions Files/Filesystem/ListedItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,6 @@ public Uri CustomIconSource
set => SetProperty(ref customIconSource, value);
}

private byte[] customIconData;

[JsonIgnore]
public byte[] CustomIconData
{
get => customIconData;
set => SetProperty(ref customIconData, value);
}

private double opacity;

public double Opacity
Expand Down Expand Up @@ -490,8 +481,7 @@ public LibraryItem(LibraryLocationItem lib, string returnFormat = null) : base(n
LoadCustomIcon = true;
CustomIcon = lib.Icon;
//CustomIconSource = lib.IconSource;
CustomIconData = lib.IconData;
LoadFileIcon = CustomIconData != null;
LoadFileIcon = true;

IsEmpty = lib.IsEmpty;
DefaultSaveFolder = lib.DefaultSaveFolder;
Expand Down
4 changes: 1 addition & 3 deletions Files/Filesystem/Search/FolderSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@ private ListedItem GetListedItemAsync(string itemPath, WIN32_FIND_DATA findData)
_ = FilesystemTasks.Wrap(() => CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
{
listedItem.FileImage = await t.Result.ToBitmapAsync();
listedItem.CustomIconData = t.Result;
listedItem.LoadFolderGlyph = false;
listedItem.LoadUnknownTypeGlyph = false;
listedItem.LoadWebShortcutGlyph = false;
Expand Down Expand Up @@ -442,8 +441,7 @@ private async Task<ListedItem> GetListedItemAsync(IStorageItem item)
var iconData = await FileThumbnailHelper.LoadIconFromStorageItemAsync(item, ThumbnailSize, ThumbnailMode.ListView);
if (iconData != null)
{
listedItem.CustomIconData = iconData;
listedItem.FileImage = await listedItem.CustomIconData.ToBitmapAsync();
listedItem.FileImage = await iconData.ToBitmapAsync();
listedItem.LoadUnknownTypeGlyph = false;
listedItem.LoadWebShortcutGlyph = false;
listedItem.LoadFolderGlyph = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ CancellationToken cancellationToken
Opacity = 1,
LoadUnknownTypeGlyph = itemEmptyImgVis,
FileImage = null,
CustomIconData = null,
LoadFileIcon = itemThumbnailImgVis,
LoadFolderGlyph = itemFolderImgVis,
ItemName = itemName,
Expand Down
130 changes: 54 additions & 76 deletions Files/ViewModels/ItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -757,48 +757,39 @@ private async Task LoadItemThumbnail(ListedItem item, uint thumbnailSize = 20, I
var wasIconLoaded = false;
if (item.IsLibraryItem || item.PrimaryItemAttribute == StorageItemTypes.File || item.IsZipItem)
{
if (!forceReload && item.CustomIconData != null)
{
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
{
item.FileImage = await item.CustomIconData.ToBitmapAsync();
item.LoadUnknownTypeGlyph = false;
item.LoadWebShortcutGlyph = false;
item.LoadFileIcon = true;
}, Windows.System.DispatcherQueuePriority.Low);
wasIconLoaded = true;
}
else
if (!item.IsShortcutItem && !item.IsHiddenItem && !FtpHelpers.IsFtpPath(item.ItemPath))
{
if (!item.IsShortcutItem && !item.IsHiddenItem && !FtpHelpers.IsFtpPath(item.ItemPath))
var matchingStorageFile = matchingStorageItem.AsBaseStorageFile() ?? await GetFileFromPathAsync(item.ItemPath);
if (matchingStorageFile != null)
{
var matchingStorageFile = matchingStorageItem.AsBaseStorageFile() ?? await GetFileFromPathAsync(item.ItemPath);
if (matchingStorageFile != null)
{
var mode = thumbnailSize < 80 ? ThumbnailMode.ListView : ThumbnailMode.SingleItem;
var mode = thumbnailSize < 80 ? ThumbnailMode.ListView : ThumbnailMode.SingleItem;

using var Thumbnail = await matchingStorageFile.GetThumbnailAsync(mode, thumbnailSize, ThumbnailOptions.ResizeThumbnail);
if (!(Thumbnail == null || Thumbnail.Size == 0 || Thumbnail.OriginalHeight == 0 || Thumbnail.OriginalWidth == 0))
using var Thumbnail = await matchingStorageFile.GetThumbnailAsync(mode, thumbnailSize, ThumbnailOptions.ResizeThumbnail);
if (!(Thumbnail == null || Thumbnail.Size == 0 || Thumbnail.OriginalHeight == 0 || Thumbnail.OriginalWidth == 0))
{
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
{
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
{
item.CustomIconData = await Thumbnail.ToByteArrayAsync();
item.FileImage = await item.CustomIconData.ToBitmapAsync();
item.LoadUnknownTypeGlyph = false;
item.LoadWebShortcutGlyph = false;
item.LoadFileIcon = true;
}, Windows.System.DispatcherQueuePriority.Low);
wasIconLoaded = true;
}
item.LoadUnknownTypeGlyph = false;
item.LoadWebShortcutGlyph = false;
item.LoadFolderGlyph = false;
item.LoadFileIcon = true;
item.FileImage ??= new BitmapImage();
item.FileImage.DecodePixelType = DecodePixelType.Logical;
item.FileImage.DecodePixelWidth = (int)thumbnailSize;
item.FileImage.DecodePixelHeight = (int)thumbnailSize;
await item.FileImage.SetSourceAsync(Thumbnail);

}, Windows.System.DispatcherQueuePriority.Normal);
wasIconLoaded = true;
}

var overlayInfo = await FileThumbnailHelper.LoadOverlayAsync(item.ItemPath);
if (overlayInfo != null)
var overlayInfo = await FileThumbnailHelper.LoadOverlayAsync(item.ItemPath);
if (overlayInfo != null)
{
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
{
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
{
item.IconOverlay = await overlayInfo.ToBitmapAsync();
}, Windows.System.DispatcherQueuePriority.Low);
}
item.IconOverlay = await overlayInfo.ToBitmapAsync();
}, Windows.System.DispatcherQueuePriority.Low);
}
}
}
Expand All @@ -811,7 +802,6 @@ await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
{
item.FileImage = await iconInfo.IconData.ToBitmapAsync();
item.CustomIconData = iconInfo.IconData;
item.LoadFileIcon = true;
item.LoadUnknownTypeGlyph = false;
item.LoadWebShortcutGlyph = false;
Expand All @@ -829,50 +819,39 @@ await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
}
else
{
if (!forceReload && item.CustomIconData != null)
{
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
{
item.FileImage = await item.CustomIconData.ToBitmapAsync();
item.LoadUnknownTypeGlyph = false;
item.LoadWebShortcutGlyph = false;
item.LoadFolderGlyph = false;
item.LoadFileIcon = true;
}, Windows.System.DispatcherQueuePriority.Low);
wasIconLoaded = true;
}
else
if (!item.IsShortcutItem && !item.IsHiddenItem && !FtpHelpers.IsFtpPath(item.ItemPath))
{
if (!item.IsShortcutItem && !item.IsHiddenItem && !FtpHelpers.IsFtpPath(item.ItemPath))
var matchingStorageFolder = matchingStorageItem.AsBaseStorageFolder() ?? await GetFolderFromPathAsync(item.ItemPath);
if (matchingStorageFolder != null)
{
var matchingStorageFolder = matchingStorageItem.AsBaseStorageFolder() ?? await GetFolderFromPathAsync(item.ItemPath);
if (matchingStorageFolder != null)
{
var mode = thumbnailSize < 80 ? ThumbnailMode.ListView : ThumbnailMode.SingleItem;
var mode = thumbnailSize < 80 ? ThumbnailMode.ListView : ThumbnailMode.SingleItem;

using var Thumbnail = await matchingStorageFolder.GetThumbnailAsync(mode, thumbnailSize, ThumbnailOptions.ResizeThumbnail);
if (!(Thumbnail == null || Thumbnail.Size == 0 || Thumbnail.OriginalHeight == 0 || Thumbnail.OriginalWidth == 0))
using var Thumbnail = await matchingStorageFolder.GetThumbnailAsync(mode, thumbnailSize, ThumbnailOptions.ResizeThumbnail);
if (!(Thumbnail == null || Thumbnail.Size == 0 || Thumbnail.OriginalHeight == 0 || Thumbnail.OriginalWidth == 0))
{
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
{
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
{
item.CustomIconData = await Thumbnail.ToByteArrayAsync();
item.FileImage = await item.CustomIconData.ToBitmapAsync();
item.LoadUnknownTypeGlyph = false;
item.LoadWebShortcutGlyph = false;
item.LoadFolderGlyph = false;
item.LoadFileIcon = true;
}, Windows.System.DispatcherQueuePriority.Low);
wasIconLoaded = true;
}
item.LoadUnknownTypeGlyph = false;
item.LoadWebShortcutGlyph = false;
item.LoadFolderGlyph = false;
item.LoadFileIcon = true;
item.FileImage ??= new BitmapImage();
item.FileImage.DecodePixelType = DecodePixelType.Logical;
item.FileImage.DecodePixelWidth = (int)thumbnailSize;
item.FileImage.DecodePixelHeight = (int)thumbnailSize;
await item.FileImage.SetSourceAsync(Thumbnail);

}, Windows.System.DispatcherQueuePriority.Normal);
wasIconLoaded = true;
}

var overlayInfo = await FileThumbnailHelper.LoadOverlayAsync(item.ItemPath);
if (overlayInfo != null)
var overlayInfo = await FileThumbnailHelper.LoadOverlayAsync(item.ItemPath);
if (overlayInfo != null)
{
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
{
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
{
item.IconOverlay = await overlayInfo.ToBitmapAsync();
}, Windows.System.DispatcherQueuePriority.Low);
}
item.IconOverlay = await overlayInfo.ToBitmapAsync();
}, Windows.System.DispatcherQueuePriority.Low);
}
}
}
Expand All @@ -885,7 +864,6 @@ await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
{
item.FileImage = await iconInfo.IconData.ToBitmapAsync();
item.CustomIconData = iconInfo.IconData;
item.LoadFileIcon = true;
item.LoadFolderGlyph = false;
item.LoadUnknownTypeGlyph = false;
Expand Down
1 change: 0 additions & 1 deletion Files/ViewModels/Properties/FileProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public override void GetBaseProperties()
ViewModel.ItemModifiedTimestamp = Item.ItemDateModified;
ViewModel.ItemCreatedTimestamp = Item.ItemDateCreated;
ViewModel.LoadFolderGlyph = Item.LoadFolderGlyph;
ViewModel.IconData = Item.CustomIconData;
ViewModel.LoadUnknownTypeGlyph = Item.LoadUnknownTypeGlyph;
ViewModel.LoadCustomIcon = Item.LoadCustomIcon;
ViewModel.CustomIconSource = Item.CustomIconSource;
Expand Down
1 change: 0 additions & 1 deletion Files/ViewModels/Properties/FolderProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public override void GetBaseProperties()
ViewModel.ItemModifiedTimestamp = Item.ItemDateModified;
ViewModel.ItemCreatedTimestamp = Item.ItemDateCreated;
ViewModel.LoadFolderGlyph = Item.LoadFolderGlyph;
ViewModel.IconData = Item.CustomIconData;
ViewModel.LoadUnknownTypeGlyph = Item.LoadUnknownTypeGlyph;
ViewModel.LoadCustomIcon = Item.LoadCustomIcon;
ViewModel.CustomIconSource = Item.CustomIconSource;
Expand Down
1 change: 0 additions & 1 deletion Files/ViewModels/Properties/LibraryProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public override void GetBaseProperties()
ViewModel.ItemType = Library.ItemType;
ViewModel.LoadCustomIcon = Library.LoadCustomIcon;
ViewModel.CustomIconSource = Library.CustomIconSource;
ViewModel.IconData = Library.CustomIconData;
ViewModel.LoadFolderGlyph = Library.LoadFolderGlyph;
ViewModel.LoadUnknownTypeGlyph = Library.LoadUnknownTypeGlyph;
ViewModel.LoadFileIcon = Library.LoadFileIcon;
Expand Down
20 changes: 10 additions & 10 deletions Files/Views/LayoutModes/ColumnViewBase.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -215,24 +215,24 @@
Source="{x:Bind FileImage, Mode=OneWay}"
Stretch="Uniform" />
</ContentPresenter>
<FontIcon
x:Name="FolderGlyphIcon"
<Border
x:Name="FolderGlyphIcon"
Width="24"
Height="24"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
x:Load="{x:Bind LoadFolderGlyph, Mode=OneWay}"
Glyph="&#xF12B;" />
<Viewbox
Background="{ThemeResource SystemChromeHighColor}"
CornerRadius="4" />
<Border
x:Name="TypeUnknownGlyph"
MaxWidth="24"
MaxHeight="24"
Height="24"
Width="24"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
x:Phase="1"
Visibility="{x:Bind LoadUnknownTypeGlyph, Mode=OneWay}">
<FontIcon Glyph="&#xE7C3;" />
</Viewbox>
x:Load="{x:Bind LoadUnknownTypeGlyph, Mode=OneWay}"
Background="{ThemeResource SystemChromeHighColor}"
CornerRadius="4" />
<Image
x:Name="IconOverlay"
Width="16"
Expand Down
20 changes: 10 additions & 10 deletions Files/Views/LayoutModes/ColumnViewBrowser.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -235,24 +235,24 @@
Source="{x:Bind FileImage, Mode=OneWay}"
Stretch="Uniform" />
</ContentPresenter>
<FontIcon
x:Name="FolderGlyphIcon"
<Border
x:Name="FolderGlyphIcon"
Width="24"
Height="24"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
x:Load="{x:Bind LoadFolderGlyph, Mode=OneWay}"
Glyph="&#xF12B;" />
<Viewbox
Background="{ThemeResource SystemChromeHighColor}"
CornerRadius="4" />
<Border
x:Name="TypeUnknownGlyph"
MaxWidth="24"
MaxHeight="24"
Height="24"
Width="24"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
x:Phase="1"
Visibility="{x:Bind LoadUnknownTypeGlyph, Mode=OneWay}">
<FontIcon Glyph="&#xE7C3;" />
</Viewbox>
x:Load="{x:Bind LoadUnknownTypeGlyph, Mode=OneWay}"
Background="{ThemeResource SystemChromeHighColor}"
CornerRadius="4" />
<Image
x:Name="IconOverlay"
Width="16"
Expand Down
Loading