|
32 | 32 | using JetBrains.Annotations;
|
33 | 33 | using Squirrel;
|
34 | 34 | using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch;
|
| 35 | +using System.ComponentModel; |
35 | 36 |
|
36 | 37 | namespace Flow.Launcher
|
37 | 38 | {
|
38 | 39 | public class PublicAPIInstance : IPublicAPI, IRemovable
|
39 | 40 | {
|
| 41 | + private static readonly string ClassName = nameof(PublicAPIInstance); |
| 42 | + |
40 | 43 | private readonly Settings _settings;
|
41 | 44 | private readonly MainViewModel _mainVM;
|
42 | 45 |
|
@@ -316,40 +319,63 @@ public void SavePluginSettings()
|
316 | 319 |
|
317 | 320 | public void OpenDirectory(string DirectoryPath, string FileNameOrFilePath = null)
|
318 | 321 | {
|
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") |
| 322 | + try |
329 | 323 | {
|
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 |
| 324 | + using var explorer = new Process(); |
| 325 | + var explorerInfo = _settings.CustomExplorer; |
| 326 | + var explorerPath = explorerInfo.Path.Trim().ToLowerInvariant(); |
| 327 | + var targetPath = FileNameOrFilePath is null |
| 328 | + ? DirectoryPath |
| 329 | + : Path.IsPathRooted(FileNameOrFilePath) |
| 330 | + ? FileNameOrFilePath |
| 331 | + : Path.Combine(DirectoryPath, FileNameOrFilePath); |
| 332 | + |
| 333 | + if (Path.GetFileNameWithoutExtension(explorerPath) == "explorer") |
333 | 334 | {
|
334 |
| - FileName = targetPath, // Not explorer, Only path. |
335 |
| - UseShellExecute = true // Must be true to open folder |
336 |
| - }; |
| 335 | + // Windows File Manager |
| 336 | + explorer.StartInfo = new ProcessStartInfo |
| 337 | + { |
| 338 | + FileName = targetPath, |
| 339 | + UseShellExecute = true |
| 340 | + }; |
| 341 | + } |
| 342 | + else |
| 343 | + { |
| 344 | + // Custom File Manager |
| 345 | + explorer.StartInfo = new ProcessStartInfo |
| 346 | + { |
| 347 | + FileName = explorerInfo.Path.Replace("%d", DirectoryPath), |
| 348 | + UseShellExecute = true, |
| 349 | + Arguments = FileNameOrFilePath is null |
| 350 | + ? explorerInfo.DirectoryArgument.Replace("%d", DirectoryPath) |
| 351 | + : explorerInfo.FileArgument |
| 352 | + .Replace("%d", DirectoryPath) |
| 353 | + .Replace("%f", targetPath) |
| 354 | + }; |
| 355 | + } |
| 356 | + |
| 357 | + explorer.Start(); |
337 | 358 | }
|
338 |
| - else |
| 359 | + catch (Win32Exception ex) when (ex.NativeErrorCode == 2) |
339 | 360 | {
|
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 |
| - }; |
| 361 | + LogError(ClassName, "File Manager not found"); |
| 362 | + ShowMsgBox( |
| 363 | + string.Format(GetTranslation("fileManagerNotFound"), ex.Message), |
| 364 | + GetTranslation("fileManagerNotFoundTitle"), |
| 365 | + MessageBoxButton.OK, |
| 366 | + MessageBoxImage.Error |
| 367 | + ); |
| 368 | + } |
| 369 | + catch (Exception ex) |
| 370 | + { |
| 371 | + LogException(ClassName, "Failed to open folder", ex); |
| 372 | + ShowMsgBox( |
| 373 | + string.Format(GetTranslation("folderOpenError"), ex.Message), |
| 374 | + GetTranslation("errorTitle"), |
| 375 | + MessageBoxButton.OK, |
| 376 | + MessageBoxImage.Error |
| 377 | + ); |
351 | 378 | }
|
352 |
| - explorer.Start(); |
353 | 379 | }
|
354 | 380 |
|
355 | 381 | private void OpenUri(Uri uri, bool? inPrivate = null)
|
|
0 commit comments