@@ -316,40 +316,63 @@ public void SavePluginSettings()
316316
317317 public void OpenDirectory ( string DirectoryPath , string FileNameOrFilePath = null )
318318 {
319- using var explorer = new Process ( ) ;
320- var explorerInfo = _settings . CustomExplorer ;
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" )
319+ try
329320 {
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
321+ using var explorer = new Process ( ) ;
322+ var explorerInfo = _settings . CustomExplorer ;
323+ var explorerPath = explorerInfo . Path . Trim ( ) . ToLowerInvariant ( ) ;
324+ var targetPath = FileNameOrFilePath is null
325+ ? DirectoryPath
326+ : Path . IsPathRooted ( FileNameOrFilePath )
327+ ? FileNameOrFilePath
328+ : Path . Combine ( DirectoryPath , FileNameOrFilePath ) ;
329+
330+ if ( Path . GetFileNameWithoutExtension ( explorerPath ) == "explorer" )
333331 {
334- FileName = targetPath , // Not explorer, Only path.
335- UseShellExecute = true // Must be true to open folder
336- } ;
332+ // Windows File Manager
333+ explorer . StartInfo = new ProcessStartInfo
334+ {
335+ FileName = targetPath ,
336+ UseShellExecute = true
337+ } ;
338+ }
339+ else
340+ {
341+ // Custom File Manager
342+ explorer . StartInfo = new ProcessStartInfo
343+ {
344+ FileName = explorerInfo . Path . Replace ( "%d" , DirectoryPath ) ,
345+ UseShellExecute = true ,
346+ Arguments = FileNameOrFilePath is null
347+ ? explorerInfo . DirectoryArgument . Replace ( "%d" , DirectoryPath )
348+ : explorerInfo . FileArgument
349+ . Replace ( "%d" , DirectoryPath )
350+ . Replace ( "%f" , targetPath )
351+ } ;
352+ }
353+
354+ explorer . Start ( ) ;
337355 }
338- else
356+ catch ( System . ComponentModel . Win32Exception ex ) when ( ex . NativeErrorCode == 2 )
339357 {
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- } ;
358+ // File Manager not found
359+ MessageBoxEx . Show (
360+ string . Format ( GetTranslation ( "fileManagerNotFound" ) , ex . Message ) ,
361+ GetTranslation ( "fileManagerNotFoundTitle" ) ,
362+ MessageBoxButton . OK ,
363+ MessageBoxImage . Error
364+ ) ;
365+ }
366+ catch ( Exception ex )
367+ {
368+ // Other exceptions
369+ MessageBoxEx . Show (
370+ string . Format ( GetTranslation ( "folderOpenError" ) , ex . Message ) ,
371+ GetTranslation ( "errorTitle" ) ,
372+ MessageBoxButton . OK ,
373+ MessageBoxImage . Error
374+ ) ;
351375 }
352- explorer . Start ( ) ;
353376 }
354377
355378 private void OpenUri ( Uri uri , bool ? inPrivate = null )
0 commit comments