diff --git a/src/Files.App/Services/Windows/WindowsDialogService.cs b/src/Files.App/Services/Windows/WindowsDialogService.cs index 60ee67f767c6..57b16c37e0fe 100644 --- a/src/Files.App/Services/Windows/WindowsDialogService.cs +++ b/src/Files.App/Services/Windows/WindowsDialogService.cs @@ -65,13 +65,17 @@ public unsafe bool Open_FileOpenDialog(nint hWnd, bool pickFoldersOnly, string[] pDialog.Get()->SetDefaultFolder(pDefaultFolderShellItem.Get()); // Show the dialog - pDialog.Get()->Show(new HWND(hWnd)); + hr = pDialog.Get()->Show(new HWND(hWnd)); + if (hr.Value == unchecked((int)0x800704C7)) // HRESULT_FROM_WIN32(ERROR_CANCELLED) + return false; + + hr.ThrowOnFailure(); // Get the file that user chose using ComPtr pResultShellItem = default; pDialog.Get()->GetResult(pResultShellItem.GetAddressOf()); - if (pResultShellItem.Get() == null) - throw new COMException("FileSaveDialog returned invalid shell item."); + if (pResultShellItem.Get() is null) + throw new COMException("FileOpenDialog returned invalid shell item."); pResultShellItem.Get()->GetDisplayName(SIGDN.SIGDN_FILESYSPATH, out var lpFilePath); filePath = lpFilePath.ToString(); @@ -135,12 +139,16 @@ public unsafe bool Open_FileSaveDialog(nint hWnd, bool pickFoldersOnly, string[] pDialog.Get()->SetDefaultFolder(pDefaultFolderShellItem.Get()); // Show the dialog - pDialog.Get()->Show(new HWND(hWnd)); + hr = pDialog.Get()->Show(new HWND(hWnd)); + if (hr.Value == unchecked((int)0x800704C7)) // HRESULT_FROM_WIN32(ERROR_CANCELLED) + return false; + + hr.ThrowOnFailure(); // Get the file that user chose using ComPtr pResultShellItem = default; pDialog.Get()->GetResult(pResultShellItem.GetAddressOf()); - if (pResultShellItem.Get() == null) + if (pResultShellItem.Get() is null) throw new COMException("FileSaveDialog returned invalid shell item."); pResultShellItem.Get()->GetDisplayName(SIGDN.SIGDN_FILESYSPATH, out var lpFilePath); filePath = lpFilePath.ToString();