@@ -318,19 +318,37 @@ public void OpenDirectory(string DirectoryPath, string FileNameOrFilePath = null
318318 {
319319 using var explorer = new Process ( ) ;
320320 var explorerInfo = _settings . CustomExplorer ;
321-
322- explorer . StartInfo = new ProcessStartInfo
321+ var explorerPath = explorerInfo . Path . Trim ( ) . ToLowerInvariant ( ) ;
322+ var targetPath = FileNameOrFilePath is null
323+ ? DirectoryPath
324+ : Path . IsPathRooted ( FileNameOrFilePath )
325+ ? FileNameOrFilePath
326+ : Path . Combine ( DirectoryPath , FileNameOrFilePath ) ;
327+
328+ if ( Path . GetFileNameWithoutExtension ( explorerPath ) == "explorer" )
323329 {
324- FileName = explorerInfo . Path . Replace ( "%d" , DirectoryPath ) ,
325- UseShellExecute = true ,
326- Arguments = FileNameOrFilePath is null
327- ? explorerInfo . DirectoryArgument . Replace ( "%d" , DirectoryPath )
328- : explorerInfo . FileArgument
329- . Replace ( "%d" , DirectoryPath )
330- . Replace ( "%f" ,
331- Path . IsPathRooted ( FileNameOrFilePath ) ? FileNameOrFilePath : Path . Combine ( DirectoryPath , FileNameOrFilePath )
332- )
333- } ;
330+ // Windows File Manager
331+ // We should ignore and pass only the path to Shell to prevent zombie explorer.exe processes
332+ explorer . StartInfo = new ProcessStartInfo
333+ {
334+ FileName = targetPath , // Not explorer, Only path.
335+ UseShellExecute = true // Must be true to open folder
336+ } ;
337+ }
338+ else
339+ {
340+ // Custom File Manager
341+ explorer . StartInfo = new ProcessStartInfo
342+ {
343+ FileName = explorerInfo . Path . Replace ( "%d" , DirectoryPath ) ,
344+ UseShellExecute = true ,
345+ Arguments = FileNameOrFilePath is null
346+ ? explorerInfo . DirectoryArgument . Replace ( "%d" , DirectoryPath )
347+ : explorerInfo . FileArgument
348+ . Replace ( "%d" , DirectoryPath )
349+ . Replace ( "%f" , targetPath )
350+ } ;
351+ }
334352 explorer . Start ( ) ;
335353 }
336354
0 commit comments