|
8 | 8 | using System.Linq; |
9 | 9 | using System.Net; |
10 | 10 | using System.Runtime.CompilerServices; |
| 11 | +using System.Runtime.InteropServices; |
11 | 12 | using System.Threading; |
12 | 13 | using System.Threading.Tasks; |
13 | 14 | using System.Windows; |
@@ -379,24 +380,35 @@ public void OpenDirectory(string directoryPath, string fileNameOrFilePath = null |
379 | 380 | explorer.Start(); |
380 | 381 | } |
381 | 382 | } |
| 383 | + catch (COMException ex) when (ex.ErrorCode == unchecked((int)0x80004004)) |
| 384 | + { |
| 385 | + /* |
| 386 | + * The COMException with HResult 0x80004004 is E_ABORT (operation aborted). |
| 387 | + * Shell APIs often return this when the operation is canceled or the shell cannot complete it cleanly. |
| 388 | + * It most likely comes from Win32Helper.OpenFolderAndSelectFile(targetPath). |
| 389 | + * Typical triggers: |
| 390 | + * The target file/folder was deleted/moved between computing targetPath and the shell call. |
| 391 | + * The folder is on an offline network/removable drive. |
| 392 | + * Explorer is restarting/busy and aborts the request. |
| 393 | + * A selection request to a new/closing Explorer window is canceled. |
| 394 | + * Because it is commonly user- or environment-driven and not actionable, |
| 395 | + * we should treat it as expected noise and ignore it to avoid bothering users. |
| 396 | + */ |
| 397 | + } |
382 | 398 | catch (Win32Exception ex) when (ex.NativeErrorCode == 2) |
383 | 399 | { |
384 | 400 | LogError(ClassName, "File Manager not found"); |
385 | | - ShowMsgBox( |
386 | | - string.Format(GetTranslation("fileManagerNotFound"), ex.Message), |
| 401 | + ShowMsgError( |
387 | 402 | GetTranslation("fileManagerNotFoundTitle"), |
388 | | - MessageBoxButton.OK, |
389 | | - MessageBoxImage.Error |
| 403 | + string.Format(GetTranslation("fileManagerNotFound"), ex.Message) |
390 | 404 | ); |
391 | 405 | } |
392 | 406 | catch (Exception ex) |
393 | 407 | { |
394 | 408 | LogException(ClassName, "Failed to open folder", ex); |
395 | | - ShowMsgBox( |
396 | | - string.Format(GetTranslation("folderOpenError"), ex.Message), |
| 409 | + ShowMsgError( |
397 | 410 | GetTranslation("errorTitle"), |
398 | | - MessageBoxButton.OK, |
399 | | - MessageBoxImage.Error |
| 411 | + string.Format(GetTranslation("folderOpenError"), ex.Message) |
400 | 412 | ); |
401 | 413 | } |
402 | 414 | } |
@@ -424,11 +436,9 @@ private void OpenUri(Uri uri, bool? inPrivate = null, bool forceBrowser = false) |
424 | 436 | { |
425 | 437 | var tabOrWindow = browserInfo.OpenInTab ? "tab" : "window"; |
426 | 438 | LogException(ClassName, $"Failed to open URL in browser {tabOrWindow}: {path}, {inPrivate ?? browserInfo.EnablePrivate}, {browserInfo.PrivateArg}", e); |
427 | | - ShowMsgBox( |
428 | | - GetTranslation("browserOpenError"), |
| 439 | + ShowMsgError( |
429 | 440 | GetTranslation("errorTitle"), |
430 | | - MessageBoxButton.OK, |
431 | | - MessageBoxImage.Error |
| 441 | + GetTranslation("browserOpenError") |
432 | 442 | ); |
433 | 443 | } |
434 | 444 | } |
|
0 commit comments