end2endzone / ShellAnything

ShellAnything is a C++ open-source software which allow one to easily customize and add new options to *Windows Explorer* context menu. Define specific actions when a user right-click on a file or a directory.
MIT License
183 stars 27 forks source link

Files and folders together do not start MENU #97

Closed DBenS closed 3 years ago

DBenS commented 3 years ago

If user selects many files AND many folders (together) the MENU does not appear; even functioning well if the same set is selected separately (just files or just folders).

To Reproduce Steps to reproduce the behavior:

  1. Go into the right window of Windows Explorer (files and folders).
  2. Select some file and some directory at the same time (one DIR and one FILE).
  3. Call the context menu.
  4. The custom option does not appear.

Expected behavior Since ShellExtension correctly handles files and folders in a separate way, would be great if the mix of both types could be handled too.

Environment

Additional context The code below functions perfectly if the selected set is separated (just files or just DIR's), but not functioning if I set both at the same time.

<menu name="Inspect OBAKE files">
<icon path="C:\OBAKEv6\Obake6.exe" index="0" />
<visibility class="file" exists="C:\OBAKEv6\Obake6.exe" />
<validity class="file" exists="C:\OBAKEv6\Obake6.exe" pattern="*.obkf???"/>
<visibility class="directory" exists="C:\OBAKEv6\Obake6.exe" />
<validity class="directory" exists="C:\OBAKEv6\Obake6.exe" />
<actions>
    <property name="selection.multi.separator" value=";" />
    <file path="${env.USERPROFILE}\obk.in" encoding="utf-8">${selection.path}</file>
    <exec path="C:\OBAKEv6\Obake6.exe" arguments="/iai ${env.USERPROFILE}\obk.in" />
    <property name="selection.multi.separator" value="${line.separator}" />
</actions>
</menu>

Thank you for your attention;

end2endzone commented 3 years ago

I am trying to figure out what you are trying to accomplish. Looking at <visibility> elements, you are filtering for file OR directory and in both cases, the file C:\OBAKEv6\Obake6.exe must exist. I think the correct way would be to merge both <visibility> elements into the following:

    <visibility class="file;directory" exists="C:\OBAKEv6\Obake6.exe" />

However, after trying out this structure myself, it does not work either.

According to the documentation of the class attribute, the use case you specified in this issue should already be supported :

If multiple classes are specified, at least one class must match for the validation to be successful. If multiple files are selected, the class of each file must match at least one allowed classes for the validation to be successful.

If you only filter for class="file;directory" and you select C:\Windows\System32 (a directory) and the file C:\Windows\notepad.exe, the above 2 sentences are respected.

I think you actually found another bug. I will revisit unit tests and try to figure out why this does not work.

DBenS commented 3 years ago

Yes, I guessed it was a BUG but I was affraid to label the occurrence as it... Thank you Antoine - I'll be looking forward a solution.

end2endzone commented 3 years ago

I have look at this problem. Indeed in unit tests, this use case is never tested.

The problem lies in Validator.cpp, line 532 where each "class" (one by one) is evaluated against all selected files/directories. For the example mentioned above, this means that class file is compared with C:\Windows\System32 (a directory) and the file C:\Windows\notepad.exe. The result is false since not all selected object are "files". The same process is repeated for directory class with the same result: not all selected object are directories.

What is actually implemented is that each class are evaluated against all files. This is incorrect and not inline with the documentation: "If multiple files are selected, the class of each file must match at least one allowed classes for the validation to be successful.".

That's a really good catch. Thank you. I will implement a fix soon. I will also try to update documentation to be more clear on the subject.