Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/Files.App/Utils/Shell/ContextMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,6 @@ private void EnumMenuItems(HMENU hMenu, List<Win32ContextMenuItem> menuItemsResu
{
Debug.WriteLine("Item {0} ({1}): {2}", index, menuItemInfo.wID, menuItemInfo.dwTypeData);

// A workaround to avoid an AccessViolationException on some items,
// notably the "Run with graphic processor" menu item of NVIDIA cards
if (menuItemInfo.wID - 1 > 5000)
{
container.Dispose();
continue;
}

menuItem.Label = menuItemInfo.dwTypeData;
menuItem.CommandString = GetCommandString(_cMenu, menuItemInfo.wID - 1);

Expand Down Expand Up @@ -314,6 +306,13 @@ public Task<bool> LoadSubMenu(List<Win32ContextMenuItem> subItems)

private static string? GetCommandString(Shell32.IContextMenu cMenu, uint offset, Shell32.GCS flags = Shell32.GCS.GCS_VERBW)
{
// A workaround to avoid an AccessViolationException on some items,
// notably the "Run with graphic processor" menu item of NVIDIA cards
if (offset > 5000)
{
return null;
}

SafeCoTaskMemString? commandString = null;

try
Expand All @@ -331,7 +330,6 @@ public Task<bool> LoadSubMenu(List<Win32ContextMenuItem> subItems)

return null;
}

catch (Exception ex) when (ex is COMException or NotImplementedException)
{
// Not every item has an associated verb
Expand Down