@joebigelow / wix / commits / 0ee63890

Always reset the system component status when registering the bundle.

Finishes 4454

Sean Hall committed Apr 22, 2022 at 16:57 UTC 0ee63890d8eacd044115524476eb9419114500a7
7 files changed +26 -165
src/burn/engine/apply.cpp
+9 -28
@@ -430,37 +430,18 @@ extern "C" HRESULT ApplyRegister(
430 hr = UserExperienceOnRegisterBegin(&pEngineState->userExperience, &registrationType);
431 ExitOnRootFailure(hr, "BA aborted register begin.");
432
433 - // If we have a resume mode that suggests the bundle is on the machine.
434 - if (BOOTSTRAPPER_RESUME_TYPE_REBOOT <= pEngineState->command.resumeType)
433 + hr = CacheCalculateBundleWorkingPath(pEngineState->plan.pCache, pEngineState->registration.sczExecutableName, &sczEngineWorkingPath);
434 + ExitOnFailure(hr, "Failed to calculate working path for engine.");
435 +
436 + if (pEngineState->registration.fPerMachine)
437 {
436 - // resume previous session
437 - if (pEngineState->registration.fPerMachine)
438 - {
439 - hr = ElevationSessionResume(pEngineState->companionConnection.hPipe, pEngineState->registration.sczResumeCommandLine, pEngineState->registration.fDisableResume, &pEngineState->variables, registrationType);
440 - ExitOnFailure(hr, "Failed to resume registration session in per-machine process.");
441 - }
442 - else
443 - {
444 - hr = RegistrationSessionResume(&pEngineState->registration, &pEngineState->variables, registrationType);
445 - ExitOnFailure(hr, "Failed to resume registration session.");
446 - }
438 + hr = ElevationSessionBegin(pEngineState->companionConnection.hPipe, sczEngineWorkingPath, pEngineState->registration.sczResumeCommandLine, pEngineState->registration.fDisableResume, &pEngineState->variables, pEngineState->plan.dwRegistrationOperations, pEngineState->registration.fDetectedForeignProviderKeyBundleId, qwEstimatedSize, registrationType);
439 + ExitOnFailure(hr, "Failed to begin registration session in per-machine process.");
440 }
448 - else // need to complete registration on the machine.
441 + else
442 {
450 - hr = CacheCalculateBundleWorkingPath(pEngineState->plan.pCache, pEngineState->registration.sczExecutableName, &sczEngineWorkingPath);
451 - ExitOnFailure(hr, "Failed to calculate working path for engine.");
452 -
453 - // begin new session
454 - if (pEngineState->registration.fPerMachine)
455 - {
456 - hr = ElevationSessionBegin(pEngineState->companionConnection.hPipe, sczEngineWorkingPath, pEngineState->registration.sczResumeCommandLine, pEngineState->registration.fDisableResume, &pEngineState->variables, pEngineState->plan.dwRegistrationOperations, pEngineState->registration.fDetectedForeignProviderKeyBundleId, qwEstimatedSize, registrationType);
457 - ExitOnFailure(hr, "Failed to begin registration session in per-machine process.");
458 - }
459 - else
460 - {
461 - hr = RegistrationSessionBegin(sczEngineWorkingPath, &pEngineState->registration, &pEngineState->cache, &pEngineState->variables, pEngineState->plan.dwRegistrationOperations, qwEstimatedSize, registrationType);
462 - ExitOnFailure(hr, "Failed to begin registration session.");
463 - }
443 + hr = RegistrationSessionBegin(sczEngineWorkingPath, &pEngineState->registration, &pEngineState->cache, &pEngineState->variables, pEngineState->plan.dwRegistrationOperations, qwEstimatedSize, registrationType);
444 + ExitOnFailure(hr, "Failed to begin registration session.");
445 }
446
447 // Apply any registration actions.
src/burn/engine/elevation.cpp
-85
@@ -11,7 +11,6 @@ typedef enum _BURN_ELEVATION_MESSAGE_TYPE
11 BURN_ELEVATION_MESSAGE_TYPE_APPLY_INITIALIZE,
12 BURN_ELEVATION_MESSAGE_TYPE_APPLY_UNINITIALIZE,
13 BURN_ELEVATION_MESSAGE_TYPE_SESSION_BEGIN,
14 - BURN_ELEVATION_MESSAGE_TYPE_SESSION_RESUME,
14 BURN_ELEVATION_MESSAGE_TYPE_SESSION_END,
15 BURN_ELEVATION_MESSAGE_TYPE_SAVE_STATE,
16 BURN_ELEVATION_MESSAGE_TYPE_CACHE_PREPARE_PACKAGE,
@@ -195,12 +194,6 @@ static HRESULT OnSessionBegin(
194 __in BYTE* pbData,
195 __in SIZE_T cbData
196 );
198 -static HRESULT OnSessionResume(
199 - __in BURN_REGISTRATION* pRegistration,
200 - __in BURN_VARIABLES* pVariables,
201 - __in BYTE* pbData,
202 - __in SIZE_T cbData
203 - );
197 static HRESULT OnSessionEnd(
198 __in BURN_CACHE* pCache,
199 __in BURN_PACKAGES* pPackages,
@@ -585,48 +578,6 @@ LExit:
578 return hr;
579 }
580
588 -/*******************************************************************
589 - ElevationSessionResume -
590 -
591 -*******************************************************************/
592 -extern "C" HRESULT ElevationSessionResume(
593 - __in HANDLE hPipe,
594 - __in_z LPCWSTR wzResumeCommandLine,
595 - __in BOOL fDisableResume,
596 - __in BURN_VARIABLES* pVariables,
597 - __in BOOTSTRAPPER_REGISTRATION_TYPE registrationType
598 - )
599 -{
600 - HRESULT hr = S_OK;
601 - BYTE* pbData = NULL;
602 - SIZE_T cbData = 0;
603 - DWORD dwResult = 0;
604 -
605 - // serialize message data
606 - hr = BuffWriteString(&pbData, &cbData, wzResumeCommandLine);
607 - ExitOnFailure(hr, "Failed to write resume command line to message buffer.");
608 -
609 - hr = BuffWriteNumber(&pbData, &cbData, fDisableResume);
610 - ExitOnFailure(hr, "Failed to write resume flag.");
611 -
612 - hr = BuffWriteNumber(&pbData, &cbData, (DWORD)registrationType);
613 - ExitOnFailure(hr, "Failed to write registration type to message buffer.");
614 -
615 - hr = VariableSerialize(pVariables, FALSE, &pbData, &cbData);
616 - ExitOnFailure(hr, "Failed to write variables.");
617 -
618 - // send message
619 - hr = PipeSendMessage(hPipe, BURN_ELEVATION_MESSAGE_TYPE_SESSION_RESUME, pbData, cbData, NULL, NULL, &dwResult);
620 - ExitOnFailure(hr, "Failed to send message to per-machine process.");
621 -
622 - hr = (HRESULT)dwResult;
623 -
624 -LExit:
625 - ReleaseBuffer(pbData);
626 -
627 - return hr;
628 -}
629 -
581 /*******************************************************************
582 ElevationSessionEnd -
583
@@ -2174,10 +2125,6 @@ static HRESULT ProcessElevatedChildMessage(
2125 hrResult = OnSessionBegin(pContext->pCache, pContext->pRegistration, pContext->pVariables, (BYTE*)pMsg->pvData, pMsg->cbData);
2126 break;
2127
2177 - case BURN_ELEVATION_MESSAGE_TYPE_SESSION_RESUME:
2178 - hrResult = OnSessionResume(pContext->pRegistration, pContext->pVariables, (BYTE*)pMsg->pvData, pMsg->cbData);
2179 - break;
2180 -
2128 case BURN_ELEVATION_MESSAGE_TYPE_SESSION_END:
2129 hrResult = OnSessionEnd(pContext->pCache, pContext->pPackages, pContext->pRegistration, pContext->pVariables, (BYTE*)pMsg->pvData, pMsg->cbData);
2130 break;
@@ -2539,38 +2486,6 @@ LExit:
2486 return hr;
2487 }
2488
2542 -static HRESULT OnSessionResume(
2543 - __in BURN_REGISTRATION* pRegistration,
2544 - __in BURN_VARIABLES* pVariables,
2545 - __in BYTE* pbData,
2546 - __in SIZE_T cbData
2547 - )
2548 -{
2549 - HRESULT hr = S_OK;
2550 - SIZE_T iData = 0;
2551 - DWORD dwRegistrationType = 0;
2552 -
2553 - // Deserialize message data.
2554 - hr = BuffReadString(pbData, cbData, &iData, &pRegistration->sczResumeCommandLine);
2555 - ExitOnFailure(hr, "Failed to read resume command line.");
2556 -
2557 - hr = BuffReadNumber(pbData, cbData, &iData, (DWORD*)&pRegistration->fDisableResume);
2558 - ExitOnFailure(hr, "Failed to read resume flag.");
2559 -
2560 - hr = BuffReadNumber(pbData, cbData, &iData, &dwRegistrationType);
2561 - ExitOnFailure(hr, "Failed to read dependency registration action.");
2562 -
2563 - hr = VariableDeserialize(pVariables, FALSE, pbData, cbData, &iData);
2564 - ExitOnFailure(hr, "Failed to read variables.");
2565 -
2566 - // resume session in per-machine process
2567 - hr = RegistrationSessionResume(pRegistration, pVariables, (BOOTSTRAPPER_REGISTRATION_TYPE)dwRegistrationType);
2568 - ExitOnFailure(hr, "Failed to resume registration session.");
2569 -
2570 -LExit:
2571 - return hr;
2572 -}
2573 -
2489 static HRESULT OnSessionEnd(
2490 __in BURN_CACHE* pCache,
2491 __in BURN_PACKAGES* pPackages,
src/burn/engine/elevation.h
-7
@@ -32,13 +32,6 @@ HRESULT ElevationSessionBegin(
32 __in DWORD64 qwEstimatedSize,
33 __in BOOTSTRAPPER_REGISTRATION_TYPE registrationType
34 );
35 -HRESULT ElevationSessionResume(
36 - __in HANDLE hPipe,
37 - __in_z LPCWSTR wzResumeCommandLine,
38 - __in BOOL fDisableResume,
39 - __in BURN_VARIABLES* pVariables,
40 - __in BOOTSTRAPPER_REGISTRATION_TYPE registrationType
41 - );
35 HRESULT ElevationSessionEnd(
36 __in HANDLE hPipe,
37 __in BURN_RESUME_MODE resumeMode,
src/burn/engine/registration.cpp
+14 -37
@@ -607,6 +607,7 @@ extern "C" HRESULT RegistrationSessionBegin(
607 HKEY hkRegistration = NULL;
608 BOOL fCreated = FALSE;
609 LPWSTR sczPublisher = NULL;
610 + DWORD er = ERROR_SUCCESS;
611
612 AssertSz(BOOTSTRAPPER_REGISTRATION_TYPE_NONE != registrationType, "Registration type can't be NONE");
613
@@ -776,6 +777,15 @@ extern "C" HRESULT RegistrationSessionBegin(
777 hr = RegWriteNumber(hkRegistration, REGISTRY_BUNDLE_SYSTEM_COMPONENT, 1);
778 ExitOnFailure(hr, "Failed to write %ls value.", REGISTRY_BUNDLE_SYSTEM_COMPONENT);
779 }
780 + else
781 + {
782 + er = ::RegDeleteValueW(hkRegistration, REGISTRY_BUNDLE_SYSTEM_COMPONENT);
783 + if (ERROR_FILE_NOT_FOUND == er || ERROR_PATH_NOT_FOUND == er)
784 + {
785 + er = ERROR_SUCCESS;
786 + }
787 + ExitOnWin32Error(er, hr, "Failed to delete %ls value.", REGISTRY_BUNDLE_SYSTEM_COMPONENT);
788 + }
789
790 // QuietUninstallString: [path to exe] /uninstall /quiet
791 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:
838 }
839
840
831 -/*******************************************************************
832 - RegistrationSessionResume - Resumes a previous run session.
833 -
834 -*******************************************************************/
835 -extern "C" HRESULT RegistrationSessionResume(
836 - __in BURN_REGISTRATION* pRegistration,
837 - __in BURN_VARIABLES* pVariables,
838 - __in BOOTSTRAPPER_REGISTRATION_TYPE registrationType
839 - )
840 -{
841 - HRESULT hr = S_OK;
842 - HKEY hkRegistration = NULL;
843 -
844 - AssertSz(BOOTSTRAPPER_REGISTRATION_TYPE_NONE != registrationType, "Registration type can't be NONE");
845 -
846 - // open registration key
847 - hr = RegOpen(pRegistration->hkRoot, pRegistration->sczRegistrationKey, KEY_WRITE, &hkRegistration);
848 - ExitOnFailure(hr, "Failed to open registration key.");
849 -
850 - // update resume mode
851 - hr = UpdateResumeMode(pRegistration, hkRegistration, BURN_RESUME_MODE_ACTIVE, registrationType, FALSE);
852 - ExitOnFailure(hr, "Failed to update resume mode.");
853 -
854 - // update display name
855 - hr = UpdateBundleNameRegistration(pRegistration, pVariables, hkRegistration, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS == registrationType);
856 - ExitOnFailure(hr, "Failed to update name and publisher.");
857 -
858 -LExit:
859 - ReleaseRegKey(hkRegistration);
860 -
861 - return hr;
862 -}
863 -
864 -
841 /*******************************************************************
842 RegistrationSessionEnd - Unregisters a run session from the system.
843
@@ -950,6 +926,7 @@ extern "C" HRESULT RegistrationSaveState(
926 LPWSTR sczValueName = NULL;
927 DWORD dwType = 0;
928 DWORD dwNumberOfExistingValues = 0;
929 + DWORD er = ERROR_SUCCESS;
930
931
932 // write data to file
@@ -989,8 +966,8 @@ extern "C" HRESULT RegistrationSaveState(
966
967 ExitOnFailure(hr, "Failed to enumerate value %u", i);
968
992 - hr = RegDeleteValue(hkRegistration, sczValueName);
993 - ExitOnFailure(hr, "Failed to delete registration variable value.");
969 + er = ::RegDeleteValueW(hkRegistration, sczValueName);
970 + ExitOnWin32Error(er, hr, "Failed to delete registration variable value.");
971 }
972
973 // Write variables.
@@ -1313,7 +1290,7 @@ static HRESULT UpdateResumeMode(
1290 }
1291 else
1292 {
1316 - ExitOnWin32Error(er, hr, "Failed to open run key.");
1293 + ExitOnFailure(hr, "Failed to open run key.");
1294
1295 er = ::RegDeleteValueW(hkRun, pRegistration->sczId);
1296 if (ERROR_FILE_NOT_FOUND == er)
src/burn/engine/registration.h
-5
@@ -201,11 +201,6 @@ HRESULT RegistrationSessionBegin(
201 __in DWORD64 qwEstimatedSize,
202 __in BOOTSTRAPPER_REGISTRATION_TYPE registrationType
203 );
204 -HRESULT RegistrationSessionResume(
205 - __in BURN_REGISTRATION* pRegistration,
206 - __in BURN_VARIABLES* pVariables,
207 - __in BOOTSTRAPPER_REGISTRATION_TYPE registrationType
208 - );
204 HRESULT RegistrationSessionEnd(
205 __in BURN_REGISTRATION* pRegistration,
206 __in BURN_CACHE* pCache,
src/burn/test/BurnUnitTest/RegistrationTest.cpp
+1 -1
@@ -793,7 +793,7 @@ namespace Bootstrapper
793 TestThrowOnFailure(hr, L"Failed to deserialize variables.");
794
795 // write active resume mode
796 - hr = RegistrationSessionResume(&registration, &variables, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS);
796 + hr = RegistrationSessionBegin(sczCurrentProcess, &registration, &cache, &variables, dwRegistrationOptions, qwEstimatedSize, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS);
797 TestThrowOnFailure(hr, L"Failed to write active resume mode.");
798
799 // verify that run key was put back
src/test/burn/WixToolsetTest.BurnE2E/BundlePackageTests.cs
+2 -2
@@ -115,12 +115,12 @@ namespace WixToolsetTest.BurnE2E
115
116 // Repair bundle so it adds itself as a reference to itself.
117 bundleAv1.Repair();
118 - bundleAv1.VerifyRegisteredAndInPackageCache(expectedSystemComponent: 1);
118 + bundleAv1.VerifyRegisteredAndInPackageCache();
119
120 upgradeBundlePackageBundlev1.Uninstall();
121 upgradeBundlePackageBundlev1.VerifyUnregisteredAndRemovedFromPackageCache();
122
123 - bundleAv1.VerifyRegisteredAndInPackageCache(expectedSystemComponent: 1);
123 + bundleAv1.VerifyRegisteredAndInPackageCache();
124 }
125
126 [Fact]