From 0ee63890d8eacd044115524476eb9419114500a7 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Fri, 22 Apr 2022 16:57:18 -0500 Subject: Always reset the system component status when registering the bundle. Finishes 4454 --- src/burn/engine/apply.cpp | 37 +++------- src/burn/engine/elevation.cpp | 85 ---------------------- src/burn/engine/elevation.h | 7 -- src/burn/engine/registration.cpp | 51 ++++--------- src/burn/engine/registration.h | 5 -- src/burn/test/BurnUnitTest/RegistrationTest.cpp | 2 +- .../WixToolsetTest.BurnE2E/BundlePackageTests.cs | 4 +- 7 files changed, 26 insertions(+), 165 deletions(-) (limited to 'src') diff --git a/src/burn/engine/apply.cpp b/src/burn/engine/apply.cpp index 69106f65..d0db053a 100644 --- a/src/burn/engine/apply.cpp +++ b/src/burn/engine/apply.cpp @@ -430,37 +430,18 @@ extern "C" HRESULT ApplyRegister( hr = UserExperienceOnRegisterBegin(&pEngineState->userExperience, ®istrationType); ExitOnRootFailure(hr, "BA aborted register begin."); - // If we have a resume mode that suggests the bundle is on the machine. - if (BOOTSTRAPPER_RESUME_TYPE_REBOOT <= pEngineState->command.resumeType) + hr = CacheCalculateBundleWorkingPath(pEngineState->plan.pCache, pEngineState->registration.sczExecutableName, &sczEngineWorkingPath); + ExitOnFailure(hr, "Failed to calculate working path for engine."); + + if (pEngineState->registration.fPerMachine) { - // resume previous session - if (pEngineState->registration.fPerMachine) - { - hr = ElevationSessionResume(pEngineState->companionConnection.hPipe, pEngineState->registration.sczResumeCommandLine, pEngineState->registration.fDisableResume, &pEngineState->variables, registrationType); - ExitOnFailure(hr, "Failed to resume registration session in per-machine process."); - } - else - { - hr = RegistrationSessionResume(&pEngineState->registration, &pEngineState->variables, registrationType); - ExitOnFailure(hr, "Failed to resume registration session."); - } + hr = ElevationSessionBegin(pEngineState->companionConnection.hPipe, sczEngineWorkingPath, pEngineState->registration.sczResumeCommandLine, pEngineState->registration.fDisableResume, &pEngineState->variables, pEngineState->plan.dwRegistrationOperations, pEngineState->registration.fDetectedForeignProviderKeyBundleId, qwEstimatedSize, registrationType); + ExitOnFailure(hr, "Failed to begin registration session in per-machine process."); } - else // need to complete registration on the machine. + else { - hr = CacheCalculateBundleWorkingPath(pEngineState->plan.pCache, pEngineState->registration.sczExecutableName, &sczEngineWorkingPath); - ExitOnFailure(hr, "Failed to calculate working path for engine."); - - // begin new session - if (pEngineState->registration.fPerMachine) - { - hr = ElevationSessionBegin(pEngineState->companionConnection.hPipe, sczEngineWorkingPath, pEngineState->registration.sczResumeCommandLine, pEngineState->registration.fDisableResume, &pEngineState->variables, pEngineState->plan.dwRegistrationOperations, pEngineState->registration.fDetectedForeignProviderKeyBundleId, qwEstimatedSize, registrationType); - ExitOnFailure(hr, "Failed to begin registration session in per-machine process."); - } - else - { - hr = RegistrationSessionBegin(sczEngineWorkingPath, &pEngineState->registration, &pEngineState->cache, &pEngineState->variables, pEngineState->plan.dwRegistrationOperations, qwEstimatedSize, registrationType); - ExitOnFailure(hr, "Failed to begin registration session."); - } + hr = RegistrationSessionBegin(sczEngineWorkingPath, &pEngineState->registration, &pEngineState->cache, &pEngineState->variables, pEngineState->plan.dwRegistrationOperations, qwEstimatedSize, registrationType); + ExitOnFailure(hr, "Failed to begin registration session."); } // Apply any registration actions. diff --git a/src/burn/engine/elevation.cpp b/src/burn/engine/elevation.cpp index 3305cf62..d2c5c8c6 100644 --- a/src/burn/engine/elevation.cpp +++ b/src/burn/engine/elevation.cpp @@ -11,7 +11,6 @@ typedef enum _BURN_ELEVATION_MESSAGE_TYPE BURN_ELEVATION_MESSAGE_TYPE_APPLY_INITIALIZE, BURN_ELEVATION_MESSAGE_TYPE_APPLY_UNINITIALIZE, BURN_ELEVATION_MESSAGE_TYPE_SESSION_BEGIN, - BURN_ELEVATION_MESSAGE_TYPE_SESSION_RESUME, BURN_ELEVATION_MESSAGE_TYPE_SESSION_END, BURN_ELEVATION_MESSAGE_TYPE_SAVE_STATE, BURN_ELEVATION_MESSAGE_TYPE_CACHE_PREPARE_PACKAGE, @@ -195,12 +194,6 @@ static HRESULT OnSessionBegin( __in BYTE* pbData, __in SIZE_T cbData ); -static HRESULT OnSessionResume( - __in BURN_REGISTRATION* pRegistration, - __in BURN_VARIABLES* pVariables, - __in BYTE* pbData, - __in SIZE_T cbData - ); static HRESULT OnSessionEnd( __in BURN_CACHE* pCache, __in BURN_PACKAGES* pPackages, @@ -585,48 +578,6 @@ LExit: return hr; } -/******************************************************************* - ElevationSessionResume - - -*******************************************************************/ -extern "C" HRESULT ElevationSessionResume( - __in HANDLE hPipe, - __in_z LPCWSTR wzResumeCommandLine, - __in BOOL fDisableResume, - __in BURN_VARIABLES* pVariables, - __in BOOTSTRAPPER_REGISTRATION_TYPE registrationType - ) -{ - HRESULT hr = S_OK; - BYTE* pbData = NULL; - SIZE_T cbData = 0; - DWORD dwResult = 0; - - // serialize message data - hr = BuffWriteString(&pbData, &cbData, wzResumeCommandLine); - ExitOnFailure(hr, "Failed to write resume command line to message buffer."); - - hr = BuffWriteNumber(&pbData, &cbData, fDisableResume); - ExitOnFailure(hr, "Failed to write resume flag."); - - hr = BuffWriteNumber(&pbData, &cbData, (DWORD)registrationType); - ExitOnFailure(hr, "Failed to write registration type to message buffer."); - - hr = VariableSerialize(pVariables, FALSE, &pbData, &cbData); - ExitOnFailure(hr, "Failed to write variables."); - - // send message - hr = PipeSendMessage(hPipe, BURN_ELEVATION_MESSAGE_TYPE_SESSION_RESUME, pbData, cbData, NULL, NULL, &dwResult); - ExitOnFailure(hr, "Failed to send message to per-machine process."); - - hr = (HRESULT)dwResult; - -LExit: - ReleaseBuffer(pbData); - - return hr; -} - /******************************************************************* ElevationSessionEnd - @@ -2174,10 +2125,6 @@ static HRESULT ProcessElevatedChildMessage( hrResult = OnSessionBegin(pContext->pCache, pContext->pRegistration, pContext->pVariables, (BYTE*)pMsg->pvData, pMsg->cbData); break; - case BURN_ELEVATION_MESSAGE_TYPE_SESSION_RESUME: - hrResult = OnSessionResume(pContext->pRegistration, pContext->pVariables, (BYTE*)pMsg->pvData, pMsg->cbData); - break; - case BURN_ELEVATION_MESSAGE_TYPE_SESSION_END: hrResult = OnSessionEnd(pContext->pCache, pContext->pPackages, pContext->pRegistration, pContext->pVariables, (BYTE*)pMsg->pvData, pMsg->cbData); break; @@ -2539,38 +2486,6 @@ LExit: return hr; } -static HRESULT OnSessionResume( - __in BURN_REGISTRATION* pRegistration, - __in BURN_VARIABLES* pVariables, - __in BYTE* pbData, - __in SIZE_T cbData - ) -{ - HRESULT hr = S_OK; - SIZE_T iData = 0; - DWORD dwRegistrationType = 0; - - // Deserialize message data. - hr = BuffReadString(pbData, cbData, &iData, &pRegistration->sczResumeCommandLine); - ExitOnFailure(hr, "Failed to read resume command line."); - - hr = BuffReadNumber(pbData, cbData, &iData, (DWORD*)&pRegistration->fDisableResume); - ExitOnFailure(hr, "Failed to read resume flag."); - - hr = BuffReadNumber(pbData, cbData, &iData, &dwRegistrationType); - ExitOnFailure(hr, "Failed to read dependency registration action."); - - hr = VariableDeserialize(pVariables, FALSE, pbData, cbData, &iData); - ExitOnFailure(hr, "Failed to read variables."); - - // resume session in per-machine process - hr = RegistrationSessionResume(pRegistration, pVariables, (BOOTSTRAPPER_REGISTRATION_TYPE)dwRegistrationType); - ExitOnFailure(hr, "Failed to resume registration session."); - -LExit: - return hr; -} - static HRESULT OnSessionEnd( __in BURN_CACHE* pCache, __in BURN_PACKAGES* pPackages, diff --git a/src/burn/engine/elevation.h b/src/burn/engine/elevation.h index a74b6027..0dc189c5 100644 --- a/src/burn/engine/elevation.h +++ b/src/burn/engine/elevation.h @@ -32,13 +32,6 @@ HRESULT ElevationSessionBegin( __in DWORD64 qwEstimatedSize, __in BOOTSTRAPPER_REGISTRATION_TYPE registrationType ); -HRESULT ElevationSessionResume( - __in HANDLE hPipe, - __in_z LPCWSTR wzResumeCommandLine, - __in BOOL fDisableResume, - __in BURN_VARIABLES* pVariables, - __in BOOTSTRAPPER_REGISTRATION_TYPE registrationType - ); HRESULT ElevationSessionEnd( __in HANDLE hPipe, __in BURN_RESUME_MODE resumeMode, diff --git a/src/burn/engine/registration.cpp b/src/burn/engine/registration.cpp index 9953be83..e83e0811 100644 --- a/src/burn/engine/registration.cpp +++ b/src/burn/engine/registration.cpp @@ -607,6 +607,7 @@ extern "C" HRESULT RegistrationSessionBegin( HKEY hkRegistration = NULL; BOOL fCreated = FALSE; LPWSTR sczPublisher = NULL; + DWORD er = ERROR_SUCCESS; AssertSz(BOOTSTRAPPER_REGISTRATION_TYPE_NONE != registrationType, "Registration type can't be NONE"); @@ -776,6 +777,15 @@ extern "C" HRESULT RegistrationSessionBegin( hr = RegWriteNumber(hkRegistration, REGISTRY_BUNDLE_SYSTEM_COMPONENT, 1); ExitOnFailure(hr, "Failed to write %ls value.", REGISTRY_BUNDLE_SYSTEM_COMPONENT); } + else + { + er = ::RegDeleteValueW(hkRegistration, REGISTRY_BUNDLE_SYSTEM_COMPONENT); + if (ERROR_FILE_NOT_FOUND == er || ERROR_PATH_NOT_FOUND == er) + { + er = ERROR_SUCCESS; + } + ExitOnWin32Error(er, hr, "Failed to delete %ls value.", REGISTRY_BUNDLE_SYSTEM_COMPONENT); + } // QuietUninstallString: [path to exe] /uninstall /quiet hr = RegWriteStringFormatted(hkRegistration, REGISTRY_BUNDLE_QUIET_UNINSTALL_STRING, L"\"%ls\" /%ls /uninstall /quiet", pRegistration->sczCacheExecutablePath, BURN_COMMANDLINE_SWITCH_CLEAN_ROOM); @@ -828,40 +838,6 @@ LExit: } -/******************************************************************* - RegistrationSessionResume - Resumes a previous run session. - -*******************************************************************/ -extern "C" HRESULT RegistrationSessionResume( - __in BURN_REGISTRATION* pRegistration, - __in BURN_VARIABLES* pVariables, - __in BOOTSTRAPPER_REGISTRATION_TYPE registrationType - ) -{ - HRESULT hr = S_OK; - HKEY hkRegistration = NULL; - - AssertSz(BOOTSTRAPPER_REGISTRATION_TYPE_NONE != registrationType, "Registration type can't be NONE"); - - // open registration key - hr = RegOpen(pRegistration->hkRoot, pRegistration->sczRegistrationKey, KEY_WRITE, &hkRegistration); - ExitOnFailure(hr, "Failed to open registration key."); - - // update resume mode - hr = UpdateResumeMode(pRegistration, hkRegistration, BURN_RESUME_MODE_ACTIVE, registrationType, FALSE); - ExitOnFailure(hr, "Failed to update resume mode."); - - // update display name - hr = UpdateBundleNameRegistration(pRegistration, pVariables, hkRegistration, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS == registrationType); - ExitOnFailure(hr, "Failed to update name and publisher."); - -LExit: - ReleaseRegKey(hkRegistration); - - return hr; -} - - /******************************************************************* RegistrationSessionEnd - Unregisters a run session from the system. @@ -950,6 +926,7 @@ extern "C" HRESULT RegistrationSaveState( LPWSTR sczValueName = NULL; DWORD dwType = 0; DWORD dwNumberOfExistingValues = 0; + DWORD er = ERROR_SUCCESS; // write data to file @@ -989,8 +966,8 @@ extern "C" HRESULT RegistrationSaveState( ExitOnFailure(hr, "Failed to enumerate value %u", i); - hr = RegDeleteValue(hkRegistration, sczValueName); - ExitOnFailure(hr, "Failed to delete registration variable value."); + er = ::RegDeleteValueW(hkRegistration, sczValueName); + ExitOnWin32Error(er, hr, "Failed to delete registration variable value."); } // Write variables. @@ -1313,7 +1290,7 @@ static HRESULT UpdateResumeMode( } else { - ExitOnWin32Error(er, hr, "Failed to open run key."); + ExitOnFailure(hr, "Failed to open run key."); er = ::RegDeleteValueW(hkRun, pRegistration->sczId); if (ERROR_FILE_NOT_FOUND == er) diff --git a/src/burn/engine/registration.h b/src/burn/engine/registration.h index cb5349a3..91c3fdcd 100644 --- a/src/burn/engine/registration.h +++ b/src/burn/engine/registration.h @@ -201,11 +201,6 @@ HRESULT RegistrationSessionBegin( __in DWORD64 qwEstimatedSize, __in BOOTSTRAPPER_REGISTRATION_TYPE registrationType ); -HRESULT RegistrationSessionResume( - __in BURN_REGISTRATION* pRegistration, - __in BURN_VARIABLES* pVariables, - __in BOOTSTRAPPER_REGISTRATION_TYPE registrationType - ); HRESULT RegistrationSessionEnd( __in BURN_REGISTRATION* pRegistration, __in BURN_CACHE* pCache, diff --git a/src/burn/test/BurnUnitTest/RegistrationTest.cpp b/src/burn/test/BurnUnitTest/RegistrationTest.cpp index 0075e937..9aadc2cc 100644 --- a/src/burn/test/BurnUnitTest/RegistrationTest.cpp +++ b/src/burn/test/BurnUnitTest/RegistrationTest.cpp @@ -793,7 +793,7 @@ namespace Bootstrapper TestThrowOnFailure(hr, L"Failed to deserialize variables."); // write active resume mode - hr = RegistrationSessionResume(®istration, &variables, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS); + hr = RegistrationSessionBegin(sczCurrentProcess, ®istration, &cache, &variables, dwRegistrationOptions, qwEstimatedSize, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS); TestThrowOnFailure(hr, L"Failed to write active resume mode."); // verify that run key was put back diff --git a/src/test/burn/WixToolsetTest.BurnE2E/BundlePackageTests.cs b/src/test/burn/WixToolsetTest.BurnE2E/BundlePackageTests.cs index bcdea974..b3015c30 100644 --- a/src/test/burn/WixToolsetTest.BurnE2E/BundlePackageTests.cs +++ b/src/test/burn/WixToolsetTest.BurnE2E/BundlePackageTests.cs @@ -115,12 +115,12 @@ namespace WixToolsetTest.BurnE2E // Repair bundle so it adds itself as a reference to itself. bundleAv1.Repair(); - bundleAv1.VerifyRegisteredAndInPackageCache(expectedSystemComponent: 1); + bundleAv1.VerifyRegisteredAndInPackageCache(); upgradeBundlePackageBundlev1.Uninstall(); upgradeBundlePackageBundlev1.VerifyUnregisteredAndRemovedFromPackageCache(); - bundleAv1.VerifyRegisteredAndInPackageCache(expectedSystemComponent: 1); + bundleAv1.VerifyRegisteredAndInPackageCache(); } [Fact] -- cgit v1.2.3-55-g6feb