private bool SetLnk( ref bool isLnkDirectory, ref string resolvedLnkPath) { bool handled = false; resolvedLnkPath = FileLnk.GetResolvedFileName(TargetFilePath); if (FileLnk.IsDirectory(resolvedLnkPath)) { icon = IconReader.GetFolderIconSTA(TargetFilePath, IconReader.FolderType.Open, true); handled = true; isLnkDirectory = true; } else if (FileLnk.IsNetworkRoot(resolvedLnkPath)) { isLnkDirectory = true; } else if (string.IsNullOrEmpty(resolvedLnkPath)) { Log.Info($"Resolve *.LNK '{TargetFilePath}' has no icon"); } else { IWshShell shell = new WshShell(); IWshShortcut lnk = shell.CreateShortcut(TargetFilePath) as IWshShortcut; arguments = lnk.Arguments; workingDirectory = lnk.WorkingDirectory; string iconLocation = lnk.IconLocation; if (iconLocation.Length > 2) { iconLocation = iconLocation[0..^ 2];
public AppNotifyIcon() { indexLoad = bitmapsLoading.Count; notifyIcon.Icon = bitmapsLoading.First(); load.Tick += Load_Tick; load.Interval = Interval60FPS; notifyIcon.Text = Translator.GetText("SystemTrayMenu"); notifyIcon.Visible = true; if (Properties.Settings.Default.UseIconFromRootFolder) { SystemTrayMenu = IconReader.GetFolderIconSTA( Config.Path, IconReader.FolderType.Closed, false); } notifyIcon.Icon = SystemTrayMenu; AppContextMenu contextMenus = new AppContextMenu(); contextMenus.ClickedOpenLog += ClickedOpenLog; void ClickedOpenLog() { OpenLog?.Invoke(); } contextMenus.ClickedRestart += ClickedRestart; void ClickedRestart() { Restart?.Invoke(); } contextMenus.ClickedExit += ClickedExit; void ClickedExit() { Exit?.Invoke(); } notifyIcon.ContextMenuStrip = contextMenus.Create(); notifyIcon.MouseClick += NotifyIcon_MouseClick; void NotifyIcon_MouseClick(object sender, MouseEventArgs e) { VerifyClick(e); } notifyIcon.MouseDoubleClick += NotifyIcon_MouseDoubleClick; void NotifyIcon_MouseDoubleClick(object sender, MouseEventArgs e) { VerifyClick(e); } }
internal bool ReadIcon(bool isDirectory, ref string resolvedLnkPath) { bool isLnkDirectory = false; if (string.IsNullOrEmpty(TargetFilePath)) { Log.Info($"TargetFilePath from {resolvedLnkPath} empty"); } else if (isDirectory) { icon = IconReader.GetFolderIconSTA( TargetFilePath, IconReader.FolderType.Closed, false); } else { bool handled = false; string fileExtension = Path.GetExtension(TargetFilePath); if (fileExtension == ".lnk") { handled = SetLnk( ref isLnkDirectory, ref resolvedLnkPath); } else if (fileExtension == ".url") { handled = SetUrl(); } else if (fileExtension == ".sln") { handled = SetSln(); } if (!handled) { 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; } catch (Exception ex) { if (ex is SecurityException || ex is ArgumentException || ex is UnauthorizedAccessException || ex is PathTooLongException || ex is NotSupportedException) { Log.Warn($"path:'{TargetFilePath}'", ex); } else { throw; } } } } return(isLnkDirectory); }
internal bool ReadIcon(bool isDirectory, ref string resolvedLnkPath) { bool isLnkDirectory = false; if (string.IsNullOrEmpty(TargetFilePath)) { Log.Info($"TargetFilePath from {resolvedLnkPath} empty"); } else if (isDirectory) { icon = IconReader.GetFolderIconSTA( TargetFilePath, IconReader.FolderType.Closed, false); } else { bool handled = false; bool showOverlay = false; string fileExtension = Path.GetExtension(TargetFilePath); if (fileExtension == ".lnk") { handled = SetLnk( ref isLnkDirectory, ref resolvedLnkPath); showOverlay = true; } else if (fileExtension == ".url") { handled = SetUrl(); showOverlay = true; } else if (fileExtension == ".sln") { handled = SetSln(); } if (!handled) { try { icon = IconReader.GetFileIconWithCache( TargetFilePath, showOverlay); diposeIcon = false; } catch (Exception ex) { if (ex is SecurityException || ex is ArgumentException || ex is UnauthorizedAccessException || ex is PathTooLongException || ex is NotSupportedException) { Log.Warn($"path:'{TargetFilePath}'", ex); } else { throw; } } } } return(isLnkDirectory); }