Skip to content

Conversation

@cypress-exe
Copy link

Upstream Issue:
On the current upstream branch, converting 17+ files at once revealed a bug where the program wouldn't necessarily choose the correct conversion profile. The issue lies in Windows Explorer's context menu, which runs an optimization when more than 16 files are selected.

Explanation of the Bug:
My investigation suggests that when 16 or less files are selected, Windows Explorer creates the context menu such that each ToolStripMenuItem is unique in memory, meaning that even two options with identical text properties are still differentiable and execute different conversion presets.

However, with 17+ files, Windows Explorer seems to do an optimization such that multiple instances of ToolStripMenuItem with identical text properties are not differentiated. I bet Windows assumes that all menu items with identical text properties reference the same callback, so it assigns them to the handler of the first item instead of creating separate callbacks. However in this case, multiple ToolStripMenuItems with identical text properties were not, in fact, identical.

My Workaround:
To prevent Windows from assigning identically named instances of ToolStripMenuItem to the same callback, I added a unique number of invisible zero-width characters to each option. This makes each menu item's text property unique while keeping the user interface unchanged.

Justification:
This approach inflicts a relatively minor refactor of just a few lines. While it is a workaround, the "proper" fix would be a major endeavor and refactor. It would probably consist of giving each menu item its own unique command ID or verb at the shell level (IContextMenu), but that would either require changes to SharpShell or would require writing native code. Suffice to say—major endeavor.

This solution is minimal, doesn’t break existing functionality, and targets a specific, reproducible bug that has been reported at least twice and likely affects all instances of the application.

Issues Resolved:
Fixes #614, #567

On the current upstream branch, converting 17+ files at once revealed an
underlying issue where the program wouldn't necessarily choose the
correct conversion profile.

After 16 files are selected, Windows Explorer seems to optimize the
context menu such that multiple `ToolStripMenuItems` with identical
`text` properties share the same callback, which causes ambiguity
issues.

As a workaround, each menu's `text` property has a unique number of
zero-width characters appended to it. This makes the text technically
unique, ensuring that Windows maintains the distinction. Furthermore, it
preserves the UI, has a minimal code refactor, and resolves an issue
that has been reported at least twice and likely impacts all instances
of FileConverter.

Fixes Tichau#614, Tichau#567
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Image Batch Conversion, Scale does not work for more than 16 files

1 participant