@joebigelow / wix-1 / commits / 6ac2cf5c

Refactor PlanRelatedBundlesBegin without changing behavior.

Sean Hall committed Dec 15, 2020 at 20:02 UTC 6ac2cf5c3dc2df77ba8be2cf12c624e1c4a20e18
2 files changed +69 -43
src/engine/plan.cpp
+61 -43
@@ -1211,6 +1211,65 @@ LExit:
1211 return hr;
1212 }
1213
1214 +extern "C" HRESULT PlanDefaultRelatedBundleRequestState(
1215 + __in BOOTSTRAPPER_RELATION_TYPE commandRelationType,
1216 + __in BOOTSTRAPPER_RELATION_TYPE relatedBundleRelationType,
1217 + __in BOOTSTRAPPER_ACTION action,
1218 + __in VERUTIL_VERSION* pRegistrationVersion,
1219 + __in VERUTIL_VERSION* pRelatedBundleVersion,
1220 + __inout BOOTSTRAPPER_REQUEST_STATE* pRequestState
1221 + )
1222 +{
1223 + HRESULT hr = S_OK;
1224 + int nCompareResult = 0;
1225 +
1226 + switch (relatedBundleRelationType)
1227 + {
1228 + case BOOTSTRAPPER_RELATION_UPGRADE:
1229 + if (BOOTSTRAPPER_RELATION_UPGRADE != commandRelationType && BOOTSTRAPPER_ACTION_UNINSTALL < action)
1230 + {
1231 + hr = VerCompareParsedVersions(pRegistrationVersion, pRelatedBundleVersion, &nCompareResult);
1232 + ExitOnFailure(hr, "Failed to compare bundle version '%ls' to related bundle version '%ls'", pRegistrationVersion ? pRegistrationVersion->sczVersion : NULL, pRelatedBundleVersion ? pRelatedBundleVersion->sczVersion : NULL);
1233 +
1234 + *pRequestState = (nCompareResult < 0) ? BOOTSTRAPPER_REQUEST_STATE_NONE : BOOTSTRAPPER_REQUEST_STATE_ABSENT;
1235 + }
1236 + break;
1237 + case BOOTSTRAPPER_RELATION_PATCH: __fallthrough;
1238 + case BOOTSTRAPPER_RELATION_ADDON:
1239 + if (BOOTSTRAPPER_ACTION_UNINSTALL == action)
1240 + {
1241 + *pRequestState = BOOTSTRAPPER_REQUEST_STATE_ABSENT;
1242 + }
1243 + else if (BOOTSTRAPPER_ACTION_INSTALL == action || BOOTSTRAPPER_ACTION_MODIFY == action)
1244 + {
1245 + *pRequestState = BOOTSTRAPPER_REQUEST_STATE_PRESENT;
1246 + }
1247 + else if (BOOTSTRAPPER_ACTION_REPAIR == action)
1248 + {
1249 + *pRequestState = BOOTSTRAPPER_REQUEST_STATE_REPAIR;
1250 + }
1251 + break;
1252 + case BOOTSTRAPPER_RELATION_DEPENDENT:
1253 + // Automatically repair dependent bundles to restore missing
1254 + // packages after uninstall unless we're being upgraded with the
1255 + // assumption that upgrades are cumulative (as intended).
1256 + if (BOOTSTRAPPER_RELATION_UPGRADE != commandRelationType && BOOTSTRAPPER_ACTION_UNINSTALL == action)
1257 + {
1258 + *pRequestState = BOOTSTRAPPER_REQUEST_STATE_REPAIR;
1259 + }
1260 + break;
1261 + case BOOTSTRAPPER_RELATION_DETECT:
1262 + break;
1263 + default:
1264 + hr = E_UNEXPECTED;
1265 + ExitOnFailure(hr, "Unexpected relation type encountered during plan: %d", relatedBundleRelationType);
1266 + break;
1267 + }
1268 +
1269 +LExit:
1270 + return hr;
1271 +}
1272 +
1273 extern "C" HRESULT PlanRelatedBundlesBegin(
1274 __in BURN_USER_EXPERIENCE* pUserExperience,
1275 __in BURN_REGISTRATION* pRegistration,
@@ -1222,7 +1281,6 @@ extern "C" HRESULT PlanRelatedBundlesBegin(
1281 LPWSTR* rgsczAncestors = NULL;
1282 UINT cAncestors = 0;
1283 STRINGDICT_HANDLE sdAncestors = NULL;
1225 - int nCompareResult = 0;
1284
1285 if (pRegistration->sczAncestors)
1286 {
@@ -1272,48 +1330,8 @@ extern "C" HRESULT PlanRelatedBundlesBegin(
1330 ExitOnFailure(hr, "Failed to copy self to related bundle ancestors.");
1331 }
1332
1275 - switch (pRelatedBundle->relationType)
1276 - {
1277 - case BOOTSTRAPPER_RELATION_UPGRADE:
1278 - if (BOOTSTRAPPER_RELATION_UPGRADE != relationType && BOOTSTRAPPER_ACTION_UNINSTALL < pPlan->action)
1279 - {
1280 - hr = VerCompareParsedVersions(pRegistration->pVersion, pRelatedBundle->pVersion, &nCompareResult);
1281 - ExitOnFailure(hr, "Failed to compare bundle version '%ls' to related bundle version '%ls'", pRegistration->pVersion, pRelatedBundle->pVersion);
1282 -
1283 - pRelatedBundle->package.requested = (nCompareResult < 0) ? BOOTSTRAPPER_REQUEST_STATE_NONE : BOOTSTRAPPER_REQUEST_STATE_ABSENT;
1284 - }
1285 - break;
1286 - case BOOTSTRAPPER_RELATION_PATCH: __fallthrough;
1287 - case BOOTSTRAPPER_RELATION_ADDON:
1288 - if (BOOTSTRAPPER_ACTION_UNINSTALL == pPlan->action)
1289 - {
1290 - pRelatedBundle->package.requested = BOOTSTRAPPER_REQUEST_STATE_ABSENT;
1291 - }
1292 - else if (BOOTSTRAPPER_ACTION_INSTALL == pPlan->action || BOOTSTRAPPER_ACTION_MODIFY == pPlan->action)
1293 - {
1294 - pRelatedBundle->package.requested = BOOTSTRAPPER_REQUEST_STATE_PRESENT;
1295 - }
1296 - else if (BOOTSTRAPPER_ACTION_REPAIR == pPlan->action)
1297 - {
1298 - pRelatedBundle->package.requested = BOOTSTRAPPER_REQUEST_STATE_REPAIR;
1299 - }
1300 - break;
1301 - case BOOTSTRAPPER_RELATION_DEPENDENT:
1302 - // Automatically repair dependent bundles to restore missing
1303 - // packages after uninstall unless we're being upgraded with the
1304 - // assumption that upgrades are cumulative (as intended).
1305 - if (BOOTSTRAPPER_RELATION_UPGRADE != relationType && BOOTSTRAPPER_ACTION_UNINSTALL == pPlan->action)
1306 - {
1307 - pRelatedBundle->package.requested = BOOTSTRAPPER_REQUEST_STATE_REPAIR;
1308 - }
1309 - break;
1310 - case BOOTSTRAPPER_RELATION_DETECT:
1311 - break;
1312 - default:
1313 - hr = E_UNEXPECTED;
1314 - ExitOnFailure(hr, "Unexpected relation type encountered during plan: %d", pRelatedBundle->relationType);
1315 - break;
1316 - }
1333 + hr = PlanDefaultRelatedBundleRequestState(relationType, pRelatedBundle->relationType, pPlan->action, pRegistration->pVersion, pRelatedBundle->pVersion, &pRelatedBundle->package.requested);
1334 + ExitOnFailure(hr, "Failed to get default request state for related bundle.");
1335
1336 pRelatedBundle->package.defaultRequested = pRelatedBundle->package.requested;
1337
src/engine/plan.h
+8
@@ -477,6 +477,14 @@ HRESULT PlanExecutePackage(
477 __in BURN_VARIABLES* pVariables,
478 __inout HANDLE* phSyncpointEvent
479 );
480 +HRESULT PlanDefaultRelatedBundleRequestState(
481 + __in BOOTSTRAPPER_RELATION_TYPE commandRelationType,
482 + __in BOOTSTRAPPER_RELATION_TYPE relatedBundleRelationType,
483 + __in BOOTSTRAPPER_ACTION action,
484 + __in VERUTIL_VERSION* pRegistrationVersion,
485 + __in VERUTIL_VERSION* pRelatedBundleVersion,
486 + __inout BOOTSTRAPPER_REQUEST_STATE* pRequestState
487 + );
488 HRESULT PlanRelatedBundlesBegin(
489 __in BURN_USER_EXPERIENCE* pUserExperience,
490 __in BURN_REGISTRATION* pRegistration,