Rob, your response inspired me to modify wixstdba to add the logging feature
I wanted. I was able to do this and removed the need for custom actions in
my MSI's and forcing all my XP users to upgrade to Windows Installer 4.5.
I've posted the code change to wixstdba below for comments and criticism.
While getting wixstdba to build I noticed that the .vcxproj file only
contained a Debug configuration. Since VS generates a Release configuration
by default it would appear some effort was expended to remove it.

Is there a problem with building wixstdba with a normal Release
configuration?

Does this mean that WiX releases contain a Debug build of wixstdba?

My code changes involved adding the following to OnShutdown juist before the
return statement:

        if (FAILED(m_hrFinal))
          VtmCopyLogfiles();

The new code is:

    // VtmCopyOneLogFile
    // Copy the log file described by the variable logVariableName to
vtmLogFileDir
    void VtmCopyOneLogFile(__in LPCWSTR logVariableName, LPCWSTR
vtmLogFileDir)
    {
      HRESULT hr = S_OK;
      LPWSTR sczLogFile = NULL;
      LPWSTR copyLogFile = NULL;
      LPWSTR pwzFullPath = NULL;
      int fullPathLen = 0;
      LPWSTR wzFileName = NULL;

      if (logVariableName && *logVariableName)
      {
        hr = BalGetStringVariable(logVariableName, &sczLogFile);
        BalExitOnFailure1(hr, "Failed to get log file variable '%ls'.",
logVariableName);
        // Get the file name part (wzFileName) from sczLogFile
        // DW Jun 22/12 - not sure if this is the best way but
GetFullPathNameW is used elsewhere in WiX.
        hr = StrAlloc(&pwzFullPath, MAX_PATH);
        BalExitOnFailure(hr, "Failed to allocate space for full path.");
        fullPathLen = ::GetFullPathNameW(sczLogFile, MAX_PATH, pwzFullPath,
&wzFileName);
        if (fullPathLen == 0 || fullPathLen >= MAX_PATH)
        {
          // Set a return code - this isn't technically correct for the
fullPathLen == 0 case but will do
          // until it is clear there is a need to distiguish these failures
which are unlikely to occur.
          hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
          BalExitOnFailure1(hr, "FAILED to extract file name from %ls",
sczLogFile);
        }
        hr = StrAllocFormatted(&copyLogFile, L"%ls%ls", vtmLogFileDir,
wzFileName);
        BalExitOnFailure(hr, "Failed to format copy file path.");
        if (CopyFileW(sczLogFile, copyLogFile, FALSE))
          BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Copied: %ls",
sczLogFile);
        else
          BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "FAILED to copy: %ls",
sczLogFile);
      }
LExit:
      ReleaseStr(copyLogFile);
      ReleaseStr(pwzFullPath);
      ReleaseStr(sczLogFile);
      return;
    }

    // VtmCopyLogfiles
    // Copy the bundle and package log files to "C:\mypath\common\setups\"
    void VtmCopyLogfiles()
    {
      HRESULT hr = S_OK;
      LPCWSTR vtmLogFileDir = L"C:\\mypath\\common\\setups\\";
      LPWSTR bundleLogVariableName = NULL;

      BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "ATTENTION: Start Copying log
files to mypath. Result Code: 0x%08x", m_hrFinal);
      hr = DirEnsureExists(vtmLogFileDir, NULL);
      BalExitOnFailure1(hr, "FAILED to create log file directory: '%ls'.",
vtmLogFileDir);
      BAL_INFO_PACKAGE* pInfoPackages = m_Bundle.packages.rgPackages;
      int infoPackagesCount = m_Bundle.packages.cPackages;
      VtmCopyOneLogFile(m_Bundle.sczLogVariable, vtmLogFileDir); // Copy the
bundle log the first time.
      for (int i = 0; i < infoPackagesCount; i++)
      {
        // Create the standard variable name for the package log file. This
code will work only if the
        // variable names have NOT been customized using the LogPathVariable
attribute for the package.
        hr = StrAllocFormatted(&bundleLogVariableName, L"WixBundleLog_%ls",
pInfoPackages[i].sczId);
        BalExitOnFailure(hr, "Failed to format bundle log variable name.");
        VtmCopyOneLogFile(bundleLogVariableName, vtmLogFileDir);
      }
      // Update the copy of the bundle log. We copied it above to increase
the chances that we'll have a
      // copy of the log already if something goes wrong during the copying
of the package log files. We
      // update it here to make it as complete as possible. It will still be
missing the tail end of the
      // full bundle log, including the dump of the bundle variables.
      VtmCopyOneLogFile(m_Bundle.sczLogVariable, vtmLogFileDir);
LExit:
      BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "ATTENTION: End Copying log
files to mypath.");
      ReleaseStr(bundleLogVariableName);
    }



--
View this message in context: 
http://windows-installer-xml-wix-toolset.687559.n2.nabble.com/Burn-and-Msi-logging-revisited-tp7578871p7579212.html
Sent from the wix-users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
WiX-users mailing list
WiX-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wix-users

Reply via email to