Skip to content

Fix: Fixed issue where icon overlays were cached #14727

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 1 commit into from
Feb 15, 2024
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
1 change: 1 addition & 0 deletions src/Files.App/Helpers/BitmapHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ internal static class BitmapHelper
{
image.DecodePixelWidth = decodeSize;
image.DecodePixelHeight = decodeSize;
image.DecodePixelType = DecodePixelType.Logical;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated but it may have slight improvement for memory usage

}
await image.SetSourceAsync(ms.AsRandomAccessStream());
return image;
Expand Down
33 changes: 0 additions & 33 deletions src/Files.App/Utils/Shell/Win32API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,6 @@ public static string ExtractStringFromDLL(string file, int number)
}
}

private class IconAndOverlayCacheEntry
{
public byte[]? Icon { get; set; }

public byte[]? Overlay { get; set; }
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have the cache in ItemViewModel, is there any benefit in keeping this around?


private static readonly ConcurrentDictionary<string, ConcurrentDictionary<int, IconAndOverlayCacheEntry>> _iconAndOverlayCache = new();

private static readonly object _lock = new object();

Expand Down Expand Up @@ -254,20 +246,6 @@ public static (byte[]? icon, byte[]? overlay, bool isIconCached) GetFileIconAndO
byte[]? iconData = null, overlayData = null;
bool isIconCached = false;

var entry = _iconAndOverlayCache.GetOrAdd(path, _ => new());

if (entry.TryGetValue(thumbnailSize, out var cacheEntry))
{
iconData = cacheEntry.Icon;
overlayData = cacheEntry.Overlay;

if ((onlyGetOverlay && overlayData is not null) ||
(!getOverlay && iconData is not null) ||
(overlayData is not null && iconData is not null))
{
return (iconData, overlayData, true);
}
}

try
{
Expand Down Expand Up @@ -386,14 +364,7 @@ public static (byte[]? icon, byte[]? overlay, bool isIconCached) GetFileIconAndO
}
finally
{
cacheEntry = new IconAndOverlayCacheEntry();
if (iconData is not null)
cacheEntry.Icon = iconData;

if (overlayData is not null)
cacheEntry.Overlay = overlayData;

entry[thumbnailSize] = cacheEntry;
}
}

Expand Down Expand Up @@ -525,8 +496,6 @@ public static bool SetCustomDirectoryIcon(string? folderPath, string? iconFile,
fcs.dwSize = (uint)Marshal.SizeOf(fcs);

var success = Shell32.SHGetSetFolderCustomSettings(ref fcs, folderPath, Shell32.FCS.FCS_FORCEWRITE).Succeeded;
if (success)
_iconAndOverlayCache[folderPath] = new();

return success;
}
Expand All @@ -537,8 +506,6 @@ public static bool SetCustomFileIcon(string? filePath, string? iconFile, int ico
return false;

var success = FileOperationsHelpers.SetLinkIcon(filePath, iconFile, iconIndex);
if (success)
_iconAndOverlayCache[filePath] = new();

return success;
}
Expand Down