From 64e7e93167877e17c507aa2f2460afcb8ae05b64 Mon Sep 17 00:00:00 2001 From: Markus Hofknecht Date: Tue, 5 Oct 2021 22:47:47 +0200 Subject: [PATCH] [Feature] Improved performance (#204), version 1.0.20.0 --- DataClasses/RowData.cs | 6 ++++++ Properties/AssemblyInfo.cs | 4 ++-- Utilities/File/FileLnk.cs | 15 ++++++++------- Utilities/File/IconReader.cs | 35 +++++++++++++++++------------------ 4 files changed, 33 insertions(+), 27 deletions(-) diff --git a/DataClasses/RowData.cs b/DataClasses/RowData.cs index 8b35672..af13e81 100644 --- a/DataClasses/RowData.cs +++ b/DataClasses/RowData.cs @@ -291,6 +291,8 @@ namespace SystemTrayMenu.DataClasses { bool handled = false; 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)) { string nameOrAdress = resolvedLnkPath.Split(@"\\")[1].Split(@"\").First(); @@ -301,6 +303,8 @@ namespace SystemTrayMenu.DataClasses } if (FileLnk.IsDirectory(resolvedLnkPath)) +#endif + if (string.IsNullOrEmpty(Path.GetExtension(resolvedLnkPath))) { icon = IconReader.GetFolderIconSTA(TargetFilePath, IconReader.FolderType.Open, true); handled = true; @@ -314,6 +318,7 @@ namespace SystemTrayMenu.DataClasses { Log.Info($"Resolve *.LNK '{TargetFilePath}' has no icon"); } +#if false //icons were incorrect, performance increase when removing else { IWshShell shell = new WshShell(); @@ -341,6 +346,7 @@ namespace SystemTrayMenu.DataClasses TargetFilePath = resolvedLnkPath; } +#endif SetText(Path.GetFileNameWithoutExtension(TargetFilePathOrig)); diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index ad6bdd5..6ad0471 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -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.19.6")] -[assembly: AssemblyFileVersion("1.0.19.6")] +[assembly: AssemblyVersion("1.0.20.0")] +[assembly: AssemblyFileVersion("1.0.20.0")] diff --git a/Utilities/File/FileLnk.cs b/Utilities/File/FileLnk.cs index a6060a0..ccb6382 100644 --- a/Utilities/File/FileLnk.cs +++ b/Utilities/File/FileLnk.cs @@ -36,6 +36,7 @@ namespace SystemTrayMenu.Utilities 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) { bool isDirectory = false; @@ -51,18 +52,18 @@ namespace SystemTrayMenu.Utilities 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) { return 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) { diff --git a/Utilities/File/IconReader.cs b/Utilities/File/IconReader.cs index 7288997..a8400fc 100644 --- a/Utilities/File/IconReader.cs +++ b/Utilities/File/IconReader.cs @@ -60,24 +60,23 @@ namespace SystemTrayMenu.Utilities 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(filePath, out icon)) - { - icon = LoadingIcon; - loading = true; - if (updateIconInBackground) + if (!DictIconCache.TryGetValue(key, out icon)) + { + icon = LoadingIcon; + loading = true; + + if (updateIconInBackground) + { + new Thread(UpdateIconInBackground).Start(); + void UpdateIconInBackground() { - new Thread(UpdateIconInBackground).Start(); - void UpdateIconInBackground() - { - DictIconCache.GetOrAdd(filePath, GetIcon); - } + DictIconCache.GetOrAdd(key, GetIcon); } } } @@ -186,17 +185,17 @@ namespace SystemTrayMenu.Utilities return icon; } - private static bool IsExtensionWitSameIcon(string fileExtension) + private static bool IsExtensionWithSameIcon(string fileExtension) { - bool isExtensionWitSameIcon = true; + bool isExtensionWithSameIcon = true; List extensionsWithDiffIcons = new List { string.Empty, ".EXE", ".LNK", ".ICO", ".URL" }; 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")]