From 3756ae7c8dc60d459511d0b067ebef5efb052746 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Wed, 10 Aug 2022 19:24:24 -0500 Subject: Use IFileOpenDialog instead of SHBrowseForFolder and GetOpenFileName. It is the recommended option since Vista and has better long path support. --- src/libs/dutil/WixToolset.DUtil/thmutil.cpp | 67 +++++++++++++---------------- 1 file changed, 30 insertions(+), 37 deletions(-) (limited to 'src/libs/dutil/WixToolset.DUtil/thmutil.cpp') diff --git a/src/libs/dutil/WixToolset.DUtil/thmutil.cpp b/src/libs/dutil/WixToolset.DUtil/thmutil.cpp index 52a52a1e..f7f7c5b6 100644 --- a/src/libs/dutil/WixToolset.DUtil/thmutil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/thmutil.cpp @@ -4992,54 +4992,47 @@ static void OnBrowseDirectory( ) { HRESULT hr = S_OK; - WCHAR wzPath[MAX_PATH] = { }; - BROWSEINFOW browseInfo = { }; - PIDLIST_ABSOLUTE pidl = NULL; + LPWSTR sczPath = NULL; + THEME_CONTROL* pTargetControl = NULL; + BOOL fSetVariable = NULL != pTheme->pfnSetStringVariable; - browseInfo.hwndOwner = pTheme->hwndParent; - browseInfo.pszDisplayName = wzPath; - browseInfo.lpszTitle = pTheme->sczCaption; - browseInfo.ulFlags = BIF_RETURNONLYFSDIRS | BIF_USENEWUI; - pidl = ::SHBrowseForFolderW(&browseInfo); - if (pidl && ::SHGetPathFromIDListW(pidl, wzPath)) + hr = WnduShowOpenFolderDialog(pTheme->hwndParent, TRUE, pTheme->sczCaption, &sczPath); + if (HRESULT_FROM_WIN32(ERROR_CANCELLED) == hr) { - // Since editbox changes aren't immediately saved off, we have to treat them differently. - THEME_CONTROL* pTargetControl = NULL; - BOOL fSetVariable = NULL != pTheme->pfnSetStringVariable; - - for (DWORD i = 0; i < pTheme->cControls; ++i) - { - THEME_CONTROL* pControl = pTheme->rgControls + i; - - if ((!pControl->wPageId || pControl->wPageId == pTheme->dwCurrentPageId) && - CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pControl->sczName, -1, pAction->BrowseDirectory.sczVariableName, -1)) - { - pTargetControl = pControl; - break; - } - } + ExitFunction(); + } + ThmExitOnFailure(hr, "Failed to prompt user for directory."); - if (pTargetControl && !pTargetControl->fDisableAutomaticFunctionality && (!fSetVariable || THEME_CONTROL_TYPE_EDITBOX == pTargetControl->type)) - { - fSetVariable = FALSE; - hr = ThemeSetTextControl(pTargetControl, wzPath); - ThmExitOnFailure(hr, "Failed to set text on control: %ls", pTargetControl->sczName); - } + for (DWORD i = 0; i < pTheme->cControls; ++i) + { + THEME_CONTROL* pControl = pTheme->rgControls + i; - if (fSetVariable) + if ((!pControl->wPageId || pControl->wPageId == pTheme->dwCurrentPageId) && + CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pControl->sczName, -1, pAction->BrowseDirectory.sczVariableName, -1)) { - hr = pTheme->pfnSetStringVariable(pAction->BrowseDirectory.sczVariableName, wzPath, FALSE, pTheme->pvVariableContext); - ThmExitOnFailure(hr, "Failed to set variable: %ls", pAction->BrowseDirectory.sczVariableName); + pTargetControl = pControl; + break; } + } - ThemeShowPageEx(pTheme, pTheme->dwCurrentPageId, SW_SHOW, THEME_SHOW_PAGE_REASON_REFRESH); + // Since editbox changes aren't immediately saved off, we have to treat them differently. + if (pTargetControl && !pTargetControl->fDisableAutomaticFunctionality && (!fSetVariable || THEME_CONTROL_TYPE_EDITBOX == pTargetControl->type)) + { + fSetVariable = FALSE; + hr = ThemeSetTextControl(pTargetControl, sczPath); + ThmExitOnFailure(hr, "Failed to set text on control: %ls", pTargetControl->sczName); } -LExit: - if (pidl) + if (fSetVariable) { - ::CoTaskMemFree(pidl); + hr = pTheme->pfnSetStringVariable(pAction->BrowseDirectory.sczVariableName, sczPath, FALSE, pTheme->pvVariableContext); + ThmExitOnFailure(hr, "Failed to set variable: %ls", pAction->BrowseDirectory.sczVariableName); } + + ThemeShowPageEx(pTheme, pTheme->dwCurrentPageId, SW_SHOW, THEME_SHOW_PAGE_REASON_REFRESH); + +LExit: + ReleaseStr(sczPath); } static BOOL OnButtonClicked( -- cgit v1.2.3-55-g6feb