Esempio n. 1
0
static HRESULT RemoveApplication(
    CPI_APPLICATION_ATTRIBUTES* pAttrs
)
{
    HRESULT hr = S_OK;

    ICatalogCollection* piAppColl = NULL;

    long lChanges = 0;

    // log
    WcaLog(LOGMSG_VERBOSE, "Removing application, key: %S", pAttrs->pwzKey);

    // get applications collection
    hr = CpiGetApplicationsCollection(pAttrs->pwzPartID, &piAppColl);
    ExitOnFailure(hr, "Failed to get applications collection");

    if (S_FALSE == hr)
    {
        // applications collection not found
        WcaLog(LOGMSG_VERBOSE, "Unable to retrieve applications collection, nothing to delete, key: %S", pAttrs->pwzKey);
        ExitFunction1(hr = S_OK);
    }

    // remove
    hr = CpiRemoveCollectionObject(piAppColl, pAttrs->pwzID, NULL, TRUE);
    ExitOnFailure(hr, "Failed to remove application");

    if (S_FALSE == hr)
    {
        // application not found
        WcaLog(LOGMSG_VERBOSE, "Application not found, nothing to delete, key: %S", pAttrs->pwzKey);
        ExitFunction1(hr = S_OK);
    }

    // save changes
    hr = piAppColl->SaveChanges(&lChanges);
    if (COMADMIN_E_OBJECTERRORS == hr)
        CpiLogCatalogErrorInfo();
    ExitOnFailure(hr, "Failed to save changes");

    // log
    WcaLog(LOGMSG_VERBOSE, "%d changes saved to catalog, key: %S", lChanges, pAttrs->pwzKey);

    hr = S_OK;

LExit:
    // clean up
    ReleaseObject(piAppColl);

    return hr;
}
Esempio n. 2
0
HRESULT CpiGetComponentsCollection(
	LPCWSTR pwzPartID,
	LPCWSTR pwzAppID,
	ICatalogCollection** ppiCompsColl
	)
{
	HRESULT hr = S_OK;

	ICatalogCollection* piAppColl = NULL;
	ICatalogObject* piAppObj = NULL;

	// get applications collection
	hr = CpiGetApplicationsCollection(pwzPartID, &piAppColl);
	ExitOnFailure(hr, "Failed to get applications collection");

	if (S_FALSE == hr)
		ExitFunction(); // applications collection not found, exit with hr = S_FALSE

	// find object
	hr = CpiFindCollectionObjectByStringKey(piAppColl, pwzAppID, &piAppObj);
	ExitOnFailure(hr, "Failed to find collection object");

	if (S_FALSE == hr)
		ExitFunction(); // application not found, exit with hr = S_FALSE

	// get components collection
	hr = CpiGetCatalogCollection(piAppColl, piAppObj, L"Components", ppiCompsColl);
	ExitOnFailure(hr, "Failed to get catalog collection");

	hr = S_OK;

LExit:
	// clean up
	ReleaseObject(piAppColl);
	ReleaseObject(piAppObj);

	return hr;
}
Esempio n. 3
0
static HRESULT CreateApplication(
    CPI_APPLICATION_ATTRIBUTES* pAttrs
)
{
    HRESULT hr = S_OK;

    ICatalogCollection* piAppColl = NULL;
    ICatalogObject* piAppObj = NULL;

    long lChanges = 0;

    // log
    WcaLog(LOGMSG_VERBOSE, "Creating application, key: %S", pAttrs->pwzKey);

    // get applications collection
    hr = CpiGetApplicationsCollection(pAttrs->pwzPartID, &piAppColl);
    if (S_FALSE == hr)
        hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND);
    ExitOnFailure(hr, "Failed to get applications collection");

    // check if application exists
    hr = CpiFindCollectionObjectByStringKey(piAppColl, pAttrs->pwzID, &piAppObj);
    ExitOnFailure(hr, "Failed to find application");

    if (S_FALSE == hr)
    {
        // create application
        hr = CpiAddCollectionObject(piAppColl, &piAppObj);
        ExitOnFailure(hr, "Failed to add application to collection");

        hr = CpiPutCollectionObjectValue(piAppObj, L"ID", pAttrs->pwzID);
        ExitOnFailure(hr, "Failed to set application id property");

        hr = CpiPutCollectionObjectValue(piAppObj, L"Name", pAttrs->pwzName);
        ExitOnFailure(hr, "Failed to set application name property");

        // save changes
        hr = piAppColl->SaveChanges(&lChanges);
        if (COMADMIN_E_OBJECTERRORS == hr)
            CpiLogCatalogErrorInfo();
        ExitOnFailure(hr, "Failed to add application");
    }

    // properties
    hr = CpiPutCollectionObjectValues(piAppObj, pAttrs->pPropList);
    ExitOnFailure(hr, "Failed to write properties");

    // save changes
    hr = piAppColl->SaveChanges(&lChanges);
    if (COMADMIN_E_OBJECTERRORS == hr)
        CpiLogCatalogErrorInfo();
    ExitOnFailure(hr, "Failed to save changes");

    // log
    WcaLog(LOGMSG_VERBOSE, "%d changes saved to catalog, key: %S", lChanges, pAttrs->pwzKey);

    hr = S_OK;

LExit:
    // clean up
    ReleaseObject(piAppColl);
    ReleaseObject(piAppObj);

    return hr;
}