[BUG] Lnk not not resolved if target contains a dot (.) (#247), version 1.1.0.4

This commit is contained in:
Markus Hofknecht 2021-11-22 21:49:36 +01:00
parent 83fa626b08
commit bba1bedede
3 changed files with 13 additions and 8 deletions

View file

@ -257,13 +257,13 @@ namespace SystemTrayMenu.DataClasses
private bool SetLnk(int level, ref bool isLnkDirectory, ref string resolvedLnkPath)
{
bool handled = false;
resolvedLnkPath = FileLnk.GetResolvedFileName(TargetFilePath);
resolvedLnkPath = FileLnk.GetResolvedFileName(TargetFilePath, out bool isFolder);
if (string.IsNullOrEmpty(resolvedLnkPath))
{
// do nothing
}
else if (string.IsNullOrEmpty(Path.GetExtension(resolvedLnkPath)))
else if (isFolder)
{
icon = IconReader.GetFolderIconWithCache(TargetFilePathOrig, IconReader.FolderType.Open, true, true, level == 0, out bool loading);
IconLoading = loading;

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.1.0.3")]
[assembly: AssemblyFileVersion("1.1.0.3")]
[assembly: AssemblyVersion("1.1.0.4")]
[assembly: AssemblyFileVersion("1.1.0.4")]

View file

@ -5,6 +5,7 @@
namespace SystemTrayMenu.Utilities
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.NetworkInformation;
using System.Threading;
@ -12,19 +13,20 @@ namespace SystemTrayMenu.Utilities
internal class FileLnk
{
public static string GetResolvedFileName(string shortcutFilename)
public static string GetResolvedFileName(string shortcutFilename, out bool isFolder)
{
bool isFolderByShell = false;
string resolvedFilename = string.Empty;
if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
{
resolvedFilename = GetShortcutFileNamePath(shortcutFilename);
resolvedFilename = GetShortcutFileNamePath(shortcutFilename, out isFolderByShell);
}
else
{
Thread staThread = new(new ParameterizedThreadStart(StaThreadMethod));
void StaThreadMethod(object obj)
{
resolvedFilename = GetShortcutFileNamePath(shortcutFilename);
resolvedFilename = GetShortcutFileNamePath(shortcutFilename, out isFolderByShell);
}
staThread.SetApartmentState(ApartmentState.STA);
@ -32,6 +34,7 @@ namespace SystemTrayMenu.Utilities
staThread.Join();
}
isFolder = isFolderByShell;
return resolvedFilename;
}
@ -67,9 +70,10 @@ namespace SystemTrayMenu.Utilities
return pingable;
}
private static string GetShortcutFileNamePath(object shortcutFilename)
private static string GetShortcutFileNamePath(object shortcutFilename, out bool isFolder)
{
string resolvedFilename = string.Empty;
isFolder = false;
string pathOnly = Path.GetDirectoryName((string)shortcutFilename);
string filenameOnly = Path.GetFileName((string)shortcutFilename);
@ -81,6 +85,7 @@ namespace SystemTrayMenu.Utilities
try
{
ShellLinkObject link = (ShellLinkObject)folderItem.GetLink;
isFolder = link.Target.IsFolder;
if (string.IsNullOrEmpty(link.Path))
{
// https://github.com/Hofknecht/SystemTrayMenu/issues/242