comdlg32: Check invalid options in IFileDialog::SetOptions.

Fix Steam chat unable to select files.

Signed-off-by: Zhiyi Zhang <zzhang@codeweavers.com>
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zhiyi Zhang 2018-09-13 17:55:07 +08:00 committed by Alexandre Julliard
parent b89e0e70e0
commit 616e5fa733
2 changed files with 29 additions and 0 deletions

View File

@ -2505,6 +2505,16 @@ static HRESULT WINAPI IFileDialog2_fnSetOptions(IFileDialog2 *iface, FILEOPENDIA
FileDialogImpl *This = impl_from_IFileDialog2(iface);
TRACE("%p (0x%x)\n", This, fos);
if (fos & ~(FOS_OVERWRITEPROMPT | FOS_STRICTFILETYPES | FOS_NOCHANGEDIR | FOS_PICKFOLDERS | FOS_FORCEFILESYSTEM
| FOS_ALLNONSTORAGEITEMS | FOS_NOVALIDATE | FOS_ALLOWMULTISELECT | FOS_PATHMUSTEXIST | FOS_FILEMUSTEXIST
| FOS_CREATEPROMPT | FOS_SHAREAWARE | FOS_NOREADONLYRETURN | FOS_NOTESTFILECREATE | FOS_HIDEMRUPLACES
| FOS_HIDEPINNEDPLACES | FOS_NODEREFERENCELINKS | FOS_DONTADDTORECENT | FOS_FORCESHOWHIDDEN
| FOS_DEFAULTNOMINIMODE | FOS_FORCEPREVIEWPANEON | FOS_SUPPORTSTREAMABLEITEMS))
{
WARN("Invalid option %#x\n", fos);
return E_INVALIDARG;
}
if( !(This->options & FOS_PICKFOLDERS) && (fos & FOS_PICKFOLDERS) )
{
WCHAR buf[30];

View File

@ -536,6 +536,8 @@ static void test_basics(void)
const WCHAR fname2[] = {'f','n','a','m','e','2', 0};
const WCHAR fspec2[] = {'*','.','e','x','e',0};
COMDLG_FILTERSPEC filterspec[2] = {{fname1, fspec1}, {fname2, fspec2}};
const DWORD invalid_fos[] = {0x1, 0x10, 0x400, 0x80000, 0x400000, 0x800000, 0x1000000, 0x4000000, 0x8000000};
INT i;
/* This should work on every platform with IFileDialog */
SHGetDesktopFolder(&psfdesktop);
@ -586,6 +588,23 @@ static void test_basics(void)
ok(fdoptions == (FOS_OVERWRITEPROMPT | FOS_NOREADONLYRETURN | FOS_PATHMUSTEXIST | FOS_NOCHANGEDIR),
"Unexpected default options: 0x%08x\n", fdoptions);
/* Check SetOptions invalid options handling */
for (i = 0; i < ARRAY_SIZE(invalid_fos); i++)
{
hr = IFileOpenDialog_SetOptions(pfod, invalid_fos[i]);
ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
hr = IFileOpenDialog_GetOptions(pfod, &fdoptions);
ok(hr == S_OK, "got 0x%08x.\n", hr);
ok(fdoptions == (FOS_PATHMUSTEXIST | FOS_FILEMUSTEXIST | FOS_NOCHANGEDIR), "got %08x\n", fdoptions);
hr = IFileSaveDialog_SetOptions(pfsd, invalid_fos[i]);
ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
hr = IFileSaveDialog_GetOptions(pfsd, &fdoptions);
ok(hr == S_OK, "got 0x%08x.\n", hr);
ok(fdoptions == (FOS_OVERWRITEPROMPT | FOS_NOREADONLYRETURN | FOS_PATHMUSTEXIST | FOS_NOCHANGEDIR),
"got %08x\n", fdoptions);
}
/* GetResult */
hr = IFileOpenDialog_GetResult(pfod, NULL);
ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);