From 352aefb0ac67ffbf74cd126db710031d4944fe89 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Sun, 1 Nov 2020 16:43:59 -0600 Subject: WIXFEAT:3816-Format variables and respect absolute paths in Log/@Prefix --- src/engine/logging.cpp | 54 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/engine/logging.cpp b/src/engine/logging.cpp index a6412da9..e69303f0 100644 --- a/src/engine/logging.cpp +++ b/src/engine/logging.cpp @@ -33,6 +33,7 @@ extern "C" HRESULT LoggingOpen( { HRESULT hr = S_OK; LPWSTR sczLoggingBaseFolder = NULL; + LPWSTR sczPrefixFormatted = NULL; // Check if the logging policy is set and configure the logging appropriately. CheckLoggingPolicy(&pLog->dwAttributes); @@ -103,30 +104,50 @@ extern "C" HRESULT LoggingOpen( pLog->state = BURN_LOGGING_STATE_OPEN; } } - else if (pLog->sczPrefix && *pLog->sczPrefix) + else { - hr = GetNonSessionSpecificTempFolder(&sczLoggingBaseFolder); - ExitOnFailure(hr, "Failed to get non-session specific TEMP folder."); + if (pLog->sczPrefix && *pLog->sczPrefix) + { + hr = VariableFormatString(pVariables, pLog->sczPrefix, &sczPrefixFormatted, NULL); + } - // Best effort to open default logging. - hr = LogOpen(sczLoggingBaseFolder, pLog->sczPrefix, NULL, pLog->sczExtension, FALSE, FALSE, &pLog->sczPath); - if (FAILED(hr)) + if (sczPrefixFormatted && *sczPrefixFormatted) { - LogDisable(); - pLog->state = BURN_LOGGING_STATE_DISABLED; + LPCWSTR wzPrefix = sczPrefixFormatted; + + // Best effort to open default logging. + if (PathIsAbsolute(sczPrefixFormatted)) + { + hr = PathGetDirectory(sczPrefixFormatted, &sczLoggingBaseFolder); + ExitOnFailure(hr, "Failed to get parent directory from '%ls'.", sczPrefixFormatted); + + wzPrefix = PathFile(sczPrefixFormatted); + } + else + { + hr = GetNonSessionSpecificTempFolder(&sczLoggingBaseFolder); + ExitOnFailure(hr, "Failed to get non-session specific TEMP folder."); + } - hr = S_OK; + hr = LogOpen(sczLoggingBaseFolder, wzPrefix, NULL, pLog->sczExtension, FALSE, FALSE, &pLog->sczPath); + if (FAILED(hr)) + { + LogDisable(); + pLog->state = BURN_LOGGING_STATE_DISABLED; + + hr = S_OK; + } + else + { + pLog->state = BURN_LOGGING_STATE_OPEN; + } } - else + else // no logging enabled. { - pLog->state = BURN_LOGGING_STATE_OPEN; + LogDisable(); + pLog->state = BURN_LOGGING_STATE_DISABLED; } } - else // no logging enabled. - { - LogDisable(); - pLog->state = BURN_LOGGING_STATE_DISABLED; - } // If the log was opened, write the header info and update the prefix and extension to match // the log name so future logs are opened with the same pattern. @@ -155,6 +176,7 @@ extern "C" HRESULT LoggingOpen( LExit: ReleaseStr(sczLoggingBaseFolder); + StrSecureZeroFreeString(sczPrefixFormatted); return hr; } -- cgit v1.2.3-55-g6feb