Skip to content

Commit

Permalink
[Feature] Improved performance (#204), version 1.0.20.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Hofknecht committed Oct 5, 2021
1 parent 693f196 commit 64e7e93
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 25 deletions.
6 changes: 6 additions & 0 deletions DataClasses/RowData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ private bool SetLnk(
{
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();
Expand All @@ -301,6 +303,8 @@ private bool SetLnk(
}

if (FileLnk.IsDirectory(resolvedLnkPath))
#endif
if (string.IsNullOrEmpty(Path.GetExtension(resolvedLnkPath)))
{
icon = IconReader.GetFolderIconSTA(TargetFilePath, IconReader.FolderType.Open, true);
handled = true;
Expand All @@ -314,6 +318,7 @@ private bool SetLnk(
{
Log.Info($"Resolve *.LNK '{TargetFilePath}' has no icon");
}
#if false //icons were incorrect, performance increase when removing
else
{
IWshShell shell = new WshShell();
Expand Down Expand Up @@ -341,6 +346,7 @@ private bool SetLnk(

TargetFilePath = resolvedLnkPath;
}
#endif

SetText(Path.GetFileNameWithoutExtension(TargetFilePathOrig));

Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@
// 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")]
13 changes: 7 additions & 6 deletions Utilities/File/FileLnk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void StaThreadMethod(object obj)
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;
Expand All @@ -51,17 +52,17 @@ public static bool IsDirectory(string filePath)
return isDirectory;
}

public static bool IsNetworkRoot(string path)
public static bool IsNetworkPath(string path)
{
return !File.Exists(path) &&
path.StartsWith(@"\\", StringComparison.InvariantCulture) &&
!path.Substring(2).Contains(@"\", StringComparison.InvariantCulture);
return path.StartsWith(@"\\", StringComparison.InvariantCulture) &&
!path.StartsWith(@"\\?\", StringComparison.InvariantCulture);
}
#endif

public static bool IsNetworkPath(string path)
public static bool IsNetworkRoot(string path)
{
return path.StartsWith(@"\\", StringComparison.InvariantCulture) &&
!path.StartsWith(@"\\?\", StringComparison.InvariantCulture);
!path.Substring(2).Contains(@"\", StringComparison.InvariantCulture);
}

public static bool PingHost(string nameOrAddress)
Expand Down
33 changes: 16 additions & 17 deletions Utilities/File/IconReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,23 @@ public static Icon GetFileIconWithCache(string filePath, bool linkOverlay, bool
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;
loading = true;
icon = LoadingIcon;
loading = true;

if (updateIconInBackground)
if (updateIconInBackground)
{
new Thread(UpdateIconInBackground).Start();
void UpdateIconInBackground()
{
new Thread(UpdateIconInBackground).Start();
void UpdateIconInBackground()
{
DictIconCache.GetOrAdd(filePath, GetIcon);
}
DictIconCache.GetOrAdd(key, GetIcon);
}
}
}
Expand Down Expand Up @@ -186,17 +185,17 @@ public static Icon AddIconOverlay(Icon originalIcon, Icon overlay)
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>
{ 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")]
Expand Down

0 comments on commit 64e7e93

Please sign in to comment.