View Issue Details

IDProjectCategoryView StatusLast Update
0001771Double CommanderFile operationspublic2020-11-30 07:43
Reporterforbjok Assigned ToAlexx2000  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
ProjectionnoneETAnone 
Platformx86-64OSWindowsOS VersionWindows 10
Product Version0.7.8 
Target Version0.8.0Fixed in Version0.8.0 
Summary0001771: Context menu commands run with wrong current directory
DescriptionWhen a context menu command (defined in HKEY_CLASSES_ROOT -> Folder -> shell -> (command name) -> command) is executed in Windows Explorer by right-clicking the background or a subdirectrory, it is executed with current working directory set to the directory you are currently browsing.

In DC, it works as expected when right-clicking the background, but if right-clicking a subdirectory and running a command it is instead always run with current directory set to the DC executable's directory.
Steps To ReproduceRight-click a file or subdirectory and execute an action in the Windows context menu. It will get run with current working directory set to the Double Commander executable's path.
Additional InformationI dug around in the code a bit and found out what's causing it.

In TShellContextMenu.PopUp, it's only setting the TCMINVOKECOMMANDINFO's lpDirectory if FBackground is true - and FBackground is only true if the user clicks the background rather than a subdirectory. So if a subdirectory is right-clicked, any commands are executed with lpDirectory unset, resulting in the current directory defaulting to Double Commander's installation path.

Code:
if FBackground then begin
  lpDirectory := PAnsiChar(CeUtf8ToSys(FFiles[0].FullPath));
end;


I don't know the reasoning behind doing this, but to me this behavior seems incorrect.
It seems to me like the desirable behavior should be to do the same thing Windows Explorer does, and execute the command with its working directory set to the currently browsed directory regardless of whether the background or a subdirectory is clicked.
This means that if a file or subdirectory is right-clicked, lpDirectory should be set to the item's parent directory rather than the item itself.

I have attached a patch with a change that seems to fix the problem.
TagsNo tags attached.
Attached Files
ushellcontextmenu.pas.patch (533 bytes)   
Index: ushellcontextmenu.pas
===================================================================
--- ushellcontextmenu.pas	(revision 7455)
+++ ushellcontextmenu.pas	(working copy)
@@ -725,6 +725,10 @@
             nShow := SW_NORMAL;
             if FBackground then begin
               lpDirectory := PAnsiChar(CeUtf8ToSys(FFiles[0].FullPath));
+            end
+            else
+            begin
+              lpDirectory := PAnsiChar(CeUtf8ToSys(ExtractFilePath(FFiles[0].FullPath)));
             end;
           end;
 
ushellcontextmenu.pas.patch (533 bytes)   
Fixed in Revision7456
Operating systemWindows
WidgetsetWin32
Architecture64-bit

Activities

Issue History

Date Modified Username Field Change
2017-03-16 20:15 forbjok New Issue
2017-03-16 20:15 forbjok File Added: ushellcontextmenu.pas.patch
2017-03-17 23:05 Alexx2000 Fixed in Revision => 7456
2017-03-17 23:05 Alexx2000 Assigned To => Alexx2000
2017-03-17 23:05 Alexx2000 Status new => resolved
2017-03-17 23:05 Alexx2000 Resolution open => fixed
2017-03-17 23:05 Alexx2000 Fixed in Version => 0.8.0
2017-03-17 23:05 Alexx2000 Target Version => 0.8.0
2020-11-30 07:43 Alexx2000 Status resolved => closed