mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-09-30 09:06:32 +13:00
[Feature] Increase performance of huge folders by iconcache #44, version 0.9.2.1
This commit is contained in:
parent
68ce47fb09
commit
5d168455c2
2 changed files with 10 additions and 16 deletions
|
@ -1,5 +1,6 @@
|
||||||
using Clearcove.Logging;
|
using Clearcove.Logging;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
@ -19,8 +20,7 @@ namespace SystemTrayMenu.Helper
|
||||||
/// </example>
|
/// </example>
|
||||||
public class IconReader
|
public class IconReader
|
||||||
{
|
{
|
||||||
static Dictionary<string, Icon> dictIconCache = new Dictionary<string, Icon>();
|
static ConcurrentDictionary<string, Icon> dictIconCache = new ConcurrentDictionary<string, Icon>();
|
||||||
static readonly object lockIconCache = new object();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Options to specify the size of icons to return.
|
/// Options to specify the size of icons to return.
|
||||||
|
@ -65,7 +65,7 @@ namespace SystemTrayMenu.Helper
|
||||||
{
|
{
|
||||||
bool isExtensionWitSameIcon = true;
|
bool isExtensionWitSameIcon = true;
|
||||||
List<string> extensionsWithDiffIcons = new List<string>
|
List<string> extensionsWithDiffIcons = new List<string>
|
||||||
{ ".exe", ".ink", ".ico", ".url" };
|
{ ".exe", ".lnk", ".ico", ".url" };
|
||||||
if (extensionsWithDiffIcons.Contains(fileExtension.ToLower()))
|
if (extensionsWithDiffIcons.Contains(fileExtension.ToLower()))
|
||||||
{
|
{
|
||||||
isExtensionWitSameIcon = false;
|
isExtensionWitSameIcon = false;
|
||||||
|
@ -75,17 +75,10 @@ namespace SystemTrayMenu.Helper
|
||||||
|
|
||||||
if (IsExtensionWitSameIcon(extension))
|
if (IsExtensionWitSameIcon(extension))
|
||||||
{
|
{
|
||||||
lock (lockIconCache)
|
icon = dictIconCache.GetOrAdd(extension, GetIcon);
|
||||||
|
Icon GetIcon(string keyExtension)
|
||||||
{
|
{
|
||||||
if (dictIconCache.ContainsKey(extension))
|
return GetFileIcon(filePath, linkOverlay, size);
|
||||||
{
|
|
||||||
icon = dictIconCache[extension];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
icon = GetFileIcon(filePath, linkOverlay, size);
|
|
||||||
dictIconCache.Add(extension, icon);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -95,6 +88,7 @@ namespace SystemTrayMenu.Helper
|
||||||
|
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Icon GetFileIcon(string filePath, bool linkOverlay,
|
private static Icon GetFileIcon(string filePath, bool linkOverlay,
|
||||||
IconSize size = IconSize.Small)
|
IconSize size = IconSize.Small)
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,7 +9,7 @@ using System.Runtime.InteropServices;
|
||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCompany("TAMAHO")]
|
[assembly: AssemblyCompany("TAMAHO")]
|
||||||
[assembly: AssemblyProduct("TAMAHO SystemTrayMenu")]
|
[assembly: AssemblyProduct("TAMAHO SystemTrayMenu")]
|
||||||
[assembly: AssemblyCopyright("Copyright © 2019, TAMAHO SystemTrayMenu")]
|
[assembly: AssemblyCopyright("Copyright © 2020, TAMAHO SystemTrayMenu")]
|
||||||
[assembly: AssemblyTrademark("TAMAHO")]
|
[assembly: AssemblyTrademark("TAMAHO")]
|
||||||
[assembly: AssemblyCulture("")]
|
[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
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("0.9.2.0")]
|
[assembly: AssemblyVersion("0.9.2.1")]
|
||||||
[assembly: AssemblyFileVersion("0.9.2.0")]
|
[assembly: AssemblyFileVersion("0.9.2.1")]
|
||||||
|
|
Loading…
Reference in a new issue