aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2022-04-22 16:57:18 -0500
committerSean Hall <r.sean.hall@gmail.com>2022-04-23 15:40:21 -0500
commit0ee63890d8eacd044115524476eb9419114500a7 (patch)
tree63f7794f98a6438d29b8aae881c20c4de583a1a2
parenta981e29d7a3df566754356c3fe1eb938a5cac4c1 (diff)
downloadwix-0ee63890d8eacd044115524476eb9419114500a7.tar.gz
wix-0ee63890d8eacd044115524476eb9419114500a7.tar.bz2
wix-0ee63890d8eacd044115524476eb9419114500a7.zip
Always reset the system component status when registering the bundle.
Finishes 4454
-rw-r--r--src/burn/engine/apply.cpp37
-rw-r--r--src/burn/engine/elevation.cpp85
-rw-r--r--src/burn/engine/elevation.h7
-rw-r--r--src/burn/engine/registration.cpp51
-rw-r--r--src/burn/engine/registration.h5
-rw-r--r--src/burn/test/BurnUnitTest/RegistrationTest.cpp2
-rw-r--r--src/test/burn/WixToolsetTest.BurnE2E/BundlePackageTests.cs4
7 files changed, 26 insertions, 165 deletions
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(
430 hr = UserExperienceOnRegisterBegin(&pEngineState->userExperience, &registrationType); 430 hr = UserExperienceOnRegisterBegin(&pEngineState->userExperience, &registrationType);
431 ExitOnRootFailure(hr, "BA aborted register begin."); 431 ExitOnRootFailure(hr, "BA aborted register begin.");
432 432
433 // If we have a resume mode that suggests the bundle is on the machine. 433 hr = CacheCalculateBundleWorkingPath(pEngineState->plan.pCache, pEngineState->registration.sczExecutableName, &sczEngineWorkingPath);
434 if (BOOTSTRAPPER_RESUME_TYPE_REBOOT <= pEngineState->command.resumeType) 434 ExitOnFailure(hr, "Failed to calculate working path for engine.");
435
436 if (pEngineState->registration.fPerMachine)
435 { 437 {
436 // resume previous session 438 hr = ElevationSessionBegin(pEngineState->companionConnection.hPipe, sczEngineWorkingPath, pEngineState->registration.sczResumeCommandLine, pEngineState->registration.fDisableResume, &pEngineState->variables, pEngineState->plan.dwRegistrationOperations, pEngineState->registration.fDetectedForeignProviderKeyBundleId, qwEstimatedSize, registrationType);
437 if (pEngineState->registration.fPerMachine) 439 ExitOnFailure(hr, "Failed to begin registration session in per-machine process.");
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 }
447 } 440 }
448 else // need to complete registration on the machine. 441 else
449 { 442 {
450 hr = CacheCalculateBundleWorkingPath(pEngineState->plan.pCache, pEngineState->registration.sczExecutableName, &sczEngineWorkingPath); 443 hr = RegistrationSessionBegin(sczEngineWorkingPath, &pEngineState->registration, &pEngineState->cache, &pEngineState->variables, pEngineState->plan.dwRegistrationOperations, qwEstimatedSize, registrationType);
451 ExitOnFailure(hr, "Failed to calculate working path for engine."); 444 ExitOnFailure(hr, "Failed to begin registration session.");
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 }
464 } 445 }
465 446
466 // Apply any registration actions. 447 // 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
11 BURN_ELEVATION_MESSAGE_TYPE_APPLY_INITIALIZE, 11 BURN_ELEVATION_MESSAGE_TYPE_APPLY_INITIALIZE,
12 BURN_ELEVATION_MESSAGE_TYPE_APPLY_UNINITIALIZE, 12 BURN_ELEVATION_MESSAGE_TYPE_APPLY_UNINITIALIZE,
13 BURN_ELEVATION_MESSAGE_TYPE_SESSION_BEGIN, 13 BURN_ELEVATION_MESSAGE_TYPE_SESSION_BEGIN,
14 BURN_ELEVATION_MESSAGE_TYPE_SESSION_RESUME,
15 BURN_ELEVATION_MESSAGE_TYPE_SESSION_END, 14 BURN_ELEVATION_MESSAGE_TYPE_SESSION_END,
16 BURN_ELEVATION_MESSAGE_TYPE_SAVE_STATE, 15 BURN_ELEVATION_MESSAGE_TYPE_SAVE_STATE,
17 BURN_ELEVATION_MESSAGE_TYPE_CACHE_PREPARE_PACKAGE, 16 BURN_ELEVATION_MESSAGE_TYPE_CACHE_PREPARE_PACKAGE,
@@ -195,12 +194,6 @@ static HRESULT OnSessionBegin(
195 __in BYTE* pbData, 194 __in BYTE* pbData,
196 __in SIZE_T cbData 195 __in SIZE_T cbData
197 ); 196 );
198static HRESULT OnSessionResume(
199 __in BURN_REGISTRATION* pRegistration,
200 __in BURN_VARIABLES* pVariables,
201 __in BYTE* pbData,
202 __in SIZE_T cbData
203 );
204static HRESULT OnSessionEnd( 197static HRESULT OnSessionEnd(
205 __in BURN_CACHE* pCache, 198 __in BURN_CACHE* pCache,
206 __in BURN_PACKAGES* pPackages, 199 __in BURN_PACKAGES* pPackages,
@@ -586,48 +579,6 @@ LExit:
586} 579}
587 580
588/******************************************************************* 581/*******************************************************************
589 ElevationSessionResume -
590
591*******************************************************************/
592extern "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
624LExit:
625 ReleaseBuffer(pbData);
626
627 return hr;
628}
629
630/*******************************************************************
631 ElevationSessionEnd - 582 ElevationSessionEnd -
632 583
633*******************************************************************/ 584*******************************************************************/
@@ -2174,10 +2125,6 @@ static HRESULT ProcessElevatedChildMessage(
2174 hrResult = OnSessionBegin(pContext->pCache, pContext->pRegistration, pContext->pVariables, (BYTE*)pMsg->pvData, pMsg->cbData); 2125 hrResult = OnSessionBegin(pContext->pCache, pContext->pRegistration, pContext->pVariables, (BYTE*)pMsg->pvData, pMsg->cbData);
2175 break; 2126 break;
2176 2127
2177 case BURN_ELEVATION_MESSAGE_TYPE_SESSION_RESUME:
2178 hrResult = OnSessionResume(pContext->pRegistration, pContext->pVariables, (BYTE*)pMsg->pvData, pMsg->cbData);
2179 break;
2180
2181 case BURN_ELEVATION_MESSAGE_TYPE_SESSION_END: 2128 case BURN_ELEVATION_MESSAGE_TYPE_SESSION_END:
2182 hrResult = OnSessionEnd(pContext->pCache, pContext->pPackages, pContext->pRegistration, pContext->pVariables, (BYTE*)pMsg->pvData, pMsg->cbData); 2129 hrResult = OnSessionEnd(pContext->pCache, pContext->pPackages, pContext->pRegistration, pContext->pVariables, (BYTE*)pMsg->pvData, pMsg->cbData);
2183 break; 2130 break;
@@ -2539,38 +2486,6 @@ LExit:
2539 return hr; 2486 return hr;
2540} 2487}
2541 2488
2542static 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
2570LExit:
2571 return hr;
2572}
2573
2574static HRESULT OnSessionEnd( 2489static HRESULT OnSessionEnd(
2575 __in BURN_CACHE* pCache, 2490 __in BURN_CACHE* pCache,
2576 __in BURN_PACKAGES* pPackages, 2491 __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(
32 __in DWORD64 qwEstimatedSize, 32 __in DWORD64 qwEstimatedSize,
33 __in BOOTSTRAPPER_REGISTRATION_TYPE registrationType 33 __in BOOTSTRAPPER_REGISTRATION_TYPE registrationType
34 ); 34 );
35HRESULT 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 );
42HRESULT ElevationSessionEnd( 35HRESULT ElevationSessionEnd(
43 __in HANDLE hPipe, 36 __in HANDLE hPipe,
44 __in BURN_RESUME_MODE resumeMode, 37 __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(
607 HKEY hkRegistration = NULL; 607 HKEY hkRegistration = NULL;
608 BOOL fCreated = FALSE; 608 BOOL fCreated = FALSE;
609 LPWSTR sczPublisher = NULL; 609 LPWSTR sczPublisher = NULL;
610 DWORD er = ERROR_SUCCESS;
610 611
611 AssertSz(BOOTSTRAPPER_REGISTRATION_TYPE_NONE != registrationType, "Registration type can't be NONE"); 612 AssertSz(BOOTSTRAPPER_REGISTRATION_TYPE_NONE != registrationType, "Registration type can't be NONE");
612 613
@@ -776,6 +777,15 @@ extern "C" HRESULT RegistrationSessionBegin(
776 hr = RegWriteNumber(hkRegistration, REGISTRY_BUNDLE_SYSTEM_COMPONENT, 1); 777 hr = RegWriteNumber(hkRegistration, REGISTRY_BUNDLE_SYSTEM_COMPONENT, 1);
777 ExitOnFailure(hr, "Failed to write %ls value.", REGISTRY_BUNDLE_SYSTEM_COMPONENT); 778 ExitOnFailure(hr, "Failed to write %ls value.", REGISTRY_BUNDLE_SYSTEM_COMPONENT);
778 } 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 }
779 789
780 // QuietUninstallString: [path to exe] /uninstall /quiet 790 // QuietUninstallString: [path to exe] /uninstall /quiet
781 hr = RegWriteStringFormatted(hkRegistration, REGISTRY_BUNDLE_QUIET_UNINSTALL_STRING, L"\"%ls\" /%ls /uninstall /quiet", pRegistration->sczCacheExecutablePath, BURN_COMMANDLINE_SWITCH_CLEAN_ROOM); 791 hr = RegWriteStringFormatted(hkRegistration, REGISTRY_BUNDLE_QUIET_UNINSTALL_STRING, L"\"%ls\" /%ls /uninstall /quiet", pRegistration->sczCacheExecutablePath, BURN_COMMANDLINE_SWITCH_CLEAN_ROOM);
@@ -829,40 +839,6 @@ LExit:
829 839
830 840
831/******************************************************************* 841/*******************************************************************
832 RegistrationSessionResume - Resumes a previous run session.
833
834*******************************************************************/
835extern "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
858LExit:
859 ReleaseRegKey(hkRegistration);
860
861 return hr;
862}
863
864
865/*******************************************************************
866 RegistrationSessionEnd - Unregisters a run session from the system. 842 RegistrationSessionEnd - Unregisters a run session from the system.
867 843
868 *******************************************************************/ 844 *******************************************************************/
@@ -950,6 +926,7 @@ extern "C" HRESULT RegistrationSaveState(
950 LPWSTR sczValueName = NULL; 926 LPWSTR sczValueName = NULL;
951 DWORD dwType = 0; 927 DWORD dwType = 0;
952 DWORD dwNumberOfExistingValues = 0; 928 DWORD dwNumberOfExistingValues = 0;
929 DWORD er = ERROR_SUCCESS;
953 930
954 931
955 // write data to file 932 // write data to file
@@ -989,8 +966,8 @@ extern "C" HRESULT RegistrationSaveState(
989 966
990 ExitOnFailure(hr, "Failed to enumerate value %u", i); 967 ExitOnFailure(hr, "Failed to enumerate value %u", i);
991 968
992 hr = RegDeleteValue(hkRegistration, sczValueName); 969 er = ::RegDeleteValueW(hkRegistration, sczValueName);
993 ExitOnFailure(hr, "Failed to delete registration variable value."); 970 ExitOnWin32Error(er, hr, "Failed to delete registration variable value.");
994 } 971 }
995 972
996 // Write variables. 973 // Write variables.
@@ -1313,7 +1290,7 @@ static HRESULT UpdateResumeMode(
1313 } 1290 }
1314 else 1291 else
1315 { 1292 {
1316 ExitOnWin32Error(er, hr, "Failed to open run key."); 1293 ExitOnFailure(hr, "Failed to open run key.");
1317 1294
1318 er = ::RegDeleteValueW(hkRun, pRegistration->sczId); 1295 er = ::RegDeleteValueW(hkRun, pRegistration->sczId);
1319 if (ERROR_FILE_NOT_FOUND == er) 1296 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(
201 __in DWORD64 qwEstimatedSize, 201 __in DWORD64 qwEstimatedSize,
202 __in BOOTSTRAPPER_REGISTRATION_TYPE registrationType 202 __in BOOTSTRAPPER_REGISTRATION_TYPE registrationType
203 ); 203 );
204HRESULT RegistrationSessionResume(
205 __in BURN_REGISTRATION* pRegistration,
206 __in BURN_VARIABLES* pVariables,
207 __in BOOTSTRAPPER_REGISTRATION_TYPE registrationType
208 );
209HRESULT RegistrationSessionEnd( 204HRESULT RegistrationSessionEnd(
210 __in BURN_REGISTRATION* pRegistration, 205 __in BURN_REGISTRATION* pRegistration,
211 __in BURN_CACHE* pCache, 206 __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
793 TestThrowOnFailure(hr, L"Failed to deserialize variables."); 793 TestThrowOnFailure(hr, L"Failed to deserialize variables.");
794 794
795 // write active resume mode 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."); 797 TestThrowOnFailure(hr, L"Failed to write active resume mode.");
798 798
799 // verify that run key was put back 799 // 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
115 115
116 // Repair bundle so it adds itself as a reference to itself. 116 // Repair bundle so it adds itself as a reference to itself.
117 bundleAv1.Repair(); 117 bundleAv1.Repair();
118 bundleAv1.VerifyRegisteredAndInPackageCache(expectedSystemComponent: 1); 118 bundleAv1.VerifyRegisteredAndInPackageCache();
119 119
120 upgradeBundlePackageBundlev1.Uninstall(); 120 upgradeBundlePackageBundlev1.Uninstall();
121 upgradeBundlePackageBundlev1.VerifyUnregisteredAndRemovedFromPackageCache(); 121 upgradeBundlePackageBundlev1.VerifyUnregisteredAndRemovedFromPackageCache();
122 122
123 bundleAv1.VerifyRegisteredAndInPackageCache(expectedSystemComponent: 1); 123 bundleAv1.VerifyRegisteredAndInPackageCache();
124 } 124 }
125 125
126 [Fact] 126 [Fact]