[Feature] Increase performance of huge folders by iconcache #44, version 0.9.2.1

This commit is contained in:
Markus Hofknecht 2020-03-15 22:30:48 +01:00
parent 68ce47fb09
commit 5d168455c2
2 changed files with 10 additions and 16 deletions

View file

@ -1,5 +1,6 @@
using Clearcove.Logging;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
@ -19,8 +20,7 @@ namespace SystemTrayMenu.Helper
/// </example>
public class IconReader
{
static Dictionary<string, Icon> dictIconCache = new Dictionary<string, Icon>();
static readonly object lockIconCache = new object();
static ConcurrentDictionary<string, Icon> dictIconCache = new ConcurrentDictionary<string, Icon>();
/// <summary>
/// Options to specify the size of icons to return.
@ -65,7 +65,7 @@ namespace SystemTrayMenu.Helper
{
bool isExtensionWitSameIcon = true;
List<string> extensionsWithDiffIcons = new List<string>
{ ".exe", ".ink", ".ico", ".url" };
{ ".exe", ".lnk", ".ico", ".url" };
if (extensionsWithDiffIcons.Contains(fileExtension.ToLower()))
{
isExtensionWitSameIcon = false;
@ -75,17 +75,10 @@ namespace SystemTrayMenu.Helper
if (IsExtensionWitSameIcon(extension))
{
lock (lockIconCache)
icon = dictIconCache.GetOrAdd(extension, GetIcon);
Icon GetIcon(string keyExtension)
{
if (dictIconCache.ContainsKey(extension))
{
icon = dictIconCache[extension];
}
else
{
icon = GetFileIcon(filePath, linkOverlay, size);
dictIconCache.Add(extension, icon);
}
return GetFileIcon(filePath, linkOverlay, size);
}
}
else
@ -95,6 +88,7 @@ namespace SystemTrayMenu.Helper
return icon;
}
private static Icon GetFileIcon(string filePath, bool linkOverlay,
IconSize size = IconSize.Small)
{

View file

@ -9,7 +9,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("TAMAHO")]
[assembly: AssemblyProduct("TAMAHO SystemTrayMenu")]
[assembly: AssemblyCopyright("Copyright © 2019, TAMAHO SystemTrayMenu")]
[assembly: AssemblyCopyright("Copyright © 2020, TAMAHO SystemTrayMenu")]
[assembly: AssemblyTrademark("TAMAHO")]
[assembly: AssemblyCulture("")]
@ -31,5 +31,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("0.9.2.0")]
[assembly: AssemblyFileVersion("0.9.2.0")]
[assembly: AssemblyVersion("0.9.2.1")]
[assembly: AssemblyFileVersion("0.9.2.1")]