diff --git a/Controls/RowData.cs b/Controls/RowData.cs
index 7267837..4f5ef6d 100644
--- a/Controls/RowData.cs
+++ b/Controls/RowData.cs
@@ -1,484 +1,504 @@
-using Clearcove.Logging;
-using IWshRuntimeLibrary;
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Diagnostics;
-using System.Drawing;
-using System.IO;
-using System.Linq;
-using System.Runtime.InteropServices;
-using System.Text;
-using System.Windows.Forms;
-using SystemTrayMenu.Helper;
-using TAFactory.IconPack;
-
-namespace SystemTrayMenu.Controls
-{
- public class RowData : IDisposable
- {
- public FileInfo FileInfo;
- public Icon Icon;
- public bool ContainsMenu;
- public bool IsContextMenuOpen;
- public bool ResolvedFileNotFound;
- public string WorkingDirectory;
- public string Arguments;
-
- public bool IsResolvedLnk;
- public string TargetFilePath;
- public string Text;
-
-
- public Menu SubMenu;
- public int RowIndex;
-
- public bool IsSelected;
- public bool IsSelectedByKeyboard;
-
+using Clearcove.Logging;
+using IWshRuntimeLibrary;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Diagnostics;
+using System.Drawing;
+using System.Drawing.Imaging;
+using System.IO;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Windows.Forms;
+using SystemTrayMenu.Helper;
+using TAFactory.IconPack;
+
+namespace SystemTrayMenu.Controls
+{
+ public class RowData : IDisposable
+ {
+ public FileInfo FileInfo;
+ public Icon Icon;
+ public bool ContainsMenu;
+ public bool IsContextMenuOpen;
+ public bool ResolvedFileNotFound;
+ public string WorkingDirectory;
+ public string Arguments;
+
+ public bool IsResolvedLnk;
+ public string TargetFilePath;
+ public string Text;
+
+
+ public Menu SubMenu;
+ public int RowIndex;
+
+ public bool IsSelected;
+ public bool IsSelectedByKeyboard;
+
///
/// Loads the icon
///
/// True = directory, false = file
/// Discovered path when functions returns true
- /// True when linking to a different directory, otherwise false
- public bool ReadIcon(bool isDirectory, ref string resolvedLnkPath)
- {
- bool isLnkDirectory = false;
-
- Logger log = new Logger(nameof(RowData));
-
+ /// True when linking to a different directory, otherwise false
+ public bool ReadIcon(bool isDirectory, ref string resolvedLnkPath)
+ {
+ bool isLnkDirectory = false;
+
+ Logger log = new Logger(nameof(RowData));
+
if (string.IsNullOrEmpty(TargetFilePath))
- {
- log.Warn($"ReadIcon called but TargetFilePath not set.");
+ {
+ log.Warn($"ReadIcon called but TargetFilePath not set.");
return isLnkDirectory;
- }
-
- if (isDirectory)
- {
- Icon = IconReader.GetFolderIcon(TargetFilePath,
- IconReader.FolderType.Closed, false);
- }
- else
- {
- bool handled = false;
- string fileExtension = Path.GetExtension(TargetFilePath);
-
- if (fileExtension == ".lnk")
- {
- handled = SetLnk(log, ref isLnkDirectory,
- ref resolvedLnkPath);
- }
- else if (fileExtension == ".url")
- {
- handled = SetUrl(log);
- }
- else if (fileExtension == ".sln")
- {
- handled = SetSln(log);
- }
-
- if (!handled)
- {
- try
- {
- Icon = IconReader.GetFileIcon(TargetFilePath, 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;
- }
- catch (Exception ex)
- {
- log.Info($"TargetFilePath:'{TargetFilePath}'");
- log.Error($"{ex.ToString()}");
- }
- }
- }
-
- return isLnkDirectory;
- }
-
- private bool SetLnk(Logger log, ref bool isLnkDirectory,
- ref string resolvedLnkPath)
- {
- bool handled = false;
- resolvedLnkPath = LnkHelper.ResolveShortcut(TargetFilePath);
- if (LnkHelper.IsDirectory(resolvedLnkPath))
- {
- Icon = IconReader.GetFolderIcon(TargetFilePath,
- IconReader.FolderType.Open, true);
- handled = true;
- isLnkDirectory = true;
- }
- else if (string.IsNullOrEmpty(resolvedLnkPath))
- {
- ResolvedFileNotFound = true;
- log.Info($"Resolve '{TargetFilePath}' not possible => no icon");
- }
- else
- {
- IWshShell shell = new WshShell();
- var lnk = shell.CreateShortcut(TargetFilePath)
- as IWshShortcut;
- Arguments = lnk.Arguments;
- WorkingDirectory = lnk.WorkingDirectory;
- string iconLocation = lnk.IconLocation;
- if (iconLocation.Length > 2)
- {
- iconLocation = iconLocation.Substring(0,
- iconLocation.Length - 2);
- if (System.IO.File.Exists(iconLocation))
- {
- try
- {
- Icon = Icon.ExtractAssociatedIcon(iconLocation);
- handled = true;
- }
- catch (Exception ex)
- {
- log.Info($"iconLocation:'{iconLocation}'");
- log.Error($"{ex.ToString()}");
- }
- }
- }
-
- TargetFilePath = resolvedLnkPath;
- }
-
- SetText(Path.GetFileNameWithoutExtension(TargetFilePathOrig));
-
- return handled;
- }
-
- private bool SetUrl(Logger log)
- {
- bool handled = false;
- string iconFile = string.Empty;
- try
- {
- FileIni file = new FileIni(TargetFilePath);
- iconFile = file.Value("IconFile", string.Empty);
- if (string.IsNullOrEmpty(iconFile))
- {
- string browserPath = FileUrl.GetDefaultBrowserPath();
- if (string.IsNullOrEmpty(browserPath))
- {
- log.Info($"No default browser found!");
- }
- else
- {
- Icon = IconReader.GetFileIcon(browserPath, false);
- handled = true;
- }
- }
- else if (System.IO.File.Exists(iconFile))
- {
- Icon = Icon.ExtractAssociatedIcon(iconFile);
- handled = true;
- }
- else
- {
- log.Info($"Resolve '{TargetFilePath}' not possible => no icon");
- }
- }
- catch (Exception ex)
- {
- log.Info($"TargetFilePath:'{TargetFilePath}', " +
- $"iconFile:'{iconFile}'");
- log.Error($"{ex.ToString()}");
- }
-
- SetText($"{FileInfo.Name.Substring(0, FileInfo.Name.Length - 4)}");
-
- return handled;
- }
-
- [DllImport("shell32.dll")]
- static extern int FindExecutable(string lpFile, string lpDirectory, [Out] StringBuilder lpResult);
- private bool SetSln(Logger log)
- {
- bool handled = false;
- var executable = new StringBuilder(1024);
- try
- {
- FindExecutable(TargetFilePath, string.Empty, executable);
- // icon = IconReader.GetFileIcon(executable, false);
- // e.g. VS 2019 icon, need another icom in imagelist
- List extractedIcons = IconHelper.ExtractAllIcons(
- executable.ToString());
- Icon = extractedIcons.Last();
- handled = true;
- }
- catch (Exception ex)
- {
- log.Info($"TargetFilePath:'{TargetFilePath}', " +
- $"executable:'{executable.ToString()}'");
- log.Error($"{ex.ToString()}");
- }
-
- return handled;
- }
-
- public void SetText(string text)
- {
- //text = $" {text}";
- if (text.Length > MenuDefines.LengthMax)
- {
- text = $"{text.Substring(0, MenuDefines.LengthMax)}...";
- }
- Text = text;
- }
-
-
-#warning sort this class and check for duplicated
-
- public event Action