Skip to content
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

[Testing only] - Load icons from FTP only for hidden and shortcut files #4205

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 2 additions & 1 deletion Files.Launcher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@ private static async Task ParseArgumentsAsync(Dictionary<string, object> message
case "GetIconOverlay":
var fileIconPath = (string)message["filePath"];
var thumbnailSize = (int)(long)message["thumbnailSize"];
var iconOverlay = Win32API.StartSTATask(() => Win32API.GetFileIconAndOverlay(fileIconPath, thumbnailSize)).Result;
var shouldLoadIcon = (bool)message["loadIcon"];
var iconOverlay = Win32API.StartSTATask(() => Win32API.GetFileIconAndOverlay(fileIconPath, shouldLoadIcon, thumbnailSize)).Result;
await Win32API.SendMessageAsync(connection, new ValueSet()
{
{ "Icon", iconOverlay.icon },
Expand Down
4 changes: 2 additions & 2 deletions Files.Launcher/Win32API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ public static string[] CommandLineToArgs(string commandLine)
}
}

public static (string icon, string overlay, bool isCustom) GetFileIconAndOverlay(string path, int thumbnailSize)
public static (string icon, string overlay, bool isCustom) GetFileIconAndOverlay(string path, bool shouldLoadIcon, int thumbnailSize)
{
string iconStr = null, overlayStr = null;

using var shellItem = new Vanara.Windows.Shell.ShellItem(path);
if (shellItem.IShellItem is Shell32.IShellItemImageFactory fctry)
if (shouldLoadIcon && shellItem.IShellItem is Shell32.IShellItemImageFactory fctry)
{
var flags = Shell32.SIIGBF.SIIGBF_BIGGERSIZEOK;
if (thumbnailSize < 80) flags |= Shell32.SIIGBF.SIIGBF_ICONONLY;
Expand Down
3 changes: 2 additions & 1 deletion Files/Helpers/FileThumbnailHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Files.Helpers
{
public static class FileThumbnailHelper
{
public static async Task<(byte[] IconData, byte[] OverlayData, bool IsCustom)> LoadIconOverlayAsync(string filePath, uint thumbnailSize)
public static async Task<(byte[] IconData, byte[] OverlayData, bool IsCustom)> LoadIconOverlayAsync(string filePath, bool shouldLoadIcon, uint thumbnailSize)
{
var connection = await AppServiceConnectionHelper.Instance;
if (connection != null)
Expand All @@ -17,6 +17,7 @@ public static class FileThumbnailHelper
{
{ "Arguments", "GetIconOverlay" },
{ "filePath", filePath },
{ "loadIcon", shouldLoadIcon },
{ "thumbnailSize", (int)thumbnailSize }
};
var (status, response) = await connection.SendMessageForResponseAsync(value);
Expand Down
2 changes: 1 addition & 1 deletion Files/ViewModels/Bundles/BundleItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private async void SetIcon()
{
if (Path.EndsWith(".lnk"))
{
var (IconData, OverlayData, IsCustom) = await associatedInstance.FilesystemViewModel.LoadIconOverlayAsync(Path, 24u);
var (IconData, OverlayData, IsCustom) = await associatedInstance.FilesystemViewModel.LoadIconOverlayAsync(Path, true, 24u);

await CoreApplication.MainView.ExecuteOnUIThreadAsync(async () =>
{
Expand Down
26 changes: 22 additions & 4 deletions Files/ViewModels/ItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ await Task.Run(async () =>
{
if (item.PrimaryItemAttribute == StorageItemTypes.File)
{
var fileIconInfo = await LoadIconOverlayAsync(item.ItemPath, thumbnailSize);
var fileIconInfo = await LoadIconOverlayAsync(item.ItemPath, item.IsHiddenItem || item.IsShortcutItem, thumbnailSize);

await CoreApplication.MainView.ExecuteOnUIThreadAsync(async () =>
{
Expand All @@ -704,7 +704,7 @@ await CoreApplication.MainView.ExecuteOnUIThreadAsync(async () =>
StorageFile matchingStorageItem = await GetFileFromPathAsync(item.ItemPath);
if (matchingStorageItem != null)
{
if (!item.LoadFileIcon) // Loading icon from fulltrust process failed
if (fileIconInfo.IconData == null) // Loading icon from fulltrust process failed
{
using (var Thumbnail = await matchingStorageItem.GetThumbnailAsync(ThumbnailMode.SingleItem, thumbnailSize, ThumbnailOptions.UseCurrentScale))
{
Expand Down Expand Up @@ -734,7 +734,7 @@ await CoreApplication.MainView.ExecuteOnUIThreadAsync(() =>
}
else
{
var fileIconInfo = await LoadIconOverlayAsync(item.ItemPath, thumbnailSize);
var fileIconInfo = await LoadIconOverlayAsync(item.ItemPath, item.IsHiddenItem || item.IsShortcutItem, thumbnailSize);

await CoreApplication.MainView.ExecuteOnUIThreadAsync(async () =>
{
Expand All @@ -752,6 +752,23 @@ await CoreApplication.MainView.ExecuteOnUIThreadAsync(async () =>
StorageFolder matchingStorageItem = await GetFolderFromPathAsync(item.ItemPath);
if (matchingStorageItem != null)
{
if (fileIconInfo.IconData == null && fileIconInfo.IsCustom) // Loading icon from fulltrust process failed
{
using (var Thumbnail = await matchingStorageItem.GetThumbnailAsync(ThumbnailMode.SingleItem, thumbnailSize, ThumbnailOptions.UseCurrentScale))
{
if (Thumbnail != null)
{
await CoreApplication.MainView.ExecuteOnUIThreadAsync(async () =>
{
item.FileImage = new BitmapImage();
await item.FileImage.SetSourceAsync(Thumbnail);
item.LoadUnknownTypeGlyph = false;
item.LoadFolderGlyph = false;
item.LoadFileIcon = true;
});
}
}
}
if (matchingStorageItem.DisplayName != item.ItemName && !matchingStorageItem.DisplayName.StartsWith("$R"))
{
await CoreApplication.MainView.ExecuteOnUIThreadAsync(() =>
Expand Down Expand Up @@ -795,13 +812,14 @@ await CoreApplication.MainView.ExecuteOnUIThreadAsync(() =>
});
}

public async Task<(byte[] IconData, byte[] OverlayData, bool IsCustom)> LoadIconOverlayAsync(string filePath, uint thumbnailSize)
public async Task<(byte[] IconData, byte[] OverlayData, bool IsCustom)> LoadIconOverlayAsync(string filePath, bool shouldLoadIcon, uint thumbnailSize)
{
if (Connection != null)
{
var value = new ValueSet();
value.Add("Arguments", "GetIconOverlay");
value.Add("filePath", filePath);
value.Add("loadIcon", shouldLoadIcon);
value.Add("thumbnailSize", (int)thumbnailSize);
var (status, response) = await Connection.SendMessageForResponseAsync(value);
if (status == AppServiceResponseStatus.Success)
Expand Down
2 changes: 1 addition & 1 deletion Files/ViewModels/Previews/BasePreviewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public virtual void PreviewControlBase_Unloaded(object sender, RoutedEventArgs e

public async virtual Task<List<FileProperty>> LoadPreviewAndDetails()
{
var (IconData, OverlayData, IsCustom) = await FileThumbnailHelper.LoadIconOverlayAsync(Item.ItemPath, 400);
var (IconData, OverlayData, IsCustom) = await FileThumbnailHelper.LoadIconOverlayAsync(Item.ItemPath, Item.IsHiddenItem || Item.IsShortcutItem, 400);

if (IconData != null)
{
Expand Down
17 changes: 15 additions & 2 deletions Files/ViewModels/Properties/FileProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
using Windows.Security.Cryptography.Core;
using Windows.Services.Maps;
using Windows.Storage;
using Windows.Storage.FileProperties;
using Windows.Storage.Streams;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media.Imaging;

namespace Files.ViewModels.Properties
{
Expand Down Expand Up @@ -107,7 +109,7 @@ public override async void GetSpecialProperties()
ViewModel.ItemSizeVisibility = Visibility.Visible;
ViewModel.ItemSize = $"{ByteSize.FromBytes(Item.FileSizeBytes).ToBinaryString().ConvertSizeAbbreviation()} ({ByteSize.FromBytes(Item.FileSizeBytes).Bytes:#,##0} {"ItemSizeBytes".GetLocalized()})";

var fileIconInfo = await AppInstance.FilesystemViewModel.LoadIconOverlayAsync(Item.ItemPath, 80);
var fileIconInfo = await AppInstance.FilesystemViewModel.LoadIconOverlayAsync(Item.ItemPath, Item.IsHiddenItem || Item.IsShortcutItem, 80);
if (fileIconInfo.IconData != null)
{
ViewModel.FileIconSource = await fileIconInfo.IconData.ToBitmapAsync();
Expand All @@ -131,7 +133,18 @@ public override async void GetSpecialProperties()
// Could not access file, can't show any other property
return;
}

if (ViewModel.FileIconSource == null)
{
using (var Thumbnail = await file.GetThumbnailAsync(ThumbnailMode.SingleItem, 80, ThumbnailOptions.UseCurrentScale))
{
if (Thumbnail != null)
{
var fileImage = new BitmapImage();
await fileImage.SetSourceAsync(Thumbnail);
ViewModel.FileIconSource = fileImage;
}
}
}
if (Item.IsShortcutItem)
{
// Can't show any other property
Expand Down
17 changes: 15 additions & 2 deletions Files/ViewModels/Properties/FolderProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
using System.Threading.Tasks;
using Windows.Foundation.Collections;
using Windows.Storage;
using Windows.Storage.FileProperties;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media.Imaging;

namespace Files.ViewModels.Properties
{
Expand Down Expand Up @@ -75,7 +77,7 @@ public async override void GetSpecialProperties()
ViewModel.IsHidden = NativeFileOperationsHelper.HasFileAttribute(
Item.ItemPath, System.IO.FileAttributes.Hidden);

var fileIconInfo = await AppInstance.FilesystemViewModel.LoadIconOverlayAsync(Item.ItemPath, 80);
var fileIconInfo = await AppInstance.FilesystemViewModel.LoadIconOverlayAsync(Item.ItemPath, Item.IsHiddenItem || Item.IsShortcutItem, 80);
if (fileIconInfo.IconData != null && fileIconInfo.IsCustom)
{
ViewModel.FileIconSource = await fileIconInfo.IconData.ToBitmapAsync();
Expand Down Expand Up @@ -105,7 +107,18 @@ public async override void GetSpecialProperties()
// Could not access folder, can't show any other property
return;
}

if (storageFolder != null && ViewModel.FileIconSource == null && fileIconInfo.IsCustom)
{
using (var Thumbnail = await storageFolder.GetThumbnailAsync(ThumbnailMode.SingleItem, 80, ThumbnailOptions.UseCurrentScale))
{
if (Thumbnail != null)
{
var fileImage = new BitmapImage();
await fileImage.SetSourceAsync(Thumbnail);
ViewModel.FileIconSource = fileImage;
}
}
}
if (storageFolder != null)
{
ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
Expand Down