From 4cd1c4e06145434ca940ac828772dc47b9d9738e Mon Sep 17 00:00:00 2001
From: Sean Hall <r.sean.hall@gmail.com>
Date: Sun, 13 Mar 2022 23:45:32 -0500
Subject: Allow the BA to override the bundle relation type during plan.

---
 .../WixStandardBootstrapperApplication.cpp         | 44 ++++++++++++++++++++++
 src/ext/Bal/wixstdba/wixstdba.mc                   |  7 ++++
 2 files changed, 51 insertions(+)

(limited to 'src/ext')

diff --git a/src/ext/Bal/wixstdba/WixStandardBootstrapperApplication.cpp b/src/ext/Bal/wixstdba/WixStandardBootstrapperApplication.cpp
index 8c7bce7e..91033a26 100644
--- a/src/ext/Bal/wixstdba/WixStandardBootstrapperApplication.cpp
+++ b/src/ext/Bal/wixstdba/WixStandardBootstrapperApplication.cpp
@@ -169,6 +169,9 @@ static LPCSTR LoggingBoolToString(
 static LPCSTR LoggingRequestStateToString(
     __in BOOTSTRAPPER_REQUEST_STATE requestState
     );
+static LPCSTR LoggingPlanRelationTypeToString(
+    __in BOOTSTRAPPER_RELATED_BUNDLE_PLAN_TYPE type
+    );
 static LPCSTR LoggingMsiFeatureStateToString(
     __in BOOTSTRAPPER_FEATURE_STATE featureState
     );
@@ -1436,6 +1439,12 @@ public: // IBootstrapperApplication
         case BOOTSTRAPPER_APPLICATION_MESSAGE_ONPLANNEDCOMPATIBLEPACKAGE:
             OnPlannedCompatiblePackageFallback(reinterpret_cast<BA_ONPLANNEDCOMPATIBLEPACKAGE_ARGS*>(pvArgs), reinterpret_cast<BA_ONPLANNEDCOMPATIBLEPACKAGE_RESULTS*>(pvResults));
             break;
+        case BOOTSTRAPPER_APPLICATION_MESSAGE_ONPLANRESTORERELATEDBUNDLE:
+            OnPlanRestoreRelatedBundleFallback(reinterpret_cast<BA_ONPLANRESTORERELATEDBUNDLE_ARGS*>(pvArgs), reinterpret_cast<BA_ONPLANRESTORERELATEDBUNDLE_RESULTS*>(pvResults));
+            break;
+        case BOOTSTRAPPER_APPLICATION_MESSAGE_ONPLANRELATEDBUNDLETYPE:
+            OnPlanRelatedBundleTypeFallback(reinterpret_cast<BA_ONPLANRELATEDBUNDLETYPE_ARGS*>(pvArgs), reinterpret_cast<BA_ONPLANRELATEDBUNDLETYPE_RESULTS*>(pvResults));
+            break;
         default:
 #ifdef DEBUG
             BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "WIXSTDBA: Forwarding unknown BA message: %d", message);
@@ -1585,6 +1594,16 @@ private: // privates
         BalLogId(BOOTSTRAPPER_LOG_LEVEL_STANDARD, MSG_WIXSTDBA_PLANNED_RELATED_BUNDLE, m_hModule, pArgs->wzBundleId, LoggingRequestStateToString(requestedState), LoggingRequestStateToString(pResults->requestedState));
     }
 
+    void OnPlanRelatedBundleTypeFallback(
+        __in BA_ONPLANRELATEDBUNDLETYPE_ARGS* pArgs,
+        __inout BA_ONPLANRELATEDBUNDLETYPE_RESULTS* pResults
+        )
+    {
+        BOOTSTRAPPER_RELATED_BUNDLE_PLAN_TYPE requestedType = pResults->requestedType;
+        m_pfnBAFunctionsProc(BA_FUNCTIONS_MESSAGE_ONPLANRELATEDBUNDLETYPE, pArgs, pResults, m_pvBAFunctionsProcContext);
+        BalLogId(BOOTSTRAPPER_LOG_LEVEL_STANDARD, MSG_WIXSTDBA_PLANNED_RELATED_BUNDLE_TYPE, m_hModule, pArgs->wzBundleId, LoggingPlanRelationTypeToString(requestedType), LoggingPlanRelationTypeToString(pResults->requestedType));
+    }
+
     void OnPlanPackageBeginFallback(
         __in BA_ONPLANPACKAGEBEGIN_ARGS* pArgs,
         __inout BA_ONPLANPACKAGEBEGIN_RESULTS* pResults
@@ -4672,6 +4691,31 @@ static LPCSTR LoggingRequestStateToString(
     }
 }
 
+static LPCSTR LoggingPlanRelationTypeToString(
+    __in BOOTSTRAPPER_RELATED_BUNDLE_PLAN_TYPE type
+    )
+{
+    switch (type)
+    {
+    case BOOTSTRAPPER_RELATED_BUNDLE_PLAN_TYPE_NONE:
+        return "None";
+    case BOOTSTRAPPER_RELATED_BUNDLE_PLAN_TYPE_DOWNGRADE:
+        return "Downgrade";
+    case BOOTSTRAPPER_RELATED_BUNDLE_PLAN_TYPE_UPGRADE:
+        return "Upgrade";
+    case BOOTSTRAPPER_RELATED_BUNDLE_PLAN_TYPE_ADDON:
+        return "Addon";
+    case BOOTSTRAPPER_RELATED_BUNDLE_PLAN_TYPE_PATCH:
+        return "Patch";
+    case BOOTSTRAPPER_RELATED_BUNDLE_PLAN_TYPE_DEPENDENT_ADDON:
+        return "DependentAddon";
+    case BOOTSTRAPPER_RELATED_BUNDLE_PLAN_TYPE_DEPENDENT_PATCH:
+        return "DependentPatch";
+    default:
+        return "Invalid";
+    }
+}
+
 static LPCSTR LoggingMsiFeatureStateToString(
     __in BOOTSTRAPPER_FEATURE_STATE featureState
     )
diff --git a/src/ext/Bal/wixstdba/wixstdba.mc b/src/ext/Bal/wixstdba/wixstdba.mc
index eeb69914..025315a5 100644
--- a/src/ext/Bal/wixstdba/wixstdba.mc
+++ b/src/ext/Bal/wixstdba/wixstdba.mc
@@ -92,3 +92,10 @@ Language=English
 WIXSTDBA: Planned restore related bundle: %1!ls!, wixstdba requested: %2!hs!, bafunctions requested: %3!hs!
 .
 
+MessageId=10
+Severity=Success
+SymbolicName=MSG_WIXSTDBA_PLANNED_RELATED_BUNDLE_TYPE
+Language=English
+WIXSTDBA: Planned related bundle type: %1!ls!, wixstdba requested: %2!hs!, bafunctions requested: %3!hs!
+.
+
-- 
cgit v1.2.3-55-g6feb