From 7d56566b7c51c49ded526466dfae6af9e1709040 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Fri, 13 May 2022 13:49:57 -0500 Subject: Update balutil and Bal.wixext to use more concise Exit* macros. --- src/ext/Bal/dnchost/dnchost.cpp | 27 +++----- src/ext/Bal/mbahost/mbahost.cpp | 18 ++--- .../WixStandardBootstrapperApplication.cpp | 78 ++++++++-------------- 3 files changed, 44 insertions(+), 79 deletions(-) (limited to 'src/ext') diff --git a/src/ext/Bal/dnchost/dnchost.cpp b/src/ext/Bal/dnchost/dnchost.cpp index dcc9fa56..644ba30e 100644 --- a/src/ext/Bal/dnchost/dnchost.cpp +++ b/src/ext/Bal/dnchost/dnchost.cpp @@ -168,21 +168,16 @@ static HRESULT LoadDncConfiguration( IXMLDOMNode* pixnHost = NULL; LPWSTR sczPayloadName = NULL; DWORD dwBool = 0; + BOOL fXmlFound = FALSE; hr = XmlLoadDocumentFromFile(pArgs->pCommand->wzBootstrapperApplicationDataPath, &pixdManifest); BalExitOnFailure(hr, "Failed to load BalManifest '%ls'", pArgs->pCommand->wzBootstrapperApplicationDataPath); hr = XmlSelectSingleNode(pixdManifest, L"/BootstrapperApplicationData/WixBalBAFactoryAssembly", &pixnHost); - BalExitOnFailure(hr, "Failed to get WixBalBAFactoryAssembly element."); - - if (S_FALSE == hr) - { - hr = E_NOTFOUND; - BalExitOnRootFailure(hr, "Failed to find WixBalBAFactoryAssembly element in bootstrapper application config."); - } + BalExitOnRequiredXmlQueryFailure(hr, "Failed to get WixBalBAFactoryAssembly element."); hr = XmlGetAttributeEx(pixnHost, L"FilePath", &sczPayloadName); - BalExitOnFailure(hr, "Failed to get WixBalBAFactoryAssembly/@FilePath."); + BalExitOnRequiredXmlQueryFailure(hr, "Failed to get WixBalBAFactoryAssembly/@FilePath."); hr = PathConcat(pArgs->pCommand->wzBootstrapperWorkingFolder, sczPayloadName, &pState->sczBaFactoryAssemblyPath); BalExitOnFailure(hr, "Failed to create BaFactoryAssemblyPath."); @@ -212,22 +207,20 @@ static HRESULT LoadDncConfiguration( pState->type = DNCHOSTTYPE_FDD; hr = XmlSelectSingleNode(pixdManifest, L"/BootstrapperApplicationData/WixDncOptions", &pixnHost); - if (S_FALSE == hr) + BalExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to find WixDncOptions element in bootstrapper application config."); + + if (!fXmlFound) { - ExitFunction1(hr = S_OK); + ExitFunction(); } - BalExitOnFailure(hr, "Failed to find WixDncOptions element in bootstrapper application config."); hr = XmlGetAttributeNumber(pixnHost, L"SelfContainedDeployment", &dwBool); - if (S_FALSE == hr) - { - hr = S_OK; - } - else if (SUCCEEDED(hr) && dwBool) + BalExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get SelfContainedDeployment value."); + + if (fXmlFound && dwBool) { pState->type = DNCHOSTTYPE_SCD; } - BalExitOnFailure(hr, "Failed to get SelfContainedDeployment value."); LExit: ReleaseStr(sczPayloadName); diff --git a/src/ext/Bal/mbahost/mbahost.cpp b/src/ext/Bal/mbahost/mbahost.cpp index 735f9f21..a9585389 100644 --- a/src/ext/Bal/mbahost/mbahost.cpp +++ b/src/ext/Bal/mbahost/mbahost.cpp @@ -290,7 +290,7 @@ static HRESULT CheckSupportedFrameworks( while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, NULL))) { hr = XmlGetAttributeEx(pNode, L"version", &sczSupportedFrameworkVersion); - ExitOnFailure(hr, "Failed to get supportedFramework/@version."); + ExitOnRequiredXmlQueryFailure(hr, "Failed to get supportedFramework/@version."); hr = StrAllocFormatted(&sczFrameworkRegistryKey, L"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\%ls", sczSupportedFrameworkVersion); ExitOnFailure(hr, "Failed to allocate path to supported framework Install registry key."); @@ -351,27 +351,23 @@ static HRESULT UpdateSupportedRuntime( LPWSTR sczSupportedRuntimeVersion = NULL; IXMLDOMNode* pixnStartup = NULL; IXMLDOMNode* pixnSupportedRuntime = NULL; + BOOL fXmlFound = FALSE; *pfUpdatedManifest = FALSE; // If the runtime version attribute is not specified, don't update the manifest. hr = XmlGetAttributeEx(pixnSupportedFramework, L"runtimeVersion", &sczSupportedRuntimeVersion); - if (E_NOTFOUND == hr) + ExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get supportedFramework/@runtimeVersion."); + + if (!fXmlFound) { - ExitFunction1(hr = S_OK); + ExitFunction(); } - ExitOnFailure(hr, "Failed to get supportedFramework/@runtimeVersion."); // Get the startup element. Fail if we can't find it since it'll be necessary to load the // correct runtime. hr = XmlSelectSingleNode(pixdManifest, L"/configuration/startup", &pixnStartup); - ExitOnFailure(hr, "Failed to get startup element."); - - if (S_FALSE == hr) - { - hr = E_NOTFOUND; - ExitOnRootFailure(hr, "Failed to find startup element in bootstrapper application config."); - } + ExitOnRequiredXmlQueryFailure(hr, "Failed to get startup element."); // Remove any pre-existing supported runtimes because they'll just get in the way and create our new one. hr = XmlRemoveChildren(pixnStartup, L"supportedRuntime"); diff --git a/src/ext/Bal/wixstdba/WixStandardBootstrapperApplication.cpp b/src/ext/Bal/wixstdba/WixStandardBootstrapperApplication.cpp index c89d12c4..dd00a563 100644 --- a/src/ext/Bal/wixstdba/WixStandardBootstrapperApplication.cpp +++ b/src/ext/Bal/wixstdba/WixStandardBootstrapperApplication.cpp @@ -2603,95 +2603,70 @@ private: HRESULT hr = S_OK; IXMLDOMNode* pNode = NULL; DWORD dwBool = 0; + BOOL fXmlFound = FALSE; hr = XmlSelectSingleNode(pixdManifest, L"/BootstrapperApplicationData/WixStdbaInformation", &pNode); - if (S_FALSE == hr) - { - hr = E_INVALIDARG; - } - BalExitOnFailure(hr, "BootstrapperApplication.xml manifest is missing wixstdba information."); + BalExitOnRequiredXmlQueryFailure(hr, "BootstrapperApplication.xml manifest is missing wixstdba information."); hr = XmlGetAttributeEx(pNode, L"LicenseFile", &m_sczLicenseFile); - if (E_NOTFOUND == hr) - { - hr = S_OK; - } - BalExitOnFailure(hr, "Failed to get license file."); + BalExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get license file."); hr = XmlGetAttributeEx(pNode, L"LicenseUrl", &m_sczLicenseUrl); - if (E_NOTFOUND == hr) - { - hr = S_OK; - } - BalExitOnFailure(hr, "Failed to get license URL."); + BalExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get license URL."); ReleaseObject(pNode); hr = XmlSelectSingleNode(pixdManifest, L"/BootstrapperApplicationData/WixStdbaOptions", &pNode); - if (S_FALSE == hr) + BalExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to read wixstdba options from BootstrapperApplication.xml manifest."); + + if (!fXmlFound) { - ExitFunction1(hr = S_OK); + ExitFunction(); } - BalExitOnFailure(hr, "Failed to read wixstdba options from BootstrapperApplication.xml manifest."); hr = XmlGetAttributeNumber(pNode, L"SuppressOptionsUI", &dwBool); - if (S_FALSE == hr) - { - hr = S_OK; - } - else if (SUCCEEDED(hr) && dwBool) + BalExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get SuppressOptionsUI value."); + + if (fXmlFound && dwBool) { hr = BalSetNumericVariable(WIXSTDBA_VARIABLE_SUPPRESS_OPTIONS_UI, 1); BalExitOnFailure(hr, "Failed to set '%ls' variable.", WIXSTDBA_VARIABLE_SUPPRESS_OPTIONS_UI); } - BalExitOnFailure(hr, "Failed to get SuppressOptionsUI value."); dwBool = 0; hr = XmlGetAttributeNumber(pNode, L"SuppressDowngradeFailure", &dwBool); - if (S_FALSE == hr) - { - hr = S_OK; - } - else if (SUCCEEDED(hr)) + BalExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get SuppressDowngradeFailure value."); + + if (fXmlFound) { m_fSuppressDowngradeFailure = 0 < dwBool; } - BalExitOnFailure(hr, "Failed to get SuppressDowngradeFailure value."); dwBool = 0; hr = XmlGetAttributeNumber(pNode, L"SuppressRepair", &dwBool); - if (S_FALSE == hr) - { - hr = S_OK; - } - else if (SUCCEEDED(hr)) + BalExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get SuppressRepair value."); + + if (fXmlFound) { m_fSuppressRepair = 0 < dwBool; } - BalExitOnFailure(hr, "Failed to get SuppressRepair value."); hr = XmlGetAttributeNumber(pNode, L"ShowVersion", &dwBool); - if (S_FALSE == hr) - { - hr = S_OK; - } - else if (SUCCEEDED(hr) && dwBool) + BalExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get ShowVersion value."); + + if (fXmlFound && dwBool) { hr = BalSetNumericVariable(WIXSTDBA_VARIABLE_SHOW_VERSION, 1); BalExitOnFailure(hr, "Failed to set '%ls' variable.", WIXSTDBA_VARIABLE_SHOW_VERSION); } - BalExitOnFailure(hr, "Failed to get ShowVersion value."); hr = XmlGetAttributeNumber(pNode, L"SupportCacheOnly", &dwBool); - if (S_FALSE == hr) - { - hr = S_OK; - } - else if (SUCCEEDED(hr)) + BalExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get SupportCacheOnly value."); + + if (fXmlFound) { m_fSupportCacheOnly = 0 < dwBool; } - BalExitOnFailure(hr, "Failed to get SupportCacheOnly value."); LExit: ReleaseObject(pNode); @@ -4149,17 +4124,18 @@ LExit: LPWSTR sczBafPath = NULL; BA_FUNCTIONS_CREATE_ARGS bafCreateArgs = { }; BA_FUNCTIONS_CREATE_RESULTS bafCreateResults = { }; + BOOL fXmlFound = FALSE; hr = XmlSelectSingleNode(pixdManifest, L"/BootstrapperApplicationData/WixBalBAFunctions", &pBAFunctionsNode); - BalExitOnFailure(hr, "Failed to read WixBalBAFunctions node from BootstrapperApplicationData.xml."); + BalExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to read WixBalBAFunctions node from BootstrapperApplicationData.xml."); - if (S_FALSE == hr) + if (!fXmlFound) { ExitFunction(); } hr = XmlGetAttributeEx(pBAFunctionsNode, L"FilePath", &sczBafName); - BalExitOnFailure(hr, "Failed to get BAFunctions FilePath."); + BalExitOnRequiredXmlQueryFailure(hr, "Failed to get BAFunctions FilePath."); hr = PathRelativeToModule(&sczBafPath, sczBafName, m_hModule); BalExitOnFailure(hr, "Failed to get path to BAFunctions DLL."); -- cgit v1.2.3-55-g6feb