mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-05-17 19:02:27 +12:00
[Feature] Show link overlay for files like lnk & URL (#166), version 1.0.17.26
This commit is contained in:
parent
c824c7a10b
commit
a005582d5e
|
@ -122,6 +122,7 @@ namespace SystemTrayMenu.DataClasses
|
|||
else
|
||||
{
|
||||
bool handled = false;
|
||||
bool showOverlay = false;
|
||||
string fileExtension = Path.GetExtension(TargetFilePath);
|
||||
|
||||
if (fileExtension == ".lnk")
|
||||
|
@ -129,10 +130,12 @@ namespace SystemTrayMenu.DataClasses
|
|||
handled = SetLnk(
|
||||
ref isLnkDirectory,
|
||||
ref resolvedLnkPath);
|
||||
showOverlay = true;
|
||||
}
|
||||
else if (fileExtension == ".url")
|
||||
{
|
||||
handled = SetUrl();
|
||||
showOverlay = true;
|
||||
}
|
||||
else if (fileExtension == ".sln")
|
||||
{
|
||||
|
@ -143,20 +146,8 @@ namespace SystemTrayMenu.DataClasses
|
|||
{
|
||||
try
|
||||
{
|
||||
icon = IconReader.GetFileIconWithCache(TargetFilePath, false);
|
||||
diposeIcon = false;
|
||||
|
||||
// other project -> fails sometimes
|
||||
// icon = IconHelper.ExtractIcon(TargetFilePath, 0);
|
||||
|
||||
// standard way -> fails sometimes
|
||||
// icon = Icon.ExtractAssociatedIcon(filePath);
|
||||
|
||||
// API Code Pack -> fails sometimes
|
||||
// ShellFile shellFile = ShellFile.FromFilePath(filePath);
|
||||
// Bitmap shellThumb = shellFile.Thumbnail.ExtraLargeBitmap;
|
||||
|
||||
// IShellItemImageFactory GetImage works, but missing link overlay there #149
|
||||
icon = IconReader.GetFileIconWithCache(TargetFilePath, showOverlay, out bool toDispose);
|
||||
diposeIcon = toDispose;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -279,6 +270,15 @@ namespace SystemTrayMenu.DataClasses
|
|||
{
|
||||
bool handled = false;
|
||||
resolvedLnkPath = FileLnk.GetResolvedFileName(TargetFilePath);
|
||||
//if (FileLnk.IsNetworkPath(resolvedLnkPath))
|
||||
//{
|
||||
// string nameOrAdress = resolvedLnkPath.Split(@"\\")[1].Split(@"\").First();
|
||||
// if (!FileLnk.PingHost(nameOrAdress))
|
||||
// {
|
||||
// return handled;
|
||||
// }
|
||||
//}
|
||||
|
||||
if (FileLnk.IsDirectory(resolvedLnkPath))
|
||||
{
|
||||
icon = IconReader.GetFolderIconSTA(TargetFilePath, IconReader.FolderType.Open, true);
|
||||
|
@ -308,7 +308,8 @@ namespace SystemTrayMenu.DataClasses
|
|||
{
|
||||
try
|
||||
{
|
||||
icon = Icon.ExtractAssociatedIcon(iconLocation);
|
||||
icon = IconReader.GetFileIconWithCache(iconLocation, true, out bool toDispose);
|
||||
diposeIcon = toDispose;
|
||||
handled = true;
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
|
@ -344,14 +345,15 @@ namespace SystemTrayMenu.DataClasses
|
|||
}
|
||||
else
|
||||
{
|
||||
icon = IconReader.GetFileIconWithCache(browserPath, false);
|
||||
diposeIcon = false;
|
||||
icon = IconReader.GetFileIconWithCache(browserPath, true, out bool toDispose);
|
||||
diposeIcon = toDispose;
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
else if (System.IO.File.Exists(iconFile))
|
||||
{
|
||||
icon = Icon.ExtractAssociatedIcon(iconFile);
|
||||
icon = IconReader.GetFileIconWithCache(iconFile, true, out bool toDispose);
|
||||
diposeIcon = toDispose;
|
||||
handled = true;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -6,6 +6,7 @@ namespace SystemTrayMenu.Utilities
|
|||
{
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using Shell32;
|
||||
|
@ -96,5 +97,37 @@ namespace SystemTrayMenu.Utilities
|
|||
|
||||
return resolvedFilename;
|
||||
}
|
||||
|
||||
public static bool IsNetworkPath(string path)
|
||||
{
|
||||
return path.StartsWith(@"\\", StringComparison.InvariantCulture) &&
|
||||
!path.StartsWith(@"\\?\", StringComparison.InvariantCulture);
|
||||
}
|
||||
|
||||
public static bool PingHost(string nameOrAddress)
|
||||
{
|
||||
bool pingable = false;
|
||||
Ping pinger = null;
|
||||
|
||||
try
|
||||
{
|
||||
pinger = new Ping();
|
||||
PingReply reply = pinger.Send(nameOrAddress);
|
||||
pingable = reply.Status == IPStatus.Success;
|
||||
}
|
||||
catch (PingException ex)
|
||||
{
|
||||
Log.Warn($"Ping {nameOrAddress} failed", ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (pinger != null)
|
||||
{
|
||||
pinger.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
return pingable;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -47,22 +47,26 @@ namespace SystemTrayMenu.Utilities
|
|||
}
|
||||
}
|
||||
|
||||
public static Icon GetFileIconWithCache(string filePath, bool linkOverlay, IconSize size = IconSize.Small)
|
||||
public static Icon GetFileIconWithCache(string filePath, bool linkOverlay, out bool toDispose)
|
||||
{
|
||||
Icon icon = null;
|
||||
string extension = Path.GetExtension(filePath);
|
||||
IconSize size = IconSize.Small;
|
||||
|
||||
if (IsExtensionWitSameIcon(extension))
|
||||
{
|
||||
icon = DictIconCache.GetOrAdd(extension, GetIcon);
|
||||
icon = DictIconCache.GetOrAdd(extension + linkOverlay, GetIcon);
|
||||
Icon GetIcon(string keyExtension)
|
||||
{
|
||||
return GetFileIconSTA(filePath, linkOverlay, size);
|
||||
}
|
||||
|
||||
toDispose = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
icon = GetFileIconSTA(filePath, linkOverlay, size);
|
||||
toDispose = true;
|
||||
}
|
||||
|
||||
return icon;
|
||||
|
|
Loading…
Reference in a new issue