Browse Source

Merge pull request #7569 from MarchingCube/win32-filepicker-no-exceptions

Avoid using COM exceptions for dialog control flow.
pull/7576/head
Dariusz Komosiński 5 years ago
committed by GitHub
parent
commit
572e91b4a0
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 31
      src/Windows/Avalonia.Win32/SystemDialogImpl.cs
  2. 2
      src/Windows/Avalonia.Win32/Win32Com/win32.idl

31
src/Windows/Avalonia.Win32/SystemDialogImpl.cs

@ -89,7 +89,16 @@ namespace Avalonia.Win32
} }
} }
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) if (openDialog?.AllowMultiple == true)
{ {
@ -118,10 +127,6 @@ namespace Avalonia.Win32
} }
catch (COMException ex) catch (COMException ex)
{ {
if ((uint)ex.HResult == (uint)UnmanagedMethods.HRESULT.E_CANCELLED)
{
return result;
}
throw new Win32Exception(ex.HResult); throw new Win32Exception(ex.HResult);
} }
})!; })!;
@ -161,7 +166,17 @@ namespace Avalonia.Win32
} }
} }
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) if (frm.Result is not null)
{ {
result = GetAbsoluteFilePath(frm.Result); result = GetAbsoluteFilePath(frm.Result);
@ -171,10 +186,6 @@ namespace Avalonia.Win32
} }
catch (COMException ex) catch (COMException ex)
{ {
if ((uint)ex.HResult == (uint)UnmanagedMethods.HRESULT.E_CANCELLED)
{
return result;
}
throw new Win32Exception(ex.HResult); throw new Win32Exception(ex.HResult);
} }
}); });

2
src/Windows/Avalonia.Win32/Win32Com/win32.idl

@ -112,7 +112,7 @@ interface IShellItemArray : IUnknown
interface IModalWindow : IUnknown interface IModalWindow : IUnknown
{ {
[local] [local]
HRESULT Show( int Show(
[in, unique] HWND hwndOwner); [in, unique] HWND hwndOwner);
} }

Loading…
Cancel
Save