Skip to content

Commit

Permalink
Merge pull request #7569 from MarchingCube/win32-filepicker-no-except…
Browse files Browse the repository at this point in the history
…ions

Avoid using COM exceptions for dialog control flow.
  • Loading branch information
MarchingCube authored Feb 9, 2022
2 parents e11c6c0 + f4ae1c9 commit 572e91b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
31 changes: 21 additions & 10 deletions src/Windows/Avalonia.Win32/SystemDialogImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,16 @@ internal class SystemDialogImpl : ISystemDialogImpl
}
}
frm.Show(hWnd);
var showResult = frm.Show(hWnd);
if ((uint)showResult == (uint)UnmanagedMethods.HRESULT.E_CANCELLED)
{
return result;
}
else if ((uint)showResult != (uint)UnmanagedMethods.HRESULT.S_OK)
{
throw new Win32Exception(showResult);
}
if (openDialog?.AllowMultiple == true)
{
Expand Down Expand Up @@ -118,10 +127,6 @@ internal class SystemDialogImpl : ISystemDialogImpl
}
catch (COMException ex)
{
if ((uint)ex.HResult == (uint)UnmanagedMethods.HRESULT.E_CANCELLED)
{
return result;
}
throw new Win32Exception(ex.HResult);
}
})!;
Expand Down Expand Up @@ -161,7 +166,17 @@ internal class SystemDialogImpl : ISystemDialogImpl
}
}
frm.Show(hWnd);
var showResult = frm.Show(hWnd);
if ((uint)showResult == (uint)UnmanagedMethods.HRESULT.E_CANCELLED)
{
return result;
}
else if ((uint)showResult != (uint)UnmanagedMethods.HRESULT.S_OK)
{
throw new Win32Exception(showResult);
}
if (frm.Result is not null)
{
result = GetAbsoluteFilePath(frm.Result);
Expand All @@ -171,10 +186,6 @@ internal class SystemDialogImpl : ISystemDialogImpl
}
catch (COMException ex)
{
if ((uint)ex.HResult == (uint)UnmanagedMethods.HRESULT.E_CANCELLED)
{
return result;
}
throw new Win32Exception(ex.HResult);
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/Windows/Avalonia.Win32/Win32Com/win32.idl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ interface IShellItemArray : IUnknown
interface IModalWindow : IUnknown
{
[local]
HRESULT Show(
int Show(
[in, unique] HWND hwndOwner);
}

Expand Down

0 comments on commit 572e91b

Please sign in to comment.