mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-09-29 08:41:12 +13:00
Fix a bunch of nullable warnings
This commit is contained in:
parent
9a33a15e83
commit
135850c9fc
11 changed files with 215 additions and 183 deletions
|
@ -28,7 +28,6 @@ namespace SystemTrayMenu
|
|||
menus.LoadStarted += menuNotifyIcon.LoadingStart;
|
||||
menus.LoadStopped += menuNotifyIcon.LoadingStop;
|
||||
menuNotifyIcon.Click += () => menus.SwitchOpenClose(true);
|
||||
menuNotifyIcon.OpenLog += Log.OpenLogFile;
|
||||
menus.MainPreload();
|
||||
|
||||
if (Settings.Default.ShowInTaskbar)
|
||||
|
|
|
@ -74,7 +74,7 @@ namespace SystemTrayMenu.Handler
|
|||
iMenuKey = 0;
|
||||
}
|
||||
|
||||
internal void CmdKeyProcessed(Menu sender, Key key, ModifierKeys modifiers)
|
||||
internal void CmdKeyProcessed(Menu? sender, Key key, ModifierKeys modifiers)
|
||||
{
|
||||
sender ??= menus[iMenuKey];
|
||||
|
||||
|
@ -253,7 +253,7 @@ namespace SystemTrayMenu.Handler
|
|||
|
||||
private bool IsAnyMenuSelectedByKey(
|
||||
ref ListView? dgv,
|
||||
ref Menu menuFromSelected,
|
||||
ref Menu? menuFromSelected,
|
||||
ref string textselected)
|
||||
{
|
||||
Menu menu = menus[iMenuKey];
|
||||
|
@ -287,9 +287,9 @@ namespace SystemTrayMenu.Handler
|
|||
int iMenuBefore = iMenuKey;
|
||||
|
||||
Menu menu = menus[iMenuKey];
|
||||
ListView dgv = null;
|
||||
ListView dgvBefore = null;
|
||||
Menu menuFromSelected = null;
|
||||
ListView? dgv = null;
|
||||
ListView? dgvBefore = null;
|
||||
Menu? menuFromSelected = null;
|
||||
string textselected = string.Empty;
|
||||
bool isStillSelected = IsAnyMenuSelectedByKey(ref dgv, ref menuFromSelected, ref textselected);
|
||||
if (isStillSelected)
|
||||
|
|
|
@ -59,16 +59,18 @@ namespace SystemTrayMenu.Business
|
|||
workerMainMenu.WorkerSupportsCancellation = true;
|
||||
workerMainMenu.DoWork += LoadMenu;
|
||||
workerMainMenu.RunWorkerCompleted += LoadMainMenuCompleted;
|
||||
void LoadMainMenuCompleted(object sender, RunWorkerCompletedEventArgs e)
|
||||
void LoadMainMenuCompleted(object? sender, RunWorkerCompletedEventArgs e)
|
||||
{
|
||||
keyboardInput.ResetSelectedByKey();
|
||||
LoadStopped();
|
||||
LoadStopped?.Invoke();
|
||||
|
||||
if (e.Result == null)
|
||||
{
|
||||
// The main menu gets loaded again
|
||||
// Clean up menu status of previous one
|
||||
ListView dgvMainMenu = menus[0].GetDataGridView();
|
||||
ListView? dgvMainMenu = menus[0].GetDataGridView();
|
||||
if (dgvMainMenu != null)
|
||||
{
|
||||
foreach (ListViewItemData item in dgvMainMenu.Items)
|
||||
{
|
||||
RowData rowDataToClear = item.data;
|
||||
|
@ -79,6 +81,7 @@ namespace SystemTrayMenu.Business
|
|||
}
|
||||
|
||||
RefreshSelection(dgvMainMenu);
|
||||
}
|
||||
|
||||
if (Settings.Default.AppearAtMouseLocation)
|
||||
{
|
||||
|
@ -144,7 +147,7 @@ namespace SystemTrayMenu.Business
|
|||
workerSubMenu.CancelAsync();
|
||||
}
|
||||
|
||||
LoadStopped();
|
||||
LoadStopped?.Invoke();
|
||||
}
|
||||
|
||||
waitToOpenMenu.StartLoadMenu += StartLoadMenu;
|
||||
|
@ -170,7 +173,7 @@ namespace SystemTrayMenu.Business
|
|||
ShowSubMenu(menuLoading);
|
||||
}
|
||||
|
||||
BackgroundWorker workerSubMenu = workersSubMenu.
|
||||
BackgroundWorker? workerSubMenu = workersSubMenu.
|
||||
Where(w => !w.IsBusy).FirstOrDefault();
|
||||
if (workerSubMenu == null)
|
||||
{
|
||||
|
@ -186,7 +189,7 @@ namespace SystemTrayMenu.Business
|
|||
workerSubMenu.RunWorkerAsync(rowData);
|
||||
}
|
||||
|
||||
void LoadSubMenuCompleted(object senderCompleted, RunWorkerCompletedEventArgs e)
|
||||
void LoadSubMenuCompleted(object? senderCompleted, RunWorkerCompletedEventArgs e)
|
||||
{
|
||||
MenuData menuData = (MenuData)e.Result;
|
||||
|
||||
|
@ -259,7 +262,7 @@ namespace SystemTrayMenu.Business
|
|||
keyboardInput.RowSelected += waitToOpenMenu.RowSelected;
|
||||
|
||||
joystickHelper = new();
|
||||
joystickHelper.KeyPressed += (key, modifiers) => menus[0].Dispatcher.Invoke(keyboardInput.CmdKeyProcessed, new object[] { null, key, modifiers });
|
||||
joystickHelper.KeyPressed += (key, modifiers) => menus[0].Dispatcher.Invoke(keyboardInput.CmdKeyProcessed, new object[] { null!, key, modifiers });
|
||||
|
||||
timerShowProcessStartedAsLoadingIcon.Interval = TimeSpan.FromMilliseconds(Settings.Default.TimeUntilClosesAfterEnterPressed);
|
||||
timerStillActiveCheck.Interval = TimeSpan.FromMilliseconds(Settings.Default.TimeUntilClosesAfterEnterPressed + 20);
|
||||
|
@ -317,9 +320,9 @@ namespace SystemTrayMenu.Business
|
|||
SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged;
|
||||
}
|
||||
|
||||
internal event Action LoadStarted;
|
||||
internal event Action? LoadStarted;
|
||||
|
||||
internal event Action LoadStopped;
|
||||
internal event Action? LoadStopped;
|
||||
|
||||
private enum OpenCloseState
|
||||
{
|
||||
|
@ -361,7 +364,7 @@ namespace SystemTrayMenu.Business
|
|||
}
|
||||
}
|
||||
|
||||
internal static MenuData GetData(BackgroundWorker worker, string path, int level)
|
||||
internal static MenuData GetData(BackgroundWorker? worker, string path, int level)
|
||||
{
|
||||
MenuData menuData = new(level);
|
||||
if (worker?.CancellationPending == true || string.IsNullOrEmpty(path))
|
||||
|
@ -478,7 +481,7 @@ namespace SystemTrayMenu.Business
|
|||
|
||||
if (!workerMainMenu.IsBusy)
|
||||
{
|
||||
LoadStarted();
|
||||
LoadStarted?.Invoke();
|
||||
workerMainMenu.RunWorkerAsync(
|
||||
new object[] { Config.Path, 0 });
|
||||
}
|
||||
|
@ -492,7 +495,7 @@ namespace SystemTrayMenu.Business
|
|||
}
|
||||
}
|
||||
|
||||
private static void LoadMenu(object senderDoWork, DoWorkEventArgs eDoWork)
|
||||
private static void LoadMenu(object? senderDoWork, DoWorkEventArgs eDoWork)
|
||||
{
|
||||
string? path;
|
||||
int level = 0;
|
||||
|
@ -512,7 +515,7 @@ namespace SystemTrayMenu.Business
|
|||
path = Config.Path;
|
||||
}
|
||||
|
||||
MenuData menuData = GetData((BackgroundWorker)senderDoWork, path, level);
|
||||
MenuData menuData = GetData((BackgroundWorker?)senderDoWork, path, level);
|
||||
menuData.RowDataParent = rowData;
|
||||
eDoWork.Result = menuData;
|
||||
}
|
||||
|
@ -567,27 +570,23 @@ namespace SystemTrayMenu.Business
|
|||
{
|
||||
bool IsShellContextMenuOpen()
|
||||
{
|
||||
bool isShellContextMenuOpen = false;
|
||||
foreach (Menu menu in menus.Where(m => m != null))
|
||||
{
|
||||
ListView dgv = menu.GetDataGridView();
|
||||
ListView? dgv = menu.GetDataGridView();
|
||||
if (dgv != null)
|
||||
{
|
||||
foreach (ListViewItemData item in dgv.Items)
|
||||
{
|
||||
RowData rowData = item.data;
|
||||
if (rowData != null && rowData.IsContextMenuOpen)
|
||||
{
|
||||
isShellContextMenuOpen = true;
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isShellContextMenuOpen)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return isShellContextMenuOpen;
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (Menu menu in menus.Where(m => m != null && m.IsActive))
|
||||
|
@ -631,7 +630,7 @@ namespace SystemTrayMenu.Business
|
|||
}
|
||||
|
||||
menu.Deactivated += Deactivate;
|
||||
void Deactivate(object sender, EventArgs e)
|
||||
void Deactivate(object? sender, EventArgs e)
|
||||
{
|
||||
if (IsOpenCloseStateOpening())
|
||||
{
|
||||
|
@ -669,7 +668,9 @@ namespace SystemTrayMenu.Business
|
|||
menu.CellMouseUp += Dgv_MouseUp;
|
||||
menu.CellMouseClick += Dgv_MouseClick;
|
||||
|
||||
ListView dgv = menu.GetDataGridView();
|
||||
ListView? dgv = menu.GetDataGridView();
|
||||
if (dgv != null)
|
||||
{
|
||||
#if TODO // Misc MouseEvents
|
||||
dgv.MouseLeave += dgvMouseRow.MouseLeave;
|
||||
dgv.MouseLeave += Dgv_MouseLeave;
|
||||
|
@ -682,6 +683,8 @@ namespace SystemTrayMenu.Business
|
|||
#if TODO // BorderColors and PaintEvent
|
||||
dgv.RowPostPaint += Dgv_RowPostPaint;
|
||||
#endif
|
||||
}
|
||||
|
||||
menu.SetCounts(foldersCount, filesCount);
|
||||
|
||||
return menu;
|
||||
|
@ -992,7 +995,7 @@ namespace SystemTrayMenu.Business
|
|||
}
|
||||
#endif
|
||||
|
||||
private void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e)
|
||||
private void SystemEvents_DisplaySettingsChanged(object? sender, EventArgs e)
|
||||
{
|
||||
dispatchter.Invoke(() =>
|
||||
{
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace SystemTrayMenu.Business
|
|||
|
||||
internal static class MenusHelpers
|
||||
{
|
||||
internal static void GetItemsForMainMenu(BackgroundWorker worker, string path, ref MenuData menuData)
|
||||
internal static void GetItemsForMainMenu(BackgroundWorker? worker, string path, ref MenuData menuData)
|
||||
{
|
||||
menuData.IsNetworkRoot = FileLnk.IsNetworkRoot(path);
|
||||
if (menuData.IsNetworkRoot)
|
||||
|
@ -60,7 +60,7 @@ namespace SystemTrayMenu.Business
|
|||
}
|
||||
}
|
||||
|
||||
internal static void ReadHiddenAndReadIcons(BackgroundWorker worker, ref MenuData menuData)
|
||||
internal static void ReadHiddenAndReadIcons(BackgroundWorker? worker, ref MenuData menuData)
|
||||
{
|
||||
List<RowData> rowDatasToRemove = new();
|
||||
foreach (RowData rowData in menuData.RowDatas)
|
||||
|
@ -117,7 +117,7 @@ namespace SystemTrayMenu.Business
|
|||
else if (Properties.Settings.Default.SortByTypeAndDate)
|
||||
{
|
||||
rowDatas = rowDatas.OrderByDescending(x => x.IsFolder)
|
||||
.ThenByDescending(x => x.FileInfo.LastWriteTime).ToList();
|
||||
.ThenByDescending(x => x.FileInfo?.LastWriteTime).ToList();
|
||||
}
|
||||
else if (Properties.Settings.Default.SortByFileExtensionAndName)
|
||||
{
|
||||
|
@ -129,7 +129,7 @@ namespace SystemTrayMenu.Business
|
|||
}
|
||||
else if (Properties.Settings.Default.SortByDate)
|
||||
{
|
||||
rowDatas = rowDatas.OrderByDescending(x => x.FileInfo.LastWriteTime).ToList();
|
||||
rowDatas = rowDatas.OrderByDescending(x => x.FileInfo?.LastWriteTime).ToList();
|
||||
}
|
||||
|
||||
return rowDatas;
|
||||
|
@ -186,7 +186,7 @@ namespace SystemTrayMenu.Business
|
|||
}
|
||||
}
|
||||
|
||||
private static void GetDirectories(BackgroundWorker worker, string path, ref MenuData menuData)
|
||||
private static void GetDirectories(BackgroundWorker? worker, string path, ref MenuData menuData)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -210,7 +210,7 @@ namespace SystemTrayMenu.Business
|
|||
}
|
||||
}
|
||||
|
||||
private static void GetFiles(BackgroundWorker worker, string path, ref MenuData menuData)
|
||||
private static void GetFiles(BackgroundWorker? worker, string path, ref MenuData menuData)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
@ -16,8 +16,8 @@ namespace SystemTrayMenu
|
|||
|
||||
public static class Config
|
||||
{
|
||||
private static readonly Icon SystemTrayMenu = new Icon(Properties.Resources.SystemTrayMenu, (int)SystemParameters.SmallIconWidth, (int)SystemParameters.SmallIconHeight);
|
||||
private static readonly Icon IconRootFolder = GetIconSTA(Path, Path, false, IconSize.Small, true);
|
||||
private static readonly Icon SystemTrayMenu = new(Properties.Resources.SystemTrayMenu, (int)SystemParameters.SmallIconWidth, (int)SystemParameters.SmallIconHeight);
|
||||
private static readonly Icon? IconRootFolder = GetIconSTA(Path, Path, false, IconSize.Small, true);
|
||||
|
||||
private static bool readDarkModeDone;
|
||||
private static bool isDarkMode;
|
||||
|
@ -63,7 +63,7 @@ namespace SystemTrayMenu
|
|||
|
||||
public static Icon GetAppIcon()
|
||||
{
|
||||
if (Settings.Default.UseIconFromRootFolder)
|
||||
if (Settings.Default.UseIconFromRootFolder && (IconRootFolder != null))
|
||||
{
|
||||
return IconRootFolder;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace SystemTrayMenu.Helper
|
|||
using System.Collections.Generic;
|
||||
using SystemTrayMenu.DllImports;
|
||||
|
||||
internal class WindowsExplorerSort : IComparer<string>
|
||||
internal class WindowsExplorerSort : IComparer<string?>
|
||||
{
|
||||
public int Compare(string? x, string? y)
|
||||
{
|
||||
|
|
|
@ -6,19 +6,24 @@ namespace SystemTrayMenu.DllImports
|
|||
{
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Versioning;
|
||||
|
||||
/// <summary>
|
||||
/// wraps the methodcalls to native windows dll's.
|
||||
/// </summary>
|
||||
public static partial class NativeMethods
|
||||
{
|
||||
public static IntPtr User32FindWindow(string lpClassName, string lpWindowName)
|
||||
public static IntPtr User32FindWindow(string? lpClassName, string? lpWindowName)
|
||||
{
|
||||
return FindWindow(lpClassName, lpWindowName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-findwindoww .
|
||||
/// </summary>
|
||||
[SupportedOSPlatform("windows")]
|
||||
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)]
|
||||
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
|
||||
private static extern IntPtr FindWindow(string? lpClassName, string? lpWindowName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,8 +16,6 @@ namespace SystemTrayMenu.Helper
|
|||
|
||||
internal class AppContextMenu
|
||||
{
|
||||
public event Action ClickedOpenLog;
|
||||
|
||||
public ContextMenu Create()
|
||||
{
|
||||
ContextMenu menu = new()
|
||||
|
@ -27,7 +25,7 @@ namespace SystemTrayMenu.Helper
|
|||
|
||||
AddItem(menu, "Settings", () => SettingsWindow.ShowSingleInstance());
|
||||
AddSeperator(menu);
|
||||
AddItem(menu, "Log File", () => ClickedOpenLog?.Invoke());
|
||||
AddItem(menu, "Log File", Log.OpenLogFile);
|
||||
AddSeperator(menu);
|
||||
AddItem(menu, "Frequently Asked Questions", Config.ShowHelpFAQ);
|
||||
AddItem(menu, "Support SystemTrayMenu", Config.ShowSupportSystemTrayMenu);
|
||||
|
@ -59,10 +57,36 @@ namespace SystemTrayMenu.Helper
|
|||
|
||||
private static void About()
|
||||
{
|
||||
FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(
|
||||
Assembly.GetEntryAssembly().Location);
|
||||
string copyright = string.Empty;
|
||||
string productName = string.Empty;
|
||||
string fileDescription = string.Empty;
|
||||
string fileVersion = string.Empty;
|
||||
string? location = Assembly.GetEntryAssembly()?.Location;
|
||||
if (location != null)
|
||||
{
|
||||
FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(location);
|
||||
if (versionInfo.LegalCopyright != null)
|
||||
{
|
||||
copyright = versionInfo.LegalCopyright;
|
||||
}
|
||||
|
||||
string moreInfo = versionInfo.LegalCopyright + Environment.NewLine;
|
||||
if (versionInfo.ProductName != null)
|
||||
{
|
||||
productName = versionInfo.ProductName;
|
||||
}
|
||||
|
||||
if (versionInfo.FileDescription != null)
|
||||
{
|
||||
fileDescription = versionInfo.FileDescription;
|
||||
}
|
||||
|
||||
if (versionInfo.FileVersion != null)
|
||||
{
|
||||
fileVersion = versionInfo.FileVersion;
|
||||
}
|
||||
}
|
||||
|
||||
string moreInfo = copyright + Environment.NewLine;
|
||||
moreInfo += "Markus Hofknecht (mailto:Markus@Hofknecht.eu)" + Environment.NewLine;
|
||||
|
||||
// Thanks for letting me being part of this project and that I am allowed to be listed here :-)
|
||||
|
@ -101,10 +125,10 @@ Sponsors - Thank you!
|
|||
";
|
||||
AboutBox aboutBox = new()
|
||||
{
|
||||
AppTitle = versionInfo.ProductName,
|
||||
AppDescription = versionInfo.FileDescription,
|
||||
AppVersion = $"Version {versionInfo.FileVersion}",
|
||||
AppCopyright = versionInfo.LegalCopyright,
|
||||
AppTitle = productName,
|
||||
AppDescription = fileDescription,
|
||||
AppVersion = $"Version {fileVersion}",
|
||||
AppCopyright = copyright,
|
||||
AppMoreInfo = moreInfo,
|
||||
};
|
||||
aboutBox.ShowDialog();
|
||||
|
|
|
@ -19,20 +19,13 @@ namespace SystemTrayMenu.UserInterface
|
|||
notifyIcon.ToolTipText = "SystemTrayMenu";
|
||||
notifyIcon.Icon = Config.GetAppIcon();
|
||||
notifyIcon.Visibility = Visibility.Visible;
|
||||
|
||||
AppContextMenu contextMenus = new();
|
||||
|
||||
contextMenus.ClickedOpenLog += () => OpenLog?.Invoke();
|
||||
|
||||
notifyIcon.ContextMenu = contextMenus.Create();
|
||||
notifyIcon.ContextMenu = new AppContextMenu().Create();
|
||||
notifyIcon.LeftClickCommand = new ActionCommand((_) => Click?.Invoke());
|
||||
notifyIcon.DoubleClickCommand = new ActionCommand((_) => Click?.Invoke());
|
||||
}
|
||||
|
||||
public event Action? Click;
|
||||
|
||||
public event Action? OpenLog;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
notifyIcon.Icon = null;
|
||||
|
|
|
@ -56,13 +56,13 @@ namespace SystemTrayMenu.Utilities
|
|||
private static Guid iidIContextMenu2 = new("{000214f4-0000-0000-c000-000000000046}");
|
||||
private static Guid iidIContextMenu3 = new("{bcfce0a0-ec17-11d0-8d10-00a0c90f2719}");
|
||||
|
||||
private IContextMenu oContextMenu;
|
||||
private IContextMenu2 oContextMenu2;
|
||||
private IContextMenu3 oContextMenu3;
|
||||
private IShellFolder oDesktopFolder;
|
||||
private IShellFolder oParentFolder;
|
||||
private IntPtr[] arrPIDLs;
|
||||
private string strParentFolder;
|
||||
private IContextMenu? oContextMenu;
|
||||
private IContextMenu2? oContextMenu2;
|
||||
private IContextMenu3? oContextMenu3;
|
||||
private IShellFolder? oDesktopFolder;
|
||||
private IShellFolder? oParentFolder;
|
||||
private IntPtr[]? arrPIDLs;
|
||||
private string? strParentFolder;
|
||||
|
||||
/// <summary>
|
||||
/// Finalizes an instance of the <see cref="ShellContextMenu"/> class.
|
||||
|
@ -874,7 +874,7 @@ namespace SystemTrayMenu.Utilities
|
|||
return null;
|
||||
}
|
||||
|
||||
IShellFolder oParentFolder = GetParentFolder(arrFI[0].DirectoryName);
|
||||
IShellFolder? oParentFolder = GetParentFolder(arrFI[0].DirectoryName);
|
||||
if (oParentFolder == null)
|
||||
{
|
||||
return null;
|
||||
|
@ -914,7 +914,7 @@ namespace SystemTrayMenu.Utilities
|
|||
return null;
|
||||
}
|
||||
|
||||
IShellFolder oParentFolder = GetParentFolder(arrFI[0].Parent.FullName);
|
||||
IShellFolder? oParentFolder = GetParentFolder(arrFI[0].Parent.FullName);
|
||||
if (oParentFolder == null)
|
||||
{
|
||||
return null;
|
||||
|
@ -1067,7 +1067,7 @@ namespace SystemTrayMenu.Utilities
|
|||
/// </summary>
|
||||
/// <param name="folderName">Folder path.</param>
|
||||
/// <returns>IShellFolder for the folder (relative from the desktop).</returns>
|
||||
private IShellFolder GetParentFolder(string folderName)
|
||||
private IShellFolder? GetParentFolder(string folderName)
|
||||
{
|
||||
if (oParentFolder == null)
|
||||
{
|
||||
|
|
|
@ -75,9 +75,9 @@ namespace SystemTrayMenu.Utilities
|
|||
}
|
||||
}
|
||||
|
||||
public static Icon GetFileIconWithCache(
|
||||
string path,
|
||||
string resolvedPath,
|
||||
public static Icon? GetFileIconWithCache(
|
||||
string? path,
|
||||
string? resolvedPath,
|
||||
bool linkOverlay,
|
||||
bool updateIconInBackground,
|
||||
bool isMainMenu,
|
||||
|
@ -85,6 +85,10 @@ namespace SystemTrayMenu.Utilities
|
|||
string keyPath = "")
|
||||
{
|
||||
loading = false;
|
||||
|
||||
Icon? icon = null;
|
||||
if (path != null)
|
||||
{
|
||||
string extension = Path.GetExtension(path);
|
||||
IconSize size = IconSize.Small;
|
||||
if (Scaling.Factor >= 1.25f ||
|
||||
|
@ -105,7 +109,7 @@ namespace SystemTrayMenu.Utilities
|
|||
key = extension + linkOverlay;
|
||||
}
|
||||
|
||||
if (!DictIconCache(isMainMenu).TryGetValue(key, out Icon? icon) &&
|
||||
if (!DictIconCache(isMainMenu).TryGetValue(key, out icon) &&
|
||||
!DictIconCache(!isMainMenu).TryGetValue(key, out icon))
|
||||
{
|
||||
icon = Resources.StaticResources.LoadingIcon;
|
||||
|
@ -119,12 +123,13 @@ namespace SystemTrayMenu.Utilities
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
public static Icon GetFolderIconWithCache(
|
||||
string path,
|
||||
public static Icon? GetFolderIconWithCache(
|
||||
string? path,
|
||||
bool linkOverlay,
|
||||
bool updateIconInBackground,
|
||||
bool isMainMenu,
|
||||
|
@ -132,6 +137,9 @@ namespace SystemTrayMenu.Utilities
|
|||
{
|
||||
loading = false;
|
||||
|
||||
Icon? icon = null;
|
||||
if (path != null)
|
||||
{
|
||||
IconSize size = IconSize.Small;
|
||||
if (Scaling.Factor >= 1.25f ||
|
||||
Scaling.FactorByDpi >= 1.25f ||
|
||||
|
@ -142,8 +150,7 @@ namespace SystemTrayMenu.Utilities
|
|||
}
|
||||
|
||||
string key = path;
|
||||
|
||||
if (!DictIconCache(isMainMenu).TryGetValue(key, out Icon? icon) &&
|
||||
if (!DictIconCache(isMainMenu).TryGetValue(key, out icon) &&
|
||||
!DictIconCache(!isMainMenu).TryGetValue(key, out icon))
|
||||
{
|
||||
icon = Resources.StaticResources.LoadingIcon;
|
||||
|
@ -163,13 +170,14 @@ namespace SystemTrayMenu.Utilities
|
|||
DictIconCache(isMainMenu).GetOrAdd(key, GetFolder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Icon GetFolder(string keyExtension)
|
||||
{
|
||||
return GetIconSTA(path, path, linkOverlay, size, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
@ -239,15 +247,15 @@ namespace SystemTrayMenu.Utilities
|
|||
return isExtensionWithSameIcon;
|
||||
}
|
||||
|
||||
private static Icon? GetIcon(string path, string resolvedPath, bool linkOverlay, IconSize size, bool isFolder)
|
||||
private static Icon? GetIcon(string path, string? resolvedPath, bool linkOverlay, IconSize size, bool isFolder)
|
||||
{
|
||||
Icon? icon;
|
||||
if (Path.GetExtension(path).Equals(".ico", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
icon = Icon.ExtractAssociatedIcon(path);
|
||||
}
|
||||
else if (Path.GetExtension(resolvedPath).Equals(".ico", StringComparison.InvariantCultureIgnoreCase) &&
|
||||
File.Exists(resolvedPath))
|
||||
else if (File.Exists(resolvedPath) &&
|
||||
Path.GetExtension(resolvedPath).Equals(".ico", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
icon = Icon.ExtractAssociatedIcon(resolvedPath);
|
||||
if (linkOverlay)
|
||||
|
|
Loading…
Reference in a new issue