HRESULT CpiApplicationRolesRead( CPI_APPLICATION_LIST* pAppList, CPI_APPLICATION_ROLE_LIST* pAppRoleList ) { HRESULT hr = S_OK; UINT er = ERROR_SUCCESS; PMSIHANDLE hView, hRec; CPI_APPLICATION_ROLE* pItm = NULL; LPWSTR pwzData = NULL; BOOL fMatchingArchitecture = FALSE; // loop through all application roles hr = WcaOpenExecuteView(vcsApplicationRoleQuery, &hView); ExitOnFailure(hr, "Failed to execute view on ComPlusApplicationRole table"); while (S_OK == (hr = WcaFetchRecord(hView, &hRec))) { // get component hr = WcaGetRecordString(hRec, arqComponent, &pwzData); ExitOnFailure(hr, "Failed to get component"); // check if the component is our processor architecture if (pwzData && *pwzData) { hr = CpiVerifyComponentArchitecure(pwzData, &fMatchingArchitecture); ExitOnFailure(hr, "Failed to get component architecture."); if (!fMatchingArchitecture) { continue; // not the same architecture, ignore } } // create entry pItm = (CPI_APPLICATION_ROLE*)::HeapAlloc(::GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CPI_APPLICATION_ROLE)); if (!pItm) ExitFunction1(hr = E_OUTOFMEMORY); // get component install state if (pwzData && *pwzData) { pItm->fHasComponent = TRUE; er = ::MsiGetComponentStateW(WcaGetInstallHandle(), pwzData, &pItm->isInstalled, &pItm->isAction); ExitOnFailure(hr = HRESULT_FROM_WIN32(er), "Failed to get component state"); } // get key hr = WcaGetRecordString(hRec, arqApplicationRole, &pwzData); ExitOnFailure(hr, "Failed to get key"); StringCchCopyW(pItm->wzKey, countof(pItm->wzKey), pwzData); // get application hr = WcaGetRecordString(hRec, arqApplication, &pwzData); ExitOnFailure(hr, "Failed to get application"); hr = CpiApplicationFindByKey(pAppList, pwzData, &pItm->pApplication); if (S_FALSE == hr) hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND); ExitOnFailure1(hr, "Failed to find application, key: %S", pwzData); // get name hr = WcaGetRecordFormattedString(hRec, arqName, &pwzData); ExitOnFailure(hr, "Failed to get name"); StringCchCopyW(pItm->wzName, countof(pItm->wzName), pwzData); // get properties if (CpiTableExists(cptComPlusApplicationRoleProperty)) { hr = CpiPropertiesRead(vcsApplicationRolePropertyQuery, pItm->wzKey, pdlApplicationRoleProperties, &pItm->pProperties, &pItm->iPropertyCount); ExitOnFailure(hr, "Failed to get properties"); } // set references & increment counters if (pItm->fHasComponent) { if (WcaIsInstalling(pItm->isInstalled, pItm->isAction)) { CpiApplicationAddReferenceInstall(pItm->pApplication); pAppRoleList->iInstallCount++; } if (WcaIsUninstalling(pItm->isInstalled, pItm->isAction)) { CpiApplicationAddReferenceUninstall(pItm->pApplication); pAppRoleList->iUninstallCount++; } } // add entry if (pAppRoleList->pFirst) pItm->pNext = pAppRoleList->pFirst; pAppRoleList->pFirst = pItm; pItm = NULL; } if (E_NOMOREITEMS == hr) hr = S_OK; LExit: // clean up if (pItm) FreeApplicationRole(pItm); ReleaseStr(pwzData); return hr; }
HRESULT CpiPartitionsRead( CPI_PARTITION_LIST* pPartList ) { HRESULT hr = S_OK; UINT er = ERROR_SUCCESS; PMSIHANDLE hView, hRec; CPI_PARTITION* pItm = NULL; LPWSTR pwzData = NULL; BOOL fMatchingArchitecture = FALSE; // loop through all partitions hr = WcaOpenExecuteView(vcsPartitionQuery, &hView); ExitOnFailure(hr, "Failed to execute view on ComPlusPartition table"); while (S_OK == (hr = WcaFetchRecord(hView, &hRec))) { // get component hr = WcaGetRecordString(hRec, pqComponent, &pwzData); ExitOnFailure(hr, "Failed to get component"); // check if the component is our processor architecture if (pwzData && *pwzData) { hr = CpiVerifyComponentArchitecure(pwzData, &fMatchingArchitecture); ExitOnFailure(hr, "Failed to get component architecture."); if (!fMatchingArchitecture) { continue; // not the same architecture, ignore } } // create entry pItm = (CPI_PARTITION*)::HeapAlloc(::GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CPI_PARTITION)); if (!pItm) ExitFunction1(hr = E_OUTOFMEMORY); // get component install state if (pwzData && *pwzData) { pItm->fHasComponent = TRUE; er = ::MsiGetComponentStateW(WcaGetInstallHandle(), pwzData, &pItm->isInstalled, &pItm->isAction); ExitOnFailure(hr = HRESULT_FROM_WIN32(er), "Failed to get component state"); } // get key hr = WcaGetRecordString(hRec, pqPartition, &pwzData); ExitOnFailure(hr, "Failed to get key"); StringCchCopyW(pItm->wzKey, countof(pItm->wzKey), pwzData); // get id hr = WcaGetRecordFormattedString(hRec, pqID, &pwzData); ExitOnFailure(hr, "Failed to get id"); if (pwzData && *pwzData) { hr = PcaGuidToRegFormat(pwzData, pItm->wzID, countof(pItm->wzID)); ExitOnFailure(hr, "Failed to parse id guid value, key: %S, value: '%S'", pItm->wzKey, pwzData); } // get name hr = WcaGetRecordFormattedString(hRec, pqName, &pwzData); ExitOnFailure(hr, "Failed to get name"); StringCchCopyW(pItm->wzName, countof(pItm->wzName), pwzData); // if partition is a locater, either an id or a name must be provided if (!pItm->fHasComponent && !*pItm->wzID && !*pItm->wzName) ExitOnFailure(hr = E_FAIL, "A partition locater must have either an id or a name associated, key: %S", pItm->wzKey); // if partition is not a locater, an name must be provided if (pItm->fHasComponent && !*pItm->wzName) ExitOnFailure(hr = E_FAIL, "A partition must have a name associated, key: %S", pItm->wzKey); // get properties if (CpiTableExists(cptComPlusPartitionProperty) && pItm->fHasComponent) { hr = CpiPropertiesRead(vcsPartitionPropertyQuery, pItm->wzKey, pdlPartitionProperties, &pItm->pProperties, &pItm->iPropertyCount); ExitOnFailure(hr, "Failed to get properties"); } // increment counters if (pItm->fHasComponent && WcaIsInstalling(pItm->isInstalled, pItm->isAction)) pPartList->iInstallCount++; if (pItm->fHasComponent && WcaIsUninstalling(pItm->isInstalled, pItm->isAction)) pPartList->iUninstallCount++; // add entry if (pPartList->pFirst) pItm->pNext = pPartList->pFirst; pPartList->pFirst = pItm; pItm = NULL; } if (E_NOMOREITEMS == hr) hr = S_OK; LExit: // clean up if (pItm) FreePartition(pItm); ReleaseStr(pwzData); return hr; }
HRESULT CpiSubscriptionsRead( CPI_ASSEMBLY_LIST* pAsmList, CPI_SUBSCRIPTION_LIST* pSubList ) { HRESULT hr = S_OK; UINT er = ERROR_SUCCESS; PMSIHANDLE hView, hRec; CPI_SUBSCRIPTION* pItm = NULL; LPWSTR pwzData = NULL; BOOL fMatchingArchitecture = FALSE; // loop through all applications hr = WcaOpenExecuteView(vcsSubscriptionQuery, &hView); ExitOnFailure(hr, "Failed to execute view on ComPlusSubscription table"); while (S_OK == (hr = WcaFetchRecord(hView, &hRec))) { // get component hr = WcaGetRecordString(hRec, sqComponent, &pwzData); ExitOnFailure(hr, "Failed to get component"); // check if the component is our processor architecture hr = CpiVerifyComponentArchitecure(pwzData, &fMatchingArchitecture); ExitOnFailure(hr, "Failed to get component architecture."); if (!fMatchingArchitecture) { continue; // not the same architecture, ignore } // create entry pItm = (CPI_SUBSCRIPTION*)::HeapAlloc(::GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CPI_SUBSCRIPTION)); if (!pItm) ExitFunction1(hr = E_OUTOFMEMORY); // get component install state er = ::MsiGetComponentStateW(WcaGetInstallHandle(), pwzData, &pItm->isInstalled, &pItm->isAction); ExitOnFailure(hr = HRESULT_FROM_WIN32(er), "Failed to get component state"); // get key hr = WcaGetRecordString(hRec, sqSubscription, &pwzData); ExitOnFailure(hr, "Failed to get key"); StringCchCopyW(pItm->wzKey, countof(pItm->wzKey), pwzData); // get com+ component hr = WcaGetRecordString(hRec, sqComPlusComponent, &pwzData); ExitOnFailure(hr, "Failed to get COM+ component"); hr = ComponentFindByKey(pAsmList, pwzData, &pItm->pAssembly, &pItm->pComponent); if (S_FALSE == hr) { // component not found ExitOnFailure1(hr = E_FAIL, "Failed to find component, key: %S", pwzData); } // get id hr = WcaGetRecordFormattedString(hRec, sqID, &pwzData); ExitOnFailure(hr, "Failed to get id"); if (pwzData && *pwzData) { hr = PcaGuidToRegFormat(pwzData, pItm->wzID, countof(pItm->wzID)); ExitOnFailure2(hr, "Failed to parse id guid value, key: %S, value: '%S'", pItm->wzKey, pwzData); } // get name hr = WcaGetRecordFormattedString(hRec, sqName, &pwzData); ExitOnFailure(hr, "Failed to get name"); StringCchCopyW(pItm->wzName, countof(pItm->wzName), pwzData); // get event clsid hr = WcaGetRecordFormattedString(hRec, sqEventCLSID, &pwzData); ExitOnFailure(hr, "Failed to get event clsid"); StringCchCopyW(pItm->wzEventCLSID, countof(pItm->wzEventCLSID), pwzData); // get publisher id hr = WcaGetRecordFormattedString(hRec, sqPublisherID, &pwzData); ExitOnFailure(hr, "Failed to get publisher id"); StringCchCopyW(pItm->wzPublisherID, countof(pItm->wzPublisherID), pwzData); // get properties if (CpiTableExists(cptComPlusSubscriptionProperty)) { hr = CpiPropertiesRead(vcsSubscriptionPropertyQuery, pItm->wzKey, pdlSubscriptionProperties, &pItm->pProperties, &pItm->iPropertyCount); ExitOnFailure(hr, "Failed to get subscription properties"); } // set references & increment counters if (WcaIsInstalling(pItm->isInstalled, pItm->isAction)) { CpiApplicationAddReferenceInstall(pItm->pAssembly->pApplication); pItm->pAssembly->fReferencedForInstall = TRUE; pSubList->iInstallCount++; if (pItm->pAssembly->iAttributes & aaRunInCommit) pSubList->iCommitCount++; } if (WcaIsUninstalling(pItm->isInstalled, pItm->isAction)) { CpiApplicationAddReferenceUninstall(pItm->pAssembly->pApplication); pItm->pAssembly->fReferencedForUninstall = TRUE; pSubList->iUninstallCount++; } // add entry if (pSubList->pFirst) pItm->pNext = pSubList->pFirst; pSubList->pFirst = pItm; pItm = NULL; } if (E_NOMOREITEMS == hr) hr = S_OK; LExit: // clean up if (pItm) FreeSubscription(pItm); ReleaseStr(pwzData); return hr; }