Skip to content
/ wix Public

Commit de80ff1

Browse files
committed
Log detected package scope and lock bundle scope.
- Fixes wixtoolset/issues#9232 - Fixes wixtoolset/issues#9240
1 parent cd5f73d commit de80ff1

File tree

11 files changed

+80
-25
lines changed

11 files changed

+80
-25
lines changed

src/burn/engine/core.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ extern "C" HRESULT CoreDetect(
379379
pEngineState->registration.fEligibleForCleanup = FALSE;
380380
}
381381

382-
LogId(REPORT_STANDARD, MSG_DETECTED_PACKAGE, pPackage->sczId, LoggingPackageStateToString(pPackage->currentState), LoggingBoolToString(pPackage->fCached), LoggingPackageRegistrationStateToString(pPackage->fCanAffectRegistration, pPackage->installRegistrationState), LoggingPackageRegistrationStateToString(pPackage->fCanAffectRegistration, pPackage->cacheRegistrationState), LoggingPackageScopeToString(pPackage->scope));
382+
LogId(REPORT_STANDARD, MSG_DETECTED_PACKAGE, pPackage->sczId, LoggingPackageStateToString(pPackage->currentState), LoggingBoolToString(pPackage->fCached), LoggingPackageRegistrationStateToString(pPackage->fCanAffectRegistration, pPackage->installRegistrationState), LoggingPackageRegistrationStateToString(pPackage->fCanAffectRegistration, pPackage->cacheRegistrationState), LoggingPackageScopeToString(pPackage->scope), LoggingInstallScopeToString(pPackage->fDetectedPerMachine));
383383

384384
if (BURN_PACKAGE_TYPE_MSI == pPackage->type)
385385
{
@@ -469,7 +469,7 @@ extern "C" HRESULT CorePlan(
469469
pEngineState->plan.fDisableRollback = pEngineState->fDisableRollback || BOOTSTRAPPER_ACTION_UNSAFE_UNINSTALL == pEngineState->plan.action;
470470
pEngineState->plan.fPlanPackageCacheRollback = BOOTSTRAPPER_REGISTRATION_TYPE_NONE == pEngineState->registration.detectedRegistrationType;
471471

472-
hr = PlanPackagesAndBundleScope(pEngineState->packages.rgPackages, pEngineState->packages.cPackages, pEngineState->plan.plannedScope, pEngineState->registration.scope, pEngineState->command.commandLineScope, &pEngineState->plan.plannedScope, &pEngineState->registration.fPerMachine);
472+
hr = PlanPackagesAndBundleScope(pEngineState->packages.rgPackages, pEngineState->packages.cPackages, pEngineState->plan.plannedScope, pEngineState->registration.scope, pEngineState->command.commandLineScope, pEngineState->registration.detectedScope, &pEngineState->plan.plannedScope, &pEngineState->registration.fPerMachine);
473473
ExitOnFailure(hr, "Failed to determine packages and bundle scope.");
474474

475475
if (BOOTSTRAPPER_PACKAGE_SCOPE_PER_MACHINE_OR_PER_USER == pEngineState->registration.scope || BOOTSTRAPPER_PACKAGE_SCOPE_PER_USER_OR_PER_MACHINE == pEngineState->registration.scope)

src/burn/engine/core.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,15 @@ const LPCWSTR BURN_COMMANDLINE_SWITCH_PREFIX = L"burn.";
4040
const LPCWSTR BURN_BUNDLE_ACTION = L"WixBundleAction";
4141
const LPCWSTR BURN_BUNDLE_ACTIVE_PARENT = L"WixBundleActiveParent";
4242
const LPCWSTR BURN_BUNDLE_COMMAND_LINE_ACTION = L"WixBundleCommandLineAction";
43+
const LPCWSTR BURN_BUNDLE_DETECTED_SCOPE = L"WixBundleDetectedScope";
4344
const LPCWSTR BURN_BUNDLE_EXECUTE_PACKAGE_CACHE_FOLDER = L"WixBundleExecutePackageCacheFolder";
4445
const LPCWSTR BURN_BUNDLE_EXECUTE_PACKAGE_ACTION = L"WixBundleExecutePackageAction";
4546
const LPCWSTR BURN_BUNDLE_FORCED_RESTART_PACKAGE = L"WixBundleForcedRestartPackage";
4647
const LPCWSTR BURN_BUNDLE_INSTALLED = L"WixBundleInstalled";
4748
const LPCWSTR BURN_BUNDLE_ELEVATED = L"WixBundleElevated";
4849
const LPCWSTR BURN_BUNDLE_PLANNED_SCOPE = L"WixBundlePlannedScope";
4950
const LPCWSTR BURN_BUNDLE_PROVIDER_KEY = L"WixBundleProviderKey";
50-
const LPCWSTR BURN_BUNDLE_SCOPE = L"WixBundleScope";
51+
const LPCWSTR BURN_BUNDLE_AUTHORED_SCOPE = L"WixBundleAuthoredScope";
5152
const LPCWSTR BURN_BUNDLE_SOURCE_PROCESS_PATH = L"WixBundleSourceProcessPath";
5253
const LPCWSTR BURN_BUNDLE_SOURCE_PROCESS_FOLDER = L"WixBundleSourceProcessFolder";
5354
const LPCWSTR BURN_BUNDLE_TAG = L"WixBundleTag";

src/burn/engine/engine.mc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ MessageId=101
271271
Severity=Success
272272
SymbolicName=MSG_DETECTED_PACKAGE
273273
Language=English
274-
Detected package: %1!ls!, state: %2!hs!, authored scope: %6!hs!, cached: %3!hs!, install registration state: %4!hs!, cache registration state: %5!hs!
274+
Detected package: %1!ls!, state: %2!hs!, authored scope: %6!hs!, detected scope: %7!hs!, cached: %3!hs!, install registration state: %4!hs!, cache registration state: %5!hs!
275275
.
276276
277277
MessageId=102
@@ -414,6 +414,13 @@ Language=English
414414
Planned configurable scope: %1!hs!
415415
.
416416
417+
MessageId=227
418+
Severity=Success
419+
SymbolicName=MSG_PLAN_INSTALLED_SCOPE
420+
Language=English
421+
Bundle was already installed with scope: %1!hs!
422+
.
423+
417424
MessageId=201
418425
Severity=Success
419426
SymbolicName=MSG_PLANNED_PACKAGE

src/burn/engine/msiengine.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,14 +457,24 @@ extern "C" HRESULT MsiEngineDetectPackage(
457457
if (BOOTSTRAPPER_PACKAGE_SCOPE_PER_MACHINE_OR_PER_USER == pPackage->scope || BOOTSTRAPPER_PACKAGE_SCOPE_PER_USER_OR_PER_MACHINE == pPackage->scope)
458458
{
459459
hr = WiuGetProductInfoEx(pPackage->Msi.sczProductCode, NULL, MSIINSTALLCONTEXT_MACHINE, INSTALLPROPERTY_VERSIONSTRING, &sczInstalledVersion);
460-
if (FAILED(hr))
460+
if (SUCCEEDED(hr))
461+
{
462+
pPackage->fDetectedPerMachine = TRUE;
463+
}
464+
else
461465
{
462466
hr = WiuGetProductInfoEx(pPackage->Msi.sczProductCode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED, INSTALLPROPERTY_VERSIONSTRING, &sczInstalledVersion);
467+
if (SUCCEEDED(hr))
468+
{
469+
pPackage->fDetectedPerMachine = FALSE;
470+
}
463471
}
464472
}
465473
else
466474
{
467-
hr = WiuGetProductInfoEx(pPackage->Msi.sczProductCode, NULL, pPackage->scope == BOOTSTRAPPER_PACKAGE_SCOPE_PER_MACHINE ? MSIINSTALLCONTEXT_MACHINE : MSIINSTALLCONTEXT_USERUNMANAGED, INSTALLPROPERTY_VERSIONSTRING, &sczInstalledVersion);
475+
pPackage->fDetectedPerMachine = BOOTSTRAPPER_PACKAGE_SCOPE_PER_MACHINE == pPackage->scope;
476+
477+
hr = WiuGetProductInfoEx(pPackage->Msi.sczProductCode, NULL, pPackage->fDetectedPerMachine ? MSIINSTALLCONTEXT_MACHINE : MSIINSTALLCONTEXT_USERUNMANAGED, INSTALLPROPERTY_VERSIONSTRING, &sczInstalledVersion);
468478
}
469479
if (SUCCEEDED(hr))
470480
{

src/burn/engine/package.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ typedef struct _BURN_PACKAGE
283283
BURN_ROLLBACK_BOUNDARY* pRollbackBoundaryForward; // used during install and repair.
284284
BURN_ROLLBACK_BOUNDARY* pRollbackBoundaryBackward; // used during uninstall.
285285

286+
BOOL fDetectedPerMachine; // only valid after Detect.
286287
BOOTSTRAPPER_PACKAGE_STATE currentState; // only valid after Detect.
287288
BOOL fCached; // only valid after Detect.
288289
BOOTSTRAPPER_CACHE_TYPE cacheType; // only valid during Plan.

src/burn/engine/plan.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ extern "C" HRESULT PlanSetVariables(
342342
hr = VariableSetNumeric(pVariables, BURN_BUNDLE_ACTION, action, TRUE);
343343
ExitOnFailure(hr, "Failed to set the bundle action built-in variable.");
344344

345-
hr = VariableSetNumeric(pVariables, BURN_BUNDLE_SCOPE, authoredScope, TRUE);
345+
hr = VariableSetNumeric(pVariables, BURN_BUNDLE_AUTHORED_SCOPE, authoredScope, TRUE);
346346
ExitOnFailure(hr, "Failed to set the bundle authored scope built-in variable.");
347347

348348
hr = VariableSetNumeric(pVariables, BURN_BUNDLE_PLANNED_SCOPE, plannedScope, TRUE);
@@ -826,6 +826,7 @@ extern "C" HRESULT PlanPackagesAndBundleScope(
826826
__in BOOTSTRAPPER_SCOPE scope,
827827
__in BOOTSTRAPPER_PACKAGE_SCOPE authoredScope,
828828
__in BOOTSTRAPPER_SCOPE commandLineScope,
829+
__in BOOTSTRAPPER_SCOPE detectedScope,
829830
__out BOOTSTRAPPER_SCOPE* pResultingScope,
830831
__out BOOL* pfRegistrationPerMachine
831832
)
@@ -854,6 +855,13 @@ extern "C" HRESULT PlanPackagesAndBundleScope(
854855
}
855856
}
856857

858+
if (BOOTSTRAPPER_SCOPE_DEFAULT != detectedScope)
859+
{
860+
scope = detectedScope;
861+
862+
LogId(REPORT_WARNING, MSG_PLAN_INSTALLED_SCOPE, LoggingBundleScopeToString(detectedScope));
863+
}
864+
857865
for (DWORD i = 0; i < cPackages; ++i)
858866
{
859867
BURN_PACKAGE* pPackage = rgPackages + i;

src/burn/engine/plan.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ HRESULT PlanPackagesAndBundleScope(
488488
__in BOOTSTRAPPER_SCOPE scope,
489489
__in BOOTSTRAPPER_PACKAGE_SCOPE authoredScope,
490490
__in BOOTSTRAPPER_SCOPE commandLineScope,
491+
__in BOOTSTRAPPER_SCOPE detectedScope,
491492
__out BOOTSTRAPPER_SCOPE* pResultingScope,
492493
__out BOOL* pfPerMachine
493494
);

src/burn/engine/registration.cpp

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const LPCWSTR REGISTRY_BUNDLE_UNINSTALL_STRING = L"UninstallString";
2929
const LPCWSTR REGISTRY_BUNDLE_RESUME_COMMAND_LINE = L"BundleResumeCommandLine";
3030
const LPCWSTR REGISTRY_BUNDLE_VERSION_MAJOR = L"VersionMajor";
3131
const LPCWSTR REGISTRY_BUNDLE_VERSION_MINOR = L"VersionMinor";
32+
const LPCWSTR REGISTRY_BUNDLE_SCOPE = L"BundleScope";
3233
const LPCWSTR SWIDTAG_FOLDER = L"swidtag";
3334
const LPCWSTR REGISTRY_BUNDLE_VARIABLE_KEY = L"variables";
3435

@@ -303,6 +304,10 @@ extern "C" HRESULT RegistrationParseFromXml(
303304
pRegistration->hkRoot = reinterpret_cast<HKEY>(0ull);
304305
}
305306

307+
// build uninstall registry key path
308+
hr = StrAllocFormatted(&pRegistration->sczRegistrationKey, L"%ls\\%ls", BURN_REGISTRATION_REGISTRY_UNINSTALL_KEY, pRegistration->sczCode);
309+
ExitOnFailure(hr, "Failed to build uninstall registry key path.");
310+
306311
LExit:
307312
ReleaseObject(pixnRegistrationNode);
308313
ReleaseObject(pixnArpNode);
@@ -458,6 +463,9 @@ extern "C" HRESULT RegistrationSetDynamicVariables(
458463
hr = VariableSetNumeric(pVariables, BURN_BUNDLE_INSTALLED, llInstalled, TRUE);
459464
ExitOnFailure(hr, "Failed to set the bundle installed built-in variable.");
460465

466+
hr = VariableSetNumeric(pVariables, BURN_BUNDLE_DETECTED_SCOPE, pRegistration->detectedScope, TRUE);
467+
ExitOnFailure(hr, "Failed to set the bundle detected scope built-in variable.");
468+
461469
hr = VariableSetNumeric(pVariables, VARIABLE_REBOOTPENDING, IsWuRebootPending() || IsRegistryRebootPending(), TRUE);
462470
ExitOnFailure(hr, "Failed to overwrite the bundle reboot-pending built-in variable.");
463471

@@ -479,16 +487,20 @@ extern "C" HRESULT RegistrationDetectInstalled(
479487
{
480488
// For PUOM/PMOU bundles, check per-machine then fall back to per-user.
481489
hr = DetectInstalled(pRegistration, HKEY_LOCAL_MACHINE);
482-
ExitOnFailure(hr, "Failed to detect HKEY_LOCAL_MACHINE bundle registration install state.");
483490

484-
if (BOOTSTRAPPER_REGISTRATION_TYPE_NONE == pRegistration->detectedRegistrationType)
491+
if (FAILED(hr))
485492
{
486493
hr = DetectInstalled(pRegistration, HKEY_CURRENT_USER);
487-
ExitOnFailure(hr, "Failed to detect HKEY_CURRENT_USER bundle registration install state.");
488494
}
489495
}
490496

491-
LExit:
497+
//LExit:
498+
// Not finding the key or value is okay.
499+
if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr)
500+
{
501+
hr = S_OK;
502+
}
503+
492504
return hr;
493505
}
494506

@@ -654,6 +666,9 @@ extern "C" HRESULT RegistrationSessionBegin(
654666
hr = RegWriteStringFormatted(hkRegistration, REGISTRY_BUNDLE_DISPLAY_ICON, L"%s,0", pRegistration->sczCacheExecutablePath);
655667
ExitOnFailure(hr, "Failed to write %ls value.", REGISTRY_BUNDLE_DISPLAY_ICON);
656668

669+
hr = RegWriteNumber(hkRegistration, REGISTRY_BUNDLE_SCOPE, pRegistration->fPerMachine ? BOOTSTRAPPER_SCOPE_PER_MACHINE : BOOTSTRAPPER_SCOPE_PER_USER);
670+
ExitOnFailure(hr, "Failed to write %ls value.", REGISTRY_BUNDLE_SCOPE);
671+
657672
// update display name
658673
hr = UpdateBundleNameRegistration(pRegistration, pVariables, hkRegistration, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS == registrationType);
659674
ExitOnFailure(hr, "Failed to update name and publisher.");
@@ -1054,10 +1069,6 @@ extern "C" HRESULT RegistrationSetPaths(
10541069
// save registration key root
10551070
pRegistration->hkRoot = pRegistration->fPerMachine ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
10561071

1057-
// build uninstall registry key path
1058-
hr = StrAllocFormatted(&pRegistration->sczRegistrationKey, L"%ls\\%ls", BURN_REGISTRATION_REGISTRY_UNINSTALL_KEY, pRegistration->sczCode);
1059-
ExitOnFailure(hr, "Failed to build uninstall registry key path.");
1060-
10611072
// build cache directory
10621073
hr = CacheGetCompletedPath(pCache, pRegistration->fPerMachine, pRegistration->sczCode, &sczCacheDirectory);
10631074
ExitOnFailure(hr, "Failed to build cache directory.");
@@ -1754,25 +1765,28 @@ static HRESULT DetectInstalled(
17541765
HRESULT hr = S_OK;
17551766
HKEY hkRegistration = NULL;
17561767
DWORD dwInstalled = 0;
1768+
DWORD dwScope = 0;
17571769

17581770
pRegistration->fCached = pRegistration->sczCacheExecutablePath && FileExistsEx(pRegistration->sczCacheExecutablePath, NULL);
17591771
pRegistration->detectedRegistrationType = BOOTSTRAPPER_REGISTRATION_TYPE_NONE;
1772+
pRegistration->detectedScope = BOOTSTRAPPER_SCOPE_DEFAULT;
17601773

17611774
// open registration key
17621775
hr = RegOpen(hkRoot, pRegistration->sczRegistrationKey, KEY_QUERY_VALUE, &hkRegistration);
17631776
if (SUCCEEDED(hr))
17641777
{
17651778
hr = RegReadNumber(hkRegistration, REGISTRY_BUNDLE_INSTALLED, &dwInstalled);
1779+
ExitOnFailure(hr, "Failed to read registration %ls@%ls.", pRegistration->sczRegistrationKey, REGISTRY_BUNDLE_INSTALLED);
17661780

17671781
pRegistration->detectedRegistrationType = (1 == dwInstalled) ? BOOTSTRAPPER_REGISTRATION_TYPE_FULL : BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS;
1768-
}
17691782

1770-
// Not finding the key or value is okay.
1771-
if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr)
1772-
{
1773-
hr = S_OK;
1783+
hr = RegReadNumber(hkRegistration, REGISTRY_BUNDLE_SCOPE, &dwScope);
1784+
ExitOnFailure(hr, "Failed to read registration %ls@%ls.", pRegistration->sczRegistrationKey, REGISTRY_BUNDLE_SCOPE);
1785+
1786+
pRegistration->detectedScope = static_cast<BOOTSTRAPPER_SCOPE>(dwScope);
17741787
}
17751788

1789+
LExit:
17761790
ReleaseRegKey(hkRegistration);
17771791

17781792
return hr;

src/burn/engine/registration.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,12 @@ typedef struct _BURN_REGISTRATION
9797
// For configurable-scope bundles, fPerMachine is only valid after
9898
// planning when scope is known. For fixed per-machine or per-user
9999
// bundles, valid immediately.
100-
BOOL fPerMachine;
100+
BOOL fPerMachine;
101101
BOOL fForceSystemComponent;
102102
BOOL fDisableResume;
103103
BOOL fCached;
104104
BOOTSTRAPPER_REGISTRATION_TYPE detectedRegistrationType;
105+
BOOTSTRAPPER_SCOPE detectedScope;
105106
BOOTSTRAPPER_PACKAGE_SCOPE scope;
106107
LPWSTR sczCode;
107108
LPWSTR sczTag;

src/burn/engine/variable.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,9 @@ extern "C" HRESULT VariableInitialize(
305305
{BURN_BUNDLE_TAG, InitializeVariableString, (DWORD_PTR)L"", FALSE, TRUE},
306306
{BURN_BUNDLE_UILEVEL, InitializeVariableNumeric, 0, FALSE, TRUE},
307307
{BURN_BUNDLE_VERSION, InitializeVariableVersion, (DWORD_PTR)L"0", FALSE, TRUE},
308-
{BURN_BUNDLE_SCOPE, InitializeVariableNumeric, 0, FALSE, TRUE},
308+
{BURN_BUNDLE_AUTHORED_SCOPE, InitializeVariableNumeric, 0, FALSE, TRUE},
309309
{BURN_BUNDLE_PLANNED_SCOPE, InitializeVariableNumeric, 0, FALSE, TRUE},
310+
{BURN_BUNDLE_DETECTED_SCOPE, InitializeVariableNumeric, 0, FALSE, TRUE},
310311
};
311312

312313
const WELL_KNOWN_VARIABLE_DECLARATION vrgWellKnownVariableNames[] =

0 commit comments

Comments
 (0)