|
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;
|
@@ -348,24 +349,35 @@ public void OpenDirectory(string directoryPath, string fileNameOrFilePath = null
|
348 | 349 | explorer.Start();
|
349 | 350 | }
|
350 | 351 | }
|
| 352 | + catch (COMException ex) when (ex.ErrorCode == unchecked((int)0x80004004)) |
| 353 | + { |
| 354 | + /* |
| 355 | + * The COMException with HResult 0x80004004 is E_ABORT (operation aborted). |
| 356 | + * Shell APIs often return this when the operation is canceled or the shell cannot complete it cleanly. |
| 357 | + * It most likely comes from Win32Helper.OpenFolderAndSelectFile(targetPath). |
| 358 | + * Typical triggers: |
| 359 | + * The target file/folder was deleted/moved between computing targetPath and the shell call. |
| 360 | + * The folder is on an offline network/removable drive. |
| 361 | + * Explorer is restarting/busy and aborts the request. |
| 362 | + * A selection request to a new/closing Explorer window is canceled. |
| 363 | + * Because it is commonly user- or environment-driven and not actionable, |
| 364 | + * we should treat it as expected noise and ignore it to avoid bothering users. |
| 365 | + */ |
| 366 | + } |
351 | 367 | catch (Win32Exception ex) when (ex.NativeErrorCode == 2)
|
352 | 368 | {
|
353 | 369 | LogError(ClassName, "File Manager not found");
|
354 |
| - ShowMsgBox( |
355 |
| - string.Format(GetTranslation("fileManagerNotFound"), ex.Message), |
| 370 | + ShowMsgError( |
356 | 371 | GetTranslation("fileManagerNotFoundTitle"),
|
357 |
| - MessageBoxButton.OK, |
358 |
| - MessageBoxImage.Error |
| 372 | + string.Format(GetTranslation("fileManagerNotFound"), ex.Message) |
359 | 373 | );
|
360 | 374 | }
|
361 | 375 | catch (Exception ex)
|
362 | 376 | {
|
363 | 377 | LogException(ClassName, "Failed to open folder", ex);
|
364 |
| - ShowMsgBox( |
365 |
| - string.Format(GetTranslation("folderOpenError"), ex.Message), |
| 378 | + ShowMsgError( |
366 | 379 | GetTranslation("errorTitle"),
|
367 |
| - MessageBoxButton.OK, |
368 |
| - MessageBoxImage.Error |
| 380 | + string.Format(GetTranslation("folderOpenError"), ex.Message) |
369 | 381 | );
|
370 | 382 | }
|
371 | 383 | }
|
@@ -393,11 +405,9 @@ private void OpenUri(Uri uri, bool? inPrivate = null, bool forceBrowser = false)
|
393 | 405 | {
|
394 | 406 | var tabOrWindow = browserInfo.OpenInTab ? "tab" : "window";
|
395 | 407 | LogException(ClassName, $"Failed to open URL in browser {tabOrWindow}: {path}, {inPrivate ?? browserInfo.EnablePrivate}, {browserInfo.PrivateArg}", e);
|
396 |
| - ShowMsgBox( |
397 |
| - GetTranslation("browserOpenError"), |
| 408 | + ShowMsgError( |
398 | 409 | GetTranslation("errorTitle"),
|
399 |
| - MessageBoxButton.OK, |
400 |
| - MessageBoxImage.Error |
| 410 | + GetTranslation("browserOpenError") |
401 | 411 | );
|
402 | 412 | }
|
403 | 413 | }
|
|
0 commit comments