From dce1c97c7d3e76c18e4f80d4ffe288d2933a74bc Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Wed, 27 Oct 2021 15:29:19 -0500 Subject: Make thmutil automatically load controls during window creation. Add control loaded event. --- .../WixStandardBootstrapperApplication.cpp | 188 +++++++++++++-------- 1 file changed, 114 insertions(+), 74 deletions(-) (limited to 'src/ext') diff --git a/src/ext/Bal/wixstdba/WixStandardBootstrapperApplication.cpp b/src/ext/Bal/wixstdba/WixStandardBootstrapperApplication.cpp index 2283880c..5546b74f 100644 --- a/src/ext/Bal/wixstdba/WixStandardBootstrapperApplication.cpp +++ b/src/ext/Bal/wixstdba/WixStandardBootstrapperApplication.cpp @@ -2389,6 +2389,11 @@ private: hr = ThemeRegisterVariableCallbacks(m_pTheme, EvaluateVariableConditionCallback, FormatVariableStringCallback, GetVariableNumericCallback, SetVariableNumericCallback, GetVariableStringCallback, SetVariableStringCallback, NULL); BalExitOnFailure(hr, "Failed to register variable theme callbacks."); + C_ASSERT(COUNT_WIXSTDBA_PAGE == countof(vrgwzPageNames)); + C_ASSERT(countof(m_rgdwPageIds) == countof(vrgwzPageNames)); + + ThemeGetPageIds(m_pTheme, vrgwzPageNames, m_rgdwPageIds, countof(m_rgdwPageIds)); + hr = ThemeLocalize(m_pTheme, m_pWixLoc); BalExitOnFailure(hr, "Failed to localize theme: %ls", sczThemePath); @@ -2697,6 +2702,8 @@ private: hr = ThemeCreateParentWindow(m_pTheme, 0, wc.lpszClassName, m_pTheme->sczCaption, dwWindowStyle, x, y, HWND_DESKTOP, m_hModule, this, THEME_WINDOW_INITIAL_POSITION_CENTER_MONITOR_FROM_COORDINATES, &m_hWnd); ExitOnFailure(hr, "Failed to create window."); + OnThemeLoaded(); + hr = S_OK; LExit: @@ -2831,16 +2838,12 @@ private: return lres; } - case WM_CREATE: - if (!pBA->OnCreate(hWnd)) - { - return -1; - } - break; - case WM_THMUTIL_LOADING_CONTROL: return pBA->OnThemeLoadingControl(reinterpret_cast(wParam), reinterpret_cast(lParam)); + case WM_THMUTIL_LOADED_CONTROL: + return pBA->OnThemeLoadedControl(reinterpret_cast(wParam), reinterpret_cast(lParam)); + case WM_QUERYENDSESSION: fCancel = true; pBA->OnSystemShutdown(static_cast(lParam), &fCancel); @@ -2896,74 +2899,14 @@ private: // - // OnCreate - finishes loading the theme. + // OnThemeLoaded - finishes loading the theme. // - BOOL OnCreate( - __in HWND /*hWnd*/ - ) + BOOL OnThemeLoaded() { HRESULT hr = S_OK; - LPWSTR sczLicenseFormatted = NULL; - LPWSTR sczLicensePath = NULL; - LPWSTR sczLicenseDirectory = NULL; - LPWSTR sczLicenseFilename = NULL; BA_FUNCTIONS_ONTHEMELOADED_ARGS themeLoadedArgs = { }; BA_FUNCTIONS_ONTHEMELOADED_RESULTS themeLoadedResults = { }; - hr = ThemeLoadControls(m_pTheme); - BalExitOnFailure(hr, "Failed to load theme controls."); - - C_ASSERT(COUNT_WIXSTDBA_PAGE == countof(vrgwzPageNames)); - C_ASSERT(countof(m_rgdwPageIds) == countof(vrgwzPageNames)); - - ThemeGetPageIds(m_pTheme, vrgwzPageNames, m_rgdwPageIds, countof(m_rgdwPageIds)); - - // Load the RTF EULA control with text if the control exists. - if (ThemeControlExists(m_pTheme, WIXSTDBA_CONTROL_EULA_RICHEDIT)) - { - hr = (m_sczLicenseFile && *m_sczLicenseFile) ? S_OK : E_INVALIDDATA; - if (SUCCEEDED(hr)) - { - hr = StrAllocString(&sczLicenseFormatted, m_sczLicenseFile, 0); - if (SUCCEEDED(hr)) - { - hr = LocLocalizeString(m_pWixLoc, &sczLicenseFormatted); - if (SUCCEEDED(hr)) - { - // Assume there is no hidden variables to be formatted - // so don't worry about securely freeing it. - hr = BalFormatString(sczLicenseFormatted, &sczLicenseFormatted); - if (SUCCEEDED(hr)) - { - hr = PathRelativeToModule(&sczLicensePath, sczLicenseFormatted, m_hModule); - if (SUCCEEDED(hr)) - { - hr = PathGetDirectory(sczLicensePath, &sczLicenseDirectory); - if (SUCCEEDED(hr)) - { - hr = StrAllocString(&sczLicenseFilename, PathFile(sczLicenseFormatted), 0); - if (SUCCEEDED(hr)) - { - hr = LocProbeForFile(sczLicenseDirectory, sczLicenseFilename, m_sczLanguage, &sczLicensePath); - if (SUCCEEDED(hr)) - { - hr = ThemeLoadRichEditFromFile(m_pTheme, WIXSTDBA_CONTROL_EULA_RICHEDIT, sczLicensePath, m_hModule); - } - } - } - } - } - } - } - } - - if (FAILED(hr)) - { - BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Failed to load file into license richedit control from path '%ls' manifest value: %ls", sczLicensePath, m_sczLicenseFile); - hr = S_OK; - } - } - if (m_pfnBAFunctionsProc) { themeLoadedArgs.cbSize = sizeof(themeLoadedArgs); @@ -2975,11 +2918,6 @@ private: } LExit: - ReleaseStr(sczLicenseFilename); - ReleaseStr(sczLicenseDirectory); - ReleaseStr(sczLicensePath); - ReleaseStr(sczLicenseFormatted); - return SUCCEEDED(hr); } @@ -3034,6 +2972,108 @@ private: return fProcessed || FAILED(hr); } + BOOL OnThemeLoadedControl( + __in const THEME_LOADEDCONTROL_ARGS* pArgs, + __in THEME_LOADEDCONTROL_RESULTS* pResults + ) + { + HRESULT hr = S_OK; + BOOL fProcessed = FALSE; + BA_FUNCTIONS_ONTHEMECONTROLLOADED_ARGS themeControlLoadedArgs = { }; + BA_FUNCTIONS_ONTHEMECONTROLLOADED_RESULTS themeControlLoadedResults = { }; + + if (WIXSTDBA_CONTROL_EULA_RICHEDIT == pArgs->pThemeControl->wId) + { + // Best effort to load the RTF EULA control with text. + OnLoadedEulaRtfControl(pArgs->pThemeControl); + fProcessed = TRUE; + ExitFunction(); + } + + if (m_pfnBAFunctionsProc) + { + themeControlLoadedArgs.cbSize = sizeof(themeControlLoadedArgs); + themeControlLoadedArgs.wzName = pArgs->pThemeControl->sczName; + themeControlLoadedArgs.wId = pArgs->pThemeControl->wId; + themeControlLoadedArgs.hWnd = pArgs->pThemeControl->hWnd; + + themeControlLoadedResults.cbSize = sizeof(themeControlLoadedResults); + + hr = m_pfnBAFunctionsProc(BA_FUNCTIONS_MESSAGE_ONTHEMECONTROLLOADED, &themeControlLoadedArgs, &themeControlLoadedResults, m_pvBAFunctionsProcContext); + + if (E_NOTIMPL == hr) + { + hr = S_OK; + } + else + { + BalExitOnFailure(hr, "BAFunctions OnThemeControlLoaded failed."); + + if (themeControlLoadedResults.fProcessed) + { + fProcessed = TRUE; + } + } + } + + LExit: + pResults->hr = hr; + return fProcessed || FAILED(hr); + } + + HRESULT OnLoadedEulaRtfControl( + const THEME_CONTROL* pThemeControl + ) + { + HRESULT hr = S_OK; + LPWSTR sczLicenseFormatted = NULL; + LPWSTR sczLicensePath = NULL; + LPWSTR sczLicenseDirectory = NULL; + LPWSTR sczLicenseFilename = NULL; + + if (!m_sczLicenseFile || !*m_sczLicenseFile) + { + ExitWithRootFailure(hr, E_INVALIDDATA, "No license file in manifest."); + } + + hr = StrAllocString(&sczLicenseFormatted, m_sczLicenseFile, 0); + ExitOnFailure(hr, "Failed to copy manifest license file."); + + hr = LocLocalizeString(m_pWixLoc, &sczLicenseFormatted); + ExitOnFailure(hr, "Failed to localize manifest license file."); + + hr = BalFormatString(sczLicenseFormatted, &sczLicenseFormatted); + ExitOnFailure(hr, "Failed to expand localized manifest license file."); + + hr = PathRelativeToModule(&sczLicensePath, sczLicenseFormatted, m_hModule); + ExitOnFailure(hr, "Failed to get relative path for license file."); + + hr = PathGetDirectory(sczLicensePath, &sczLicenseDirectory); + ExitOnFailure(hr, "Failed to get license file directory."); + + hr = StrAllocString(&sczLicenseFilename, PathFile(sczLicenseFormatted), 0); + ExitOnFailure(hr, "Failed to copy license file name."); + + hr = LocProbeForFile(sczLicenseDirectory, sczLicenseFilename, m_sczLanguage, &sczLicensePath); + ExitOnFailure(hr, "Failed to probe for localized license file."); + + hr = ThemeLoadRichEditFromFile(m_pTheme, pThemeControl->wId, sczLicensePath, m_hModule); + ExitOnFailure(hr, "Failed to load license file into richedit control."); + + LExit: + if (FAILED(hr)) + { + BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Failed to load file into license richedit control from path '%ls' manifest value: %ls", sczLicensePath, m_sczLicenseFile); + } + + ReleaseStr(sczLicenseFilename); + ReleaseStr(sczLicenseDirectory); + ReleaseStr(sczLicensePath); + ReleaseStr(sczLicenseFormatted); + + return hr; + } + // // OnShowFailure - display the failure page. -- cgit v1.2.3-55-g6feb