Fix a bunch of nullable warnings

This commit is contained in:
Peter Kirmeier 2022-12-05 21:46:53 +01:00
parent 9a33a15e83
commit 135850c9fc
11 changed files with 215 additions and 183 deletions

View file

@ -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)

View file

@ -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)

View file

@ -59,26 +59,29 @@ 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();
foreach (ListViewItemData item in dgvMainMenu.Items)
ListView? dgvMainMenu = menus[0].GetDataGridView();
if (dgvMainMenu != null)
{
RowData rowDataToClear = item.data;
rowDataToClear.IsMenuOpen = false;
rowDataToClear.IsClicking = false;
rowDataToClear.IsSelected = false;
rowDataToClear.IsContextMenuOpen = false;
}
foreach (ListViewItemData item in dgvMainMenu.Items)
{
RowData rowDataToClear = item.data;
rowDataToClear.IsMenuOpen = false;
rowDataToClear.IsClicking = false;
rowDataToClear.IsSelected = false;
rowDataToClear.IsContextMenuOpen = false;
}
RefreshSelection(dgvMainMenu);
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();
foreach (ListViewItemData item in dgv.Items)
ListView? dgv = menu.GetDataGridView();
if (dgv != null)
{
RowData rowData = item.data;
if (rowData != null && rowData.IsContextMenuOpen)
foreach (ListViewItemData item in dgv.Items)
{
isShellContextMenuOpen = true;
break;
RowData rowData = item.data;
if (rowData != null && rowData.IsContextMenuOpen)
{
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,19 +668,23 @@ 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;
dgv.MouseMove += waitToOpenMenu.MouseMove;
dgv.MouseLeave += dgvMouseRow.MouseLeave;
dgv.MouseLeave += Dgv_MouseLeave;
dgv.MouseMove += waitToOpenMenu.MouseMove;
#endif
#if TODO // TOUCH
dgv.MouseMove += Dgv_MouseMove;
dgv.MouseMove += Dgv_MouseMove;
#endif
dgv.SelectionChanged += Dgv_SelectionChanged;
dgv.SelectionChanged += Dgv_SelectionChanged;
#if TODO // BorderColors and PaintEvent
dgv.RowPostPaint += Dgv_RowPostPaint;
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(() =>
{

View file

@ -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
{

View file

@ -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;
}

View file

@ -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)
{

View file

@ -5,20 +5,25 @@
namespace SystemTrayMenu.DllImports
{
using System;
using System.Runtime.InteropServices;
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);
}
}

View file

@ -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 :-)
@ -74,19 +98,19 @@ namespace SystemTrayMenu.Helper
moreInfo += "GNU GENERAL PUBLIC LICENSE" + Environment.NewLine;
moreInfo += "(Version 3, 29 June 2007)" + Environment.NewLine;
moreInfo += "Thanks for ideas, reporting issues and contributing!" + Environment.NewLine;
moreInfo += "#123 Mordecai00, #125 Holgermh, #135 #153 #154 #164 jakkaas, #145 Pascal Aloy, #153 #158 #160 blackcrack,";
moreInfo += "#162 HansieNL, #163 igorruckert, #171 kehoen, #186 Dtrieb, #188 #189 #191 #195 iJahangard, #195 #197 #225 #238 the-phuctran, ";
moreInfo += "#205 kristofzerbe, #209 jonaskohl, #211 blacksparrow15, #220 #403 Yavuz E., #229 #230 #239 Peter O., #231 Ryonez, ";
moreInfo += "#235 #242 243 #247, #271 Tom, #237 Torsten S., #240 video Patrick, #244 Gunter D., #246 #329 MACE4GITHUB, #259 #310 vanjac, ";
moreInfo += "#262 terencemcdonnell, #269 petersnows25, #272 Peter M., #273 #274 ParasiteDelta, #275 #276 #278 donaldaken, ";
moreInfo += "#277 Jan S., #282 akuznets, #283 #284 #289 RuSieg, #285 #286 dao-net, #288 William P., #294 #295 #296 Stefan Mahrer, ";
moreInfo += "#225 #297 #299 #317 #321 #324 #330 #386 #390 #401 #402 #407 #409 #414 #416 #418 #428 #430 #443 chip33, ";
moreInfo += "#298 phanirithvij, #306 wini2, #370 dna5589, #372 not-nef, #376 Michelle H., ";
moreInfo += "#377 SoenkeHob, #380 #394 TransLucida, #384 #434 #435 boydfields, #386 visusys, #387 #411 #444 yrctw" + Environment.NewLine;
moreInfo += "#446 timinformatica, #450 ppt-oldoerp, #453 fubaWoW, #454 WouterVanGoey" + Environment.NewLine;
moreInfo += "#462 verdammt89x, #463 Dirk S." + Environment.NewLine;
moreInfo += @"
moreInfo += "Thanks for ideas, reporting issues and contributing!" + Environment.NewLine;
moreInfo += "#123 Mordecai00, #125 Holgermh, #135 #153 #154 #164 jakkaas, #145 Pascal Aloy, #153 #158 #160 blackcrack,";
moreInfo += "#162 HansieNL, #163 igorruckert, #171 kehoen, #186 Dtrieb, #188 #189 #191 #195 iJahangard, #195 #197 #225 #238 the-phuctran, ";
moreInfo += "#205 kristofzerbe, #209 jonaskohl, #211 blacksparrow15, #220 #403 Yavuz E., #229 #230 #239 Peter O., #231 Ryonez, ";
moreInfo += "#235 #242 243 #247, #271 Tom, #237 Torsten S., #240 video Patrick, #244 Gunter D., #246 #329 MACE4GITHUB, #259 #310 vanjac, ";
moreInfo += "#262 terencemcdonnell, #269 petersnows25, #272 Peter M., #273 #274 ParasiteDelta, #275 #276 #278 donaldaken, ";
moreInfo += "#277 Jan S., #282 akuznets, #283 #284 #289 RuSieg, #285 #286 dao-net, #288 William P., #294 #295 #296 Stefan Mahrer, ";
moreInfo += "#225 #297 #299 #317 #321 #324 #330 #386 #390 #401 #402 #407 #409 #414 #416 #418 #428 #430 #443 chip33, ";
moreInfo += "#298 phanirithvij, #306 wini2, #370 dna5589, #372 not-nef, #376 Michelle H., ";
moreInfo += "#377 SoenkeHob, #380 #394 TransLucida, #384 #434 #435 boydfields, #386 visusys, #387 #411 #444 yrctw" + Environment.NewLine;
moreInfo += "#446 timinformatica, #450 ppt-oldoerp, #453 fubaWoW, #454 WouterVanGoey" + Environment.NewLine;
moreInfo += "#462 verdammt89x, #463 Dirk S." + Environment.NewLine;
moreInfo += @"
Sponsors - Thank you!
------------------
* Stefan Mahrer
@ -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();

View file

@ -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;

View file

@ -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)
{

View file

@ -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,46 +85,51 @@ namespace SystemTrayMenu.Utilities
string keyPath = "")
{
loading = false;
string extension = Path.GetExtension(path);
IconSize size = IconSize.Small;
if (Scaling.Factor >= 1.25f ||
Scaling.FactorByDpi >= 1.25f ||
Properties.Settings.Default.IconSizeInPercent / 100f >= 1.25f)
{
size = IconSize.Large;
}
string key = path;
if (!string.IsNullOrEmpty(keyPath))
{
key = keyPath;
}
if (IsExtensionWithSameIcon(extension))
{
key = extension + linkOverlay;
}
if (!DictIconCache(isMainMenu).TryGetValue(key, out Icon? icon) &&
!DictIconCache(!isMainMenu).TryGetValue(key, out icon))
{
icon = Resources.StaticResources.LoadingIcon;
loading = true;
if (updateIconInBackground)
{
new Thread(UpdateIconInBackground).Start();
void UpdateIconInBackground()
{
DictIconCache(isMainMenu).GetOrAdd(key, GetIconSTA(path, resolvedPath, linkOverlay, size, false));
}
Icon? icon = null;
if (path != null)
{
string extension = Path.GetExtension(path);
IconSize size = IconSize.Small;
if (Scaling.Factor >= 1.25f ||
Scaling.FactorByDpi >= 1.25f ||
Properties.Settings.Default.IconSizeInPercent / 100f >= 1.25f)
{
size = IconSize.Large;
}
string key = path;
if (!string.IsNullOrEmpty(keyPath))
{
key = keyPath;
}
if (IsExtensionWithSameIcon(extension))
{
key = extension + linkOverlay;
}
if (!DictIconCache(isMainMenu).TryGetValue(key, out icon) &&
!DictIconCache(!isMainMenu).TryGetValue(key, out icon))
{
icon = Resources.StaticResources.LoadingIcon;
loading = true;
if (updateIconInBackground)
{
new Thread(UpdateIconInBackground).Start();
void UpdateIconInBackground()
{
DictIconCache(isMainMenu).GetOrAdd(key, GetIconSTA(path, resolvedPath, linkOverlay, size, false));
}
}
}
}
return icon;
}
public static Icon GetFolderIconWithCache(
string path,
public static Icon? GetFolderIconWithCache(
string? path,
bool linkOverlay,
bool updateIconInBackground,
bool isMainMenu,
@ -132,43 +137,46 @@ namespace SystemTrayMenu.Utilities
{
loading = false;
IconSize size = IconSize.Small;
if (Scaling.Factor >= 1.25f ||
Scaling.FactorByDpi >= 1.25f ||
Properties.Settings.Default.IconSizeInPercent / 100f >= 1.25f)
{
// IconSize.Large returns another folder icon than windows explorer
size = IconSize.Large;
}
string key = path;
if (!DictIconCache(isMainMenu).TryGetValue(key, out Icon? icon) &&
!DictIconCache(!isMainMenu).TryGetValue(key, out icon))
{
icon = Resources.StaticResources.LoadingIcon;
loading = true;
if (updateIconInBackground)
{
if (MainPreload)
{
DictIconCache(isMainMenu).GetOrAdd(key, GetFolder);
}
else
{
new Thread(UpdateIconInBackground).Start();
void UpdateIconInBackground()
{
DictIconCache(isMainMenu).GetOrAdd(key, GetFolder);
}
}
}
}
Icon GetFolder(string keyExtension)
{
return GetIconSTA(path, path, linkOverlay, size, true);
Icon? icon = null;
if (path != null)
{
IconSize size = IconSize.Small;
if (Scaling.Factor >= 1.25f ||
Scaling.FactorByDpi >= 1.25f ||
Properties.Settings.Default.IconSizeInPercent / 100f >= 1.25f)
{
// IconSize.Large returns another folder icon than windows explorer
size = IconSize.Large;
}
string key = path;
if (!DictIconCache(isMainMenu).TryGetValue(key, out icon) &&
!DictIconCache(!isMainMenu).TryGetValue(key, out icon))
{
icon = Resources.StaticResources.LoadingIcon;
loading = true;
if (updateIconInBackground)
{
if (MainPreload)
{
DictIconCache(isMainMenu).GetOrAdd(key, GetFolder);
}
else
{
new Thread(UpdateIconInBackground).Start();
void UpdateIconInBackground()
{
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)