Question

I'm working on a burn bootstrapper that needs to download prerequisites from a http repository that require authentication. So, how I should handle this request?

Thanks!

Was it helpful?

Solution

Got it! This can be achieved on OnResolveSource() event:

// variable used for authentication
static const LPCWSTR WIXSTDBA_VARIABLE_HTTP_DOWNLOAD_USER = L"HTTPDownloadUserName";
static const LPCWSTR WIXSTDBA_VARIABLE_HTTP_DOWNLOAD_PASS = L"HTTPDownloadPassword";

virtual STDMETHODIMP_(int) OnResolveSource(
    __in_z LPCWSTR wzPackageOrContainerId,
    __in_z_opt LPCWSTR wzPayloadId,
    __in_z LPCWSTR wzLocalSource,
    __in_z_opt LPCWSTR wzDownloadSource
    )
{
    int nResult = IDERROR; // assume we won't resolve source and that is unexpected.

    LPWSTR sczHTTPDwnUserName = NULL;
    LPWSTR sczHTTPDwnPassword = NULL;
    BOOL bUseHTTPAuth = FALSE;

    if (BalStringVariableExists(WIXSTDBA_VARIABLE_HTTP_DOWNLOAD_USER))
    {
        HRESULT hrUsr = BalGetStringVariable(WIXSTDBA_VARIABLE_HTTP_DOWNLOAD_USER, &sczHTTPDwnUserName);
        HRESULT hrPwd = BalGetStringVariable(WIXSTDBA_VARIABLE_HTTP_DOWNLOAD_PASS, &sczHTTPDwnPassword);
        if (SUCCEEDED(hrUsr) && SUCCEEDED(hrPwd)) bUseHTTPAuth = TRUE;
    }

    if (BOOTSTRAPPER_DISPLAY_FULL == m_command.display)
    {
        if (wzDownloadSource)
        {
            if (bUseHTTPAuth)
            {
                HRESULT hr = m_pEngine->SetDownloadSource(wzPackageOrContainerId, wzPayloadId, wzDownloadSource, sczHTTPDwnUserName, sczHTTPDwnPassword);
                nResult = SUCCEEDED(hr) ? IDDOWNLOAD : IDERROR;
            } 
            else
                nResult = IDDOWNLOAD;
        }
        else // prompt to change the source location.
        {
            // related stuff
        }
    }
    else if (wzDownloadSource)
    {
        // If doing a non-interactive install and download source is available, let's try downloading the package silently
        if (bUseHTTPAuth)
        {
            HRESULT hr = m_pEngine->SetDownloadSource(wzPackageOrContainerId, wzPayloadId, wzDownloadSource, sczHTTPDwnUserName, sczHTTPDwnPassword);
            nResult = SUCCEEDED(hr) ? IDRETRY : IDERROR;
        } 
        else
            nResult = IDDOWNLOAD;
    }
    // else there's nothing more we can do in non-interactive mode

    return CheckCanceled() ? IDCANCEL : nResult;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top