aboutsummaryrefslogtreecommitdiff
path: root/src/libs/dutil/WixToolset.DUtil
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2022-08-08 18:02:15 -0500
committerSean Hall <r.sean.hall@gmail.com>2022-08-09 09:57:02 -0500
commit240b663ad5fc94ed6d19c966b5c9105a176ecf40 (patch)
treed194e242ccb5bb69f0dbbc388ede87cef65c700f /src/libs/dutil/WixToolset.DUtil
parent8e1cbe8d7b468553d76c20452561e89726de5c47 (diff)
downloadwix-240b663ad5fc94ed6d19c966b5c9105a176ecf40.tar.gz
wix-240b663ad5fc94ed6d19c966b5c9105a176ecf40.tar.bz2
wix-240b663ad5fc94ed6d19c966b5c9105a176ecf40.zip
Skip logging errors in some places when they are due to missing files or registry keys or values.
Related to 6696
Diffstat (limited to 'src/libs/dutil/WixToolset.DUtil')
-rw-r--r--src/libs/dutil/WixToolset.DUtil/butil.cpp127
-rw-r--r--src/libs/dutil/WixToolset.DUtil/deputil.cpp145
-rw-r--r--src/libs/dutil/WixToolset.DUtil/dirutil.cpp42
-rw-r--r--src/libs/dutil/WixToolset.DUtil/file2utl.cpp31
-rw-r--r--src/libs/dutil/WixToolset.DUtil/fileutil.cpp12
-rw-r--r--src/libs/dutil/WixToolset.DUtil/inc/dutil.h4
-rw-r--r--src/libs/dutil/WixToolset.DUtil/inc/logutil.h2
-rw-r--r--src/libs/dutil/WixToolset.DUtil/monutil.cpp14
-rw-r--r--src/libs/dutil/WixToolset.DUtil/osutil.cpp16
-rw-r--r--src/libs/dutil/WixToolset.DUtil/path3utl.cpp14
-rw-r--r--src/libs/dutil/WixToolset.DUtil/polcutil.cpp48
-rw-r--r--src/libs/dutil/WixToolset.DUtil/regutil.cpp49
-rw-r--r--src/libs/dutil/WixToolset.DUtil/wiutil.cpp15
13 files changed, 286 insertions, 233 deletions
diff --git a/src/libs/dutil/WixToolset.DUtil/butil.cpp b/src/libs/dutil/WixToolset.DUtil/butil.cpp
index 175903ad..47f206ea 100644
--- a/src/libs/dutil/WixToolset.DUtil/butil.cpp
+++ b/src/libs/dutil/WixToolset.DUtil/butil.cpp
@@ -15,6 +15,7 @@
15#define ButilExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_BUTIL, p, x, e, s, __VA_ARGS__) 15#define ButilExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_BUTIL, p, x, e, s, __VA_ARGS__)
16#define ButilExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_BUTIL, p, x, s, __VA_ARGS__) 16#define ButilExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_BUTIL, p, x, s, __VA_ARGS__)
17#define ButilExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_BUTIL, e, x, s, __VA_ARGS__) 17#define ButilExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_BUTIL, e, x, s, __VA_ARGS__)
18#define ButilExitOnPathFailure(x, b, s, ...) ExitOnPathFailureSource(DUTIL_SOURCE_BUTIL, x, b, s, __VA_ARGS__)
18 19
19// constants 20// constants
20// From engine/registration.h 21// From engine/registration.h
@@ -82,19 +83,6 @@ static HRESULT LocateAndQueryBundleValue(
82 __inout DWORD* pdwType, 83 __inout DWORD* pdwType,
83 __out INTERNAL_BUNDLE_STATUS* pStatus 84 __out INTERNAL_BUNDLE_STATUS* pStatus
84 ); 85 );
85
86/********************************************************************
87OpenBundleKey - Opens the bundle uninstallation key for a given bundle
88
89NOTE: caller is responsible for closing key
90********************************************************************/
91static HRESULT OpenBundleKey(
92 __in_z LPCWSTR wzBundleId,
93 __in BUNDLE_INSTALL_CONTEXT context,
94 __in_opt LPCWSTR wzSubKey,
95 __in REG_KEY_BITNESS kbKeyBitness,
96 __inout HKEY* phKey
97 );
98static HRESULT CopyStringToBuffer( 86static HRESULT CopyStringToBuffer(
99 __in_z LPWSTR wzValue, 87 __in_z LPWSTR wzValue,
100 __in_z_opt LPWSTR wzBuffer, 88 __in_z_opt LPWSTR wzBuffer,
@@ -389,12 +377,12 @@ DAPI_(HRESULT) BundleQueryRelatedBundles(
389 queryContext.regBitness = REG_KEY_32BIT; 377 queryContext.regBitness = REG_KEY_32BIT;
390 378
391 hr = QueryRelatedBundlesForScopeAndBitness(&queryContext); 379 hr = QueryRelatedBundlesForScopeAndBitness(&queryContext);
392 ExitOnFailure(hr, "Failed to query 32-bit related bundles."); 380 ButilExitOnFailure(hr, "Failed to query 32-bit related bundles.");
393 381
394 queryContext.regBitness = REG_KEY_64BIT; 382 queryContext.regBitness = REG_KEY_64BIT;
395 383
396 hr = QueryRelatedBundlesForScopeAndBitness(&queryContext); 384 hr = QueryRelatedBundlesForScopeAndBitness(&queryContext);
397 ExitOnFailure(hr, "Failed to query 64-bit related bundles."); 385 ButilExitOnFailure(hr, "Failed to query 64-bit related bundles.");
398 386
399LExit: 387LExit:
400 return hr; 388 return hr;
@@ -407,15 +395,17 @@ static HRESULT QueryRelatedBundlesForScopeAndBitness(
407 HRESULT hr = S_OK; 395 HRESULT hr = S_OK;
408 HKEY hkRoot = BUNDLE_INSTALL_CONTEXT_USER == pQueryContext->installContext ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; 396 HKEY hkRoot = BUNDLE_INSTALL_CONTEXT_USER == pQueryContext->installContext ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
409 HKEY hkUninstallKey = NULL; 397 HKEY hkUninstallKey = NULL;
398 BOOL fExists = FALSE;
410 LPWSTR sczRelatedBundleId = NULL; 399 LPWSTR sczRelatedBundleId = NULL;
411 BUNDLE_QUERY_CALLBACK_RESULT result = BUNDLE_QUERY_CALLBACK_RESULT_CONTINUE; 400 BUNDLE_QUERY_CALLBACK_RESULT result = BUNDLE_QUERY_CALLBACK_RESULT_CONTINUE;
412 401
413 hr = RegOpenEx(hkRoot, BUNDLE_REGISTRATION_REGISTRY_UNINSTALL_KEY, KEY_READ, pQueryContext->regBitness, &hkUninstallKey); 402 hr = RegOpenEx(hkRoot, BUNDLE_REGISTRATION_REGISTRY_UNINSTALL_KEY, KEY_READ, pQueryContext->regBitness, &hkUninstallKey);
414 if (HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) == hr || HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) == hr) 403 ButilExitOnPathFailure(hr, fExists, "Failed to open uninstall registry key.");
404
405 if (!fExists)
415 { 406 {
416 ExitFunction1(hr = S_OK); 407 ExitFunction1(hr = S_OK);
417 } 408 }
418 ExitOnFailure(hr, "Failed to open uninstall registry key.");
419 409
420 for (DWORD dwIndex = 0; /* exit via break below */; ++dwIndex) 410 for (DWORD dwIndex = 0; /* exit via break below */; ++dwIndex)
421 { 411 {
@@ -425,7 +415,7 @@ static HRESULT QueryRelatedBundlesForScopeAndBitness(
425 hr = S_OK; 415 hr = S_OK;
426 break; 416 break;
427 } 417 }
428 ExitOnFailure(hr, "Failed to enumerate uninstall key for related bundles."); 418 ButilExitOnFailure(hr, "Failed to enumerate uninstall key for related bundles.");
429 419
430 // Ignore failures here since we'll often find products that aren't actually 420 // Ignore failures here since we'll often find products that aren't actually
431 // related bundles (or even bundles at all). 421 // related bundles (or even bundles at all).
@@ -456,7 +446,7 @@ static HRESULT QueryPotentialRelatedBundle(
456 BUNDLE_QUERY_RELATED_BUNDLE_RESULT bundle = { }; 446 BUNDLE_QUERY_RELATED_BUNDLE_RESULT bundle = { };
457 447
458 hr = RegOpenEx(hkUninstallKey, wzRelatedBundleId, KEY_READ, pQueryContext->regBitness, &hkBundleId); 448 hr = RegOpenEx(hkUninstallKey, wzRelatedBundleId, KEY_READ, pQueryContext->regBitness, &hkBundleId);
459 ExitOnFailure(hr, "Failed to open uninstall key for potential related bundle: %ls", wzRelatedBundleId); 449 ButilExitOnFailure(hr, "Failed to open uninstall key for potential related bundle: %ls", wzRelatedBundleId);
460 450
461 hr = DetermineRelationType(pQueryContext, hkBundleId, &relationType); 451 hr = DetermineRelationType(pQueryContext, hkBundleId, &relationType);
462 if (FAILED(hr)) 452 if (FAILED(hr))
@@ -506,7 +496,7 @@ static HRESULT DetermineRelationType(
506 TraceError(hr, "Failed to read upgrade codes as REG_MULTI_SZ. Trying again as REG_SZ in case of older bundles."); 496 TraceError(hr, "Failed to read upgrade codes as REG_MULTI_SZ. Trying again as REG_SZ in case of older bundles.");
507 497
508 rgsczUpgradeCodes = reinterpret_cast<LPWSTR*>(MemAlloc(sizeof(LPWSTR), TRUE)); 498 rgsczUpgradeCodes = reinterpret_cast<LPWSTR*>(MemAlloc(sizeof(LPWSTR), TRUE));
509 ExitOnNull(rgsczUpgradeCodes, hr, E_OUTOFMEMORY, "Failed to allocate list for a single upgrade code from older bundle."); 499 ButilExitOnNull(rgsczUpgradeCodes, hr, E_OUTOFMEMORY, "Failed to allocate list for a single upgrade code from older bundle.");
510 500
511 hr = RegReadString(hkBundleId, BUNDLE_REGISTRATION_REGISTRY_BUNDLE_UPGRADE_CODE, &rgsczUpgradeCodes[0]); 501 hr = RegReadString(hkBundleId, BUNDLE_REGISTRATION_REGISTRY_BUNDLE_UPGRADE_CODE, &rgsczUpgradeCodes[0]);
512 if (SUCCEEDED(hr)) 502 if (SUCCEEDED(hr))
@@ -519,7 +509,7 @@ static HRESULT DetermineRelationType(
519 if (SUCCEEDED(hr)) 509 if (SUCCEEDED(hr))
520 { 510 {
521 hr = DictCreateStringListFromArray(&sdUpgradeCodes, rgsczUpgradeCodes, cUpgradeCodes, DICT_FLAG_CASEINSENSITIVE); 511 hr = DictCreateStringListFromArray(&sdUpgradeCodes, rgsczUpgradeCodes, cUpgradeCodes, DICT_FLAG_CASEINSENSITIVE);
522 ExitOnFailure(hr, "Failed to create string dictionary for %hs.", "upgrade codes"); 512 ButilExitOnFailure(hr, "Failed to create string dictionary for %hs.", "upgrade codes");
523 513
524 // Upgrade relationship: when their upgrade codes match our upgrade codes. 514 // Upgrade relationship: when their upgrade codes match our upgrade codes.
525 hr = DictCompareStringListToArray(sdUpgradeCodes, const_cast<LPCWSTR*>(pQueryContext->rgwzUpgradeCodes), pQueryContext->cUpgradeCodes); 515 hr = DictCompareStringListToArray(sdUpgradeCodes, const_cast<LPCWSTR*>(pQueryContext->rgwzUpgradeCodes), pQueryContext->cUpgradeCodes);
@@ -529,7 +519,7 @@ static HRESULT DetermineRelationType(
529 } 519 }
530 else 520 else
531 { 521 {
532 ExitOnFailure(hr, "Failed to do array search for upgrade code match."); 522 ButilExitOnFailure(hr, "Failed to do array search for upgrade code match.");
533 523
534 *pRelationType = BUNDLE_RELATION_UPGRADE; 524 *pRelationType = BUNDLE_RELATION_UPGRADE;
535 ExitFunction(); 525 ExitFunction();
@@ -543,7 +533,7 @@ static HRESULT DetermineRelationType(
543 } 533 }
544 else 534 else
545 { 535 {
546 ExitOnFailure(hr, "Failed to do array search for detect code match."); 536 ButilExitOnFailure(hr, "Failed to do array search for detect code match.");
547 537
548 *pRelationType = BUNDLE_RELATION_DETECT; 538 *pRelationType = BUNDLE_RELATION_DETECT;
549 ExitFunction(); 539 ExitFunction();
@@ -557,7 +547,7 @@ static HRESULT DetermineRelationType(
557 } 547 }
558 else 548 else
559 { 549 {
560 ExitOnFailure(hr, "Failed to do array search for addon code match."); 550 ButilExitOnFailure(hr, "Failed to do array search for addon code match.");
561 551
562 *pRelationType = BUNDLE_RELATION_DEPENDENT_ADDON; 552 *pRelationType = BUNDLE_RELATION_DEPENDENT_ADDON;
563 ExitFunction(); 553 ExitFunction();
@@ -571,7 +561,7 @@ static HRESULT DetermineRelationType(
571 } 561 }
572 else 562 else
573 { 563 {
574 ExitOnFailure(hr, "Failed to do array search for patch code match."); 564 ButilExitOnFailure(hr, "Failed to do array search for patch code match.");
575 565
576 *pRelationType = BUNDLE_RELATION_DEPENDENT_PATCH; 566 *pRelationType = BUNDLE_RELATION_DEPENDENT_PATCH;
577 ExitFunction(); 567 ExitFunction();
@@ -586,7 +576,7 @@ static HRESULT DetermineRelationType(
586 if (SUCCEEDED(hr)) 576 if (SUCCEEDED(hr))
587 { 577 {
588 hr = DictCreateStringListFromArray(&sdAddonCodes, rgsczAddonCodes, cAddonCodes, DICT_FLAG_CASEINSENSITIVE); 578 hr = DictCreateStringListFromArray(&sdAddonCodes, rgsczAddonCodes, cAddonCodes, DICT_FLAG_CASEINSENSITIVE);
589 ExitOnFailure(hr, "Failed to create string dictionary for %hs.", "addon codes"); 579 ButilExitOnFailure(hr, "Failed to create string dictionary for %hs.", "addon codes");
590 580
591 // Addon relationship: when their addon codes match our detect codes. 581 // Addon relationship: when their addon codes match our detect codes.
592 hr = DictCompareStringListToArray(sdAddonCodes, const_cast<LPCWSTR*>(pQueryContext->rgwzDetectCodes), pQueryContext->cDetectCodes); 582 hr = DictCompareStringListToArray(sdAddonCodes, const_cast<LPCWSTR*>(pQueryContext->rgwzDetectCodes), pQueryContext->cDetectCodes);
@@ -596,7 +586,7 @@ static HRESULT DetermineRelationType(
596 } 586 }
597 else 587 else
598 { 588 {
599 ExitOnFailure(hr, "Failed to do array search for addon code match."); 589 ButilExitOnFailure(hr, "Failed to do array search for addon code match.");
600 590
601 *pRelationType = BUNDLE_RELATION_ADDON; 591 *pRelationType = BUNDLE_RELATION_ADDON;
602 ExitFunction(); 592 ExitFunction();
@@ -610,7 +600,7 @@ static HRESULT DetermineRelationType(
610 } 600 }
611 else 601 else
612 { 602 {
613 ExitOnFailure(hr, "Failed to do array search for addon code match."); 603 ButilExitOnFailure(hr, "Failed to do array search for addon code match.");
614 604
615 *pRelationType = BUNDLE_RELATION_ADDON; 605 *pRelationType = BUNDLE_RELATION_ADDON;
616 ExitFunction(); 606 ExitFunction();
@@ -625,7 +615,7 @@ static HRESULT DetermineRelationType(
625 if (SUCCEEDED(hr)) 615 if (SUCCEEDED(hr))
626 { 616 {
627 hr = DictCreateStringListFromArray(&sdPatchCodes, rgsczPatchCodes, cPatchCodes, DICT_FLAG_CASEINSENSITIVE); 617 hr = DictCreateStringListFromArray(&sdPatchCodes, rgsczPatchCodes, cPatchCodes, DICT_FLAG_CASEINSENSITIVE);
628 ExitOnFailure(hr, "Failed to create string dictionary for %hs.", "patch codes"); 618 ButilExitOnFailure(hr, "Failed to create string dictionary for %hs.", "patch codes");
629 619
630 // Patch relationship: when their patch codes match our detect codes. 620 // Patch relationship: when their patch codes match our detect codes.
631 hr = DictCompareStringListToArray(sdPatchCodes, const_cast<LPCWSTR*>(pQueryContext->rgwzDetectCodes), pQueryContext->cDetectCodes); 621 hr = DictCompareStringListToArray(sdPatchCodes, const_cast<LPCWSTR*>(pQueryContext->rgwzDetectCodes), pQueryContext->cDetectCodes);
@@ -635,7 +625,7 @@ static HRESULT DetermineRelationType(
635 } 625 }
636 else 626 else
637 { 627 {
638 ExitOnFailure(hr, "Failed to do array search for patch code match."); 628 ButilExitOnFailure(hr, "Failed to do array search for patch code match.");
639 629
640 *pRelationType = BUNDLE_RELATION_PATCH; 630 *pRelationType = BUNDLE_RELATION_PATCH;
641 ExitFunction(); 631 ExitFunction();
@@ -649,7 +639,7 @@ static HRESULT DetermineRelationType(
649 } 639 }
650 else 640 else
651 { 641 {
652 ExitOnFailure(hr, "Failed to do array search for patch code match."); 642 ButilExitOnFailure(hr, "Failed to do array search for patch code match.");
653 643
654 *pRelationType = BUNDLE_RELATION_PATCH; 644 *pRelationType = BUNDLE_RELATION_PATCH;
655 ExitFunction(); 645 ExitFunction();
@@ -664,7 +654,7 @@ static HRESULT DetermineRelationType(
664 if (SUCCEEDED(hr)) 654 if (SUCCEEDED(hr))
665 { 655 {
666 hr = DictCreateStringListFromArray(&sdDetectCodes, rgsczDetectCodes, cDetectCodes, DICT_FLAG_CASEINSENSITIVE); 656 hr = DictCreateStringListFromArray(&sdDetectCodes, rgsczDetectCodes, cDetectCodes, DICT_FLAG_CASEINSENSITIVE);
667 ExitOnFailure(hr, "Failed to create string dictionary for %hs.", "detect codes"); 657 ButilExitOnFailure(hr, "Failed to create string dictionary for %hs.", "detect codes");
668 658
669 // Detect relationship: when their detect codes match our detect codes. 659 // Detect relationship: when their detect codes match our detect codes.
670 hr = DictCompareStringListToArray(sdDetectCodes, const_cast<LPCWSTR*>(pQueryContext->rgwzDetectCodes), pQueryContext->cDetectCodes); 660 hr = DictCompareStringListToArray(sdDetectCodes, const_cast<LPCWSTR*>(pQueryContext->rgwzDetectCodes), pQueryContext->cDetectCodes);
@@ -674,7 +664,7 @@ static HRESULT DetermineRelationType(
674 } 664 }
675 else 665 else
676 { 666 {
677 ExitOnFailure(hr, "Failed to do array search for detect code match."); 667 ButilExitOnFailure(hr, "Failed to do array search for detect code match.");
678 668
679 *pRelationType = BUNDLE_RELATION_DETECT; 669 *pRelationType = BUNDLE_RELATION_DETECT;
680 ExitFunction(); 670 ExitFunction();
@@ -688,7 +678,7 @@ static HRESULT DetermineRelationType(
688 } 678 }
689 else 679 else
690 { 680 {
691 ExitOnFailure(hr, "Failed to do array search for addon code match."); 681 ButilExitOnFailure(hr, "Failed to do array search for addon code match.");
692 682
693 *pRelationType = BUNDLE_RELATION_DEPENDENT_ADDON; 683 *pRelationType = BUNDLE_RELATION_DEPENDENT_ADDON;
694 ExitFunction(); 684 ExitFunction();
@@ -702,7 +692,7 @@ static HRESULT DetermineRelationType(
702 } 692 }
703 else 693 else
704 { 694 {
705 ExitOnFailure(hr, "Failed to do array search for patch code match."); 695 ButilExitOnFailure(hr, "Failed to do array search for patch code match.");
706 696
707 *pRelationType = BUNDLE_RELATION_DEPENDENT_PATCH; 697 *pRelationType = BUNDLE_RELATION_DEPENDENT_PATCH;
708 ExitFunction(); 698 ExitFunction();
@@ -740,54 +730,11 @@ static HRESULT LocateAndQueryBundleValue(
740 ) 730 )
741{ 731{
742 HRESULT hr = S_OK; 732 HRESULT hr = S_OK;
733 LPWSTR sczKeypath = NULL;
734 BOOL fExists = TRUE;
743 735
744 *pStatus = INTERNAL_BUNDLE_STATUS_SUCCESS; 736 *pStatus = INTERNAL_BUNDLE_STATUS_SUCCESS;
745 737
746 if (FAILED(hr = OpenBundleKey(wzBundleId, BUNDLE_INSTALL_CONTEXT_MACHINE, wzSubKey, REG_KEY_32BIT, phKey)) &&
747 FAILED(hr = OpenBundleKey(wzBundleId, BUNDLE_INSTALL_CONTEXT_MACHINE, wzSubKey, REG_KEY_64BIT, phKey)) &&
748 FAILED(hr = OpenBundleKey(wzBundleId, BUNDLE_INSTALL_CONTEXT_USER, wzSubKey, REG_KEY_DEFAULT, phKey)))
749 {
750 if (E_FILENOTFOUND == hr)
751 {
752 *pStatus = INTERNAL_BUNDLE_STATUS_UNKNOWN_BUNDLE;
753 ExitFunction1(hr = S_OK);
754 }
755
756 ButilExitOnFailure(hr, "Failed to open bundle key.");
757 }
758
759 // If the bundle doesn't have the value defined, return ERROR_UNKNOWN_PROPERTY
760 hr = RegGetType(*phKey, wzValueName, pdwType);
761 if (FAILED(hr))
762 {
763 if (E_FILENOTFOUND == hr)
764 {
765 *pStatus = INTERNAL_BUNDLE_STATUS_UNKNOWN_PROPERTY;
766 ExitFunction1(hr = S_OK);
767 }
768
769 ButilExitOnFailure(hr, "Failed to read bundle value.");
770 }
771
772LExit:
773 return hr;
774}
775
776static HRESULT OpenBundleKey(
777 __in_z LPCWSTR wzBundleId,
778 __in BUNDLE_INSTALL_CONTEXT context,
779 __in_opt LPCWSTR wzSubKey,
780 __in REG_KEY_BITNESS kbKeyBitness,
781 __inout HKEY* phKey
782 )
783{
784 Assert(phKey && wzBundleId);
785 AssertSz(NULL == *phKey, "*key should be null");
786
787 HRESULT hr = S_OK;
788 HKEY hkRoot = BUNDLE_INSTALL_CONTEXT_USER == context ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
789 LPWSTR sczKeypath = NULL;
790
791 if (wzSubKey) 738 if (wzSubKey)
792 { 739 {
793 hr = StrAllocFormatted(&sczKeypath, L"%ls\\%ls\\%ls", BUNDLE_REGISTRATION_REGISTRY_UNINSTALL_KEY, wzBundleId, wzSubKey); 740 hr = StrAllocFormatted(&sczKeypath, L"%ls\\%ls\\%ls", BUNDLE_REGISTRATION_REGISTRY_UNINSTALL_KEY, wzBundleId, wzSubKey);
@@ -798,8 +745,24 @@ static HRESULT OpenBundleKey(
798 } 745 }
799 ButilExitOnFailure(hr, "Failed to allocate bundle uninstall key path."); 746 ButilExitOnFailure(hr, "Failed to allocate bundle uninstall key path.");
800 747
801 hr = RegOpenEx(hkRoot, sczKeypath, KEY_READ, kbKeyBitness, phKey); 748 if (FAILED(hr = RegOpenEx(HKEY_LOCAL_MACHINE, sczKeypath, KEY_READ, REG_KEY_32BIT, phKey)) &&
802 ButilExitOnFailure(hr, "Failed to open bundle uninstall key path."); 749 FAILED(hr = RegOpenEx(HKEY_LOCAL_MACHINE, sczKeypath, KEY_READ, REG_KEY_64BIT, phKey)) &&
750 FAILED(hr = RegOpenEx(HKEY_CURRENT_USER, sczKeypath, KEY_READ, REG_KEY_DEFAULT, phKey)))
751 {
752 ButilExitOnPathFailure(hr, fExists, "Failed to open bundle key.");
753
754 *pStatus = INTERNAL_BUNDLE_STATUS_UNKNOWN_BUNDLE;
755 ExitFunction1(hr = S_OK);
756 }
757
758 hr = RegGetType(*phKey, wzValueName, pdwType);
759 ButilExitOnPathFailure(hr, fExists, "Failed to read bundle value.");
760
761 if (!fExists)
762 {
763 *pStatus = INTERNAL_BUNDLE_STATUS_UNKNOWN_PROPERTY;
764 ExitFunction1(hr = S_OK);
765 }
803 766
804LExit: 767LExit:
805 ReleaseStr(sczKeypath); 768 ReleaseStr(sczKeypath);
diff --git a/src/libs/dutil/WixToolset.DUtil/deputil.cpp b/src/libs/dutil/WixToolset.DUtil/deputil.cpp
index 4de85199..f92c7d18 100644
--- a/src/libs/dutil/WixToolset.DUtil/deputil.cpp
+++ b/src/libs/dutil/WixToolset.DUtil/deputil.cpp
@@ -16,6 +16,7 @@
16#define DepExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_DEPUTIL, p, x, s, __VA_ARGS__) 16#define DepExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_DEPUTIL, p, x, s, __VA_ARGS__)
17#define DepExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_DEPUTIL, e, x, s, __VA_ARGS__) 17#define DepExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_DEPUTIL, e, x, s, __VA_ARGS__)
18#define DepExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_DEPUTIL, g, x, s, __VA_ARGS__) 18#define DepExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_DEPUTIL, g, x, s, __VA_ARGS__)
19#define DepExitOnPathFailure(x, b, s, ...) ExitOnPathFailureSource(DUTIL_SOURCE_DEPUTIL, x, b, s, __VA_ARGS__)
19 20
20#define ARRAY_GROWTH_SIZE 5 21#define ARRAY_GROWTH_SIZE 5
21 22
@@ -54,6 +55,7 @@ DAPI_(HRESULT) DepGetProviderInformation(
54 HRESULT hr = S_OK; 55 HRESULT hr = S_OK;
55 LPWSTR sczKey = NULL; 56 LPWSTR sczKey = NULL;
56 HKEY hkKey = NULL; 57 HKEY hkKey = NULL;
58 BOOL fExists = FALSE;
57 59
58 // Format the provider dependency registry key. 60 // Format the provider dependency registry key.
59 hr = AllocDependencyKeyName(wzProviderKey, &sczKey); 61 hr = AllocDependencyKeyName(wzProviderKey, &sczKey);
@@ -61,43 +63,32 @@ DAPI_(HRESULT) DepGetProviderInformation(
61 63
62 // Try to open the dependency key. 64 // Try to open the dependency key.
63 hr = RegOpen(hkHive, sczKey, KEY_READ, &hkKey); 65 hr = RegOpen(hkHive, sczKey, KEY_READ, &hkKey);
64 if (E_FILENOTFOUND == hr) 66 DepExitOnPathFailure(hr, fExists, "Failed to open the registry key for the dependency \"%ls\".", wzProviderKey);
67
68 if (!fExists)
65 { 69 {
66 ExitFunction1(hr = E_NOTFOUND); 70 ExitFunction1(hr = E_NOTFOUND);
67 } 71 }
68 DepExitOnFailure(hr, "Failed to open the registry key for the dependency \"%ls\".", wzProviderKey);
69 72
70 // Get the Id if requested and available. 73 // Get the Id if requested and available.
71 if (psczId) 74 if (psczId)
72 { 75 {
73 hr = RegReadString(hkKey, NULL, psczId); 76 hr = RegReadString(hkKey, NULL, psczId);
74 if (E_FILENOTFOUND == hr) 77 DepExitOnPathFailure(hr, fExists, "Failed to get the id for the dependency \"%ls\".", wzProviderKey);
75 {
76 hr = S_OK;
77 }
78 DepExitOnFailure(hr, "Failed to get the id for the dependency \"%ls\".", wzProviderKey);
79 } 78 }
80 79
81 // Get the DisplayName if requested and available. 80 // Get the DisplayName if requested and available.
82 if (psczName) 81 if (psczName)
83 { 82 {
84 hr = RegReadString(hkKey, vcszDisplayNameValue, psczName); 83 hr = RegReadString(hkKey, vcszDisplayNameValue, psczName);
85 if (E_FILENOTFOUND == hr) 84 DepExitOnPathFailure(hr, fExists, "Failed to get the name for the dependency \"%ls\".", wzProviderKey);
86 {
87 hr = S_OK;
88 }
89 DepExitOnFailure(hr, "Failed to get the name for the dependency \"%ls\".", wzProviderKey);
90 } 85 }
91 86
92 // Get the Version if requested and available. 87 // Get the Version if requested and available.
93 if (psczVersion) 88 if (psczVersion)
94 { 89 {
95 hr = RegReadString(hkKey, vcszVersionValue, psczVersion); 90 hr = RegReadString(hkKey, vcszVersionValue, psczVersion);
96 if (E_FILENOTFOUND == hr) 91 DepExitOnPathFailure(hr, fExists, "Failed to get the version for the dependency \"%ls\".", wzProviderKey);
97 {
98 hr = S_OK;
99 }
100 DepExitOnFailure(hr, "Failed to get the version for the dependency \"%ls\".", wzProviderKey);
101 } 92 }
102 93
103LExit: 94LExit:
@@ -121,6 +112,7 @@ DAPI_(HRESULT) DepCheckDependency(
121 HRESULT hr = S_OK; 112 HRESULT hr = S_OK;
122 LPWSTR sczKey = NULL; 113 LPWSTR sczKey = NULL;
123 HKEY hkKey = NULL; 114 HKEY hkKey = NULL;
115 BOOL fExists = FALSE;
124 VERUTIL_VERSION* pVersion = NULL; 116 VERUTIL_VERSION* pVersion = NULL;
125 VERUTIL_VERSION* pMinVersion = NULL; 117 VERUTIL_VERSION* pMinVersion = NULL;
126 VERUTIL_VERSION* pMaxVersion = NULL; 118 VERUTIL_VERSION* pMaxVersion = NULL;
@@ -134,20 +126,17 @@ DAPI_(HRESULT) DepCheckDependency(
134 126
135 // Try to open the key. If that fails, add the missing dependency key to the dependency array if it doesn't already exist. 127 // Try to open the key. If that fails, add the missing dependency key to the dependency array if it doesn't already exist.
136 hr = RegOpen(hkHive, sczKey, KEY_READ, &hkKey); 128 hr = RegOpen(hkHive, sczKey, KEY_READ, &hkKey);
137 if (E_FILENOTFOUND != hr) 129 DepExitOnPathFailure(hr, fExists, "Failed to open the registry key for dependency \"%ls\".", wzProviderKey);
138 {
139 DepExitOnFailure(hr, "Failed to open the registry key for dependency \"%ls\".", wzProviderKey);
140 130
131 if (fExists)
132 {
141 // If there are no registry values, consider the key orphaned and treat it as missing. 133 // If there are no registry values, consider the key orphaned and treat it as missing.
142 hr = RegReadWixVersion(hkKey, vcszVersionValue, &pVersion); 134 hr = RegReadWixVersion(hkKey, vcszVersionValue, &pVersion);
143 if (E_FILENOTFOUND != hr) 135 DepExitOnPathFailure(hr, fExists, "Failed to read the %ls registry value for dependency \"%ls\".", vcszVersionValue, wzProviderKey);
144 {
145 DepExitOnFailure(hr, "Failed to read the %ls registry value for dependency \"%ls\".", vcszVersionValue, wzProviderKey);
146 }
147 } 136 }
148 137
149 // If the key was not found or the Version value was not found, add the missing dependency key to the dependency array. 138 // If the key was not found or the Version value was not found, add the missing dependency key to the dependency array.
150 if (E_FILENOTFOUND == hr) 139 if (!fExists)
151 { 140 {
152 hr = DictKeyExists(sdDependencies, wzProviderKey); 141 hr = DictKeyExists(sdDependencies, wzProviderKey);
153 if (E_NOTFOUND != hr) 142 if (E_NOTFOUND != hr)
@@ -190,7 +179,7 @@ DAPI_(HRESULT) DepCheckDependency(
190 else 179 else
191 { 180 {
192 hr = RegReadString(hkKey, vcszDisplayNameValue, &sczName); 181 hr = RegReadString(hkKey, vcszDisplayNameValue, &sczName);
193 DepExitOnFailure(hr, "Failed to get the display name of the older dependency \"%ls\".", wzProviderKey); 182 DepExitOnPathFailure(hr, fExists, "Failed to get the display name of the older dependency \"%ls\".", wzProviderKey);
194 183
195 hr = DepDependencyArrayAlloc(prgDependencies, pcDependencies, wzProviderKey, sczName); 184 hr = DepDependencyArrayAlloc(prgDependencies, pcDependencies, wzProviderKey, sczName);
196 DepExitOnFailure(hr, "Failed to add the older dependency \"%ls\" to the dependencies array.", wzProviderKey); 185 DepExitOnFailure(hr, "Failed to add the older dependency \"%ls\" to the dependencies array.", wzProviderKey);
@@ -228,7 +217,7 @@ DAPI_(HRESULT) DepCheckDependency(
228 else 217 else
229 { 218 {
230 hr = RegReadString(hkKey, vcszDisplayNameValue, &sczName); 219 hr = RegReadString(hkKey, vcszDisplayNameValue, &sczName);
231 DepExitOnFailure(hr, "Failed to get the display name of the newer dependency \"%ls\".", wzProviderKey); 220 DepExitOnPathFailure(hr, fExists, "Failed to get the display name of the newer dependency \"%ls\".", wzProviderKey);
232 221
233 hr = DepDependencyArrayAlloc(prgDependencies, pcDependencies, wzProviderKey, sczName); 222 hr = DepDependencyArrayAlloc(prgDependencies, pcDependencies, wzProviderKey, sczName);
234 DepExitOnFailure(hr, "Failed to add the newer dependency \"%ls\" to the dependencies array.", wzProviderKey); 223 DepExitOnFailure(hr, "Failed to add the newer dependency \"%ls\" to the dependencies array.", wzProviderKey);
@@ -267,6 +256,7 @@ DAPI_(HRESULT) DepCheckDependents(
267 LPWSTR sczKey = NULL; 256 LPWSTR sczKey = NULL;
268 HKEY hkProviderKey = NULL; 257 HKEY hkProviderKey = NULL;
269 HKEY hkDependentsKey = NULL; 258 HKEY hkDependentsKey = NULL;
259 BOOL fExists = FALSE;
270 LPWSTR sczDependentKey = NULL; 260 LPWSTR sczDependentKey = NULL;
271 LPWSTR sczDependentName = NULL; 261 LPWSTR sczDependentName = NULL;
272 BOOL fIgnore = FALSE; 262 BOOL fIgnore = FALSE;
@@ -277,15 +267,18 @@ DAPI_(HRESULT) DepCheckDependents(
277 267
278 // Try to open the key. If that fails, the dependency information is corrupt. 268 // Try to open the key. If that fails, the dependency information is corrupt.
279 hr = RegOpen(hkHive, sczKey, KEY_READ, &hkProviderKey); 269 hr = RegOpen(hkHive, sczKey, KEY_READ, &hkProviderKey);
280 DepExitOnFailure(hr, "Failed to open the registry key \"%ls\". The dependency store is corrupt.", sczKey); 270 DepExitOnPathFailure(hr, fExists, "Failed to open the registry key \"%ls\". The dependency store is corrupt.", sczKey);
281 271
282 // Try to open the dependencies key. If that does not exist, there are no dependents. 272 if (!fExists)
283 hr = RegOpen(hkProviderKey, vsczRegistryDependents, KEY_READ, &hkDependentsKey);
284 if (E_FILENOTFOUND != hr)
285 { 273 {
286 DepExitOnFailure(hr, "Failed to open the registry key for dependents of \"%ls\".", wzProviderKey); 274 ExitFunction1(hr = S_OK);
287 } 275 }
288 else 276
277 // Try to open the dependencies key. If that does not exist, there are no dependents.
278 hr = RegOpen(hkProviderKey, vsczRegistryDependents, KEY_READ, &hkDependentsKey);
279 DepExitOnPathFailure(hr, fExists, "Failed to open the registry key for dependents of \"%ls\".", wzProviderKey);
280
281 if (!fExists)
289 { 282 {
290 ExitFunction1(hr = S_OK); 283 ExitFunction1(hr = S_OK);
291 } 284 }
@@ -399,15 +392,18 @@ DAPI_(HRESULT) DepDependentExists(
399 HRESULT hr = S_OK; 392 HRESULT hr = S_OK;
400 LPWSTR sczDependentKey = NULL; 393 LPWSTR sczDependentKey = NULL;
401 HKEY hkDependentKey = NULL; 394 HKEY hkDependentKey = NULL;
395 BOOL fExists = FALSE;
402 396
403 // Format the provider dependents registry key. 397 // Format the provider dependents registry key.
404 hr = StrAllocFormatted(&sczDependentKey, L"%ls%ls\\%ls\\%ls", vsczRegistryRoot, wzDependencyProviderKey, vsczRegistryDependents, wzProviderKey); 398 hr = StrAllocFormatted(&sczDependentKey, L"%ls%ls\\%ls\\%ls", vsczRegistryRoot, wzDependencyProviderKey, vsczRegistryDependents, wzProviderKey);
405 DepExitOnFailure(hr, "Failed to format registry key to dependent."); 399 DepExitOnFailure(hr, "Failed to format registry key to dependent.");
406 400
407 hr = RegOpen(hkHive, sczDependentKey, KEY_READ, &hkDependentKey); 401 hr = RegOpen(hkHive, sczDependentKey, KEY_READ, &hkDependentKey);
408 if (E_FILENOTFOUND != hr) 402 DepExitOnPathFailure(hr, fExists, "Failed to open the dependent registry key at: \"%ls\".", sczDependentKey);
403
404 if (!fExists)
409 { 405 {
410 DepExitOnFailure(hr, "Failed to open the dependent registry key at: \"%ls\".", sczDependentKey); 406 hr = E_FILENOTFOUND;
411 } 407 }
412 408
413LExit: 409LExit:
@@ -480,6 +476,7 @@ DAPI_(HRESULT) DepUnregisterDependency(
480 HRESULT hr = S_OK; 476 HRESULT hr = S_OK;
481 LPWSTR sczKey = NULL; 477 LPWSTR sczKey = NULL;
482 HKEY hkKey = NULL; 478 HKEY hkKey = NULL;
479 BOOL fExists = FALSE;
483 480
484 // Format the provider dependency registry key. 481 // Format the provider dependency registry key.
485 hr = AllocDependencyKeyName(wzProviderKey, &sczKey); 482 hr = AllocDependencyKeyName(wzProviderKey, &sczKey);
@@ -487,9 +484,11 @@ DAPI_(HRESULT) DepUnregisterDependency(
487 484
488 // Delete the entire key including all sub-keys. 485 // Delete the entire key including all sub-keys.
489 hr = RegDelete(hkHive, sczKey, REG_KEY_DEFAULT, TRUE); 486 hr = RegDelete(hkHive, sczKey, REG_KEY_DEFAULT, TRUE);
490 if (E_FILENOTFOUND != hr) 487 DepExitOnPathFailure(hr, fExists, "Failed to delete the key \"%ls\".", sczKey);
488
489 if (!fExists)
491 { 490 {
492 DepExitOnFailure(hr, "Failed to delete the key \"%ls\".", sczKey); 491 hr = E_FILENOTFOUND;
493 } 492 }
494 493
495LExit: 494LExit:
@@ -506,6 +505,7 @@ DAPI_(HRESULT) DepUnregisterDependent(
506 ) 505 )
507{ 506{
508 HRESULT hr = S_OK; 507 HRESULT hr = S_OK;
508 BOOL fExists = FALSE;
509 HKEY hkRegistryRoot = NULL; 509 HKEY hkRegistryRoot = NULL;
510 HKEY hkDependencyProviderKey = NULL; 510 HKEY hkDependencyProviderKey = NULL;
511 HKEY hkRegistryDependents = NULL; 511 HKEY hkRegistryDependents = NULL;
@@ -514,40 +514,39 @@ DAPI_(HRESULT) DepUnregisterDependent(
514 514
515 // Open the root key. We may delete the wzDependencyProviderKey during clean up. 515 // Open the root key. We may delete the wzDependencyProviderKey during clean up.
516 hr = RegOpen(hkHive, vsczRegistryRoot, KEY_READ, &hkRegistryRoot); 516 hr = RegOpen(hkHive, vsczRegistryRoot, KEY_READ, &hkRegistryRoot);
517 if (E_FILENOTFOUND != hr) 517 DepExitOnPathFailure(hr, fExists, "Failed to open root registry key \"%ls\".", vsczRegistryRoot);
518 { 518
519 DepExitOnFailure(hr, "Failed to open root registry key \"%ls\".", vsczRegistryRoot); 519 if (!fExists)
520 }
521 else
522 { 520 {
523 ExitFunction(); 521 ExitFunction1(hr = E_FILENOTFOUND);
524 } 522 }
525 523
526 // Try to open the dependency key. If that does not exist, simply return. 524 // Try to open the dependency key. If that does not exist, simply return.
527 hr = RegOpen(hkRegistryRoot, wzDependencyProviderKey, KEY_READ, &hkDependencyProviderKey); 525 hr = RegOpen(hkRegistryRoot, wzDependencyProviderKey, KEY_READ, &hkDependencyProviderKey);
528 if (E_FILENOTFOUND != hr) 526 DepExitOnPathFailure(hr, fExists, "Failed to open the registry key for the dependency \"%ls\".", wzDependencyProviderKey);
529 { 527
530 DepExitOnFailure(hr, "Failed to open the registry key for the dependency \"%ls\".", wzDependencyProviderKey); 528 if (!fExists)
531 }
532 else
533 { 529 {
534 ExitFunction(); 530 ExitFunction1(hr = E_FILENOTFOUND);
535 } 531 }
536 532
537 // Try to open the dependents subkey to enumerate. 533 // Try to open the dependents subkey to enumerate.
538 hr = RegOpen(hkDependencyProviderKey, vsczRegistryDependents, KEY_READ, &hkRegistryDependents); 534 hr = RegOpen(hkDependencyProviderKey, vsczRegistryDependents, KEY_READ, &hkRegistryDependents);
539 if (E_FILENOTFOUND != hr) 535 DepExitOnPathFailure(hr, fExists, "Failed to open the dependents subkey under the dependency \"%ls\".", wzDependencyProviderKey);
540 { 536
541 DepExitOnFailure(hr, "Failed to open the dependents subkey under the dependency \"%ls\".", wzDependencyProviderKey); 537 if (!fExists)
542 }
543 else
544 { 538 {
545 ExitFunction(); 539 ExitFunction1(hr = E_FILENOTFOUND);
546 } 540 }
547 541
548 // Delete the wzProviderKey dependent sub-key. 542 // Delete the wzProviderKey dependent sub-key.
549 hr = RegDelete(hkRegistryDependents, wzProviderKey, REG_KEY_DEFAULT, TRUE); 543 hr = RegDelete(hkRegistryDependents, wzProviderKey, REG_KEY_DEFAULT, TRUE);
550 DepExitOnFailure(hr, "Failed to delete the dependent \"%ls\" under the dependency \"%ls\".", wzProviderKey, wzDependencyProviderKey); 544 DepExitOnPathFailure(hr, fExists, "Failed to delete the dependent \"%ls\" under the dependency \"%ls\".", wzProviderKey, wzDependencyProviderKey);
545
546 if (!fExists)
547 {
548 ExitFunction1(hr = E_FILENOTFOUND);
549 }
551 550
552 // If there are no remaining dependents, delete the Dependents subkey. 551 // If there are no remaining dependents, delete the Dependents subkey.
553 hr = RegQueryKey(hkRegistryDependents, &cSubKeys, NULL); 552 hr = RegQueryKey(hkRegistryDependents, &cSubKeys, NULL);
@@ -563,7 +562,12 @@ DAPI_(HRESULT) DepUnregisterDependent(
563 562
564 // Fail if there are any subkeys since we just checked. 563 // Fail if there are any subkeys since we just checked.
565 hr = RegDelete(hkDependencyProviderKey, vsczRegistryDependents, REG_KEY_DEFAULT, FALSE); 564 hr = RegDelete(hkDependencyProviderKey, vsczRegistryDependents, REG_KEY_DEFAULT, FALSE);
566 DepExitOnFailure(hr, "Failed to delete the dependents subkey under the dependency \"%ls\".", wzDependencyProviderKey); 565 DepExitOnPathFailure(hr, fExists, "Failed to delete the dependents subkey under the dependency \"%ls\".", wzDependencyProviderKey);
566
567 if (!fExists)
568 {
569 ExitFunction1(hr = E_FILENOTFOUND);
570 }
567 571
568 // If there are no values, delete the provider dependency key. 572 // If there are no values, delete the provider dependency key.
569 hr = RegQueryKey(hkDependencyProviderKey, NULL, &cValues); 573 hr = RegQueryKey(hkDependencyProviderKey, NULL, &cValues);
@@ -576,7 +580,12 @@ DAPI_(HRESULT) DepUnregisterDependent(
576 580
577 // Fail if there are any subkeys since we just checked. 581 // Fail if there are any subkeys since we just checked.
578 hr = RegDelete(hkRegistryRoot, wzDependencyProviderKey, REG_KEY_DEFAULT, FALSE); 582 hr = RegDelete(hkRegistryRoot, wzDependencyProviderKey, REG_KEY_DEFAULT, FALSE);
579 DepExitOnFailure(hr, "Failed to delete the dependency \"%ls\".", wzDependencyProviderKey); 583 DepExitOnPathFailure(hr, fExists, "Failed to delete the dependency \"%ls\".", wzDependencyProviderKey);
584
585 if (!fExists)
586 {
587 ExitFunction1(hr = E_FILENOTFOUND);
588 }
580 } 589 }
581 590
582LExit: 591LExit:
@@ -685,6 +694,7 @@ static HRESULT GetDependencyNameFromKey(
685 HRESULT hr = S_OK; 694 HRESULT hr = S_OK;
686 LPWSTR sczKey = NULL; 695 LPWSTR sczKey = NULL;
687 HKEY hkKey = NULL; 696 HKEY hkKey = NULL;
697 BOOL fExists = FALSE;
688 698
689 // Format the provider dependency registry key. 699 // Format the provider dependency registry key.
690 hr = AllocDependencyKeyName(wzProviderKey, &sczKey); 700 hr = AllocDependencyKeyName(wzProviderKey, &sczKey);
@@ -692,25 +702,16 @@ static HRESULT GetDependencyNameFromKey(
692 702
693 // Try to open the dependency key. 703 // Try to open the dependency key.
694 hr = RegOpen(hkHive, sczKey, KEY_READ, &hkKey); 704 hr = RegOpen(hkHive, sczKey, KEY_READ, &hkKey);
695 if (E_FILENOTFOUND != hr) 705 DepExitOnPathFailure(hr, fExists, "Failed to open the registry key for the dependency \"%ls\".", wzProviderKey);
696 { 706
697 DepExitOnFailure(hr, "Failed to open the registry key for the dependency \"%ls\".", wzProviderKey); 707 if (!fExists)
698 }
699 else
700 { 708 {
701 ExitFunction1(hr = S_OK); 709 ExitFunction();
702 } 710 }
703 711
704 // Get the DisplayName if available. 712 // Get the DisplayName if available.
705 hr = RegReadString(hkKey, vcszDisplayNameValue, psczName); 713 hr = RegReadString(hkKey, vcszDisplayNameValue, psczName);
706 if (E_FILENOTFOUND != hr) 714 DepExitOnPathFailure(hr, fExists, "Failed to get the dependency name for the dependency \"%ls\".", wzProviderKey);
707 {
708 DepExitOnFailure(hr, "Failed to get the dependency name for the dependency \"%ls\".", wzProviderKey);
709 }
710 else
711 {
712 ExitFunction1(hr = S_OK);
713 }
714 715
715LExit: 716LExit:
716 ReleaseRegKey(hkKey); 717 ReleaseRegKey(hkKey);
diff --git a/src/libs/dutil/WixToolset.DUtil/dirutil.cpp b/src/libs/dutil/WixToolset.DUtil/dirutil.cpp
index 2c02225d..8c7ef461 100644
--- a/src/libs/dutil/WixToolset.DUtil/dirutil.cpp
+++ b/src/libs/dutil/WixToolset.DUtil/dirutil.cpp
@@ -17,6 +17,8 @@
17#define DirExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_DIRUTIL, p, x, s, __VA_ARGS__) 17#define DirExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_DIRUTIL, p, x, s, __VA_ARGS__)
18#define DirExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_DIRUTIL, e, x, s, __VA_ARGS__) 18#define DirExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_DIRUTIL, e, x, s, __VA_ARGS__)
19#define DirExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_DIRUTIL, g, x, s, __VA_ARGS__) 19#define DirExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_DIRUTIL, g, x, s, __VA_ARGS__)
20#define DirExitOnPathFailure(x, b, s, ...) ExitOnPathFailureSource(DUTIL_SOURCE_DIRUTIL, x, b, s, __VA_ARGS__)
21#define DirExitWithPathLastError(x, s, ...) ExitWithPathLastErrorSource(DUTIL_SOURCE_DIRUTIL, x, s, __VA_ARGS__)
20 22
21 23
22/******************************************************************* 24/*******************************************************************
@@ -184,13 +186,9 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx(
184 186
185 if (-1 == (dwAttrib = ::GetFileAttributesW(wzPath))) 187 if (-1 == (dwAttrib = ::GetFileAttributesW(wzPath)))
186 { 188 {
187 er = ::GetLastError(); 189 DirExitWithPathLastError(hr, "Failed to get attributes for path: %ls", wzPath);
188 if (ERROR_FILE_NOT_FOUND == er) // change "file not found" to "path not found" since we were looking for a directory. 190
189 { 191 ExitFunction1(hr = E_PATHNOTFOUND);
190 er = ERROR_PATH_NOT_FOUND;
191 }
192 hr = HRESULT_FROM_WIN32(er);
193 DirExitOnRootFailure(hr, "Failed to get attributes for path: %ls", wzPath);
194 } 192 }
195 193
196 if (dwAttrib & FILE_ATTRIBUTE_DIRECTORY) 194 if (dwAttrib & FILE_ATTRIBUTE_DIRECTORY)
@@ -199,7 +197,9 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx(
199 { 197 {
200 if (!::SetFileAttributesW(wzPath, FILE_ATTRIBUTE_NORMAL)) 198 if (!::SetFileAttributesW(wzPath, FILE_ATTRIBUTE_NORMAL))
201 { 199 {
202 DirExitWithLastError(hr, "Failed to remove read-only attribute from path: %ls", wzPath); 200 DirExitWithPathLastError(hr, "Failed to remove read-only attribute from path: %ls", wzPath);
201
202 ExitFunction1(hr = E_PATHNOTFOUND);
203 } 203 }
204 } 204 }
205 205
@@ -245,9 +245,12 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx(
245 hr = DirEnsureDeleteEx(sczDelete, dwFlags); // recursive call 245 hr = DirEnsureDeleteEx(sczDelete, dwFlags); // recursive call
246 if (FAILED(hr)) 246 if (FAILED(hr))
247 { 247 {
248 // if we failed to delete a subdirectory, keep trying to finish any remaining files 248 // if we failed to delete a subdirectory, keep trying to finish any remaining files
249 ExitTraceSource(DUTIL_SOURCE_DIRUTIL, hr, "Failed to delete subdirectory; continuing: %ls", sczDelete); 249 if (E_PATHNOTFOUND != hr)
250 hr = S_OK; 250 {
251 ExitTraceSource(DUTIL_SOURCE_DIRUTIL, hr, "Failed to delete subdirectory; continuing: %ls", sczDelete);
252 }
253 hr = S_OK;
251 } 254 }
252 } 255 }
253 else if (fDeleteFiles) // this is a file, just delete it 256 else if (fDeleteFiles) // this is a file, just delete it
@@ -256,7 +259,8 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx(
256 { 259 {
257 if (!::SetFileAttributesW(sczDelete, FILE_ATTRIBUTE_NORMAL)) 260 if (!::SetFileAttributesW(sczDelete, FILE_ATTRIBUTE_NORMAL))
258 { 261 {
259 DirExitWithLastError(hr, "Failed to remove attributes from file: %ls", sczDelete); 262 DirExitWithPathLastError(hr, "Failed to remove attributes from file: %ls", sczDelete);
263 continue;
260 } 264 }
261 } 265 }
262 266
@@ -280,7 +284,7 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx(
280 } 284 }
281 else 285 else
282 { 286 {
283 DirExitWithLastError(hr, "Failed to delete file: %ls", sczDelete); 287 DirExitWithPathLastError(hr, "Failed to delete file: %ls", sczDelete);
284 } 288 }
285 } 289 }
286 } 290 }
@@ -308,13 +312,21 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx(
308 } 312 }
309 } 313 }
310 314
315 if (E_PATHNOTFOUND == hr || E_FILENOTFOUND == hr)
316 {
317 ExitFunction1(hr = E_PATHNOTFOUND);
318 }
319 else if (HRESULT_FROM_WIN32(ERROR_DIR_NOT_EMPTY) == hr && !fDeleteFiles && !fRecurse)
320 {
321 ExitFunction();
322 }
323
311 DirExitOnRootFailure(hr, "Failed to remove directory: %ls", wzPath); 324 DirExitOnRootFailure(hr, "Failed to remove directory: %ls", wzPath);
312 } 325 }
313 } 326 }
314 else 327 else
315 { 328 {
316 hr = E_UNEXPECTED; 329 DirExitWithRootFailure(hr, E_UNEXPECTED, "Directory delete cannot delete file: %ls", wzPath);
317 DirExitOnFailure(hr, "Directory delete cannot delete file: %ls", wzPath);
318 } 330 }
319 331
320 Assert(S_OK == hr); 332 Assert(S_OK == hr);
diff --git a/src/libs/dutil/WixToolset.DUtil/file2utl.cpp b/src/libs/dutil/WixToolset.DUtil/file2utl.cpp
index 88f8377c..3ab47f59 100644
--- a/src/libs/dutil/WixToolset.DUtil/file2utl.cpp
+++ b/src/libs/dutil/WixToolset.DUtil/file2utl.cpp
@@ -16,6 +16,7 @@
16#define FileExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_FILEUTIL, p, x, s, __VA_ARGS__) 16#define FileExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_FILEUTIL, p, x, s, __VA_ARGS__)
17#define FileExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_FILEUTIL, e, x, s, __VA_ARGS__) 17#define FileExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_FILEUTIL, e, x, s, __VA_ARGS__)
18#define FileExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_FILEUTIL, g, x, s, __VA_ARGS__) 18#define FileExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_FILEUTIL, g, x, s, __VA_ARGS__)
19#define FileExitOnPathFailure(x, b, s, ...) ExitOnPathFailureSource(DUTIL_SOURCE_FILEUTIL, x, b, s, __VA_ARGS__)
19 20
20// constants 21// constants
21 22
@@ -35,6 +36,7 @@ extern "C" BOOL DAPI FileExistsAfterRestart(
35{ 36{
36 HRESULT hr = S_OK; 37 HRESULT hr = S_OK;
37 BOOL fExists = FALSE; 38 BOOL fExists = FALSE;
39 BOOL fRegExists = FALSE;
38 HKEY hkPendingFileRename = NULL; 40 HKEY hkPendingFileRename = NULL;
39 LPWSTR* rgsczRenames = NULL; 41 LPWSTR* rgsczRenames = NULL;
40 DWORD cRenames = 0; 42 DWORD cRenames = 0;
@@ -44,18 +46,20 @@ extern "C" BOOL DAPI FileExistsAfterRestart(
44 if (fExists) 46 if (fExists)
45 { 47 {
46 hr = RegOpen(HKEY_LOCAL_MACHINE, REGISTRY_PENDING_FILE_RENAME_KEY, KEY_QUERY_VALUE, &hkPendingFileRename); 48 hr = RegOpen(HKEY_LOCAL_MACHINE, REGISTRY_PENDING_FILE_RENAME_KEY, KEY_QUERY_VALUE, &hkPendingFileRename);
47 if (E_FILENOTFOUND == hr) 49 FileExitOnPathFailure(hr, fRegExists, "Failed to open pending file rename registry key.");
50
51 if (!fRegExists)
48 { 52 {
49 ExitFunction1(hr = S_OK); 53 ExitFunction();
50 } 54 }
51 FileExitOnFailure(hr, "Failed to open pending file rename registry key.");
52 55
53 hr = RegReadStringArray(hkPendingFileRename, REGISTRY_PENDING_FILE_RENAME_VALUE, &rgsczRenames, &cRenames); 56 hr = RegReadStringArray(hkPendingFileRename, REGISTRY_PENDING_FILE_RENAME_VALUE, &rgsczRenames, &cRenames);
54 if (E_FILENOTFOUND == hr) 57 FileExitOnPathFailure(hr, fRegExists, "Failed to read pending file renames.");
58
59 if (!fRegExists)
55 { 60 {
56 ExitFunction1(hr = S_OK); 61 ExitFunction();
57 } 62 }
58 FileExitOnFailure(hr, "Failed to read pending file renames.");
59 63
60 // The pending file renames array is pairs of source and target paths. We only care 64 // The pending file renames array is pairs of source and target paths. We only care
61 // about checking the source paths so skip the target paths (i += 2). 65 // about checking the source paths so skip the target paths (i += 2).
@@ -95,6 +99,7 @@ extern "C" HRESULT DAPI FileRemoveFromPendingRename(
95{ 99{
96 HRESULT hr = S_OK; 100 HRESULT hr = S_OK;
97 HKEY hkPendingFileRename = NULL; 101 HKEY hkPendingFileRename = NULL;
102 BOOL fExists = FALSE;
98 LPWSTR* rgsczRenames = NULL; 103 LPWSTR* rgsczRenames = NULL;
99 DWORD cRenames = 0; 104 DWORD cRenames = 0;
100 BOOL fPathEqual = FALSE; 105 BOOL fPathEqual = FALSE;
@@ -102,18 +107,20 @@ extern "C" HRESULT DAPI FileRemoveFromPendingRename(
102 DWORD cNewRenames = 0; 107 DWORD cNewRenames = 0;
103 108
104 hr = RegOpen(HKEY_LOCAL_MACHINE, REGISTRY_PENDING_FILE_RENAME_KEY, KEY_QUERY_VALUE | KEY_SET_VALUE, &hkPendingFileRename); 109 hr = RegOpen(HKEY_LOCAL_MACHINE, REGISTRY_PENDING_FILE_RENAME_KEY, KEY_QUERY_VALUE | KEY_SET_VALUE, &hkPendingFileRename);
105 if (E_FILENOTFOUND == hr) 110 FileExitOnPathFailure(hr, fExists, "Failed to open pending file rename registry key.");
111
112 if (!fExists)
106 { 113 {
107 ExitFunction1(hr = S_OK); 114 ExitFunction();
108 } 115 }
109 FileExitOnFailure(hr, "Failed to open pending file rename registry key.");
110 116
111 hr = RegReadStringArray(hkPendingFileRename, REGISTRY_PENDING_FILE_RENAME_VALUE, &rgsczRenames, &cRenames); 117 hr = RegReadStringArray(hkPendingFileRename, REGISTRY_PENDING_FILE_RENAME_VALUE, &rgsczRenames, &cRenames);
112 if (E_FILENOTFOUND == hr) 118 FileExitOnPathFailure(hr, fExists, "Failed to read pending file renames.");
119
120 if (!fExists)
113 { 121 {
114 ExitFunction1(hr = S_OK); 122 ExitFunction();
115 } 123 }
116 FileExitOnFailure(hr, "Failed to read pending file renames.");
117 124
118 // The pending file renames array is pairs of source and target paths. We only care 125 // The pending file renames array is pairs of source and target paths. We only care
119 // about checking the source paths so skip the target paths (i += 2). 126 // about checking the source paths so skip the target paths (i += 2).
diff --git a/src/libs/dutil/WixToolset.DUtil/fileutil.cpp b/src/libs/dutil/WixToolset.DUtil/fileutil.cpp
index ac407916..a9369ea1 100644
--- a/src/libs/dutil/WixToolset.DUtil/fileutil.cpp
+++ b/src/libs/dutil/WixToolset.DUtil/fileutil.cpp
@@ -443,6 +443,7 @@ extern "C" HRESULT DAPI FileSize(
443 ) 443 )
444{ 444{
445 HRESULT hr = S_OK; 445 HRESULT hr = S_OK;
446 DWORD er = ERROR_SUCCESS;
446 HANDLE hFile = INVALID_HANDLE_VALUE; 447 HANDLE hFile = INVALID_HANDLE_VALUE;
447 448
448 FileExitOnNull(pwzFileName, hr, E_INVALIDARG, "Attempted to check filename, but no filename was provided"); 449 FileExitOnNull(pwzFileName, hr, E_INVALIDARG, "Attempted to check filename, but no filename was provided");
@@ -450,6 +451,11 @@ extern "C" HRESULT DAPI FileSize(
450 hFile = ::CreateFileW(pwzFileName, FILE_READ_ATTRIBUTES, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); 451 hFile = ::CreateFileW(pwzFileName, FILE_READ_ATTRIBUTES, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
451 if (INVALID_HANDLE_VALUE == hFile) 452 if (INVALID_HANDLE_VALUE == hFile)
452 { 453 {
454 er = ::GetLastError();
455 if (ERROR_PATH_NOT_FOUND == er || ERROR_FILE_NOT_FOUND == er)
456 {
457 ExitFunction1(hr = HRESULT_FROM_WIN32(er));
458 }
453 FileExitWithLastError(hr, "Failed to open file %ls while checking file size", pwzFileName); 459 FileExitWithLastError(hr, "Failed to open file %ls while checking file size", pwzFileName);
454 } 460 }
455 461
@@ -617,11 +623,11 @@ extern "C" HRESULT DAPI FileReadPartialEx(
617 if (INVALID_HANDLE_VALUE == hFile) 623 if (INVALID_HANDLE_VALUE == hFile)
618 { 624 {
619 er = ::GetLastError(); 625 er = ::GetLastError();
620 if (E_FILENOTFOUND == HRESULT_FROM_WIN32(er)) 626 if (ERROR_PATH_NOT_FOUND == er || ERROR_FILE_NOT_FOUND == er)
621 { 627 {
622 ExitFunction1(hr = E_FILENOTFOUND); 628 ExitFunction1(hr = HRESULT_FROM_WIN32(er));
623 } 629 }
624 FileExitOnWin32Error(er, hr, "Failed to open file: %ls", wzSrcPath); 630 FileExitWithLastError(hr, "Failed to open file: %ls", wzSrcPath);
625 } 631 }
626 632
627 if (!::GetFileSizeEx(hFile, &liFileSize)) 633 if (!::GetFileSizeEx(hFile, &liFileSize))
diff --git a/src/libs/dutil/WixToolset.DUtil/inc/dutil.h b/src/libs/dutil/WixToolset.DUtil/inc/dutil.h
index 2db64812..4a172f46 100644
--- a/src/libs/dutil/WixToolset.DUtil/inc/dutil.h
+++ b/src/libs/dutil/WixToolset.DUtil/inc/dutil.h
@@ -131,6 +131,8 @@ void DAPI Dutil_RootFailure(__in_z LPCSTR szFile, __in int iLine, __in HRESULT h
131#define ExitOnOptionalXmlQueryFailureSource(d, x, b, s, ...) { { if (S_FALSE == x || E_NOTFOUND == x) { b = FALSE; x = S_OK; } else { b = SUCCEEDED(x); } }; ExitOnRootFailureSource(d, x, s, __VA_ARGS__); } 131#define ExitOnOptionalXmlQueryFailureSource(d, x, b, s, ...) { { if (S_FALSE == x || E_NOTFOUND == x) { b = FALSE; x = S_OK; } else { b = SUCCEEDED(x); } }; ExitOnRootFailureSource(d, x, s, __VA_ARGS__); }
132#define ExitOnRequiredXmlQueryFailureSource(d, x, s, ...) { if (S_FALSE == x) { x = E_NOTFOUND; } ExitOnRootFailureSource(d, x, s, __VA_ARGS__); } 132#define ExitOnRequiredXmlQueryFailureSource(d, x, s, ...) { if (S_FALSE == x) { x = E_NOTFOUND; } ExitOnRootFailureSource(d, x, s, __VA_ARGS__); }
133#define ExitOnWaitObjectFailureSource(d, x, b, s, ...) { { if (HRESULT_FROM_WIN32(WAIT_TIMEOUT) == x) { b = TRUE; x = S_OK; } else { b = FALSE; } }; ExitOnFailureSource(d, x, s, __VA_ARGS__); } 133#define ExitOnWaitObjectFailureSource(d, x, b, s, ...) { { if (HRESULT_FROM_WIN32(WAIT_TIMEOUT) == x) { b = TRUE; x = S_OK; } else { b = FALSE; } }; ExitOnFailureSource(d, x, s, __VA_ARGS__); }
134#define ExitOnPathFailureSource(d, x, b, s, ...) { { if (E_PATHNOTFOUND == x || E_FILENOTFOUND == x) { b = FALSE; x = S_OK; } else { b = SUCCEEDED(x); } }; ExitOnFailureSource(d, x, s, __VA_ARGS__); }
135#define ExitWithPathLastErrorSource(d, x, s, ...) { DWORD Dutil_er = ::GetLastError(); x = HRESULT_FROM_WIN32(Dutil_er); if (!FAILED(x)) { x = E_FAIL; } else if (E_PATHNOTFOUND == x || E_FILENOTFOUND == x) { x = S_OK; } ExitOnRootFailureSource(d, x, s, __VA_ARGS__); }
134 136
135#define ExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_DEFAULT, x, s, __VA_ARGS__) 137#define ExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_DEFAULT, x, s, __VA_ARGS__)
136#define ExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_DEFAULT, x, s, __VA_ARGS__) 138#define ExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_DEFAULT, x, s, __VA_ARGS__)
@@ -147,6 +149,8 @@ void DAPI Dutil_RootFailure(__in_z LPCSTR szFile, __in int iLine, __in HRESULT h
147#define ExitOnOptionalXmlQueryFailure(x, b, s, ...) ExitOnOptionalXmlQueryFailureSource(DUTIL_SOURCE_DEFAULT, x, b, s, __VA_ARGS__) 149#define ExitOnOptionalXmlQueryFailure(x, b, s, ...) ExitOnOptionalXmlQueryFailureSource(DUTIL_SOURCE_DEFAULT, x, b, s, __VA_ARGS__)
148#define ExitOnRequiredXmlQueryFailure(x, s, ...) ExitOnRequiredXmlQueryFailureSource(DUTIL_SOURCE_DEFAULT, x, s, __VA_ARGS__) 150#define ExitOnRequiredXmlQueryFailure(x, s, ...) ExitOnRequiredXmlQueryFailureSource(DUTIL_SOURCE_DEFAULT, x, s, __VA_ARGS__)
149#define ExitOnWaitObjectFailure(x, b, s, ...) ExitOnWaitObjectFailureSource(DUTIL_SOURCE_DEFAULT, x, b, s, __VA_ARGS__) 151#define ExitOnWaitObjectFailure(x, b, s, ...) ExitOnWaitObjectFailureSource(DUTIL_SOURCE_DEFAULT, x, b, s, __VA_ARGS__)
152#define ExitOnPathFailure(x, b, s, ...) ExitOnPathFailureSource(DUTIL_SOURCE_DEFAULT, x, b, s, __VA_ARGS__)
153#define ExitWithPathLastError(x, s, ...) ExitWithPathLastErrorSource(DUTIL_SOURCE_DEFAULT, x, s, __VA_ARGS__)
150 154
151// release macros 155// release macros
152#define ReleaseObject(x) if (x) { x->Release(); } 156#define ReleaseObject(x) if (x) { x->Release(); }
diff --git a/src/libs/dutil/WixToolset.DUtil/inc/logutil.h b/src/libs/dutil/WixToolset.DUtil/inc/logutil.h
index 1636e297..8f38e0ce 100644
--- a/src/libs/dutil/WixToolset.DUtil/inc/logutil.h
+++ b/src/libs/dutil/WixToolset.DUtil/inc/logutil.h
@@ -8,9 +8,11 @@ extern "C" {
8 8
9#define LogExitOnFailureSource(d, x, i, f, ...) if (FAILED(x)) { LogErrorId(x, i, __VA_ARGS__); ExitTraceSource(d, x, f, __VA_ARGS__); goto LExit; } 9#define LogExitOnFailureSource(d, x, i, f, ...) if (FAILED(x)) { LogErrorId(x, i, __VA_ARGS__); ExitTraceSource(d, x, f, __VA_ARGS__); goto LExit; }
10#define LogExitOnRootFailureSource(d, x, i, f, ...) if (FAILED(x)) { LogErrorId(x, i, __VA_ARGS__); Dutil_RootFailure(__FILE__, __LINE__, x); ExitTraceSource(d, x, f, __VA_ARGS__); goto LExit; } 10#define LogExitOnRootFailureSource(d, x, i, f, ...) if (FAILED(x)) { LogErrorId(x, i, __VA_ARGS__); Dutil_RootFailure(__FILE__, __LINE__, x); ExitTraceSource(d, x, f, __VA_ARGS__); goto LExit; }
11#define LogExitWithRootFailureSource(d, x, e, i, f, ...) { x = FAILED(e) ? e : E_FAIL; LogErrorId(x, i, __VA_ARGS__); Dutil_RootFailure(__FILE__, __LINE__, x); ExitTraceSource(d, x, f, __VA_ARGS__); goto LExit; }
11 12
12#define LogExitOnFailure(x, i, f, ...) LogExitOnFailureSource(DUTIL_SOURCE_DEFAULT, x, i, f, __VA_ARGS__) 13#define LogExitOnFailure(x, i, f, ...) LogExitOnFailureSource(DUTIL_SOURCE_DEFAULT, x, i, f, __VA_ARGS__)
13#define LogExitOnRootFailure(x, i, f, ...) LogExitOnRootFailureSource(DUTIL_SOURCE_DEFAULT, x, i, f, __VA_ARGS__) 14#define LogExitOnRootFailure(x, i, f, ...) LogExitOnRootFailureSource(DUTIL_SOURCE_DEFAULT, x, i, f, __VA_ARGS__)
15#define LogExitWithRootFailure(x, e, i, f, ...) LogExitWithRootFailureSource(DUTIL_SOURCE_DEFAULT, x, e, i, f, __VA_ARGS__)
14 16
15typedef HRESULT (DAPI *PFN_LOGSTRINGWORKRAW)( 17typedef HRESULT (DAPI *PFN_LOGSTRINGWORKRAW)(
16 __in_z LPCSTR szString, 18 __in_z LPCSTR szString,
diff --git a/src/libs/dutil/WixToolset.DUtil/monutil.cpp b/src/libs/dutil/WixToolset.DUtil/monutil.cpp
index 10954164..d7bcfa52 100644
--- a/src/libs/dutil/WixToolset.DUtil/monutil.cpp
+++ b/src/libs/dutil/WixToolset.DUtil/monutil.cpp
@@ -17,6 +17,7 @@
17#define MonExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_MONUTIL, e, x, s, __VA_ARGS__) 17#define MonExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_MONUTIL, e, x, s, __VA_ARGS__)
18#define MonExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_MONUTIL, g, x, s, __VA_ARGS__) 18#define MonExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_MONUTIL, g, x, s, __VA_ARGS__)
19#define MonExitOnWaitObjectFailure(x, b, s, ...) ExitOnWaitObjectFailureSource(DUTIL_SOURCE_MONUTIL, x, b, s, __VA_ARGS__) 19#define MonExitOnWaitObjectFailure(x, b, s, ...) ExitOnWaitObjectFailureSource(DUTIL_SOURCE_MONUTIL, x, b, s, __VA_ARGS__)
20#define MonExitOnPathFailure(x, b, s, ...) ExitOnPathFailureSource(DUTIL_SOURCE_MONUTIL, x, b, s, __VA_ARGS__)
20 21
21const int MON_THREAD_GROWTH = 5; 22const int MON_THREAD_GROWTH = 5;
22const int MON_ARRAY_GROWTH = 40; 23const int MON_ARRAY_GROWTH = 40;
@@ -982,6 +983,7 @@ static HRESULT InitiateWait(
982 DWORD dwIndex = 0; 983 DWORD dwIndex = 0;
983 HKEY hk = NULL; 984 HKEY hk = NULL;
984 HANDLE hTemp = INVALID_HANDLE_VALUE; 985 HANDLE hTemp = INVALID_HANDLE_VALUE;
986 BOOL fExists = FALSE;
985 987
986 if (pRequest->hNotify) 988 if (pRequest->hNotify)
987 { 989 {
@@ -1025,11 +1027,12 @@ static HRESULT InitiateWait(
1025 case MON_REGKEY: 1027 case MON_REGKEY:
1026 ReleaseRegKey(pRequest->regkey.hkSubKey); 1028 ReleaseRegKey(pRequest->regkey.hkSubKey);
1027 hr = RegOpen(pRequest->regkey.hkRoot, pRequest->rgsczPathHierarchy[dwIndex], KEY_NOTIFY | GetRegKeyBitness(pRequest), &pRequest->regkey.hkSubKey); 1029 hr = RegOpen(pRequest->regkey.hkRoot, pRequest->rgsczPathHierarchy[dwIndex], KEY_NOTIFY | GetRegKeyBitness(pRequest), &pRequest->regkey.hkSubKey);
1028 if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) 1030 MonExitOnPathFailure(hr, fExists, "Failed to open regkey %ls", pRequest->rgsczPathHierarchy[dwIndex]);
1031
1032 if (!fExists)
1029 { 1033 {
1030 continue; 1034 continue;
1031 } 1035 }
1032 MonExitOnFailure(hr, "Failed to open regkey %ls", pRequest->rgsczPathHierarchy[dwIndex]);
1033 1036
1034 er = ::RegNotifyChangeKeyValue(pRequest->regkey.hkSubKey, GetRecursiveFlag(pRequest, dwIndex), REG_NOTIFY_CHANGE_NAME | REG_NOTIFY_CHANGE_LAST_SET | REG_NOTIFY_CHANGE_SECURITY, *pHandle, TRUE); 1037 er = ::RegNotifyChangeKeyValue(pRequest->regkey.hkSubKey, GetRecursiveFlag(pRequest, dwIndex), REG_NOTIFY_CHANGE_NAME | REG_NOTIFY_CHANGE_LAST_SET | REG_NOTIFY_CHANGE_SECURITY, *pHandle, TRUE);
1035 ReleaseRegKey(hk); 1038 ReleaseRegKey(hk);
@@ -1038,12 +1041,9 @@ static HRESULT InitiateWait(
1038 { 1041 {
1039 continue; 1042 continue;
1040 } 1043 }
1041 else 1044 MonExitOnFailure(hr, "Failed to wait on subkey %ls", pRequest->rgsczPathHierarchy[dwIndex]);
1042 {
1043 MonExitOnWin32Error(er, hr, "Failed to wait on subkey %ls", pRequest->rgsczPathHierarchy[dwIndex]);
1044 1045
1045 fHandleFound = TRUE; 1046 fHandleFound = TRUE;
1046 }
1047 1047
1048 break; 1048 break;
1049 default: 1049 default:
diff --git a/src/libs/dutil/WixToolset.DUtil/osutil.cpp b/src/libs/dutil/WixToolset.DUtil/osutil.cpp
index 880ec3ea..4798dc58 100644
--- a/src/libs/dutil/WixToolset.DUtil/osutil.cpp
+++ b/src/libs/dutil/WixToolset.DUtil/osutil.cpp
@@ -16,6 +16,7 @@
16#define OsExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_OSUTIL, p, x, s, __VA_ARGS__) 16#define OsExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_OSUTIL, p, x, s, __VA_ARGS__)
17#define OsExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_OSUTIL, e, x, s, __VA_ARGS__) 17#define OsExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_OSUTIL, e, x, s, __VA_ARGS__)
18#define OsExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_OSUTIL, g, x, s, __VA_ARGS__) 18#define OsExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_OSUTIL, g, x, s, __VA_ARGS__)
19#define OsExitOnPathFailure(x, b, s, ...) ExitOnPathFailureSource(DUTIL_SOURCE_OSUTIL, x, b, s, __VA_ARGS__)
19 20
20typedef NTSTATUS(NTAPI* PFN_RTL_GET_VERSION)(_Out_ PRTL_OSVERSIONINFOEXW lpVersionInformation); 21typedef NTSTATUS(NTAPI* PFN_RTL_GET_VERSION)(_Out_ PRTL_OSVERSIONINFOEXW lpVersionInformation);
21 22
@@ -186,23 +187,26 @@ extern "C" HRESULT DAPI OsIsUacEnabled(
186{ 187{
187 HRESULT hr = S_OK; 188 HRESULT hr = S_OK;
188 HKEY hk = NULL; 189 HKEY hk = NULL;
190 BOOL fExists = FALSE;
189 DWORD dwUacEnabled = 0; 191 DWORD dwUacEnabled = 0;
190 192
191 *pfUacEnabled = FALSE; // assume UAC not enabled. 193 *pfUacEnabled = FALSE; // assume UAC not enabled.
192 194
193 hr = RegOpen(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", KEY_READ, &hk); 195 hr = RegOpen(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", KEY_READ, &hk);
194 if (E_FILENOTFOUND == hr) 196 OsExitOnPathFailure(hr, fExists, "Failed to open system policy key to detect UAC.");
197
198 if (!fExists)
195 { 199 {
196 ExitFunction1(hr = S_OK); 200 ExitFunction();
197 } 201 }
198 OsExitOnFailure(hr, "Failed to open system policy key to detect UAC.");
199 202
200 hr = RegReadNumber(hk, L"EnableLUA", &dwUacEnabled); 203 hr = RegReadNumber(hk, L"EnableLUA", &dwUacEnabled);
201 if (E_FILENOTFOUND == hr) 204 OsExitOnPathFailure(hr, fExists, "Failed to read registry value to detect UAC.");
205
206 if (!fExists)
202 { 207 {
203 ExitFunction1(hr = S_OK); 208 ExitFunction();
204 } 209 }
205 OsExitOnFailure(hr, "Failed to read registry value to detect UAC.");
206 210
207 *pfUacEnabled = (0 != dwUacEnabled); 211 *pfUacEnabled = (0 != dwUacEnabled);
208 212
diff --git a/src/libs/dutil/WixToolset.DUtil/path3utl.cpp b/src/libs/dutil/WixToolset.DUtil/path3utl.cpp
index cb6ce6d5..844cbfbb 100644
--- a/src/libs/dutil/WixToolset.DUtil/path3utl.cpp
+++ b/src/libs/dutil/WixToolset.DUtil/path3utl.cpp
@@ -17,6 +17,7 @@
17#define PathExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_PATHUTIL, p, x, s, __VA_ARGS__) 17#define PathExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_PATHUTIL, p, x, s, __VA_ARGS__)
18#define PathExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_PATHUTIL, e, x, s, __VA_ARGS__) 18#define PathExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_PATHUTIL, e, x, s, __VA_ARGS__)
19#define PathExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_PATHUTIL, g, x, s, __VA_ARGS__) 19#define PathExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_PATHUTIL, g, x, s, __VA_ARGS__)
20#define PathExitOnPathFailure(x, b, s, ...) ExitOnPathFailureSource(DUTIL_SOURCE_PATHUTIL, x, b, s, __VA_ARGS__)
20 21
21static HRESULT GetTempPathFromSystemEnvironmentVariable( 22static HRESULT GetTempPathFromSystemEnvironmentVariable(
22 __in HKEY hKey, 23 __in HKEY hKey,
@@ -32,6 +33,7 @@ DAPI_(HRESULT) PathGetSystemTempPaths(
32 HRESULT hr = S_OK; 33 HRESULT hr = S_OK;
33 HMODULE hModule = NULL; 34 HMODULE hModule = NULL;
34 BOOL fSystem = FALSE; 35 BOOL fSystem = FALSE;
36 BOOL fExists = FALSE;
35 HKEY hKey = NULL; 37 HKEY hKey = NULL;
36 LPWSTR sczTemp = NULL; 38 LPWSTR sczTemp = NULL;
37 39
@@ -61,10 +63,10 @@ DAPI_(HRESULT) PathGetSystemTempPaths(
61 63
62 // There is no documented API to get system environment variables, so read them from the registry. 64 // There is no documented API to get system environment variables, so read them from the registry.
63 hr = RegOpen(HKEY_LOCAL_MACHINE, L"System\\CurrentControlSet\\Control\\Session Manager\\Environment", KEY_READ, &hKey); 65 hr = RegOpen(HKEY_LOCAL_MACHINE, L"System\\CurrentControlSet\\Control\\Session Manager\\Environment", KEY_READ, &hKey);
64 if (E_FILENOTFOUND != hr) 66 PathExitOnPathFailure(hr, fExists, "Failed to open system environment registry key.");
65 {
66 PathExitOnFailure(hr, "Failed to open system environment registry key.");
67 67
68 if (fExists)
69 {
68 hr = GetTempPathFromSystemEnvironmentVariable(hKey, L"TMP", &sczTemp); 70 hr = GetTempPathFromSystemEnvironmentVariable(hKey, L"TMP", &sczTemp);
69 PathExitOnFailure(hr, "Failed to get temp path from system TMP."); 71 PathExitOnFailure(hr, "Failed to get temp path from system TMP.");
70 72
@@ -118,14 +120,16 @@ static HRESULT GetTempPathFromSystemEnvironmentVariable(
118 HRESULT hr = S_OK; 120 HRESULT hr = S_OK;
119 LPWSTR sczValue = NULL; 121 LPWSTR sczValue = NULL;
120 BOOL fNeedsExpansion = FALSE; 122 BOOL fNeedsExpansion = FALSE;
123 BOOL fExists = FALSE;
121 124
122 // Read the value unexpanded so that it can be expanded with system environment variables. 125 // Read the value unexpanded so that it can be expanded with system environment variables.
123 hr = RegReadUnexpandedString(hKey, wzName, &fNeedsExpansion, &sczValue); 126 hr = RegReadUnexpandedString(hKey, wzName, &fNeedsExpansion, &sczValue);
124 if (E_FILENOTFOUND == hr) 127 PathExitOnPathFailure(hr, fExists, "Failed to get system '%ls' value.", wzName);
128
129 if (!fExists)
125 { 130 {
126 ExitFunction1(hr = S_FALSE); 131 ExitFunction1(hr = S_FALSE);
127 } 132 }
128 PathExitOnFailure(hr, "Failed to get system '%ls' value.", wzName);
129 133
130 if (fNeedsExpansion) 134 if (fNeedsExpansion)
131 { 135 {
diff --git a/src/libs/dutil/WixToolset.DUtil/polcutil.cpp b/src/libs/dutil/WixToolset.DUtil/polcutil.cpp
index c2247bc1..a56c380b 100644
--- a/src/libs/dutil/WixToolset.DUtil/polcutil.cpp
+++ b/src/libs/dutil/WixToolset.DUtil/polcutil.cpp
@@ -16,6 +16,7 @@
16#define PolcExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_POLCUTIL, p, x, s, __VA_ARGS__) 16#define PolcExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_POLCUTIL, p, x, s, __VA_ARGS__)
17#define PolcExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_POLCUTIL, e, x, s, __VA_ARGS__) 17#define PolcExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_POLCUTIL, e, x, s, __VA_ARGS__)
18#define PolcExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_POLCUTIL, g, x, s, __VA_ARGS__) 18#define PolcExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_POLCUTIL, g, x, s, __VA_ARGS__)
19#define PolcExitOnPathFailure(x, b, s, ...) ExitOnPathFailureSource(DUTIL_SOURCE_POLCUTIL, x, b, s, __VA_ARGS__)
19 20
20const LPCWSTR REGISTRY_POLICIES_KEY = L"SOFTWARE\\Policies\\"; 21const LPCWSTR REGISTRY_POLICIES_KEY = L"SOFTWARE\\Policies\\";
21 22
@@ -34,25 +35,28 @@ extern "C" HRESULT DAPI PolcReadNumber(
34{ 35{
35 HRESULT hr = S_OK; 36 HRESULT hr = S_OK;
36 HKEY hk = NULL; 37 HKEY hk = NULL;
38 BOOL fExists = FALSE;
37 39
38 hr = OpenPolicyKey(wzPolicyPath, &hk); 40 hr = OpenPolicyKey(wzPolicyPath, &hk);
39 if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) 41 PolcExitOnFailure(hr, "Failed to open policy key: %ls", wzPolicyPath);
42
43 if (!hk)
40 { 44 {
41 ExitFunction1(hr = S_FALSE); 45 ExitFunction1(hr = S_FALSE);
42 } 46 }
43 PolcExitOnFailure(hr, "Failed to open policy key: %ls", wzPolicyPath);
44 47
45 hr = RegReadNumber(hk, wzPolicyName, pdw); 48 hr = RegReadNumber(hk, wzPolicyName, pdw);
46 if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) 49 PolcExitOnPathFailure(hr, fExists, "Failed to open policy key: %ls, name: %ls", wzPolicyPath, wzPolicyName);
50
51 if (!fExists)
47 { 52 {
48 ExitFunction1(hr = S_FALSE); 53 ExitFunction1(hr = S_FALSE);
49 } 54 }
50 PolcExitOnFailure(hr, "Failed to open policy key: %ls, name: %ls", wzPolicyPath, wzPolicyName);
51 55
52LExit: 56LExit:
53 ReleaseRegKey(hk); 57 ReleaseRegKey(hk);
54 58
55 if (S_FALSE == hr || FAILED(hr)) 59 if (!fExists)
56 { 60 {
57 *pdw = dwDefault; 61 *pdw = dwDefault;
58 } 62 }
@@ -69,25 +73,28 @@ extern "C" HRESULT DAPI PolcReadString(
69{ 73{
70 HRESULT hr = S_OK; 74 HRESULT hr = S_OK;
71 HKEY hk = NULL; 75 HKEY hk = NULL;
76 BOOL fExists = FALSE;
72 77
73 hr = OpenPolicyKey(wzPolicyPath, &hk); 78 hr = OpenPolicyKey(wzPolicyPath, &hk);
74 if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) 79 PolcExitOnFailure(hr, "Failed to open policy key: %ls", wzPolicyPath);
80
81 if (!hk)
75 { 82 {
76 ExitFunction1(hr = S_FALSE); 83 ExitFunction1(hr = S_FALSE);
77 } 84 }
78 PolcExitOnFailure(hr, "Failed to open policy key: %ls", wzPolicyPath);
79 85
80 hr = RegReadString(hk, wzPolicyName, pscz); 86 hr = RegReadString(hk, wzPolicyName, pscz);
81 if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) 87 PolcExitOnPathFailure(hr, fExists, "Failed to open policy key: %ls, name: %ls", wzPolicyPath, wzPolicyName);
88
89 if (!fExists)
82 { 90 {
83 ExitFunction1(hr = S_FALSE); 91 ExitFunction1(hr = S_FALSE);
84 } 92 }
85 PolcExitOnFailure(hr, "Failed to open policy key: %ls, name: %ls", wzPolicyPath, wzPolicyName);
86 93
87LExit: 94LExit:
88 ReleaseRegKey(hk); 95 ReleaseRegKey(hk);
89 96
90 if (S_FALSE == hr || FAILED(hr)) 97 if (!fExists)
91 { 98 {
92 if (NULL == wzDefault) 99 if (NULL == wzDefault)
93 { 100 {
@@ -112,25 +119,28 @@ extern "C" HRESULT DAPI PolcReadUnexpandedString(
112{ 119{
113 HRESULT hr = S_OK; 120 HRESULT hr = S_OK;
114 HKEY hk = NULL; 121 HKEY hk = NULL;
122 BOOL fExists = FALSE;
115 123
116 hr = OpenPolicyKey(wzPolicyPath, &hk); 124 hr = OpenPolicyKey(wzPolicyPath, &hk);
117 if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) 125 PolcExitOnFailure(hr, "Failed to open policy key: %ls", wzPolicyPath);
126
127 if (!hk)
118 { 128 {
119 ExitFunction1(hr = S_FALSE); 129 ExitFunction1(hr = S_FALSE);
120 } 130 }
121 PolcExitOnFailure(hr, "Failed to open policy key: %ls", wzPolicyPath);
122 131
123 hr = RegReadUnexpandedString(hk, wzPolicyName, pfNeedsExpansion, pscz); 132 hr = RegReadUnexpandedString(hk, wzPolicyName, pfNeedsExpansion, pscz);
124 if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) 133 PolcExitOnPathFailure(hr, fExists, "Failed to open policy key: %ls, name: %ls", wzPolicyPath, wzPolicyName);
134
135 if (!fExists)
125 { 136 {
126 ExitFunction1(hr = S_FALSE); 137 ExitFunction1(hr = S_FALSE);
127 } 138 }
128 PolcExitOnFailure(hr, "Failed to open policy key: %ls, name: %ls", wzPolicyPath, wzPolicyName);
129 139
130LExit: 140LExit:
131 ReleaseRegKey(hk); 141 ReleaseRegKey(hk);
132 142
133 if (S_FALSE == hr || FAILED(hr)) 143 if (!fExists)
134 { 144 {
135 if (NULL == wzDefault) 145 if (NULL == wzDefault)
136 { 146 {
@@ -155,12 +165,18 @@ static HRESULT OpenPolicyKey(
155{ 165{
156 HRESULT hr = S_OK; 166 HRESULT hr = S_OK;
157 LPWSTR sczPath = NULL; 167 LPWSTR sczPath = NULL;
168 BOOL fExists = FALSE;
158 169
159 hr = PathConcat(REGISTRY_POLICIES_KEY, wzPolicyPath, &sczPath); 170 hr = PathConcat(REGISTRY_POLICIES_KEY, wzPolicyPath, &sczPath);
160 PolcExitOnFailure(hr, "Failed to combine logging path with root path."); 171 PolcExitOnFailure(hr, "Failed to combine logging path with root path.");
161 172
162 hr = RegOpen(HKEY_LOCAL_MACHINE, sczPath, KEY_READ, phk); 173 hr = RegOpen(HKEY_LOCAL_MACHINE, sczPath, KEY_READ, phk);
163 PolcExitOnFailure(hr, "Failed to open policy registry key."); 174 PolcExitOnPathFailure(hr, fExists, "Failed to open policy registry key.");
175
176 if (!fExists)
177 {
178 ReleaseRegKey(*phk);
179 }
164 180
165LExit: 181LExit:
166 ReleaseStr(sczPath); 182 ReleaseStr(sczPath);
diff --git a/src/libs/dutil/WixToolset.DUtil/regutil.cpp b/src/libs/dutil/WixToolset.DUtil/regutil.cpp
index 9a1b9ced..744e7a3f 100644
--- a/src/libs/dutil/WixToolset.DUtil/regutil.cpp
+++ b/src/libs/dutil/WixToolset.DUtil/regutil.cpp
@@ -17,6 +17,7 @@
17#define RegExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_REGUTIL, p, x, s, __VA_ARGS__) 17#define RegExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_REGUTIL, p, x, s, __VA_ARGS__)
18#define RegExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_REGUTIL, e, x, s, __VA_ARGS__) 18#define RegExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_REGUTIL, e, x, s, __VA_ARGS__)
19#define RegExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_REGUTIL, g, x, s, __VA_ARGS__) 19#define RegExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_REGUTIL, g, x, s, __VA_ARGS__)
20#define RegExitOnPathFailure(x, b, s, ...) ExitOnPathFailureSource(DUTIL_SOURCE_REGUTIL, x, b, s, __VA_ARGS__)
20 21
21static PFN_REGCREATEKEYEXW vpfnRegCreateKeyExW = ::RegCreateKeyExW; 22static PFN_REGCREATEKEYEXW vpfnRegCreateKeyExW = ::RegCreateKeyExW;
22static PFN_REGOPENKEYEXW vpfnRegOpenKeyExW = ::RegOpenKeyExW; 23static PFN_REGOPENKEYEXW vpfnRegOpenKeyExW = ::RegOpenKeyExW;
@@ -179,7 +180,7 @@ DAPI_(HRESULT) RegOpen(
179 __in_z LPCWSTR wzSubKey, 180 __in_z LPCWSTR wzSubKey,
180 __in DWORD dwAccess, 181 __in DWORD dwAccess,
181 __out HKEY* phk 182 __out HKEY* phk
182) 183 )
183{ 184{
184 return RegOpenEx(hkRoot, wzSubKey, dwAccess, REG_KEY_DEFAULT, phk); 185 return RegOpenEx(hkRoot, wzSubKey, dwAccess, REG_KEY_DEFAULT, phk);
185} 186}
@@ -191,18 +192,18 @@ DAPI_(HRESULT) RegOpenEx(
191 __in DWORD dwAccess, 192 __in DWORD dwAccess,
192 __in REG_KEY_BITNESS kbKeyBitness, 193 __in REG_KEY_BITNESS kbKeyBitness,
193 __out HKEY* phk 194 __out HKEY* phk
194) 195 )
195{ 196{
196 HRESULT hr = S_OK; 197 HRESULT hr = S_OK;
197 DWORD er = ERROR_SUCCESS; 198 DWORD er = ERROR_SUCCESS;
198 199
199 REGSAM samDesired = RegTranslateKeyBitness(kbKeyBitness); 200 REGSAM samDesired = RegTranslateKeyBitness(kbKeyBitness);
200 er = vpfnRegOpenKeyExW(hkRoot, wzSubKey, 0, dwAccess | samDesired, phk); 201 er = vpfnRegOpenKeyExW(hkRoot, wzSubKey, 0, dwAccess | samDesired, phk);
201 if (E_FILENOTFOUND == HRESULT_FROM_WIN32(er)) 202 if (ERROR_PATH_NOT_FOUND == er || ERROR_FILE_NOT_FOUND == er)
202 { 203 {
203 ExitFunction1(hr = E_FILENOTFOUND); 204 ExitFunction1(hr = HRESULT_FROM_WIN32(er));
204 } 205 }
205 RegExitOnWin32Error(er, hr, "Failed to open registry key."); 206 RegExitOnWin32Error(er, hr, "Failed to open registry key, root: %x, subkey: %ls.", hkRoot, wzSubKey);
206 207
207LExit: 208LExit:
208 return hr; 209 return hr;
@@ -221,6 +222,7 @@ DAPI_(HRESULT) RegDelete(
221 LPWSTR pszEnumeratedSubKey = NULL; 222 LPWSTR pszEnumeratedSubKey = NULL;
222 LPWSTR pszRecursiveSubKey = NULL; 223 LPWSTR pszRecursiveSubKey = NULL;
223 HKEY hkKey = NULL; 224 HKEY hkKey = NULL;
225 BOOL fExists = FALSE;
224 226
225 if (!vfRegInitialized && REG_KEY_DEFAULT != kbKeyBitness) 227 if (!vfRegInitialized && REG_KEY_DEFAULT != kbKeyBitness)
226 { 228 {
@@ -231,9 +233,9 @@ DAPI_(HRESULT) RegDelete(
231 if (fDeleteTree) 233 if (fDeleteTree)
232 { 234 {
233 hr = RegOpenEx(hkRoot, wzSubKey, KEY_READ, kbKeyBitness, &hkKey); 235 hr = RegOpenEx(hkRoot, wzSubKey, KEY_READ, kbKeyBitness, &hkKey);
234 if (E_FILENOTFOUND == hr) 236 if (E_PATHNOTFOUND == hr || E_FILENOTFOUND == hr)
235 { 237 {
236 ExitFunction1(hr = S_OK); 238 ExitFunction();
237 } 239 }
238 RegExitOnFailure(hr, "Failed to open this key for enumerating subkeys: %ls", wzSubKey); 240 RegExitOnFailure(hr, "Failed to open this key for enumerating subkeys: %ls", wzSubKey);
239 241
@@ -246,28 +248,31 @@ DAPI_(HRESULT) RegDelete(
246 RegExitOnFailure(hr, "Failed to concatenate paths while recursively deleting subkeys. Path1: %ls, Path2: %ls", wzSubKey, pszEnumeratedSubKey); 248 RegExitOnFailure(hr, "Failed to concatenate paths while recursively deleting subkeys. Path1: %ls, Path2: %ls", wzSubKey, pszEnumeratedSubKey);
247 249
248 hr = RegDelete(hkRoot, pszRecursiveSubKey, kbKeyBitness, fDeleteTree); 250 hr = RegDelete(hkRoot, pszRecursiveSubKey, kbKeyBitness, fDeleteTree);
249 RegExitOnFailure(hr, "Failed to recursively delete subkey: %ls", pszRecursiveSubKey); 251 RegExitOnPathFailure(hr, fExists, "Failed to recursively delete subkey: %ls", pszRecursiveSubKey);
250 } 252 }
251 253
252 hr = S_OK; 254 hr = S_OK;
255
256 // Release the handle to make sure it's deleted immediately.
257 ReleaseRegKey(hkKey);
253 } 258 }
254 259
255 if (NULL != vpfnRegDeleteKeyExW) 260 if (NULL != vpfnRegDeleteKeyExW)
256 { 261 {
257 REGSAM samDesired = RegTranslateKeyBitness(kbKeyBitness); 262 REGSAM samDesired = RegTranslateKeyBitness(kbKeyBitness);
258 er = vpfnRegDeleteKeyExW(hkRoot, wzSubKey, samDesired, 0); 263 er = vpfnRegDeleteKeyExW(hkRoot, wzSubKey, samDesired, 0);
259 if (E_FILENOTFOUND == HRESULT_FROM_WIN32(er)) 264 if (ERROR_PATH_NOT_FOUND == er || ERROR_FILE_NOT_FOUND == er)
260 { 265 {
261 ExitFunction1(hr = E_FILENOTFOUND); 266 ExitFunction1(hr = HRESULT_FROM_WIN32(er));
262 } 267 }
263 RegExitOnWin32Error(er, hr, "Failed to delete registry key (ex)."); 268 RegExitOnWin32Error(er, hr, "Failed to delete registry key (ex).");
264 } 269 }
265 else 270 else
266 { 271 {
267 er = vpfnRegDeleteKeyW(hkRoot, wzSubKey); 272 er = vpfnRegDeleteKeyW(hkRoot, wzSubKey);
268 if (E_FILENOTFOUND == HRESULT_FROM_WIN32(er)) 273 if (ERROR_PATH_NOT_FOUND == er || ERROR_FILE_NOT_FOUND == er)
269 { 274 {
270 ExitFunction1(hr = E_FILENOTFOUND); 275 ExitFunction1(hr = HRESULT_FROM_WIN32(er));
271 } 276 }
272 RegExitOnWin32Error(er, hr, "Failed to delete registry key."); 277 RegExitOnWin32Error(er, hr, "Failed to delete registry key.");
273 } 278 }
@@ -772,7 +777,7 @@ DAPI_(HRESULT) RegReadNumber(
772 DWORD cb = sizeof(DWORD); 777 DWORD cb = sizeof(DWORD);
773 778
774 er = vpfnRegQueryValueExW(hk, wzName, NULL, &dwType, reinterpret_cast<LPBYTE>(pdwValue), &cb); 779 er = vpfnRegQueryValueExW(hk, wzName, NULL, &dwType, reinterpret_cast<LPBYTE>(pdwValue), &cb);
775 if (E_FILENOTFOUND == HRESULT_FROM_WIN32(er)) 780 if (ERROR_FILE_NOT_FOUND == er)
776 { 781 {
777 ExitFunction1(hr = E_FILENOTFOUND); 782 ExitFunction1(hr = E_FILENOTFOUND);
778 } 783 }
@@ -801,7 +806,7 @@ DAPI_(HRESULT) RegReadQword(
801 DWORD cb = sizeof(DWORD64); 806 DWORD cb = sizeof(DWORD64);
802 807
803 er = vpfnRegQueryValueExW(hk, wzName, NULL, &dwType, reinterpret_cast<LPBYTE>(pqwValue), &cb); 808 er = vpfnRegQueryValueExW(hk, wzName, NULL, &dwType, reinterpret_cast<LPBYTE>(pqwValue), &cb);
804 if (E_FILENOTFOUND == HRESULT_FROM_WIN32(er)) 809 if (ERROR_FILE_NOT_FOUND == er)
805 { 810 {
806 ExitFunction1(hr = E_FILENOTFOUND); 811 ExitFunction1(hr = E_FILENOTFOUND);
807 } 812 }
@@ -1015,9 +1020,17 @@ DAPI_(HRESULT) RegKeyReadNumber(
1015 HKEY hkKey = NULL; 1020 HKEY hkKey = NULL;
1016 1021
1017 hr = RegOpenEx(hk, wzSubKey, KEY_READ, kbKeyBitness, &hkKey); 1022 hr = RegOpenEx(hk, wzSubKey, KEY_READ, kbKeyBitness, &hkKey);
1023 if (E_PATHNOTFOUND == hr || E_FILENOTFOUND == hr)
1024 {
1025 ExitFunction();
1026 }
1018 RegExitOnFailure(hr, "Failed to open key: %ls", wzSubKey); 1027 RegExitOnFailure(hr, "Failed to open key: %ls", wzSubKey);
1019 1028
1020 hr = RegReadNumber(hkKey, wzName, pdwValue); 1029 hr = RegReadNumber(hkKey, wzName, pdwValue);
1030 if (E_FILENOTFOUND == hr)
1031 {
1032 ExitFunction();
1033 }
1021 RegExitOnFailure(hr, "Failed to read value: %ls/@%ls", wzSubKey, wzName); 1034 RegExitOnFailure(hr, "Failed to read value: %ls/@%ls", wzSubKey, wzName);
1022 1035
1023LExit: 1036LExit:
@@ -1038,9 +1051,17 @@ DAPI_(BOOL) RegValueExists(
1038 DWORD dwType = 0; 1051 DWORD dwType = 0;
1039 1052
1040 hr = RegOpenEx(hk, wzSubKey, KEY_READ, kbKeyBitness, &hkKey); 1053 hr = RegOpenEx(hk, wzSubKey, KEY_READ, kbKeyBitness, &hkKey);
1054 if (E_PATHNOTFOUND == hr || E_FILENOTFOUND == hr)
1055 {
1056 ExitFunction();
1057 }
1041 RegExitOnFailure(hr, "Failed to open key: %ls", wzSubKey); 1058 RegExitOnFailure(hr, "Failed to open key: %ls", wzSubKey);
1042 1059
1043 hr = RegGetType(hkKey, wzName, &dwType); 1060 hr = RegGetType(hkKey, wzName, &dwType);
1061 if (E_FILENOTFOUND == hr)
1062 {
1063 ExitFunction();
1064 }
1044 RegExitOnFailure(hr, "Failed to read value type: %ls/@%ls", wzSubKey, wzName); 1065 RegExitOnFailure(hr, "Failed to read value type: %ls/@%ls", wzSubKey, wzName);
1045 1066
1046LExit: 1067LExit:
diff --git a/src/libs/dutil/WixToolset.DUtil/wiutil.cpp b/src/libs/dutil/WixToolset.DUtil/wiutil.cpp
index da7cffe7..5f81cf3a 100644
--- a/src/libs/dutil/WixToolset.DUtil/wiutil.cpp
+++ b/src/libs/dutil/WixToolset.DUtil/wiutil.cpp
@@ -427,6 +427,11 @@ extern "C" HRESULT DAPI WiuGetProductInfo(
427 427
428 er = vpfnMsiGetProductInfoW(wzProductCode, wzProperty, *psczValue, &cch); 428 er = vpfnMsiGetProductInfoW(wzProductCode, wzProperty, *psczValue, &cch);
429 } 429 }
430
431 if (ERROR_UNKNOWN_PRODUCT == er || ERROR_UNKNOWN_PROPERTY == er)
432 {
433 ExitFunction1(hr = HRESULT_FROM_WIN32(er));
434 }
430 WiuExitOnWin32Error(er, hr, "Failed to get product info."); 435 WiuExitOnWin32Error(er, hr, "Failed to get product info.");
431 436
432LExit: 437LExit:
@@ -449,7 +454,10 @@ extern "C" HRESULT DAPI WiuGetProductInfoEx(
449 if (!vpfnMsiGetProductInfoExW) 454 if (!vpfnMsiGetProductInfoExW)
450 { 455 {
451 hr = WiuGetProductInfo(wzProductCode, wzProperty, psczValue); 456 hr = WiuGetProductInfo(wzProductCode, wzProperty, psczValue);
452 WiuExitOnFailure(hr, "Failed to get product info when extended info was not available."); 457 if (HRESULT_FROM_WIN32(ERROR_UNKNOWN_PRODUCT) != hr && HRESULT_FROM_WIN32(ERROR_UNKNOWN_PROPERTY) != hr)
458 {
459 WiuExitOnFailure(hr, "Failed to get product info when extended info was not available.");
460 }
453 461
454 ExitFunction(); 462 ExitFunction();
455 } 463 }
@@ -466,6 +474,11 @@ extern "C" HRESULT DAPI WiuGetProductInfoEx(
466 474
467 er = vpfnMsiGetProductInfoExW(wzProductCode, wzUserSid, dwContext, wzProperty, *psczValue, &cch); 475 er = vpfnMsiGetProductInfoExW(wzProductCode, wzUserSid, dwContext, wzProperty, *psczValue, &cch);
468 } 476 }
477
478 if (ERROR_UNKNOWN_PRODUCT == er || ERROR_UNKNOWN_PROPERTY == er)
479 {
480 ExitFunction1(hr = HRESULT_FROM_WIN32(er));
481 }
469 WiuExitOnWin32Error(er, hr, "Failed to get extended product info."); 482 WiuExitOnWin32Error(er, hr, "Failed to get extended product info.");
470 483
471LExit: 484LExit: