mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-09-28 07:11:28 +12:00
[Feature] Improved performance (#204), version 1.0.20.0
This commit is contained in:
parent
693f196225
commit
64e7e93167
4 changed files with 33 additions and 27 deletions
|
@ -291,6 +291,8 @@ namespace SystemTrayMenu.DataClasses
|
||||||
{
|
{
|
||||||
bool handled = false;
|
bool handled = false;
|
||||||
resolvedLnkPath = FileLnk.GetResolvedFileName(TargetFilePath);
|
resolvedLnkPath = FileLnk.GetResolvedFileName(TargetFilePath);
|
||||||
|
|
||||||
|
#if false // FileLnk.IsDirectory was very slow if it was a network path, PingHost was still slow if not exists therefore we used IsNetworkPath
|
||||||
if (FileLnk.IsNetworkPath(resolvedLnkPath))
|
if (FileLnk.IsNetworkPath(resolvedLnkPath))
|
||||||
{
|
{
|
||||||
string nameOrAdress = resolvedLnkPath.Split(@"\\")[1].Split(@"\").First();
|
string nameOrAdress = resolvedLnkPath.Split(@"\\")[1].Split(@"\").First();
|
||||||
|
@ -301,6 +303,8 @@ namespace SystemTrayMenu.DataClasses
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FileLnk.IsDirectory(resolvedLnkPath))
|
if (FileLnk.IsDirectory(resolvedLnkPath))
|
||||||
|
#endif
|
||||||
|
if (string.IsNullOrEmpty(Path.GetExtension(resolvedLnkPath)))
|
||||||
{
|
{
|
||||||
icon = IconReader.GetFolderIconSTA(TargetFilePath, IconReader.FolderType.Open, true);
|
icon = IconReader.GetFolderIconSTA(TargetFilePath, IconReader.FolderType.Open, true);
|
||||||
handled = true;
|
handled = true;
|
||||||
|
@ -314,6 +318,7 @@ namespace SystemTrayMenu.DataClasses
|
||||||
{
|
{
|
||||||
Log.Info($"Resolve *.LNK '{TargetFilePath}' has no icon");
|
Log.Info($"Resolve *.LNK '{TargetFilePath}' has no icon");
|
||||||
}
|
}
|
||||||
|
#if false //icons were incorrect, performance increase when removing
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
IWshShell shell = new WshShell();
|
IWshShell shell = new WshShell();
|
||||||
|
@ -341,6 +346,7 @@ namespace SystemTrayMenu.DataClasses
|
||||||
|
|
||||||
TargetFilePath = resolvedLnkPath;
|
TargetFilePath = resolvedLnkPath;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
SetText(Path.GetFileNameWithoutExtension(TargetFilePathOrig));
|
SetText(Path.GetFileNameWithoutExtension(TargetFilePathOrig));
|
||||||
|
|
||||||
|
|
|
@ -39,5 +39,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("1.0.19.6")]
|
[assembly: AssemblyVersion("1.0.20.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.19.6")]
|
[assembly: AssemblyFileVersion("1.0.20.0")]
|
||||||
|
|
|
@ -36,6 +36,7 @@ namespace SystemTrayMenu.Utilities
|
||||||
return resolvedFilename;
|
return resolvedFilename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if false // FileLnk.IsDirectory was very slow if it was a network path, PingHost was still slow if not exists therefore we used IsNetworkPath
|
||||||
public static bool IsDirectory(string filePath)
|
public static bool IsDirectory(string filePath)
|
||||||
{
|
{
|
||||||
bool isDirectory = false;
|
bool isDirectory = false;
|
||||||
|
@ -51,18 +52,18 @@ namespace SystemTrayMenu.Utilities
|
||||||
return isDirectory;
|
return isDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsNetworkRoot(string path)
|
|
||||||
{
|
|
||||||
return !File.Exists(path) &&
|
|
||||||
path.StartsWith(@"\\", StringComparison.InvariantCulture) &&
|
|
||||||
!path.Substring(2).Contains(@"\", StringComparison.InvariantCulture);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool IsNetworkPath(string path)
|
public static bool IsNetworkPath(string path)
|
||||||
{
|
{
|
||||||
return path.StartsWith(@"\\", StringComparison.InvariantCulture) &&
|
return path.StartsWith(@"\\", StringComparison.InvariantCulture) &&
|
||||||
!path.StartsWith(@"\\?\", StringComparison.InvariantCulture);
|
!path.StartsWith(@"\\?\", StringComparison.InvariantCulture);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public static bool IsNetworkRoot(string path)
|
||||||
|
{
|
||||||
|
return path.StartsWith(@"\\", StringComparison.InvariantCulture) &&
|
||||||
|
!path.Substring(2).Contains(@"\", StringComparison.InvariantCulture);
|
||||||
|
}
|
||||||
|
|
||||||
public static bool PingHost(string nameOrAddress)
|
public static bool PingHost(string nameOrAddress)
|
||||||
{
|
{
|
||||||
|
|
|
@ -60,13 +60,13 @@ namespace SystemTrayMenu.Utilities
|
||||||
size = IconSize.Large;
|
size = IconSize.Large;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsExtensionWitSameIcon(extension))
|
string key = filePath;
|
||||||
|
if (IsExtensionWithSameIcon(extension))
|
||||||
{
|
{
|
||||||
icon = DictIconCache.GetOrAdd(extension + linkOverlay, GetIcon);
|
key = extension + linkOverlay;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
if (!DictIconCache.TryGetValue(key, out icon))
|
||||||
if (!DictIconCache.TryGetValue(filePath, out icon))
|
|
||||||
{
|
{
|
||||||
icon = LoadingIcon;
|
icon = LoadingIcon;
|
||||||
loading = true;
|
loading = true;
|
||||||
|
@ -76,8 +76,7 @@ namespace SystemTrayMenu.Utilities
|
||||||
new Thread(UpdateIconInBackground).Start();
|
new Thread(UpdateIconInBackground).Start();
|
||||||
void UpdateIconInBackground()
|
void UpdateIconInBackground()
|
||||||
{
|
{
|
||||||
DictIconCache.GetOrAdd(filePath, GetIcon);
|
DictIconCache.GetOrAdd(key, GetIcon);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -186,17 +185,17 @@ namespace SystemTrayMenu.Utilities
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool IsExtensionWitSameIcon(string fileExtension)
|
private static bool IsExtensionWithSameIcon(string fileExtension)
|
||||||
{
|
{
|
||||||
bool isExtensionWitSameIcon = true;
|
bool isExtensionWithSameIcon = true;
|
||||||
List<string> extensionsWithDiffIcons = new List<string>
|
List<string> extensionsWithDiffIcons = new List<string>
|
||||||
{ string.Empty, ".EXE", ".LNK", ".ICO", ".URL" };
|
{ string.Empty, ".EXE", ".LNK", ".ICO", ".URL" };
|
||||||
if (extensionsWithDiffIcons.Contains(fileExtension.ToUpperInvariant()))
|
if (extensionsWithDiffIcons.Contains(fileExtension.ToUpperInvariant()))
|
||||||
{
|
{
|
||||||
isExtensionWitSameIcon = false;
|
isExtensionWithSameIcon = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return isExtensionWitSameIcon;
|
return isExtensionWithSameIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA2008:Do not create tasks without passing a TaskScheduler", Justification = "todo")]
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA2008:Do not create tasks without passing a TaskScheduler", Justification = "todo")]
|
||||||
|
|
Loading…
Reference in a new issue