[BUG] Icons of shortcuts not displayed correctly (#209, #218, #155), version 1.0.22.1

This commit is contained in:
Markus Hofknecht 2021-10-21 20:25:13 +02:00
parent 56ba365909
commit 15cf58c28c
3 changed files with 25 additions and 4 deletions

View file

@ -9,7 +9,7 @@
<Identity
Name="49543SystemTrayMenu.SystemTrayMenu"
Publisher="CN=5884501C-92ED-45DE-9508-9D987C314243"
Version="1.0.21.0" />
Version="1.0.22.0" />
<Properties>
<DisplayName>SystemTrayMenu</DisplayName>

View file

@ -39,5 +39,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.22.0")]
[assembly: AssemblyFileVersion("1.0.22.0")]
[assembly: AssemblyVersion("1.0.22.1")]
[assembly: AssemblyFileVersion("1.0.22.1")]

View file

@ -25,7 +25,6 @@ namespace SystemTrayMenu.Utilities
private static readonly ConcurrentDictionary<string, Icon> DictIconCache = new ConcurrentDictionary<string, Icon>();
private static readonly Icon LoadingIcon = Properties.Resources.Loading;
// private static readonly object ReadIcon = new object();
public enum IconSize
{
Large = 0, // 32x32 pixels
@ -38,6 +37,7 @@ namespace SystemTrayMenu.Utilities
Closed = 1,
}
// see https://github.com/Hofknecht/SystemTrayMenu/issues/209.
public static bool SingleThread { get; set; }
public static void Dispose()
@ -74,6 +74,8 @@ namespace SystemTrayMenu.Utilities
key = extension + linkOverlay;
}
ClearBadIcons();
if (!DictIconCache.TryGetValue(key, out Icon icon))
{
icon = LoadingIcon;
@ -154,6 +156,8 @@ namespace SystemTrayMenu.Utilities
key = extension + linkOverlay;
}
ClearBadIcons();
if (!DictIconCache.TryGetValue(key, out Icon icon))
{
icon = LoadingIcon;
@ -210,6 +214,8 @@ namespace SystemTrayMenu.Utilities
string key = path;
ClearBadIcons();
if (!DictIconCache.TryGetValue(key, out Icon icon))
{
icon = LoadingIcon;
@ -351,6 +357,21 @@ namespace SystemTrayMenu.Utilities
return icon;
}
/// <summary>
/// Clear icons which are null.
/// see https://github.com/Hofknecht/SystemTrayMenu/issues/209.
/// This only happens with the MainPreload method. SingleThread had only partially solved it before.
/// It is unclear exactly where the problem comes from, because it never seems to be null later.
/// </summary>
private static void ClearBadIcons()
{
IEnumerable<string> badKeysList = DictIconCache.Where(x => x.Value == null).Select(x => x.Key);
foreach (string badKey in badKeysList)
{
DictIconCache.Remove(badKey, out _);
}
}
private static bool IsExtensionWithSameIcon(string fileExtension)
{
bool isExtensionWithSameIcon = true;