From 318784fc1b85c6efdb4281f5ad6f20b51edb311f Mon Sep 17 00:00:00 2001 From: PB Date: Sat, 1 May 2021 09:19:29 +0200 Subject: [PATCH] Handle invalid paths better in MSW wxDirDialog When setting a path including an invalid drive in IFileDialog-based wxDirDialog, Windows returned ERROR_INVALID_DRIVE error. wxWidgets treated this as an error and reverted to showing the old ShowSHBrowseForFolder()-based dialog. However, it is better to just ignore any errors produced when attempting to set the default folder (as the code already did for ERROR_FILE_NOT_FOUND) and show IFileDialog-based dialog anyway. Closes https://github.com/wxWidgets/wxWidgets/pull/2356 --- src/msw/dirdlg.cpp | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/msw/dirdlg.cpp b/src/msw/dirdlg.cpp index 87328553af..44431a43dd 100644 --- a/src/msw/dirdlg.cpp +++ b/src/msw/dirdlg.cpp @@ -360,25 +360,14 @@ bool InitIFileOpenDialog(const wxString& message, const wxString& defaultPath, wxIID_PPV_ARGS(IShellItem, &folder)); - // Failing to parse the folder name is not really an error, we'll just - // ignore the initial directory in this case, but we should still show - // the dialog. - if ( FAILED(hr) ) - { - if ( hr != HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) ) - { - wxLogApiError(wxS("SHCreateItemFromParsingName"), hr); - return false; - } - } - else // The folder was parsed correctly. + // Failing to parse the folder name or set it is not really an error, + // we'll just ignore the initial directory in this case, but we should + // still show the dialog. + if ( SUCCEEDED(hr) ) { hr = dlg->SetFolder(folder); if ( FAILED(hr) ) - { wxLogApiError(wxS("IFileOpenDialog::SetFolder"), hr); - return false; - } } }