From 0d873d28c2dd18444afa08b748e91f495ed1cf5c Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Sun, 15 Nov 2020 19:54:20 -0600 Subject: Add plan tests. --- src/engine/container.cpp | 36 ++++++++++++++++++++++++++--------- src/engine/container.h | 5 ++++- src/engine/core.cpp | 4 ++++ src/engine/logging.cpp | 21 +++++++++++++++++++++ src/engine/logging.h | 4 ++++ src/engine/manifest.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++----- src/engine/manifest.h | 5 +++++ src/engine/msiengine.cpp | 5 +---- src/engine/msiengine.h | 6 ++++++ src/engine/plan.cpp | 34 ++++++++++++++++++--------------- src/engine/plan.h | 3 +++ 11 files changed, 138 insertions(+), 34 deletions(-) (limited to 'src/engine') diff --git a/src/engine/container.cpp b/src/engine/container.cpp index ada9025b..55a16afb 100644 --- a/src/engine/container.cpp +++ b/src/engine/container.cpp @@ -17,7 +17,6 @@ static HRESULT GetAttachedContainerInfo( // function definitions extern "C" HRESULT ContainersParseFromXml( - __in BURN_SECTION* pSection, __in BURN_CONTAINERS* pContainers, __in IXMLDOMNode* pixnBundle ) @@ -128,14 +127,6 @@ extern "C" HRESULT ContainersParseFromXml( ExitOnFailure(hr, "Failed to get @Hash."); } - // If the container is attached, make sure the information in the section matches what the - // manifest contained and get the offset to the container. - if (pContainer->fAttached) - { - hr = SectionGetAttachedContainerInfo(pSection, pContainer->dwAttachedIndex, pContainer->type, &pContainer->qwAttachedOffset, &pContainer->qwFileSize, &pContainer->fActuallyAttached); - ExitOnFailure(hr, "Failed to get attached container information."); - } - // prepare next iteration ReleaseNullObject(pixnNode); } @@ -150,6 +141,33 @@ LExit: return hr; } +extern "C" HRESULT ContainersInitialize( + __in BURN_CONTAINERS* pContainers, + __in BURN_SECTION* pSection + ) +{ + HRESULT hr = S_OK; + + if (pContainers->rgContainers) + { + for (DWORD i = 0; i < pContainers->cContainers; ++i) + { + BURN_CONTAINER* pContainer = &pContainers->rgContainers[i]; + + // If the container is attached, make sure the information in the section matches what the + // manifest contained and get the offset to the container. + if (pContainer->fAttached) + { + hr = SectionGetAttachedContainerInfo(pSection, pContainer->dwAttachedIndex, pContainer->type, &pContainer->qwAttachedOffset, &pContainer->qwFileSize, &pContainer->fActuallyAttached); + ExitOnFailure(hr, "Failed to get attached container information."); + } + } + } + +LExit: + return hr; +} + extern "C" void ContainersUninitialize( __in BURN_CONTAINERS* pContainers ) diff --git a/src/engine/container.h b/src/engine/container.h index 2ca3d7ad..bbd9fa72 100644 --- a/src/engine/container.h +++ b/src/engine/container.h @@ -135,10 +135,13 @@ typedef struct _BURN_CONTAINER_CONTEXT // functions HRESULT ContainersParseFromXml( - __in BURN_SECTION* pSection, __in BURN_CONTAINERS* pContainers, __in IXMLDOMNode* pixnBundle ); +HRESULT ContainersInitialize( + __in BURN_CONTAINERS* pContainers, + __in BURN_SECTION* pSection + ); void ContainersUninitialize( __in BURN_CONTAINERS* pContainers ); diff --git a/src/engine/core.cpp b/src/engine/core.cpp index c34024fd..aeae6bea 100644 --- a/src/engine/core.cpp +++ b/src/engine/core.cpp @@ -96,6 +96,9 @@ extern "C" HRESULT CoreInitialize( hr = ManifestLoadXmlFromBuffer(pbBuffer, cbBuffer, pEngineState); ExitOnFailure(hr, "Failed to load manifest."); + hr = ContainersInitialize(&pEngineState->containers, &pEngineState->section); + ExitOnFailure(hr, "Failed to intialize containers."); + // Parse command line. hr = ParseCommandLine(pEngineState->argc, pEngineState->argv, &pEngineState->command, &pEngineState->companionConnection, &pEngineState->embeddedConnection, &pEngineState->variables, &pEngineState->mode, &pEngineState->automaticUpdates, &pEngineState->fDisableSystemRestore, &sczSourceProcessPath, &sczOriginalSource, &pEngineState->fDisableUnelevate, &pEngineState->log.dwAttributes, &pEngineState->log.sczPath, &pEngineState->registration.sczActiveParent, &pEngineState->sczIgnoreDependencies, &pEngineState->registration.sczAncestors, &sczSanitizedCommandLine); ExitOnFailure(hr, "Failed to parse command line."); @@ -411,6 +414,7 @@ extern "C" HRESULT CorePlan( pEngineState->plan.action = action; pEngineState->plan.wzBundleId = pEngineState->registration.sczId; pEngineState->plan.wzBundleProviderKey = pEngineState->registration.sczId; + pEngineState->plan.fDisableRollback = pEngineState->fDisableRollback; hr = PlanSetVariables(action, &pEngineState->variables); ExitOnFailure(hr, "Failed to update action."); diff --git a/src/engine/logging.cpp b/src/engine/logging.cpp index e69303f0..512b562c 100644 --- a/src/engine/logging.cpp +++ b/src/engine/logging.cpp @@ -468,6 +468,27 @@ extern "C" LPCSTR LoggingMsiInstallContext( } } +extern "C" LPCWSTR LoggingBurnMsiPropertyToString( + __in BURN_MSI_PROPERTY burnMsiProperty + ) +{ + switch (burnMsiProperty) + { + case BURN_MSI_PROPERTY_INSTALL: + return BURNMSIINSTALL_PROPERTY_NAME; + case BURN_MSI_PROPERTY_MODIFY: + return BURNMSIMODIFY_PROPERTY_NAME; + case BURN_MSI_PROPERTY_NONE: + return L"(none)"; + case BURN_MSI_PROPERTY_REPAIR: + return BURNMSIREPAIR_PROPERTY_NAME; + case BURN_MSI_PROPERTY_UNINSTALL: + return BURNMSIUNINSTALL_PROPERTY_NAME; + default: + return L"Invalid"; + } +} + extern "C" LPCSTR LoggingPerMachineToString( __in BOOL fPerMachine ) diff --git a/src/engine/logging.h b/src/engine/logging.h index 22dd54d9..381a295b 100644 --- a/src/engine/logging.h +++ b/src/engine/logging.h @@ -101,6 +101,10 @@ LPCSTR LoggingMsiInstallContext( __in MSIINSTALLCONTEXT context ); +LPCWSTR LoggingBurnMsiPropertyToString( + __in BURN_MSI_PROPERTY burnMsiProperty + ); + LPCSTR LoggingPerMachineToString( __in BOOL fPerMachine ); diff --git a/src/engine/manifest.cpp b/src/engine/manifest.cpp index 8783b15e..270b6b74 100644 --- a/src/engine/manifest.cpp +++ b/src/engine/manifest.cpp @@ -3,8 +3,33 @@ #include "precomp.h" +static HRESULT ParseFromXml( + __in IXMLDOMDocument* pixdDocument, + __in BURN_ENGINE_STATE* pEngineState + ); + // function definitions +extern "C" HRESULT ManifestLoadXml( + __in LPCWSTR wzDocument, + __in BURN_ENGINE_STATE* pEngineState + ) +{ + HRESULT hr = S_OK; + IXMLDOMDocument* pixdDocument = NULL; + + // load xml document + hr = XmlLoadDocument(wzDocument, &pixdDocument); + ExitOnFailure(hr, "Failed to load manifest as XML document."); + + hr = ParseFromXml(pixdDocument, pEngineState); + +LExit: + ReleaseObject(pixdDocument); + + return hr; +} + extern "C" HRESULT ManifestLoadXmlFromBuffer( __in_bcount(cbBuffer) BYTE* pbBuffer, __in SIZE_T cbBuffer, @@ -13,14 +38,29 @@ extern "C" HRESULT ManifestLoadXmlFromBuffer( { HRESULT hr = S_OK; IXMLDOMDocument* pixdDocument = NULL; - IXMLDOMElement* pixeBundle = NULL; - IXMLDOMNode* pixnLog = NULL; - IXMLDOMNode* pixnChain = NULL; // load xml document hr = XmlLoadDocumentFromBuffer(pbBuffer, cbBuffer, &pixdDocument); ExitOnFailure(hr, "Failed to load manifest as XML document."); + hr = ParseFromXml(pixdDocument, pEngineState); + +LExit: + ReleaseObject(pixdDocument); + + return hr; +} + +static HRESULT ParseFromXml( + __in IXMLDOMDocument* pixdDocument, + __in BURN_ENGINE_STATE* pEngineState + ) +{ + HRESULT hr = S_OK; + IXMLDOMElement* pixeBundle = NULL; + IXMLDOMNode* pixnLog = NULL; + IXMLDOMNode* pixnChain = NULL; + // get bundle element hr = pixdDocument->get_documentElement(&pixeBundle); ExitOnFailure(hr, "Failed to get bundle element."); @@ -105,7 +145,7 @@ extern "C" HRESULT ManifestLoadXmlFromBuffer( ExitOnFailure(hr, "Failed to parse update."); // parse containers - hr = ContainersParseFromXml(&pEngineState->section, &pEngineState->containers, pixeBundle); + hr = ContainersParseFromXml(&pEngineState->containers, pixeBundle); ExitOnFailure(hr, "Failed to parse containers."); // parse payloads @@ -124,6 +164,5 @@ LExit: ReleaseObject(pixnChain); ReleaseObject(pixnLog); ReleaseObject(pixeBundle); - ReleaseObject(pixdDocument); return hr; } diff --git a/src/engine/manifest.h b/src/engine/manifest.h index 6e535d60..223181d9 100644 --- a/src/engine/manifest.h +++ b/src/engine/manifest.h @@ -11,6 +11,11 @@ extern "C" { // function declarations +HRESULT ManifestLoadXml( + __in LPCWSTR wzDocument, + __in BURN_ENGINE_STATE* pEngineState + ); + HRESULT ManifestLoadXmlFromBuffer( __in_bcount(cbBuffer) BYTE* pbBuffer, __in SIZE_T cbBuffer, diff --git a/src/engine/msiengine.cpp b/src/engine/msiengine.cpp index 066734d0..c20e2ef8 100644 --- a/src/engine/msiengine.cpp +++ b/src/engine/msiengine.cpp @@ -4,10 +4,7 @@ // constants -#define BURNMSIINSTALL_PROPERTY_NAME L"BURNMSIINSTALL" -#define BURNMSIMODIFY_PROPERTY_NAME L"BURNMSIMODIFY" -#define BURNMSIREPAIR_PROPERTY_NAME L"BURNMSIREPAIR" -#define BURNMSIUNINSTALL_PROPERTY_NAME L"BURNMSIUNINSTALL" + // structs diff --git a/src/engine/msiengine.h b/src/engine/msiengine.h index 04c375c2..64bddcf0 100644 --- a/src/engine/msiengine.h +++ b/src/engine/msiengine.h @@ -1,6 +1,12 @@ #pragma once // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. +// constants +#define BURNMSIINSTALL_PROPERTY_NAME L"BURNMSIINSTALL" +#define BURNMSIMODIFY_PROPERTY_NAME L"BURNMSIMODIFY" +#define BURNMSIREPAIR_PROPERTY_NAME L"BURNMSIREPAIR" +#define BURNMSIUNINSTALL_PROPERTY_NAME L"BURNMSIUNINSTALL" + #if defined(__cplusplus) extern "C" { diff --git a/src/engine/plan.cpp b/src/engine/plan.cpp index 3c0e1c50..e2a3437d 100644 --- a/src/engine/plan.cpp +++ b/src/engine/plan.cpp @@ -74,7 +74,9 @@ static BOOL AlreadyPlannedCachePackage( __in_z LPCWSTR wzPackageId, __out HANDLE* phSyncpointEvent ); -static DWORD GetNextCheckpointId(); +static DWORD GetNextCheckpointId( + __in BURN_PLAN* pPlan + ); static HRESULT AppendCacheAction( __in BURN_PLAN* pPlan, __out BURN_CACHE_ACTION** ppCacheAction @@ -1621,7 +1623,7 @@ extern "C" HRESULT PlanExecuteCheckpoint( { HRESULT hr = S_OK; BURN_EXECUTE_ACTION* pAction = NULL; - DWORD dwCheckpointId = GetNextCheckpointId(); + DWORD dwCheckpointId = GetNextCheckpointId(pPlan); // execute checkpoint hr = PlanAppendExecuteAction(pPlan, &pAction); @@ -1808,7 +1810,7 @@ extern "C" HRESULT PlanRollbackBoundaryComplete( DWORD dwCheckpointId = 0; // Add checkpoints. - dwCheckpointId = GetNextCheckpointId(); + dwCheckpointId = GetNextCheckpointId(pPlan); hr = PlanAppendExecuteAction(pPlan, &pExecuteAction); ExitOnFailure(hr, "Failed to append execute action."); @@ -2095,7 +2097,7 @@ static HRESULT AddCachePackageHelper( // Cache checkpoints happen before the package is cached because downloading packages' // payloads will not roll themselves back the way installation packages rollback on // failure automatically. - dwCheckpoint = GetNextCheckpointId(); + dwCheckpoint = GetNextCheckpointId(pPlan); hr = AppendCacheAction(pPlan, &pCacheAction); ExitOnFailure(hr, "Failed to append package start action."); @@ -2234,10 +2236,11 @@ static BOOL AlreadyPlannedCachePackage( return fPlanned; } -static DWORD GetNextCheckpointId() +static DWORD GetNextCheckpointId( + __in BURN_PLAN* pPlan + ) { - static DWORD dwCounter = 0; - return ++dwCounter; + return ++pPlan->dwNextCheckpointId; } static HRESULT AppendCacheAction( @@ -3039,11 +3042,11 @@ static void CacheActionLog( break; case BURN_CACHE_ACTION_TYPE_SIGNAL_SYNCPOINT: - LogStringLine(REPORT_STANDARD, "%ls action[%u]: SIGNAL_SYNCPOINT event handle: 0x%x, skip until retried: %hs", wzBase, iAction, pAction->syncpoint.hEvent, LoggingBoolToString(pAction->fSkipUntilRetried)); + LogStringLine(REPORT_STANDARD, "%ls action[%u]: SIGNAL_SYNCPOINT event handle: 0x%p, skip until retried: %hs", wzBase, iAction, pAction->syncpoint.hEvent, LoggingBoolToString(pAction->fSkipUntilRetried)); break; case BURN_CACHE_ACTION_TYPE_TRANSACTION_BOUNDARY: - LogStringLine(REPORT_STANDARD, "%ls action[%u]: TRANSACTION_BOUNDARY id: %ls, event handle: 0x%x, vital: %ls, transaction: %ls", wzBase, iAction, pAction->rollbackBoundary.pRollbackBoundary->sczId, pAction->rollbackBoundary.hEvent, pAction->rollbackBoundary.pRollbackBoundary->fVital ? L"yes" : L"no", pAction->rollbackBoundary.pRollbackBoundary->fTransaction ? L"yes" : L"no"); + LogStringLine(REPORT_STANDARD, "%ls action[%u]: TRANSACTION_BOUNDARY id: %ls, event handle: 0x%p, vital: %ls, transaction: %ls", wzBase, iAction, pAction->rollbackBoundary.pRollbackBoundary->sczId, pAction->rollbackBoundary.hEvent, pAction->rollbackBoundary.pRollbackBoundary->fVital ? L"yes" : L"no", pAction->rollbackBoundary.pRollbackBoundary->fTransaction ? L"yes" : L"no"); break; default: @@ -3066,11 +3069,11 @@ static void ExecuteActionLog( break; case BURN_EXECUTE_ACTION_TYPE_PACKAGE_PROVIDER: - LogStringLine(REPORT_STANDARD, "%ls action[%u]: PACKAGE_PROVIDER package id: %ls, action: %u", wzBase, iAction, pAction->packageProvider.pPackage->sczId, pAction->packageProvider.action); + LogStringLine(REPORT_STANDARD, "%ls action[%u]: PACKAGE_PROVIDER package id: %ls, action: %hs", wzBase, iAction, pAction->packageProvider.pPackage->sczId, LoggingDependencyActionToString(pAction->packageProvider.action)); break; case BURN_EXECUTE_ACTION_TYPE_PACKAGE_DEPENDENCY: - LogStringLine(REPORT_STANDARD, "%ls action[%u]: PACKAGE_DEPENDENCY package id: %ls, bundle provider key: %ls, action: %u", wzBase, iAction, pAction->packageDependency.pPackage->sczId, pAction->packageDependency.sczBundleProviderKey, pAction->packageDependency.action); + LogStringLine(REPORT_STANDARD, "%ls action[%u]: PACKAGE_DEPENDENCY package id: %ls, bundle provider key: %ls, action: %hs", wzBase, iAction, pAction->packageDependency.pPackage->sczId, pAction->packageDependency.sczBundleProviderKey, LoggingDependencyActionToString(pAction->packageDependency.action)); break; case BURN_EXECUTE_ACTION_TYPE_EXE_PACKAGE: @@ -3078,15 +3081,15 @@ static void ExecuteActionLog( break; case BURN_EXECUTE_ACTION_TYPE_MSI_PACKAGE: - LogStringLine(REPORT_STANDARD, "%ls action[%u]: MSI_PACKAGE package id: %ls, action: %hs, action msi property: %u, ui level: %u, disable externaluihandler: %ls, log path: %ls, logging attrib: %u", wzBase, iAction, pAction->msiPackage.pPackage->sczId, LoggingActionStateToString(pAction->msiPackage.action), pAction->msiPackage.actionMsiProperty, pAction->msiPackage.uiLevel, pAction->msiPackage.fDisableExternalUiHandler ? L"yes" : L"no", pAction->msiPackage.sczLogPath, pAction->msiPackage.dwLoggingAttributes); + LogStringLine(REPORT_STANDARD, "%ls action[%u]: MSI_PACKAGE package id: %ls, action: %hs, action msi property: %ls, ui level: %u, disable externaluihandler: %ls, log path: %ls, logging attrib: %u", wzBase, iAction, pAction->msiPackage.pPackage->sczId, LoggingActionStateToString(pAction->msiPackage.action), LoggingBurnMsiPropertyToString(pAction->msiPackage.actionMsiProperty), pAction->msiPackage.uiLevel, pAction->msiPackage.fDisableExternalUiHandler ? L"yes" : L"no", pAction->msiPackage.sczLogPath, pAction->msiPackage.dwLoggingAttributes); for (DWORD j = 0; j < pAction->msiPackage.cPatches; ++j) { - LogStringLine(REPORT_STANDARD, " Patch[%u]: order: %u, msp package id: %ls", j, pAction->msiPackage.rgOrderedPatches->dwOrder, pAction->msiPackage.rgOrderedPatches[j].dwOrder, pAction->msiPackage.rgOrderedPatches[j].pPackage->sczId); + LogStringLine(REPORT_STANDARD, " Patch[%u]: order: %u, msp package id: %ls", j, pAction->msiPackage.rgOrderedPatches[j].dwOrder, pAction->msiPackage.rgOrderedPatches[j].pPackage->sczId); } break; case BURN_EXECUTE_ACTION_TYPE_MSP_TARGET: - LogStringLine(REPORT_STANDARD, "%ls action[%u]: MSP_TARGET package id: %ls, action: %hs, target product code: %ls, target per-machine: %ls, action msi property: %u, ui level: %u, disable externaluihandler: %ls, log path: %ls", wzBase, iAction, pAction->mspTarget.pPackage->sczId, LoggingActionStateToString(pAction->mspTarget.action), pAction->mspTarget.sczTargetProductCode, pAction->mspTarget.fPerMachineTarget ? L"yes" : L"no", pAction->mspTarget.actionMsiProperty, pAction->mspTarget.uiLevel, pAction->mspTarget.fDisableExternalUiHandler ? L"yes" : L"no", pAction->mspTarget.sczLogPath); + LogStringLine(REPORT_STANDARD, "%ls action[%u]: MSP_TARGET package id: %ls, action: %hs, target product code: %ls, target per-machine: %ls, action msi property: %ls, ui level: %u, disable externaluihandler: %ls, log path: %ls", wzBase, iAction, pAction->mspTarget.pPackage->sczId, LoggingActionStateToString(pAction->mspTarget.action), pAction->mspTarget.sczTargetProductCode, pAction->mspTarget.fPerMachineTarget ? L"yes" : L"no", LoggingBurnMsiPropertyToString(pAction->mspTarget.actionMsiProperty), pAction->mspTarget.uiLevel, pAction->mspTarget.fDisableExternalUiHandler ? L"yes" : L"no", pAction->mspTarget.sczLogPath); for (DWORD j = 0; j < pAction->mspTarget.cOrderedPatches; ++j) { LogStringLine(REPORT_STANDARD, " Patch[%u]: order: %u, msp package id: %ls", j, pAction->mspTarget.rgOrderedPatches[j].dwOrder, pAction->mspTarget.rgOrderedPatches[j].pPackage->sczId); @@ -3106,7 +3109,7 @@ static void ExecuteActionLog( break; case BURN_EXECUTE_ACTION_TYPE_WAIT_SYNCPOINT: - LogStringLine(REPORT_STANDARD, "%ls action[%u]: WAIT_SYNCPOINT event handle: 0x%x", wzBase, iAction, pAction->syncpoint.hEvent); + LogStringLine(REPORT_STANDARD, "%ls action[%u]: WAIT_SYNCPOINT event handle: 0x%p", wzBase, iAction, pAction->syncpoint.hEvent); break; case BURN_EXECUTE_ACTION_TYPE_UNCACHE_PACKAGE: @@ -3131,6 +3134,7 @@ extern "C" void PlanDump( LogStringLine(REPORT_STANDARD, "Plan action: %hs", LoggingBurnActionToString(pPlan->action)); LogStringLine(REPORT_STANDARD, " per-machine: %hs", LoggingTrueFalseToString(pPlan->fPerMachine)); + LogStringLine(REPORT_STANDARD, " disable-rollback: %hs", LoggingTrueFalseToString(pPlan->fDisableRollback)); LogStringLine(REPORT_STANDARD, " keep registration by default: %hs", LoggingTrueFalseToString(pPlan->fKeepRegistrationDefault)); LogStringLine(REPORT_STANDARD, " estimated size: %llu", pPlan->qwEstimatedSize); diff --git a/src/engine/plan.h b/src/engine/plan.h index 4fd3380e..5fddd72f 100644 --- a/src/engine/plan.h +++ b/src/engine/plan.h @@ -325,6 +325,7 @@ typedef struct _BURN_PLAN DWORD dwRegistrationOperations; BOOL fKeepRegistrationDefault; BOOL fDisallowRemoval; + BOOL fDisableRollback; DWORD64 qwCacheSizeTotal; @@ -366,6 +367,8 @@ typedef struct _BURN_PLAN BURN_CACHE_PAYLOAD_PROGRESS* rgPayloadProgress; DWORD cPayloadProgress; STRINGDICT_HANDLE shPayloadProgress; + + DWORD dwNextCheckpointId; } BURN_PLAN; -- cgit v1.2.3-55-g6feb