Skip to content

Commit 8c4b871

Browse files
authored
Don't convert primary thumbnail to byte array (#6104)
1 parent 0770c87 commit 8c4b871

File tree

11 files changed

+107
-142
lines changed

11 files changed

+107
-142
lines changed

Files/Filesystem/ListedItem.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,6 @@ public Uri CustomIconSource
136136
set => SetProperty(ref customIconSource, value);
137137
}
138138

139-
private byte[] customIconData;
140-
141-
[JsonIgnore]
142-
public byte[] CustomIconData
143-
{
144-
get => customIconData;
145-
set => SetProperty(ref customIconData, value);
146-
}
147-
148139
private double opacity;
149140

150141
public double Opacity
@@ -499,8 +490,7 @@ public LibraryItem(LibraryLocationItem lib, string returnFormat = null) : base(n
499490
LoadCustomIcon = true;
500491
CustomIcon = lib.Icon;
501492
//CustomIconSource = lib.IconSource;
502-
CustomIconData = lib.IconData;
503-
LoadFileIcon = CustomIconData != null;
493+
LoadFileIcon = true;
504494

505495
IsEmpty = lib.IsEmpty;
506496
DefaultSaveFolder = lib.DefaultSaveFolder;

Files/Filesystem/Search/FolderSearch.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,6 @@ private ListedItem GetListedItemAsync(string itemPath, WIN32_FIND_DATA findData)
375375
_ = FilesystemTasks.Wrap(() => CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
376376
{
377377
listedItem.FileImage = await t.Result.ToBitmapAsync();
378-
listedItem.CustomIconData = t.Result;
379378
listedItem.LoadFolderGlyph = false;
380379
listedItem.LoadUnknownTypeGlyph = false;
381380
listedItem.LoadWebShortcutGlyph = false;
@@ -442,8 +441,7 @@ private async Task<ListedItem> GetListedItemAsync(IStorageItem item)
442441
var iconData = await FileThumbnailHelper.LoadIconFromStorageItemAsync(item, ThumbnailSize, ThumbnailMode.ListView);
443442
if (iconData != null)
444443
{
445-
listedItem.CustomIconData = iconData;
446-
listedItem.FileImage = await listedItem.CustomIconData.ToBitmapAsync();
444+
listedItem.FileImage = await iconData.ToBitmapAsync();
447445
listedItem.LoadUnknownTypeGlyph = false;
448446
listedItem.LoadWebShortcutGlyph = false;
449447
listedItem.LoadFolderGlyph = false;

Files/Filesystem/StorageEnumerators/UniversalStorageEnumerator.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ CancellationToken cancellationToken
218218
Opacity = 1,
219219
LoadUnknownTypeGlyph = itemEmptyImgVis,
220220
FileImage = null,
221-
CustomIconData = null,
222221
LoadFileIcon = itemThumbnailImgVis,
223222
LoadFolderGlyph = itemFolderImgVis,
224223
ItemName = itemName,

Files/ViewModels/ItemViewModel.cs

Lines changed: 54 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -756,48 +756,39 @@ private async Task LoadItemThumbnail(ListedItem item, uint thumbnailSize = 20, I
756756
var wasIconLoaded = false;
757757
if (item.IsLibraryItem || item.PrimaryItemAttribute == StorageItemTypes.File || item.IsZipItem)
758758
{
759-
if (!forceReload && item.CustomIconData != null)
760-
{
761-
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
762-
{
763-
item.FileImage = await item.CustomIconData.ToBitmapAsync();
764-
item.LoadUnknownTypeGlyph = false;
765-
item.LoadWebShortcutGlyph = false;
766-
item.LoadFileIcon = true;
767-
}, Windows.System.DispatcherQueuePriority.Low);
768-
wasIconLoaded = true;
769-
}
770-
else
759+
if (!item.IsShortcutItem && !item.IsHiddenItem && !FtpHelpers.IsFtpPath(item.ItemPath))
771760
{
772-
if (!item.IsShortcutItem && !item.IsHiddenItem && !FtpHelpers.IsFtpPath(item.ItemPath))
761+
var matchingStorageFile = matchingStorageItem.AsBaseStorageFile() ?? await GetFileFromPathAsync(item.ItemPath);
762+
if (matchingStorageFile != null)
773763
{
774-
var matchingStorageFile = matchingStorageItem.AsBaseStorageFile() ?? await GetFileFromPathAsync(item.ItemPath);
775-
if (matchingStorageFile != null)
776-
{
777-
var mode = thumbnailSize < 80 ? ThumbnailMode.ListView : ThumbnailMode.SingleItem;
764+
var mode = thumbnailSize < 80 ? ThumbnailMode.ListView : ThumbnailMode.SingleItem;
778765

779-
using var Thumbnail = await matchingStorageFile.GetThumbnailAsync(mode, thumbnailSize, ThumbnailOptions.ResizeThumbnail);
780-
if (!(Thumbnail == null || Thumbnail.Size == 0 || Thumbnail.OriginalHeight == 0 || Thumbnail.OriginalWidth == 0))
766+
using var Thumbnail = await matchingStorageFile.GetThumbnailAsync(mode, thumbnailSize, ThumbnailOptions.ResizeThumbnail);
767+
if (!(Thumbnail == null || Thumbnail.Size == 0 || Thumbnail.OriginalHeight == 0 || Thumbnail.OriginalWidth == 0))
768+
{
769+
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
781770
{
782-
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
783-
{
784-
item.CustomIconData = await Thumbnail.ToByteArrayAsync();
785-
item.FileImage = await item.CustomIconData.ToBitmapAsync();
786-
item.LoadUnknownTypeGlyph = false;
787-
item.LoadWebShortcutGlyph = false;
788-
item.LoadFileIcon = true;
789-
}, Windows.System.DispatcherQueuePriority.Low);
790-
wasIconLoaded = true;
791-
}
771+
item.LoadUnknownTypeGlyph = false;
772+
item.LoadWebShortcutGlyph = false;
773+
item.LoadFolderGlyph = false;
774+
item.LoadFileIcon = true;
775+
item.FileImage ??= new BitmapImage();
776+
item.FileImage.DecodePixelType = DecodePixelType.Logical;
777+
item.FileImage.DecodePixelWidth = (int)thumbnailSize;
778+
item.FileImage.DecodePixelHeight = (int)thumbnailSize;
779+
await item.FileImage.SetSourceAsync(Thumbnail);
780+
781+
}, Windows.System.DispatcherQueuePriority.Normal);
782+
wasIconLoaded = true;
783+
}
792784

793-
var overlayInfo = await FileThumbnailHelper.LoadOverlayAsync(item.ItemPath);
794-
if (overlayInfo != null)
785+
var overlayInfo = await FileThumbnailHelper.LoadOverlayAsync(item.ItemPath);
786+
if (overlayInfo != null)
787+
{
788+
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
795789
{
796-
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
797-
{
798-
item.IconOverlay = await overlayInfo.ToBitmapAsync();
799-
}, Windows.System.DispatcherQueuePriority.Low);
800-
}
790+
item.IconOverlay = await overlayInfo.ToBitmapAsync();
791+
}, Windows.System.DispatcherQueuePriority.Low);
801792
}
802793
}
803794
}
@@ -810,7 +801,6 @@ await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
810801
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
811802
{
812803
item.FileImage = await iconInfo.IconData.ToBitmapAsync();
813-
item.CustomIconData = iconInfo.IconData;
814804
item.LoadFileIcon = true;
815805
item.LoadUnknownTypeGlyph = false;
816806
item.LoadWebShortcutGlyph = false;
@@ -828,50 +818,39 @@ await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
828818
}
829819
else
830820
{
831-
if (!forceReload && item.CustomIconData != null)
832-
{
833-
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
834-
{
835-
item.FileImage = await item.CustomIconData.ToBitmapAsync();
836-
item.LoadUnknownTypeGlyph = false;
837-
item.LoadWebShortcutGlyph = false;
838-
item.LoadFolderGlyph = false;
839-
item.LoadFileIcon = true;
840-
}, Windows.System.DispatcherQueuePriority.Low);
841-
wasIconLoaded = true;
842-
}
843-
else
821+
if (!item.IsShortcutItem && !item.IsHiddenItem && !FtpHelpers.IsFtpPath(item.ItemPath))
844822
{
845-
if (!item.IsShortcutItem && !item.IsHiddenItem && !FtpHelpers.IsFtpPath(item.ItemPath))
823+
var matchingStorageFolder = matchingStorageItem.AsBaseStorageFolder() ?? await GetFolderFromPathAsync(item.ItemPath);
824+
if (matchingStorageFolder != null)
846825
{
847-
var matchingStorageFolder = matchingStorageItem.AsBaseStorageFolder() ?? await GetFolderFromPathAsync(item.ItemPath);
848-
if (matchingStorageFolder != null)
849-
{
850-
var mode = thumbnailSize < 80 ? ThumbnailMode.ListView : ThumbnailMode.SingleItem;
826+
var mode = thumbnailSize < 80 ? ThumbnailMode.ListView : ThumbnailMode.SingleItem;
851827

852-
using var Thumbnail = await matchingStorageFolder.GetThumbnailAsync(mode, thumbnailSize, ThumbnailOptions.ResizeThumbnail);
853-
if (!(Thumbnail == null || Thumbnail.Size == 0 || Thumbnail.OriginalHeight == 0 || Thumbnail.OriginalWidth == 0))
828+
using var Thumbnail = await matchingStorageFolder.GetThumbnailAsync(mode, thumbnailSize, ThumbnailOptions.ResizeThumbnail);
829+
if (!(Thumbnail == null || Thumbnail.Size == 0 || Thumbnail.OriginalHeight == 0 || Thumbnail.OriginalWidth == 0))
830+
{
831+
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
854832
{
855-
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
856-
{
857-
item.CustomIconData = await Thumbnail.ToByteArrayAsync();
858-
item.FileImage = await item.CustomIconData.ToBitmapAsync();
859-
item.LoadUnknownTypeGlyph = false;
860-
item.LoadWebShortcutGlyph = false;
861-
item.LoadFolderGlyph = false;
862-
item.LoadFileIcon = true;
863-
}, Windows.System.DispatcherQueuePriority.Low);
864-
wasIconLoaded = true;
865-
}
833+
item.LoadUnknownTypeGlyph = false;
834+
item.LoadWebShortcutGlyph = false;
835+
item.LoadFolderGlyph = false;
836+
item.LoadFileIcon = true;
837+
item.FileImage ??= new BitmapImage();
838+
item.FileImage.DecodePixelType = DecodePixelType.Logical;
839+
item.FileImage.DecodePixelWidth = (int)thumbnailSize;
840+
item.FileImage.DecodePixelHeight = (int)thumbnailSize;
841+
await item.FileImage.SetSourceAsync(Thumbnail);
842+
843+
}, Windows.System.DispatcherQueuePriority.Normal);
844+
wasIconLoaded = true;
845+
}
866846

867-
var overlayInfo = await FileThumbnailHelper.LoadOverlayAsync(item.ItemPath);
868-
if (overlayInfo != null)
847+
var overlayInfo = await FileThumbnailHelper.LoadOverlayAsync(item.ItemPath);
848+
if (overlayInfo != null)
849+
{
850+
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
869851
{
870-
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
871-
{
872-
item.IconOverlay = await overlayInfo.ToBitmapAsync();
873-
}, Windows.System.DispatcherQueuePriority.Low);
874-
}
852+
item.IconOverlay = await overlayInfo.ToBitmapAsync();
853+
}, Windows.System.DispatcherQueuePriority.Low);
875854
}
876855
}
877856
}
@@ -884,7 +863,6 @@ await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
884863
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
885864
{
886865
item.FileImage = await iconInfo.IconData.ToBitmapAsync();
887-
item.CustomIconData = iconInfo.IconData;
888866
item.LoadFileIcon = true;
889867
item.LoadFolderGlyph = false;
890868
item.LoadUnknownTypeGlyph = false;

Files/ViewModels/Properties/FileProperties.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public override void GetBaseProperties()
5858
ViewModel.ItemModifiedTimestamp = Item.ItemDateModified;
5959
ViewModel.ItemCreatedTimestamp = Item.ItemDateCreated;
6060
ViewModel.LoadFolderGlyph = Item.LoadFolderGlyph;
61-
ViewModel.IconData = Item.CustomIconData;
6261
ViewModel.LoadUnknownTypeGlyph = Item.LoadUnknownTypeGlyph;
6362
ViewModel.LoadCustomIcon = Item.LoadCustomIcon;
6463
ViewModel.CustomIconSource = Item.CustomIconSource;

Files/ViewModels/Properties/FolderProperties.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public override void GetBaseProperties()
4747
ViewModel.ItemModifiedTimestamp = Item.ItemDateModified;
4848
ViewModel.ItemCreatedTimestamp = Item.ItemDateCreated;
4949
ViewModel.LoadFolderGlyph = Item.LoadFolderGlyph;
50-
ViewModel.IconData = Item.CustomIconData;
5150
ViewModel.LoadUnknownTypeGlyph = Item.LoadUnknownTypeGlyph;
5251
ViewModel.LoadCustomIcon = Item.LoadCustomIcon;
5352
ViewModel.CustomIconSource = Item.CustomIconSource;

Files/ViewModels/Properties/LibraryProperties.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public override void GetBaseProperties()
4747
ViewModel.ItemType = Library.ItemType;
4848
ViewModel.LoadCustomIcon = Library.LoadCustomIcon;
4949
ViewModel.CustomIconSource = Library.CustomIconSource;
50-
ViewModel.IconData = Library.CustomIconData;
5150
ViewModel.LoadFolderGlyph = Library.LoadFolderGlyph;
5251
ViewModel.LoadUnknownTypeGlyph = Library.LoadUnknownTypeGlyph;
5352
ViewModel.LoadFileIcon = Library.LoadFileIcon;

Files/Views/LayoutModes/ColumnViewBase.xaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -215,24 +215,24 @@
215215
Source="{x:Bind FileImage, Mode=OneWay}"
216216
Stretch="Uniform" />
217217
</ContentPresenter>
218-
<FontIcon
219-
x:Name="FolderGlyphIcon"
218+
<Border
219+
x:Name="FolderGlyphIcon"
220220
Width="24"
221221
Height="24"
222222
HorizontalAlignment="Stretch"
223223
VerticalAlignment="Stretch"
224224
x:Load="{x:Bind LoadFolderGlyph, Mode=OneWay}"
225-
Glyph="&#xF12B;" />
226-
<Viewbox
225+
Background="{ThemeResource SystemChromeHighColor}"
226+
CornerRadius="4" />
227+
<Border
227228
x:Name="TypeUnknownGlyph"
228-
MaxWidth="24"
229-
MaxHeight="24"
229+
Height="24"
230+
Width="24"
230231
HorizontalAlignment="Stretch"
231232
VerticalAlignment="Stretch"
232-
x:Phase="1"
233-
Visibility="{x:Bind LoadUnknownTypeGlyph, Mode=OneWay}">
234-
<FontIcon Glyph="&#xE7C3;" />
235-
</Viewbox>
233+
x:Load="{x:Bind LoadUnknownTypeGlyph, Mode=OneWay}"
234+
Background="{ThemeResource SystemChromeHighColor}"
235+
CornerRadius="4" />
236236
<Image
237237
x:Name="IconOverlay"
238238
Width="16"

Files/Views/LayoutModes/ColumnViewBrowser.xaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -235,24 +235,24 @@
235235
Source="{x:Bind FileImage, Mode=OneWay}"
236236
Stretch="Uniform" />
237237
</ContentPresenter>
238-
<FontIcon
239-
x:Name="FolderGlyphIcon"
238+
<Border
239+
x:Name="FolderGlyphIcon"
240240
Width="24"
241241
Height="24"
242242
HorizontalAlignment="Stretch"
243243
VerticalAlignment="Stretch"
244244
x:Load="{x:Bind LoadFolderGlyph, Mode=OneWay}"
245-
Glyph="&#xF12B;" />
246-
<Viewbox
245+
Background="{ThemeResource SystemChromeHighColor}"
246+
CornerRadius="4" />
247+
<Border
247248
x:Name="TypeUnknownGlyph"
248-
MaxWidth="24"
249-
MaxHeight="24"
249+
Height="24"
250+
Width="24"
250251
HorizontalAlignment="Stretch"
251252
VerticalAlignment="Stretch"
252-
x:Phase="1"
253-
Visibility="{x:Bind LoadUnknownTypeGlyph, Mode=OneWay}">
254-
<FontIcon Glyph="&#xE7C3;" />
255-
</Viewbox>
253+
x:Load="{x:Bind LoadUnknownTypeGlyph, Mode=OneWay}"
254+
Background="{ThemeResource SystemChromeHighColor}"
255+
CornerRadius="4" />
256256
<Image
257257
x:Name="IconOverlay"
258258
Width="16"

0 commit comments

Comments
 (0)