예제 #1
0
파일: eseutil.cpp 프로젝트: BMurri/wix3
HRESULT DAPI EseBeginSession(
    __out JET_INSTANCE *pjiInstance,
    __out JET_SESID *pjsSession,
    __in_z LPCWSTR pszInstance,
    __in_z LPCWSTR pszPath
    )
{
    HRESULT hr = S_OK;
    JET_ERR jEr = JET_errSuccess;
    LPSTR pszAnsiInstance = NULL;
    LPSTR pszAnsiPath = NULL;

    hr = DirEnsureExists(pszPath, NULL);
    ExitOnFailure(hr, "Failed to ensure database directory exists");

    // Sigh. JETblue requires Vista and up for the wide character version of this function, so we'll convert to ANSI before calling,
    // likely breaking everyone with unicode characters in their path.
    hr = StrAnsiAllocString(&pszAnsiInstance, pszInstance, 0, CP_ACP);
    ExitOnFailure(hr, "Failed converting instance name to ansi");

    hr = StrAnsiAllocString(&pszAnsiPath, pszPath, 0, CP_ACP);
    ExitOnFailure(hr, "Failed converting session path name to ansi");

    jEr = JetCreateInstanceA(pjiInstance, pszAnsiInstance);
    ExitOnJetFailure(jEr, hr, "Failed to create instance");

    jEr = JetSetSystemParameter(pjiInstance, NULL, JET_paramSystemPath, NULL, pszAnsiPath);
    ExitOnJetFailure1(jEr, hr, "Failed to set jet system path to: %s", pszAnsiPath);

    // This makes sure log files that are created are created next to the database, not next to our EXE (note they last after execution)
    jEr = JetSetSystemParameter(pjiInstance, NULL, JET_paramLogFilePath, NULL, pszAnsiPath);
    ExitOnJetFailure1(jEr, hr, "Failed to set jet log file path to: %s", pszAnsiPath);

    jEr = JetSetSystemParameter(pjiInstance, NULL, JET_paramMaxOpenTables, 10, NULL);
    ExitOnJetFailure(jEr, hr, "Failed to set jet max open tables parameter");

    // TODO: Use callback hooks so that Jet Engine uses our memory allocation methods, etc.? (search docs for "JET_PFNREALLOC" - there are other callbacks too)

    jEr = JetInit(pjiInstance);
    ExitOnJetFailure(jEr, hr, "Failed to initialize jet engine instance");

    jEr = JetBeginSession(*pjiInstance, pjsSession, NULL, NULL);
    ExitOnJetFailure(jEr, hr, "Failed to begin jet session");

LExit:
    ReleaseStr(pszAnsiInstance);
    ReleaseStr(pszAnsiPath);

    return hr;
}
예제 #2
0
/*******************************************************************
 DirEnsureExists

*******************************************************************/
extern "C" HRESULT DAPI DirEnsureExists(
	__in LPCWSTR wzPath,
	__in_opt LPSECURITY_ATTRIBUTES psa
	)
{
	HRESULT hr = S_OK;
	UINT er;

	// try to create this directory
	if (!::CreateDirectoryW(wzPath, psa))
	{
		// if the directory already exists, bail
		er = ::GetLastError();
		if (ERROR_ALREADY_EXISTS == er)
			ExitFunction1(hr = S_OK);

		// get the parent path and try to create it
		LPWSTR pwzLastSlash = NULL;
		for (LPWSTR pwz = const_cast<LPWSTR>(wzPath); *pwz; pwz++)
			if (*pwz == L'\\')
				pwzLastSlash = pwz;

		// if there is no parent directory fail
		ExitOnNullDebugTrace(pwzLastSlash, hr, HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "cannot find parent path");

		*pwzLastSlash = L'\0';	// null terminate the parent path
		hr = DirEnsureExists(wzPath, psa);   // recurse!
		*pwzLastSlash = L'\\';  // put the slash back
		ExitOnFailureDebugTrace1(hr, "failed to create path: %S", wzPath);

		// try to create the directory now that all parents are created
		if (!::CreateDirectoryW(wzPath, psa))
		{
			// if the directory already exists for some reason no error
			er = ::GetLastError();
			if (ERROR_ALREADY_EXISTS == er)
				hr = S_FALSE;
			else
				hr = HRESULT_FROM_WIN32(er);
		}
		else
			hr = S_OK;
	}

LExit:
	return hr;
}
예제 #3
0
파일: payload.cpp 프로젝트: firegiant/wix4
extern "C" HRESULT PayloadExtractFromContainer(
    __in BURN_PAYLOADS* pPayloads,
    __in_opt BURN_CONTAINER* pContainer,
    __in BURN_CONTAINER_CONTEXT* pContainerContext,
    __in_z LPCWSTR wzTargetDir
    )
{
    HRESULT hr = S_OK;
    LPWSTR sczStreamName = NULL;
    LPWSTR sczDirectory = NULL;
    BURN_PAYLOAD* pPayload = NULL;

    // extract all payloads
    for (;;)
    {
        // get next stream
        hr = ContainerNextStream(pContainerContext, &sczStreamName);
        if (E_NOMOREITEMS == hr)
        {
            hr = S_OK;
            break;
        }
        ExitOnFailure(hr, "Failed to get next stream.");

        // find payload by stream name
        hr = FindEmbeddedBySourcePath(pPayloads, pContainer, sczStreamName, &pPayload);
        ExitOnFailure(hr, "Failed to find embedded payload: %ls", sczStreamName);

        // make file path
        hr = PathConcat(wzTargetDir, pPayload->sczFilePath, &pPayload->sczLocalFilePath);
        ExitOnFailure(hr, "Failed to concat file paths.");

        // extract file
        hr = PathGetDirectory(pPayload->sczLocalFilePath, &sczDirectory);
        ExitOnFailure(hr, "Failed to get directory portion of local file path");

        hr = DirEnsureExists(sczDirectory, NULL);
        ExitOnFailure(hr, "Failed to ensure directory exists");

        hr = ContainerStreamToFile(pContainerContext, pPayload->sczLocalFilePath);
        ExitOnFailure(hr, "Failed to extract file.");

        // flag that the payload has been acquired
        pPayload->state = BURN_PAYLOAD_STATE_ACQUIRED;
    }

    // locate any payloads that were not extracted
    for (DWORD i = 0; i < pPayloads->cPayloads; ++i)
    {
        pPayload = &pPayloads->rgPayloads[i];

        // if the payload is part of the container
        if (!pContainer || pPayload->pContainer == pContainer)
        {
            // if the payload has not been acquired
            if (BURN_PAYLOAD_STATE_ACQUIRED > pPayload->state)
            {
                hr = E_INVALIDDATA;
                ExitOnRootFailure(hr, "Payload was not found in container: %ls", pPayload->sczKey);
            }
        }
    }

LExit:
    ReleaseStr(sczStreamName);
    ReleaseStr(sczDirectory);

    return hr;
}