[BUG] Fix performance when open subfolder, Fix rare unknown exception (#124)

This commit is contained in:
Markus Hofknecht 2020-07-26 22:36:31 +02:00
parent 6038d2ae20
commit 6b0fb14ec6
9 changed files with 56 additions and 7 deletions

View file

@ -104,7 +104,7 @@ namespace SystemTrayMenu.DataClasses
}
else if (isDirectory)
{
icon = IconReader.GetFolderIcon(
icon = IconReader.GetFolderIconSTA(
TargetFilePath,
IconReader.FolderType.Closed,
false);
@ -256,7 +256,7 @@ namespace SystemTrayMenu.DataClasses
resolvedLnkPath = FileLnk.GetResolvedFileName(TargetFilePath);
if (FileLnk.IsDirectory(resolvedLnkPath))
{
icon = IconReader.GetFolderIcon(TargetFilePath, IconReader.FolderType.Open, true);
icon = IconReader.GetFolderIconSTA(TargetFilePath, IconReader.FolderType.Open, true);
handled = true;
isLnkDirectory = true;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 75 KiB

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 107 KiB

After

Width:  |  Height:  |  Size: 99 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 136 KiB

After

Width:  |  Height:  |  Size: 125 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 156 KiB

After

Width:  |  Height:  |  Size: 137 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 543 KiB

After

Width:  |  Height:  |  Size: 472 KiB

View file

@ -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.10.0")]
[assembly: AssemblyFileVersion("1.0.10.0")]
[assembly: AssemblyVersion("1.0.11.0")]
[assembly: AssemblyFileVersion("1.0.11.0")]

View file

@ -160,6 +160,14 @@
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<None Include="LICENSE">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
<None Include="Resources\icon.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>
<ItemGroup>
<Content Include="Resources\SystemTrayMenu.ico" />
@ -206,9 +214,18 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Packaging\AppPackages\" />
</ItemGroup>
<PropertyGroup>
<PreBuildEvent>taskkill /fi "pid gt 0" /im SystemTrayMenu.exe
taskkill /f /fi "pid gt 0" /im SystemTrayMenu.exe
EXIT 0</PreBuildEvent>
<RepositoryUrl>https://github.com/Hofknecht/SystemTrayMenu</RepositoryUrl>
<PackageIcon>icon.png</PackageIcon>
<PackageProjectUrl>hofknecht.eu/systemtraymenu/</PackageProjectUrl>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<RepositoryType></RepositoryType>
<PackageTags>SystemTrayMenu</PackageTags>
</PropertyGroup>
</Project>

View file

@ -11,6 +11,7 @@ namespace SystemTrayMenu.Utilities
using System.Drawing.Imaging;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
// from https://www.codeproject.com/Articles/2532/Obtaining-and-managing-file-and-folder-icons-using
// added ImageList_GetIcon, IconCache, AddIconOverlay
@ -58,18 +59,39 @@ namespace SystemTrayMenu.Utilities
icon = DictIconCache.GetOrAdd(extension, GetIcon);
Icon GetIcon(string keyExtension)
{
return GetFileIcon(filePath, linkOverlay, size);
return GetFileIconSTA(filePath, linkOverlay, size);
}
}
else
{
icon = GetFileIcon(filePath, linkOverlay, size);
icon = GetFileIconSTA(filePath, linkOverlay, size);
}
// }
return icon;
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA2008:Do not create tasks without passing a TaskScheduler", Justification = "todo")]
public static Icon GetFolderIconSTA(
string directoryPath,
FolderType folderType,
bool linkOverlay,
IconSize size = IconSize.Small)
{
Icon icon = null;
Task<Icon> task = Task.Factory.StartNew(() => GetFolderIcon(
directoryPath,
folderType,
linkOverlay,
size));
icon = task.Result;
return icon;
}
public static Icon GetFolderIcon(
string directoryPath,
FolderType folderType,
@ -116,7 +138,6 @@ namespace SystemTrayMenu.Utilities
{
try
{
Icon.FromHandle(shfi.hIcon);
icon = (Icon)Icon.FromHandle(shfi.hIcon).Clone();
DllImports.NativeMethods.User32DestroyIcon(shfi.hIcon);
}
@ -163,6 +184,17 @@ namespace SystemTrayMenu.Utilities
return isExtensionWitSameIcon;
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA2008:Do not create tasks without passing a TaskScheduler", Justification = "todo")]
private static Icon GetFileIconSTA(string filePath, bool linkOverlay, IconSize size = IconSize.Small)
{
Icon icon = null;
Task<Icon> task = Task.Factory.StartNew(() => GetFileIcon(filePath, linkOverlay, size));
icon = task.Result;
return icon;
}
private static Icon GetFileIcon(string filePath, bool linkOverlay, IconSize size = IconSize.Small)
{
Icon icon = null;