aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/burn/engine/apply.cpp16
-rw-r--r--src/burn/engine/bundlepackageengine.cpp14
-rw-r--r--src/burn/engine/cache.cpp3
-rw-r--r--src/burn/engine/dependency.cpp44
-rw-r--r--src/burn/engine/exeengine.cpp21
-rw-r--r--src/burn/engine/registration.cpp32
-rw-r--r--src/burn/engine/relatedbundle.cpp17
-rw-r--r--src/burn/engine/search.cpp89
-rw-r--r--src/ext/Bal/dnchost/dncutil.cpp2
-rw-r--r--src/ext/Bal/mbahost/mbahost.cpp99
-rw-r--r--src/ext/Dependency/ca/wixdepca.cpp7
-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
24 files changed, 438 insertions, 425 deletions
diff --git a/src/burn/engine/apply.cpp b/src/burn/engine/apply.cpp
index 31d756a8..e67208b4 100644
--- a/src/burn/engine/apply.cpp
+++ b/src/burn/engine/apply.cpp
@@ -611,7 +611,7 @@ extern "C" HRESULT ApplyCache(
611 ExitOnFailure(hr, "Failed cache action: %ls", L"layout bundle"); 611 ExitOnFailure(hr, "Failed cache action: %ls", L"layout bundle");
612 612
613 hr = ReportOverallProgressTicks(pUX, FALSE, pPlan->cOverallProgressTicksTotal, pContext); 613 hr = ReportOverallProgressTicks(pUX, FALSE, pPlan->cOverallProgressTicksTotal, pContext);
614 LogExitOnFailure(hr, MSG_USER_CANCELED, "Cancel during cache: %ls", L"layout bundle"); 614 LogExitOnRootFailure(hr, MSG_USER_CANCELED, "Cancel during cache: %ls", L"layout bundle");
615 615
616 break; 616 break;
617 617
@@ -637,7 +637,7 @@ extern "C" HRESULT ApplyCache(
637 ExitOnFailure(hr, "Failed cache action: %ls", L"cache package"); 637 ExitOnFailure(hr, "Failed cache action: %ls", L"cache package");
638 638
639 hr = ReportOverallProgressTicks(pUX, FALSE, pPlan->cOverallProgressTicksTotal, pContext); 639 hr = ReportOverallProgressTicks(pUX, FALSE, pPlan->cOverallProgressTicksTotal, pContext);
640 LogExitOnFailure(hr, MSG_USER_CANCELED, "Cancel during cache: %ls", L"cache package"); 640 LogExitOnRootFailure(hr, MSG_USER_CANCELED, "Cancel during cache: %ls", L"cache package");
641 641
642 break; 642 break;
643 643
@@ -1038,7 +1038,7 @@ static HRESULT ApplyCachePackage(
1038 } 1038 }
1039 else if (fCanceledBegin) 1039 else if (fCanceledBegin)
1040 { 1040 {
1041 LogExitOnFailure(hr, MSG_USER_CANCELED, "Cancel during cache: %ls: %ls", L"begin cache package", pPackage->sczId); 1041 LogExitOnRootFailure(hr, MSG_USER_CANCELED, "Cancel during cache: %ls: %ls", L"begin cache package", pPackage->sczId);
1042 } 1042 }
1043 1043
1044 break; 1044 break;
@@ -1796,8 +1796,7 @@ static HRESULT AcquireContainerOrPayload(
1796 1796
1797 break; 1797 break;
1798 default: 1798 default:
1799 hr = E_FILENOTFOUND; 1799 LogExitWithRootFailure(hr, E_FILENOTFOUND, MSG_RESOLVE_SOURCE_FAILED, "Failed to resolve source, payload: %ls, package: %ls, container: %ls", wzPayloadId, pPackage ? pPackage->sczId : NULL, pContainer ? pContainer->sczId : NULL);
1800 LogExitOnFailure(hr, MSG_RESOLVE_SOURCE_FAILED, "Failed to resolve source, payload: %ls, package: %ls, container: %ls", wzPayloadId, pPackage ? pPackage->sczId : NULL, pContainer ? pContainer->sczId : NULL);
1801 } 1800 }
1802 1801
1803 // Send 100% complete here. This is sometimes the only progress sent to the BA. 1802 // Send 100% complete here. This is sometimes the only progress sent to the BA.
@@ -1965,17 +1964,12 @@ static HRESULT PreparePayloadDestinationPath(
1965 dwFileAttributes &= ~FILE_ATTRIBUTE_READONLY; 1964 dwFileAttributes &= ~FILE_ATTRIBUTE_READONLY;
1966 if (!::SetFileAttributes(wzDestinationPath, dwFileAttributes)) 1965 if (!::SetFileAttributes(wzDestinationPath, dwFileAttributes))
1967 { 1966 {
1968 ExitWithLastError(hr, "Failed to clear readonly bit on payload destination path: %ls", wzDestinationPath); 1967 ExitWithPathLastError(hr, "Failed to clear readonly bit on payload destination path: %ls", wzDestinationPath);
1969 } 1968 }
1970 } 1969 }
1971 } 1970 }
1972 1971
1973LExit: 1972LExit:
1974 if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr)
1975 {
1976 hr = S_OK;
1977 }
1978
1979 return hr; 1973 return hr;
1980} 1974}
1981 1975
diff --git a/src/burn/engine/bundlepackageengine.cpp b/src/burn/engine/bundlepackageengine.cpp
index dafe1967..8896fdd0 100644
--- a/src/burn/engine/bundlepackageengine.cpp
+++ b/src/burn/engine/bundlepackageengine.cpp
@@ -1049,6 +1049,7 @@ static HRESULT DetectArpEntry(
1049{ 1049{
1050 HRESULT hr = S_OK; 1050 HRESULT hr = S_OK;
1051 HKEY hKey = NULL; 1051 HKEY hKey = NULL;
1052 BOOL fExists = FALSE;
1052 HKEY hkRoot = pPackage->fPerMachine ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 1053 HKEY hkRoot = pPackage->fPerMachine ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
1053 REG_KEY_BITNESS keyBitness = pPackage->Bundle.fWin64 ? REG_KEY_64BIT : REG_KEY_32BIT; 1054 REG_KEY_BITNESS keyBitness = pPackage->Bundle.fWin64 ? REG_KEY_64BIT : REG_KEY_32BIT;
1054 1055
@@ -1065,20 +1066,17 @@ static HRESULT DetectArpEntry(
1065 } 1066 }
1066 1067
1067 hr = RegOpenEx(hkRoot, pPackage->Bundle.sczArpKeyPath, KEY_READ, keyBitness, &hKey); 1068 hr = RegOpenEx(hkRoot, pPackage->Bundle.sczArpKeyPath, KEY_READ, keyBitness, &hKey);
1068 if (HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) == hr || HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) == hr) 1069 ExitOnPathFailure(hr, fExists, "Failed to open registry key: %ls.", pPackage->Bundle.sczArpKeyPath);
1070
1071 if (!fExists)
1069 { 1072 {
1070 ExitFunction1(hr = S_OK); 1073 ExitFunction();
1071 } 1074 }
1072 ExitOnFailure(hr, "Failed to open registry key: %ls.", pPackage->Bundle.sczArpKeyPath);
1073 1075
1074 *pfRegistered = TRUE; 1076 *pfRegistered = TRUE;
1075 1077
1076 hr = RegReadString(hKey, L"QuietUninstallString", psczQuietUninstallString); 1078 hr = RegReadString(hKey, L"QuietUninstallString", psczQuietUninstallString);
1077 if (HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) == hr) 1079 ExitOnPathFailure(hr, fExists, "Failed to read QuietUninstallString.");
1078 {
1079 hr = S_OK;
1080 }
1081 ExitOnFailure(hr, "Failed to read QuietUninstallString.");
1082 1080
1083LExit: 1081LExit:
1084 ReleaseRegKey(hKey); 1082 ReleaseRegKey(hKey);
diff --git a/src/burn/engine/cache.cpp b/src/burn/engine/cache.cpp
index a23ce9ed..01237162 100644
--- a/src/burn/engine/cache.cpp
+++ b/src/burn/engine/cache.cpp
@@ -1144,8 +1144,7 @@ extern "C" HRESULT CacheCompletePayload(
1144 } 1144 }
1145 else // if the working path and unverified path do not exist, nothing we can do. 1145 else // if the working path and unverified path do not exist, nothing we can do.
1146 { 1146 {
1147 hr = E_FILENOTFOUND; 1147 ExitWithRootFailure(hr, E_FILENOTFOUND, "Failed to find payload: %ls in working path: %ls and unverified path: %ls", pPayload->sczKey, wzWorkingPayloadPath, sczUnverifiedPayloadPath);
1148 ExitOnFailure(hr, "Failed to find payload: %ls in working path: %ls and unverified path: %ls", pPayload->sczKey, wzWorkingPayloadPath, sczUnverifiedPayloadPath);
1149 } 1148 }
1150 1149
1151 hr = ResetPathPermissions(fPerMachine, sczUnverifiedPayloadPath); 1150 hr = ResetPathPermissions(fPerMachine, sczUnverifiedPayloadPath);
diff --git a/src/burn/engine/dependency.cpp b/src/burn/engine/dependency.cpp
index 221c7bbf..d6698680 100644
--- a/src/burn/engine/dependency.cpp
+++ b/src/burn/engine/dependency.cpp
@@ -279,19 +279,13 @@ extern "C" HRESULT DependencyDetectBundle(
279 ) 279 )
280{ 280{
281 HRESULT hr = S_OK; 281 HRESULT hr = S_OK;
282 BOOL fExists = FALSE;
282 283
283 hr = DependencyDetectProviderKeyBundleId(pRegistration); 284 hr = DependencyDetectProviderKeyBundleId(pRegistration);
284 ExitOnFailure(hr, "Failed to detect provider key bundle id."); 285 ExitOnFailure(hr, "Failed to detect provider key bundle id.");
285 286
286 hr = DepCheckDependents(pRegistration->hkRoot, pRegistration->sczProviderKey, 0, NULL, &pRegistration->rgDependents, &pRegistration->cDependents); 287 hr = DepCheckDependents(pRegistration->hkRoot, pRegistration->sczProviderKey, 0, NULL, &pRegistration->rgDependents, &pRegistration->cDependents);
287 if (E_FILENOTFOUND != hr) 288 ExitOnPathFailure(hr, fExists, "Failed dependents check on bundle.");
288 {
289 ExitOnFailure(hr, "Failed dependents check on bundle.");
290 }
291 else
292 {
293 hr = S_OK;
294 }
295 289
296 if (pDependencies->fSelfDependent || pDependencies->fActiveParent) 290 if (pDependencies->fSelfDependent || pDependencies->fActiveParent)
297 { 291 {
@@ -813,6 +807,7 @@ extern "C" HRESULT DependencyProcessDependentRegistration(
813 ) 807 )
814{ 808{
815 HRESULT hr = S_OK; 809 HRESULT hr = S_OK;
810 BOOL fDeleted = FALSE;
816 811
817 switch (pAction->type) 812 switch (pAction->type)
818 { 813 {
@@ -823,12 +818,11 @@ extern "C" HRESULT DependencyProcessDependentRegistration(
823 818
824 case BURN_DEPENDENT_REGISTRATION_ACTION_TYPE_UNREGISTER: 819 case BURN_DEPENDENT_REGISTRATION_ACTION_TYPE_UNREGISTER:
825 hr = DepUnregisterDependent(pRegistration->hkRoot, pRegistration->sczProviderKey, pAction->sczDependentProviderKey); 820 hr = DepUnregisterDependent(pRegistration->hkRoot, pRegistration->sczProviderKey, pAction->sczDependentProviderKey);
826 ExitOnFailure(hr, "Failed to unregister dependent: %ls", pAction->sczDependentProviderKey); 821 ExitOnPathFailure(hr, fDeleted, "Failed to unregister dependent: %ls", pAction->sczDependentProviderKey);
827 break; 822 break;
828 823
829 default: 824 default:
830 hr = E_INVALIDARG; 825 ExitWithRootFailure(hr, E_INVALIDARG, "Unrecognized registration action type: %d", pAction->type);
831 ExitOnRootFailure(hr, "Unrecognized registration action type: %d", pAction->type);
832 } 826 }
833 827
834LExit: 828LExit:
@@ -848,11 +842,11 @@ extern "C" void DependencyUnregisterBundle(
848 { 842 {
849 // Remove the bundle provider key. 843 // Remove the bundle provider key.
850 hr = DepUnregisterDependency(pRegistration->hkRoot, pRegistration->sczProviderKey); 844 hr = DepUnregisterDependency(pRegistration->hkRoot, pRegistration->sczProviderKey);
851 if (SUCCEEDED(hr)) 845 if (SUCCEEDED(hr) || E_FILENOTFOUND == hr)
852 { 846 {
853 LogId(REPORT_VERBOSE, MSG_DEPENDENCY_BUNDLE_UNREGISTERED, pRegistration->sczProviderKey); 847 LogId(REPORT_VERBOSE, MSG_DEPENDENCY_BUNDLE_UNREGISTERED, pRegistration->sczProviderKey);
854 } 848 }
855 else if (FAILED(hr) && E_FILENOTFOUND != hr) 849 else
856 { 850 {
857 LogId(REPORT_VERBOSE, MSG_DEPENDENCY_BUNDLE_UNREGISTERED_FAILED, pRegistration->sczProviderKey, hr); 851 LogId(REPORT_VERBOSE, MSG_DEPENDENCY_BUNDLE_UNREGISTERED_FAILED, pRegistration->sczProviderKey, hr);
858 } 852 }
@@ -961,13 +955,10 @@ static HRESULT DetectPackageDependents(
961 for (DWORD i = 0; i < pPackage->cDependencyProviders; ++i) 955 for (DWORD i = 0; i < pPackage->cDependencyProviders; ++i)
962 { 956 {
963 BURN_DEPENDENCY_PROVIDER* pProvider = &pPackage->rgDependencyProviders[i]; 957 BURN_DEPENDENCY_PROVIDER* pProvider = &pPackage->rgDependencyProviders[i];
958 BOOL fExists = FALSE;
964 959
965 hr = DepCheckDependents(hkHive, pProvider->sczKey, 0, NULL, &pProvider->rgDependents, &pProvider->cDependents); 960 hr = DepCheckDependents(hkHive, pProvider->sczKey, 0, NULL, &pProvider->rgDependents, &pProvider->cDependents);
966 if (E_FILENOTFOUND == hr) 961 ExitOnPathFailure(hr, fExists, "Failed dependents check on package provider: %ls", pProvider->sczKey);
967 {
968 hr = S_OK;
969 }
970 ExitOnFailure(hr, "Failed dependents check on package provider: %ls", pProvider->sczKey);
971 962
972 if (0 < pProvider->cDependents || GetProviderExists(hkHive, pProvider->sczKey)) 963 if (0 < pProvider->cDependents || GetProviderExists(hkHive, pProvider->sczKey))
973 { 964 {
@@ -1366,11 +1357,11 @@ static void UnregisterPackageProvider(
1366 HRESULT hr = S_OK; 1357 HRESULT hr = S_OK;
1367 1358
1368 hr = DepUnregisterDependency(hkRoot, pProvider->sczKey); 1359 hr = DepUnregisterDependency(hkRoot, pProvider->sczKey);
1369 if (SUCCEEDED(hr)) 1360 if (SUCCEEDED(hr) || E_FILENOTFOUND == hr)
1370 { 1361 {
1371 LogId(REPORT_VERBOSE, MSG_DEPENDENCY_PACKAGE_UNREGISTERED, pProvider->sczKey, wzPackageId); 1362 LogId(REPORT_VERBOSE, MSG_DEPENDENCY_PACKAGE_UNREGISTERED, pProvider->sczKey, wzPackageId);
1372 } 1363 }
1373 else if (FAILED(hr) && E_FILENOTFOUND != hr) 1364 else
1374 { 1365 {
1375 LogId(REPORT_VERBOSE, MSG_DEPENDENCY_PACKAGE_UNREGISTERED_FAILED, pProvider->sczKey, wzPackageId, hr); 1366 LogId(REPORT_VERBOSE, MSG_DEPENDENCY_PACKAGE_UNREGISTERED_FAILED, pProvider->sczKey, wzPackageId, hr);
1376 } 1367 }
@@ -1390,15 +1381,14 @@ static HRESULT RegisterPackageProviderDependent(
1390 ) 1381 )
1391{ 1382{
1392 HRESULT hr = S_OK; 1383 HRESULT hr = S_OK;
1384 BOOL fExists = FALSE;
1393 1385
1394 LogId(REPORT_VERBOSE, MSG_DEPENDENCY_PACKAGE_REGISTER_DEPENDENCY, wzDependentProviderKey, pProvider->sczKey, wzPackageId); 1386 LogId(REPORT_VERBOSE, MSG_DEPENDENCY_PACKAGE_REGISTER_DEPENDENCY, wzDependentProviderKey, pProvider->sczKey, wzPackageId);
1395 1387
1396 hr = DepRegisterDependent(hkRoot, pProvider->sczKey, wzDependentProviderKey, NULL, NULL, 0); 1388 hr = DepRegisterDependent(hkRoot, pProvider->sczKey, wzDependentProviderKey, NULL, NULL, 0);
1397 if (E_FILENOTFOUND != hr) 1389 ExitOnPathFailure(hr, fExists, "Failed to register the dependency on package dependency provider: %ls", pProvider->sczKey);
1398 { 1390
1399 ExitOnFailure(hr, "Failed to register the dependency on package dependency provider: %ls", pProvider->sczKey); 1391 if (!fExists)
1400 }
1401 else
1402 { 1392 {
1403 LogId(REPORT_VERBOSE, MSG_DEPENDENCY_PACKAGE_SKIP_MISSING, pProvider->sczKey, wzPackageId); 1393 LogId(REPORT_VERBOSE, MSG_DEPENDENCY_PACKAGE_SKIP_MISSING, pProvider->sczKey, wzPackageId);
1404 } 1394 }
@@ -1454,11 +1444,11 @@ static void UnregisterPackageProviderDependent(
1454 HRESULT hr = S_OK; 1444 HRESULT hr = S_OK;
1455 1445
1456 hr = DepUnregisterDependent(hkRoot, pProvider->sczKey, wzDependentProviderKey); 1446 hr = DepUnregisterDependent(hkRoot, pProvider->sczKey, wzDependentProviderKey);
1457 if (SUCCEEDED(hr)) 1447 if (SUCCEEDED(hr) || E_FILENOTFOUND == hr)
1458 { 1448 {
1459 LogId(REPORT_VERBOSE, MSG_DEPENDENCY_PACKAGE_UNREGISTERED_DEPENDENCY, wzDependentProviderKey, pProvider->sczKey, wzPackageId); 1449 LogId(REPORT_VERBOSE, MSG_DEPENDENCY_PACKAGE_UNREGISTERED_DEPENDENCY, wzDependentProviderKey, pProvider->sczKey, wzPackageId);
1460 } 1450 }
1461 else if (FAILED(hr) && E_FILENOTFOUND != hr) 1451 else
1462 { 1452 {
1463 LogId(REPORT_VERBOSE, MSG_DEPENDENCY_PACKAGE_UNREGISTERED_DEPENDENCY_FAILED, wzDependentProviderKey, pProvider->sczKey, wzPackageId, hr); 1453 LogId(REPORT_VERBOSE, MSG_DEPENDENCY_PACKAGE_UNREGISTERED_DEPENDENCY_FAILED, wzDependentProviderKey, pProvider->sczKey, wzPackageId, hr);
1464 } 1454 }
diff --git a/src/burn/engine/exeengine.cpp b/src/burn/engine/exeengine.cpp
index ef0015ac..b4898d42 100644
--- a/src/burn/engine/exeengine.cpp
+++ b/src/burn/engine/exeengine.cpp
@@ -1040,6 +1040,7 @@ static HRESULT DetectArpEntry(
1040{ 1040{
1041 HRESULT hr = S_OK; 1041 HRESULT hr = S_OK;
1042 HKEY hKey = NULL; 1042 HKEY hKey = NULL;
1043 BOOL fExists = FALSE;
1043 VERUTIL_VERSION* pVersion = NULL; 1044 VERUTIL_VERSION* pVersion = NULL;
1044 int nCompareResult = 0; 1045 int nCompareResult = 0;
1045 HKEY hkRoot = pPackage->fPerMachine ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 1046 HKEY hkRoot = pPackage->fPerMachine ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
@@ -1052,18 +1053,20 @@ static HRESULT DetectArpEntry(
1052 } 1053 }
1053 1054
1054 hr = RegOpenEx(hkRoot, pPackage->Exe.sczArpKeyPath, KEY_READ, keyBitness, &hKey); 1055 hr = RegOpenEx(hkRoot, pPackage->Exe.sczArpKeyPath, KEY_READ, keyBitness, &hKey);
1055 if (HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) == hr || HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) == hr) 1056 ExitOnPathFailure(hr, fExists, "Failed to open registry key: %ls.", pPackage->Exe.sczArpKeyPath);
1057
1058 if (!fExists)
1056 { 1059 {
1057 ExitFunction1(hr = S_OK); 1060 ExitFunction();
1058 } 1061 }
1059 ExitOnFailure(hr, "Failed to open registry key: %ls.", pPackage->Exe.sczArpKeyPath);
1060 1062
1061 hr = RegReadWixVersion(hKey, L"DisplayVersion", &pVersion); 1063 hr = RegReadWixVersion(hKey, L"DisplayVersion", &pVersion);
1062 if (HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) == hr) 1064 ExitOnPathFailure(hr, fExists, "Failed to read DisplayVersion.");
1065
1066 if (!fExists)
1063 { 1067 {
1064 ExitFunction1(hr = S_OK); 1068 ExitFunction();
1065 } 1069 }
1066 ExitOnFailure(hr, "Failed to read DisplayVersion.");
1067 1070
1068 if (pVersion->fInvalid) 1071 if (pVersion->fInvalid)
1069 { 1072 {
@@ -1089,11 +1092,7 @@ static HRESULT DetectArpEntry(
1089 if (psczQuietUninstallString) 1092 if (psczQuietUninstallString)
1090 { 1093 {
1091 hr = RegReadString(hKey, L"QuietUninstallString", psczQuietUninstallString); 1094 hr = RegReadString(hKey, L"QuietUninstallString", psczQuietUninstallString);
1092 if (HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) == hr) 1095 ExitOnPathFailure(hr, fExists, "Failed to read QuietUninstallString.");
1093 {
1094 hr = S_OK;
1095 }
1096 ExitOnFailure(hr, "Failed to read QuietUninstallString.");
1097 } 1096 }
1098 1097
1099LExit: 1098LExit:
diff --git a/src/burn/engine/registration.cpp b/src/burn/engine/registration.cpp
index 484c08ac..35100336 100644
--- a/src/burn/engine/registration.cpp
+++ b/src/burn/engine/registration.cpp
@@ -492,25 +492,28 @@ extern "C" HRESULT RegistrationDetectResumeType(
492{ 492{
493 HRESULT hr = S_OK; 493 HRESULT hr = S_OK;
494 HKEY hkRegistration = NULL; 494 HKEY hkRegistration = NULL;
495 BOOL fExists = FALSE;
495 DWORD dwResume = 0; 496 DWORD dwResume = 0;
496 497
497 // open registration key 498 // open registration key
498 hr = RegOpen(pRegistration->hkRoot, pRegistration->sczRegistrationKey, KEY_QUERY_VALUE, &hkRegistration); 499 hr = RegOpen(pRegistration->hkRoot, pRegistration->sczRegistrationKey, KEY_QUERY_VALUE, &hkRegistration);
499 if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) 500 ExitOnPathFailure(hr, fExists, "Failed to open registration key.");
501
502 if (!fExists)
500 { 503 {
501 *pResumeType = BOOTSTRAPPER_RESUME_TYPE_NONE; 504 *pResumeType = BOOTSTRAPPER_RESUME_TYPE_NONE;
502 ExitFunction1(hr = S_OK); 505 ExitFunction();
503 } 506 }
504 ExitOnFailure(hr, "Failed to open registration key.");
505 507
506 // read Resume value 508 // read Resume value
507 hr = RegReadNumber(hkRegistration, L"Resume", &dwResume); 509 hr = RegReadNumber(hkRegistration, L"Resume", &dwResume);
508 if (E_FILENOTFOUND == hr) 510 ExitOnPathFailure(hr, fExists, "Failed to read Resume value.");
511
512 if (!fExists)
509 { 513 {
510 *pResumeType = BOOTSTRAPPER_RESUME_TYPE_INVALID; 514 *pResumeType = BOOTSTRAPPER_RESUME_TYPE_INVALID;
511 ExitFunction1(hr = S_OK); 515 ExitFunction();
512 } 516 }
513 ExitOnFailure(hr, "Failed to read Resume value.");
514 517
515 switch (dwResume) 518 switch (dwResume)
516 { 519 {
@@ -855,6 +858,7 @@ extern "C" HRESULT RegistrationSessionEnd(
855{ 858{
856 HRESULT hr = S_OK; 859 HRESULT hr = S_OK;
857 HKEY hkRegistration = NULL; 860 HKEY hkRegistration = NULL;
861 BOOL fDeleted = FALSE;
858 862
859 // If no resume mode, then remove the bundle registration. 863 // If no resume mode, then remove the bundle registration.
860 if (BURN_RESUME_MODE_NONE == resumeMode) 864 if (BURN_RESUME_MODE_NONE == resumeMode)
@@ -874,10 +878,7 @@ extern "C" HRESULT RegistrationSessionEnd(
874 878
875 // Delete registration key. 879 // Delete registration key.
876 hr = RegDelete(pRegistration->hkRoot, pRegistration->sczRegistrationKey, REG_KEY_DEFAULT, TRUE); 880 hr = RegDelete(pRegistration->hkRoot, pRegistration->sczRegistrationKey, REG_KEY_DEFAULT, TRUE);
877 if (E_FILENOTFOUND != hr) 881 ExitOnPathFailure(hr, fDeleted, "Failed to delete registration key: %ls", pRegistration->sczRegistrationKey);
878 {
879 ExitOnFailure(hr, "Failed to delete registration key: %ls", pRegistration->sczRegistrationKey);
880 }
881 882
882 CacheRemoveBundle(pCache, pRegistration->fPerMachine, pRegistration->sczId); 883 CacheRemoveBundle(pCache, pRegistration->fPerMachine, pRegistration->sczId);
883 } 884 }
@@ -967,7 +968,10 @@ extern "C" HRESULT RegistrationSaveState(
967 ExitOnFailure(hr, "Failed to enumerate value %u", i); 968 ExitOnFailure(hr, "Failed to enumerate value %u", i);
968 969
969 er = ::RegDeleteValueW(hkRegistration, sczValueName); 970 er = ::RegDeleteValueW(hkRegistration, sczValueName);
970 ExitOnWin32Error(er, hr, "Failed to delete registration variable value."); 971 if (ERROR_FILE_NOT_FOUND != er)
972 {
973 ExitOnWin32Error(er, hr, "Failed to delete registration variable value.");
974 }
971 } 975 }
972 976
973 // Write variables. 977 // Write variables.
@@ -1486,6 +1490,7 @@ static HRESULT RemoveUpdateRegistration(
1486 LPWSTR sczPackageVersion = NULL; 1490 LPWSTR sczPackageVersion = NULL;
1487 HKEY hkKey = NULL; 1491 HKEY hkKey = NULL;
1488 BOOL fDeleteRegKey = TRUE; 1492 BOOL fDeleteRegKey = TRUE;
1493 BOOL fDeleted = FALSE;
1489 1494
1490 hr = FormatUpdateRegistrationKey(pRegistration, &sczKey); 1495 hr = FormatUpdateRegistrationKey(pRegistration, &sczKey);
1491 ExitOnFailure(hr, "Failed to format key for update registration."); 1496 ExitOnFailure(hr, "Failed to format key for update registration.");
@@ -1513,10 +1518,7 @@ static HRESULT RemoveUpdateRegistration(
1513 if (fDeleteRegKey) 1518 if (fDeleteRegKey)
1514 { 1519 {
1515 hr = RegDelete(pRegistration->hkRoot, sczKey, REG_KEY_DEFAULT, FALSE); 1520 hr = RegDelete(pRegistration->hkRoot, sczKey, REG_KEY_DEFAULT, FALSE);
1516 if (E_FILENOTFOUND != hr) 1521 ExitOnPathFailure(hr, fDeleted, "Failed to remove update registration key: %ls", sczKey);
1517 {
1518 ExitOnFailure(hr, "Failed to remove update registration key: %ls", sczKey);
1519 }
1520 } 1522 }
1521 1523
1522LExit: 1524LExit:
diff --git a/src/burn/engine/relatedbundle.cpp b/src/burn/engine/relatedbundle.cpp
index 586446b1..23e0f352 100644
--- a/src/burn/engine/relatedbundle.cpp
+++ b/src/burn/engine/relatedbundle.cpp
@@ -322,6 +322,7 @@ static HRESULT LoadRelatedBundleFromKey(
322 LPWSTR sczCachePath = NULL; 322 LPWSTR sczCachePath = NULL;
323 BOOL fCached = FALSE; 323 BOOL fCached = FALSE;
324 DWORD64 qwFileSize = 0; 324 DWORD64 qwFileSize = 0;
325 BOOL fExists = FALSE;
325 BURN_DEPENDENCY_PROVIDER dependencyProvider = { }; 326 BURN_DEPENDENCY_PROVIDER dependencyProvider = { };
326 BURN_DEPENDENCY_PROVIDER* pBundleDependencyProvider = NULL; 327 BURN_DEPENDENCY_PROVIDER* pBundleDependencyProvider = NULL;
327 328
@@ -369,10 +370,7 @@ static HRESULT LoadRelatedBundleFromKey(
369 pRelatedBundle->fPlannable = fCached; 370 pRelatedBundle->fPlannable = fCached;
370 371
371 hr = RegReadString(hkBundleId, BURN_REGISTRATION_REGISTRY_BUNDLE_PROVIDER_KEY, &dependencyProvider.sczKey); 372 hr = RegReadString(hkBundleId, BURN_REGISTRATION_REGISTRY_BUNDLE_PROVIDER_KEY, &dependencyProvider.sczKey);
372 if (E_FILENOTFOUND != hr) 373 ExitOnPathFailure(hr, fExists, "Failed to read provider key from registry for bundle: %ls", wzRelatedBundleId);
373 {
374 ExitOnFailure(hr, "Failed to read provider key from registry for bundle: %ls", wzRelatedBundleId);
375 }
376 374
377 if (dependencyProvider.sczKey && *dependencyProvider.sczKey) 375 if (dependencyProvider.sczKey && *dependencyProvider.sczKey)
378 { 376 {
@@ -384,18 +382,11 @@ static HRESULT LoadRelatedBundleFromKey(
384 ExitOnFailure(hr, "Failed to copy version for bundle: %ls", wzRelatedBundleId); 382 ExitOnFailure(hr, "Failed to copy version for bundle: %ls", wzRelatedBundleId);
385 383
386 hr = RegReadString(hkBundleId, BURN_REGISTRATION_REGISTRY_BUNDLE_DISPLAY_NAME, &dependencyProvider.sczDisplayName); 384 hr = RegReadString(hkBundleId, BURN_REGISTRATION_REGISTRY_BUNDLE_DISPLAY_NAME, &dependencyProvider.sczDisplayName);
387 if (E_FILENOTFOUND != hr) 385 ExitOnPathFailure(hr, fExists, "Failed to copy display name for bundle: %ls", wzRelatedBundleId);
388 {
389 ExitOnFailure(hr, "Failed to copy display name for bundle: %ls", wzRelatedBundleId);
390 }
391 } 386 }
392 387
393 hr = RegReadString(hkBundleId, BURN_REGISTRATION_REGISTRY_BUNDLE_TAG, &pRelatedBundle->sczTag); 388 hr = RegReadString(hkBundleId, BURN_REGISTRATION_REGISTRY_BUNDLE_TAG, &pRelatedBundle->sczTag);
394 if (E_FILENOTFOUND == hr) 389 ExitOnPathFailure(hr, fExists, "Failed to read tag from registry for bundle: %ls", wzRelatedBundleId);
395 {
396 hr = S_OK;
397 }
398 ExitOnFailure(hr, "Failed to read tag from registry for bundle: %ls", wzRelatedBundleId);
399 390
400 pRelatedBundle->detectRelationType = relationType; 391 pRelatedBundle->detectRelationType = relationType;
401 392
diff --git a/src/burn/engine/search.cpp b/src/burn/engine/search.cpp
index b37dc9bd..a1b6b74a 100644
--- a/src/burn/engine/search.cpp
+++ b/src/burn/engine/search.cpp
@@ -610,6 +610,7 @@ static HRESULT DirectorySearchExists(
610 ) 610 )
611{ 611{
612 HRESULT hr = S_OK; 612 HRESULT hr = S_OK;
613 DWORD er = ERROR_SUCCESS;
613 LPWSTR sczPath = NULL; 614 LPWSTR sczPath = NULL;
614 BOOL fExists = FALSE; 615 BOOL fExists = FALSE;
615 616
@@ -629,21 +630,25 @@ static HRESULT DirectorySearchExists(
629 DWORD dwAttributes = ::GetFileAttributesW(sczPath); 630 DWORD dwAttributes = ::GetFileAttributesW(sczPath);
630 if (INVALID_FILE_ATTRIBUTES == dwAttributes) 631 if (INVALID_FILE_ATTRIBUTES == dwAttributes)
631 { 632 {
632 hr = HRESULT_FROM_WIN32(::GetLastError()); 633 er = ::GetLastError();
633 if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) 634 if (ERROR_FILE_NOT_FOUND == er || ERROR_PATH_NOT_FOUND == er)
634 { 635 {
635 hr = S_OK; // didn't find file, fExists still is false. 636 LogStringLine(REPORT_STANDARD, "Directory search: %ls, did not find path: %ls", pSearch->sczKey, pSearch->DirectorySearch.sczPath);
637 }
638 else
639 {
640 ExitOnWin32Error(er, hr, "Directory search: %ls, failed get to directory attributes. '%ls'", pSearch->sczKey, pSearch->DirectorySearch.sczPath);
636 } 641 }
637 } 642 }
638 else if (dwAttributes & FILE_ATTRIBUTE_DIRECTORY) 643 else if (FILE_ATTRIBUTE_DIRECTORY != (dwAttributes & FILE_ATTRIBUTE_DIRECTORY))
644 {
645 LogStringLine(REPORT_STANDARD, "Directory search: %ls, found file at path: %ls", pSearch->sczKey, pSearch->DirectorySearch.sczPath);
646 }
647 else
639 { 648 {
640 fExists = TRUE; 649 fExists = TRUE;
641 } 650 }
642 651
643 // else must have found a file.
644 // What if there is a hidden variable in sczPath?
645 ExitOnFailure(hr, "Failed while searching directory search: %ls, for path: %ls", pSearch->sczKey, sczPath);
646
647 // set variable 652 // set variable
648 hr = VariableSetNumeric(pVariables, pSearch->sczVariable, fExists, FALSE); 653 hr = VariableSetNumeric(pVariables, pSearch->sczVariable, fExists, FALSE);
649 ExitOnFailure(hr, "Failed to set variable."); 654 ExitOnFailure(hr, "Failed to set variable.");
@@ -694,13 +699,12 @@ static HRESULT DirectorySearchPath(
694 hr = E_PATHNOTFOUND; 699 hr = E_PATHNOTFOUND;
695 } 700 }
696 701
697 // What if there is a hidden variable in sczPath?
698 if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) 702 if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr)
699 { 703 {
700 LogStringLine(REPORT_STANDARD, "Directory search: %ls, did not find path: %ls, reason: 0x%x", pSearch->sczKey, sczPath, hr); 704 LogStringLine(REPORT_STANDARD, "Directory search: %ls, did not find path: %ls, reason: 0x%x", pSearch->sczKey, pSearch->DirectorySearch.sczPath, hr);
701 ExitFunction1(hr = S_OK); 705 ExitFunction1(hr = S_OK);
702 } 706 }
703 ExitOnFailure(hr, "Failed while searching directory search: %ls, for path: %ls", pSearch->sczKey, sczPath); 707 ExitOnFailure(hr, "Failed while searching directory search: %ls, for path: %ls", pSearch->sczKey, pSearch->DirectorySearch.sczPath);
704 708
705LExit: 709LExit:
706#if !defined(_WIN64) 710#if !defined(_WIN64)
@@ -742,15 +746,18 @@ static HRESULT FileSearchExists(
742 er = ::GetLastError(); 746 er = ::GetLastError();
743 if (ERROR_FILE_NOT_FOUND == er || ERROR_PATH_NOT_FOUND == er) 747 if (ERROR_FILE_NOT_FOUND == er || ERROR_PATH_NOT_FOUND == er)
744 { 748 {
745 // What if there is a hidden variable in sczPath? 749 LogStringLine(REPORT_STANDARD, "File search: %ls, did not find path: %ls", pSearch->sczKey, pSearch->FileSearch.sczPath);
746 LogStringLine(REPORT_STANDARD, "File search: %ls, did not find path: %ls", pSearch->sczKey, sczPath);
747 } 750 }
748 else 751 else
749 { 752 {
750 ExitOnWin32Error(er, hr, "Failed get to file attributes. '%ls'", pSearch->FileSearch.sczPath); 753 ExitOnWin32Error(er, hr, "File search: %ls, failed get to file attributes. '%ls'", pSearch->sczKey, pSearch->FileSearch.sczPath);
751 } 754 }
752 } 755 }
753 else if (FILE_ATTRIBUTE_DIRECTORY != (dwAttributes & FILE_ATTRIBUTE_DIRECTORY)) 756 else if (FILE_ATTRIBUTE_DIRECTORY == (dwAttributes & FILE_ATTRIBUTE_DIRECTORY))
757 {
758 LogStringLine(REPORT_STANDARD, "File search: %ls, found directory at path: %ls", pSearch->sczKey, pSearch->FileSearch.sczPath);
759 }
760 else
754 { 761 {
755 fExists = TRUE; 762 fExists = TRUE;
756 } 763 }
@@ -795,8 +802,7 @@ static HRESULT FileSearchVersion(
795 hr = FileVersion(sczPath, &uliVersion.HighPart, &uliVersion.LowPart); 802 hr = FileVersion(sczPath, &uliVersion.HighPart, &uliVersion.LowPart);
796 if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) 803 if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr)
797 { 804 {
798 // What if there is a hidden variable in sczPath? 805 LogStringLine(REPORT_STANDARD, "File search: %ls, did not find path: %ls", pSearch->sczKey, pSearch->FileSearch.sczPath);
799 LogStringLine(REPORT_STANDARD, "File search: %ls, did not find path: %ls", pSearch->sczKey, sczPath);
800 ExitFunction1(hr = S_OK); 806 ExitFunction1(hr = S_OK);
801 } 807 }
802 ExitOnFailure(hr, "Failed to get file version."); 808 ExitOnFailure(hr, "Failed to get file version.");
@@ -854,13 +860,12 @@ static HRESULT FileSearchPath(
854 ExitOnFailure(hr, "Failed to set variable to file search path."); 860 ExitOnFailure(hr, "Failed to set variable to file search path.");
855 } 861 }
856 862
857 // What if there is a hidden variable in sczPath?
858 if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) 863 if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr)
859 { 864 {
860 LogStringLine(REPORT_STANDARD, "File search: %ls, did not find path: %ls", pSearch->sczKey, sczPath); 865 LogStringLine(REPORT_STANDARD, "File search: %ls, did not find path: %ls", pSearch->sczKey, pSearch->FileSearch.sczPath);
861 ExitFunction1(hr = S_OK); 866 ExitFunction1(hr = S_OK);
862 } 867 }
863 ExitOnFailure(hr, "Failed while searching file search: %ls, for path: %ls", pSearch->sczKey, sczPath); 868 ExitOnFailure(hr, "Failed while searching file search: %ls, for path: %ls", pSearch->sczKey, pSearch->FileSearch.sczPath);
864 869
865LExit: 870LExit:
866#if !defined(_WIN64) 871#if !defined(_WIN64)
@@ -891,24 +896,13 @@ static HRESULT RegistrySearchExists(
891 896
892 // open key 897 // open key
893 hr = RegOpenEx(pSearch->RegistrySearch.hRoot, sczKey, KEY_QUERY_VALUE, pSearch->RegistrySearch.fWin64 ? REG_KEY_64BIT : REG_KEY_32BIT, &hKey); 898 hr = RegOpenEx(pSearch->RegistrySearch.hRoot, sczKey, KEY_QUERY_VALUE, pSearch->RegistrySearch.fWin64 ? REG_KEY_64BIT : REG_KEY_32BIT, &hKey);
894 if (SUCCEEDED(hr)) 899 ExitOnPathFailure(hr, fExists, "Failed to open registry key. Key = '%ls'", pSearch->RegistrySearch.sczKey);
895 { 900
896 fExists = TRUE; 901 if (!fExists)
897 }
898 else if (E_FILENOTFOUND == hr)
899 {
900 // What if there is a hidden variable in sczKey?
901 LogStringLine(REPORT_STANDARD, "Registry key not found. Key = '%ls'", sczKey);
902 fExists = FALSE;
903 hr = S_OK;
904 }
905 else
906 { 902 {
907 // What if there is a hidden variable in sczKey? 903 LogStringLine(REPORT_STANDARD, "Registry key not found. Key = '%ls'", pSearch->RegistrySearch.sczKey);
908 ExitOnFailure(hr, "Failed to open registry key. Key = '%ls'", sczKey);
909 } 904 }
910 905 else if (pSearch->RegistrySearch.sczValue)
911 if (fExists && pSearch->RegistrySearch.sczValue)
912 { 906 {
913 // format value string 907 // format value string
914 hr = VariableFormatString(pVariables, pSearch->RegistrySearch.sczValue, &sczValue, NULL); 908 hr = VariableFormatString(pVariables, pSearch->RegistrySearch.sczValue, &sczValue, NULL);
@@ -922,8 +916,7 @@ static HRESULT RegistrySearchExists(
922 fExists = TRUE; 916 fExists = TRUE;
923 break; 917 break;
924 case ERROR_FILE_NOT_FOUND: 918 case ERROR_FILE_NOT_FOUND:
925 // What if there is a hidden variable in sczKey or sczValue? 919 LogStringLine(REPORT_STANDARD, "Registry value not found. Key = '%ls', Value = '%ls'", pSearch->RegistrySearch.sczKey, pSearch->RegistrySearch.sczValue);
926 LogStringLine(REPORT_STANDARD, "Registry value not found. Key = '%ls', Value = '%ls'", sczKey, sczValue);
927 fExists = FALSE; 920 fExists = FALSE;
928 break; 921 break;
929 default: 922 default:
@@ -938,8 +931,7 @@ static HRESULT RegistrySearchExists(
938LExit: 931LExit:
939 if (FAILED(hr)) 932 if (FAILED(hr))
940 { 933 {
941 // What if there is a hidden variable in sczKey? 934 LogStringLine(REPORT_STANDARD, "RegistrySearchExists failed: ID '%ls', HRESULT 0x%x", pSearch->sczKey, hr);
942 LogStringLine(REPORT_STANDARD, "RegistrySearchExists failed: ID '%ls', HRESULT 0x%x", sczKey, hr);
943 } 935 }
944 936
945 StrSecureZeroFreeString(sczKey); 937 StrSecureZeroFreeString(sczKey);
@@ -958,6 +950,7 @@ static HRESULT RegistrySearchValue(
958 LPWSTR sczKey = NULL; 950 LPWSTR sczKey = NULL;
959 LPWSTR sczValue = NULL; 951 LPWSTR sczValue = NULL;
960 HKEY hKey = NULL; 952 HKEY hKey = NULL;
953 BOOL fExists = FALSE;
961 DWORD dwType = 0; 954 DWORD dwType = 0;
962 SIZE_T cbData = 0; 955 SIZE_T cbData = 0;
963 LPBYTE pData = NULL; 956 LPBYTE pData = NULL;
@@ -978,21 +971,20 @@ static HRESULT RegistrySearchValue(
978 971
979 // open key 972 // open key
980 hr = RegOpenEx(pSearch->RegistrySearch.hRoot, sczKey, KEY_QUERY_VALUE, pSearch->RegistrySearch.fWin64 ? REG_KEY_64BIT : REG_KEY_32BIT, &hKey); 973 hr = RegOpenEx(pSearch->RegistrySearch.hRoot, sczKey, KEY_QUERY_VALUE, pSearch->RegistrySearch.fWin64 ? REG_KEY_64BIT : REG_KEY_32BIT, &hKey);
981 if (E_FILENOTFOUND == hr) 974 ExitOnPathFailure(hr, fExists, "Failed to open registry key.");
975
976 if (!fExists)
982 { 977 {
983 // What if there is a hidden variable in sczKey? 978 LogStringLine(REPORT_STANDARD, "Registry key not found. Key = '%ls'", pSearch->RegistrySearch.sczKey);
984 LogStringLine(REPORT_STANDARD, "Registry key not found. Key = '%ls'", sczKey);
985 979
986 ExitFunction1(hr = S_OK); 980 ExitFunction();
987 } 981 }
988 ExitOnFailure(hr, "Failed to open registry key.");
989 982
990 // get value 983 // get value
991 hr = RegReadValue(hKey, sczValue, pSearch->RegistrySearch.fExpandEnvironment, &pData, &cbData, &dwType); 984 hr = RegReadValue(hKey, sczValue, pSearch->RegistrySearch.fExpandEnvironment, &pData, &cbData, &dwType);
992 if (E_FILENOTFOUND == hr) 985 if (E_FILENOTFOUND == hr)
993 { 986 {
994 // What if there is a hidden variable in sczKey or sczValue? 987 LogStringLine(REPORT_STANDARD, "Registry value not found. Key = '%ls', Value = '%ls'", pSearch->RegistrySearch.sczKey, pSearch->RegistrySearch.sczValue);
995 LogStringLine(REPORT_STANDARD, "Registry value not found. Key = '%ls', Value = '%ls'", sczKey, sczValue);
996 988
997 ExitFunction1(hr = S_OK); 989 ExitFunction1(hr = S_OK);
998 } 990 }
@@ -1034,8 +1026,7 @@ static HRESULT RegistrySearchValue(
1034LExit: 1026LExit:
1035 if (FAILED(hr)) 1027 if (FAILED(hr))
1036 { 1028 {
1037 // What if there is a hidden variable in sczKey? 1029 LogStringLine(REPORT_STANDARD, "RegistrySearchValue failed: ID '%ls', HRESULT 0x%x", pSearch->sczKey, hr);
1038 LogStringLine(REPORT_STANDARD, "RegistrySearchValue failed: ID '%ls', HRESULT 0x%x", sczKey, hr);
1039 } 1030 }
1040 1031
1041 StrSecureZeroFreeString(sczKey); 1032 StrSecureZeroFreeString(sczKey);
diff --git a/src/ext/Bal/dnchost/dncutil.cpp b/src/ext/Bal/dnchost/dncutil.cpp
index 6486e6e9..a8d4f4ff 100644
--- a/src/ext/Bal/dnchost/dncutil.cpp
+++ b/src/ext/Bal/dnchost/dncutil.cpp
@@ -338,7 +338,7 @@ static HRESULT InitializeCoreClrPre5(
338 { 338 {
339 BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "%ls: %ls", rgPropertyKeys[i], rgPropertyValues[i]); 339 BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "%ls: %ls", rgPropertyKeys[i], rgPropertyValues[i]);
340 } 340 }
341 BalExitOnFailure(hr = E_FILENOTFOUND, "Failed to locate coreclr.dll."); 341 BalExitWithRootFailure(hr, E_FILENOTFOUND, "Failed to locate coreclr.dll.");
342 } 342 }
343 343
344 hr = LoadCoreClr(pState, sczCoreClrPath); 344 hr = LoadCoreClr(pState, sczCoreClrPath);
diff --git a/src/ext/Bal/mbahost/mbahost.cpp b/src/ext/Bal/mbahost/mbahost.cpp
index 5edbe376..9d8acc8a 100644
--- a/src/ext/Bal/mbahost/mbahost.cpp
+++ b/src/ext/Bal/mbahost/mbahost.cpp
@@ -228,31 +228,31 @@ static HRESULT GetAppDomain(
228 228
229 // Create the setup information for a new AppDomain to set the app base and config. 229 // Create the setup information for a new AppDomain to set the app base and config.
230 hr = pState->pCLRHost->CreateDomainSetup(&pUnk); 230 hr = pState->pCLRHost->CreateDomainSetup(&pUnk);
231 ExitOnRootFailure(hr, "Failed to create the AppDomainSetup object."); 231 BalExitOnRootFailure(hr, "Failed to create the AppDomainSetup object.");
232 232
233 hr = pUnk->QueryInterface(__uuidof(IAppDomainSetup), reinterpret_cast<LPVOID*>(&pAppDomainSetup)); 233 hr = pUnk->QueryInterface(__uuidof(IAppDomainSetup), reinterpret_cast<LPVOID*>(&pAppDomainSetup));
234 ExitOnRootFailure(hr, "Failed to query for the IAppDomainSetup interface."); 234 BalExitOnRootFailure(hr, "Failed to query for the IAppDomainSetup interface.");
235 ReleaseNullObject(pUnk); 235 ReleaseNullObject(pUnk);
236 236
237 // Set properties on the AppDomainSetup object. 237 // Set properties on the AppDomainSetup object.
238 bstrAppBase = ::SysAllocString(pState->sczAppBase); 238 bstrAppBase = ::SysAllocString(pState->sczAppBase);
239 ExitOnNull(bstrAppBase, hr, E_OUTOFMEMORY, "Failed to allocate the application base path for the AppDomainSetup."); 239 BalExitOnNull(bstrAppBase, hr, E_OUTOFMEMORY, "Failed to allocate the application base path for the AppDomainSetup.");
240 240
241 hr = pAppDomainSetup->put_ApplicationBase(bstrAppBase); 241 hr = pAppDomainSetup->put_ApplicationBase(bstrAppBase);
242 ExitOnRootFailure(hr, "Failed to set the application base path for the AppDomainSetup."); 242 BalExitOnRootFailure(hr, "Failed to set the application base path for the AppDomainSetup.");
243 243
244 bstrConfigPath = ::SysAllocString(pState->sczConfigPath); 244 bstrConfigPath = ::SysAllocString(pState->sczConfigPath);
245 ExitOnNull(bstrConfigPath, hr, E_OUTOFMEMORY, "Failed to allocate the application configuration file for the AppDomainSetup."); 245 BalExitOnNull(bstrConfigPath, hr, E_OUTOFMEMORY, "Failed to allocate the application configuration file for the AppDomainSetup.");
246 246
247 hr = pAppDomainSetup->put_ConfigurationFile(bstrConfigPath); 247 hr = pAppDomainSetup->put_ConfigurationFile(bstrConfigPath);
248 ExitOnRootFailure(hr, "Failed to set the configuration file path for the AppDomainSetup."); 248 BalExitOnRootFailure(hr, "Failed to set the configuration file path for the AppDomainSetup.");
249 249
250 // Create the AppDomain to load the factory type. 250 // Create the AppDomain to load the factory type.
251 hr = pState->pCLRHost->CreateDomainEx(L"MBA", pAppDomainSetup, NULL, &pUnk); 251 hr = pState->pCLRHost->CreateDomainEx(L"MBA", pAppDomainSetup, NULL, &pUnk);
252 ExitOnRootFailure(hr, "Failed to create the MBA AppDomain."); 252 BalExitOnRootFailure(hr, "Failed to create the MBA AppDomain.");
253 253
254 hr = pUnk->QueryInterface(__uuidof(_AppDomain), reinterpret_cast<LPVOID*>(&pState->pAppDomain)); 254 hr = pUnk->QueryInterface(__uuidof(_AppDomain), reinterpret_cast<LPVOID*>(&pState->pAppDomain));
255 ExitOnRootFailure(hr, "Failed to query for the _AppDomain interface."); 255 BalExitOnRootFailure(hr, "Failed to query for the _AppDomain interface.");
256 256
257LExit: 257LExit:
258 ReleaseBSTR(bstrConfigPath); 258 ReleaseBSTR(bstrConfigPath);
@@ -270,13 +270,13 @@ static HRESULT LoadModulePaths(
270 LPWSTR sczFullPath = NULL; 270 LPWSTR sczFullPath = NULL;
271 271
272 hr = PathForCurrentProcess(&sczFullPath, pState->hInstance); 272 hr = PathForCurrentProcess(&sczFullPath, pState->hInstance);
273 ExitOnFailure(hr, "Failed to get the full host path."); 273 BalExitOnFailure(hr, "Failed to get the full host path.");
274 274
275 hr = PathGetDirectory(sczFullPath, &pState->sczAppBase); 275 hr = PathGetDirectory(sczFullPath, &pState->sczAppBase);
276 ExitOnFailure(hr, "Failed to get the directory of the full process path."); 276 BalExitOnFailure(hr, "Failed to get the directory of the full process path.");
277 277
278 hr = PathConcat(pState->sczAppBase, MBA_CONFIG_FILE_NAME, &pState->sczConfigPath); 278 hr = PathConcat(pState->sczAppBase, MBA_CONFIG_FILE_NAME, &pState->sczConfigPath);
279 ExitOnFailure(hr, "Failed to get the full path to the application configuration file."); 279 BalExitOnFailure(hr, "Failed to get the full path to the application configuration file.");
280 280
281LExit: 281LExit:
282 ReleaseStr(sczFullPath); 282 ReleaseStr(sczFullPath);
@@ -332,23 +332,23 @@ static HRESULT CheckSupportedFrameworks(
332 BOOL fUpdatedManifest = FALSE; 332 BOOL fUpdatedManifest = FALSE;
333 333
334 hr = XmlLoadDocumentFromFile(wzConfigPath, &pixdManifest); 334 hr = XmlLoadDocumentFromFile(wzConfigPath, &pixdManifest);
335 ExitOnFailure(hr, "Failed to load bootstrapper config file from path: %ls", wzConfigPath); 335 BalExitOnFailure(hr, "Failed to load bootstrapper config file from path: %ls", wzConfigPath);
336 336
337 hr = XmlSelectNodes(pixdManifest, L"/configuration/wix.bootstrapper/host/supportedFramework", &pNodeList); 337 hr = XmlSelectNodes(pixdManifest, L"/configuration/wix.bootstrapper/host/supportedFramework", &pNodeList);
338 ExitOnFailure(hr, "Failed to select all supportedFramework elements."); 338 BalExitOnFailure(hr, "Failed to select all supportedFramework elements.");
339 339
340 hr = pNodeList->get_length(reinterpret_cast<long*>(&cSupportedFrameworks)); 340 hr = pNodeList->get_length(reinterpret_cast<long*>(&cSupportedFrameworks));
341 ExitOnFailure(hr, "Failed to get the supported framework count."); 341 BalExitOnFailure(hr, "Failed to get the supported framework count.");
342 342
343 if (cSupportedFrameworks) 343 if (cSupportedFrameworks)
344 { 344 {
345 while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, NULL))) 345 while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, NULL)))
346 { 346 {
347 hr = XmlGetAttributeEx(pNode, L"version", &sczSupportedFrameworkVersion); 347 hr = XmlGetAttributeEx(pNode, L"version", &sczSupportedFrameworkVersion);
348 ExitOnRequiredXmlQueryFailure(hr, "Failed to get supportedFramework/@version."); 348 BalExitOnRequiredXmlQueryFailure(hr, "Failed to get supportedFramework/@version.");
349 349
350 hr = StrAllocFormatted(&sczFrameworkRegistryKey, L"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\%ls", sczSupportedFrameworkVersion); 350 hr = StrAllocFormatted(&sczFrameworkRegistryKey, L"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\%ls", sczSupportedFrameworkVersion);
351 ExitOnFailure(hr, "Failed to allocate path to supported framework Install registry key."); 351 BalExitOnFailure(hr, "Failed to allocate path to supported framework Install registry key.");
352 352
353 hr = RegOpen(HKEY_LOCAL_MACHINE, sczFrameworkRegistryKey, KEY_READ, &hkFramework); 353 hr = RegOpen(HKEY_LOCAL_MACHINE, sczFrameworkRegistryKey, KEY_READ, &hkFramework);
354 if (SUCCEEDED(hr)) 354 if (SUCCEEDED(hr))
@@ -367,19 +367,18 @@ static HRESULT CheckSupportedFrameworks(
367 // If we looped through all the supported frameworks but didn't find anything, ensure we return a failure. 367 // If we looped through all the supported frameworks but didn't find anything, ensure we return a failure.
368 if (S_FALSE == hr) 368 if (S_FALSE == hr)
369 { 369 {
370 hr = E_NOTFOUND; 370 BalExitWithRootFailure(hr, E_NOTFOUND, "Failed to find a supported framework.");
371 ExitOnRootFailure(hr, "Failed to find a supported framework.");
372 } 371 }
373 372
374 hr = UpdateSupportedRuntime(pixdManifest, pNode, &fUpdatedManifest); 373 hr = UpdateSupportedRuntime(pixdManifest, pNode, &fUpdatedManifest);
375 ExitOnFailure(hr, "Failed to update supportedRuntime."); 374 BalExitOnFailure(hr, "Failed to update supportedRuntime.");
376 } 375 }
377 // else no supported frameworks specified, so the startup/supportedRuntime must be enough. 376 // else no supported frameworks specified, so the startup/supportedRuntime must be enough.
378 377
379 if (fUpdatedManifest) 378 if (fUpdatedManifest)
380 { 379 {
381 hr = XmlSaveDocument(pixdManifest, wzConfigPath); 380 hr = XmlSaveDocument(pixdManifest, wzConfigPath);
382 ExitOnFailure(hr, "Failed to save updated manifest over config file: %ls", wzConfigPath); 381 BalExitOnFailure(hr, "Failed to save updated manifest over config file: %ls", wzConfigPath);
383 } 382 }
384 383
385LExit: 384LExit:
@@ -410,7 +409,7 @@ static HRESULT UpdateSupportedRuntime(
410 409
411 // If the runtime version attribute is not specified, don't update the manifest. 410 // If the runtime version attribute is not specified, don't update the manifest.
412 hr = XmlGetAttributeEx(pixnSupportedFramework, L"runtimeVersion", &sczSupportedRuntimeVersion); 411 hr = XmlGetAttributeEx(pixnSupportedFramework, L"runtimeVersion", &sczSupportedRuntimeVersion);
413 ExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get supportedFramework/@runtimeVersion."); 412 BalExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get supportedFramework/@runtimeVersion.");
414 413
415 if (!fXmlFound) 414 if (!fXmlFound)
416 { 415 {
@@ -420,17 +419,17 @@ static HRESULT UpdateSupportedRuntime(
420 // Get the startup element. Fail if we can't find it since it'll be necessary to load the 419 // Get the startup element. Fail if we can't find it since it'll be necessary to load the
421 // correct runtime. 420 // correct runtime.
422 hr = XmlSelectSingleNode(pixdManifest, L"/configuration/startup", &pixnStartup); 421 hr = XmlSelectSingleNode(pixdManifest, L"/configuration/startup", &pixnStartup);
423 ExitOnRequiredXmlQueryFailure(hr, "Failed to get startup element."); 422 BalExitOnRequiredXmlQueryFailure(hr, "Failed to get startup element.");
424 423
425 // Remove any pre-existing supported runtimes because they'll just get in the way and create our new one. 424 // Remove any pre-existing supported runtimes because they'll just get in the way and create our new one.
426 hr = XmlRemoveChildren(pixnStartup, L"supportedRuntime"); 425 hr = XmlRemoveChildren(pixnStartup, L"supportedRuntime");
427 ExitOnFailure(hr, "Failed to remove pre-existing supportedRuntime elements."); 426 BalExitOnFailure(hr, "Failed to remove pre-existing supportedRuntime elements.");
428 427
429 hr = XmlCreateChild(pixnStartup, L"supportedRuntime", &pixnSupportedRuntime); 428 hr = XmlCreateChild(pixnStartup, L"supportedRuntime", &pixnSupportedRuntime);
430 ExitOnFailure(hr, "Failed to create supportedRuntime element."); 429 BalExitOnFailure(hr, "Failed to create supportedRuntime element.");
431 430
432 hr = XmlSetAttribute(pixnSupportedRuntime, L"version", sczSupportedRuntimeVersion); 431 hr = XmlSetAttribute(pixnSupportedRuntime, L"version", sczSupportedRuntimeVersion);
433 ExitOnFailure(hr, "Failed to set supportedRuntime/@version to '%ls'.", sczSupportedRuntimeVersion); 432 BalExitOnFailure(hr, "Failed to set supportedRuntime/@version to '%ls'.", sczSupportedRuntimeVersion);
434 433
435 *pfUpdatedManifest = TRUE; 434 *pfUpdatedManifest = TRUE;
436 435
@@ -465,14 +464,14 @@ static HRESULT LoadRuntime(
465 464
466 // Check that the supported framework is installed. 465 // Check that the supported framework is installed.
467 hr = CheckSupportedFrameworks(pState->sczConfigPath); 466 hr = CheckSupportedFrameworks(pState->sczConfigPath);
468 ExitOnFailure(hr, "Failed to find supported framework."); 467 BalExitOnFailure(hr, "Failed to find supported framework.");
469 468
470 // Cache the CLR host to be shutdown later. This can occur on a different thread. 469 // Cache the CLR host to be shutdown later. This can occur on a different thread.
471 // Disable message boxes from being displayed on error and blocking execution. 470 // Disable message boxes from being displayed on error and blocking execution.
472 ::SetErrorMode(uiMode | SEM_FAILCRITICALERRORS); 471 ::SetErrorMode(uiMode | SEM_FAILCRITICALERRORS);
473 472
474 hr = LoadSystemLibrary(L"mscoree.dll", &hModule); 473 hr = LoadSystemLibrary(L"mscoree.dll", &hModule);
475 ExitOnFailure(hr, "Failed to load mscoree.dll"); 474 BalExitOnFailure(hr, "Failed to load mscoree.dll");
476 475
477 pfnCLRCreateInstance = reinterpret_cast<CLRCreateInstanceFnPtr>(::GetProcAddress(hModule, "CLRCreateInstance")); 476 pfnCLRCreateInstance = reinterpret_cast<CLRCreateInstanceFnPtr>(::GetProcAddress(hModule, "CLRCreateInstance"));
478 477
@@ -481,7 +480,7 @@ static HRESULT LoadRuntime(
481 hr = pfnCLRCreateInstance(CLSID_CLRMetaHostPolicy, IID_ICLRMetaHostPolicy, reinterpret_cast<LPVOID*>(&pCLRMetaHostPolicy)); 480 hr = pfnCLRCreateInstance(CLSID_CLRMetaHostPolicy, IID_ICLRMetaHostPolicy, reinterpret_cast<LPVOID*>(&pCLRMetaHostPolicy));
482 if (E_NOTIMPL != hr) 481 if (E_NOTIMPL != hr)
483 { 482 {
484 ExitOnRootFailure(hr, "Failed to create instance of ICLRMetaHostPolicy."); 483 BalExitOnRootFailure(hr, "Failed to create instance of ICLRMetaHostPolicy.");
485 484
486 fFallbackToCorBindToCurrentRuntime = FALSE; 485 fFallbackToCorBindToCurrentRuntime = FALSE;
487 } 486 }
@@ -490,19 +489,19 @@ static HRESULT LoadRuntime(
490 if (fFallbackToCorBindToCurrentRuntime) 489 if (fFallbackToCorBindToCurrentRuntime)
491 { 490 {
492 pfnCorBindToCurrentRuntime = reinterpret_cast<PFN_CORBINDTOCURRENTRUNTIME>(::GetProcAddress(hModule, "CorBindToCurrentRuntime")); 491 pfnCorBindToCurrentRuntime = reinterpret_cast<PFN_CORBINDTOCURRENTRUNTIME>(::GetProcAddress(hModule, "CorBindToCurrentRuntime"));
493 ExitOnNullWithLastError(pfnCorBindToCurrentRuntime, hr, "Failed to get procedure address for CorBindToCurrentRuntime."); 492 BalExitOnNullWithLastError(pfnCorBindToCurrentRuntime, hr, "Failed to get procedure address for CorBindToCurrentRuntime.");
494 493
495 hr = pfnCorBindToCurrentRuntime(pState->sczConfigPath, CLSID_CorRuntimeHost, IID_ICorRuntimeHost, reinterpret_cast<LPVOID*>(&pState->pCLRHost)); 494 hr = pfnCorBindToCurrentRuntime(pState->sczConfigPath, CLSID_CorRuntimeHost, IID_ICorRuntimeHost, reinterpret_cast<LPVOID*>(&pState->pCLRHost));
496 ExitOnRootFailure(hr, "Failed to create the CLR host using the application configuration file path."); 495 BalExitOnRootFailure(hr, "Failed to create the CLR host using the application configuration file path.");
497 } 496 }
498 else 497 else
499 { 498 {
500 499
501 hr = SHCreateStreamOnFileEx(pState->sczConfigPath, STGM_READ | STGM_SHARE_DENY_WRITE, 0, FALSE, NULL, &pCfgStream); 500 hr = SHCreateStreamOnFileEx(pState->sczConfigPath, STGM_READ | STGM_SHARE_DENY_WRITE, 0, FALSE, NULL, &pCfgStream);
502 ExitOnFailure(hr, "Failed to load bootstrapper config file from path: %ls", pState->sczConfigPath); 501 BalExitOnFailure(hr, "Failed to load bootstrapper config file from path: %ls", pState->sczConfigPath);
503 502
504 hr = pCLRMetaHostPolicy->GetRequestedRuntime(METAHOST_POLICY_HIGHCOMPAT, NULL, pCfgStream, NULL, &cchVersion, NULL, NULL, &dwConfigFlags, IID_ICLRRuntimeInfo, reinterpret_cast<LPVOID*>(&pCLRRuntimeInfo)); 503 hr = pCLRMetaHostPolicy->GetRequestedRuntime(METAHOST_POLICY_HIGHCOMPAT, NULL, pCfgStream, NULL, &cchVersion, NULL, NULL, &dwConfigFlags, IID_ICLRRuntimeInfo, reinterpret_cast<LPVOID*>(&pCLRRuntimeInfo));
505 ExitOnRootFailure(hr, "Failed to get the CLR runtime info using the application configuration file path."); 504 BalExitOnRootFailure(hr, "Failed to get the CLR runtime info using the application configuration file path.");
506 505
507 // .NET 4 RTM had a bug where it wouldn't set pcchVersion if pwzVersion was NULL. 506 // .NET 4 RTM had a bug where it wouldn't set pcchVersion if pwzVersion was NULL.
508 if (!cchVersion) 507 if (!cchVersion)
@@ -510,7 +509,7 @@ static HRESULT LoadRuntime(
510 hr = pCLRRuntimeInfo->GetVersionString(NULL, &cchVersion); 509 hr = pCLRRuntimeInfo->GetVersionString(NULL, &cchVersion);
511 if (HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) != hr) 510 if (HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) != hr)
512 { 511 {
513 ExitOnFailure(hr, "Failed to get the length of the CLR version string."); 512 BalExitOnFailure(hr, "Failed to get the length of the CLR version string.");
514 } 513 }
515 } 514 }
516 515
@@ -523,21 +522,21 @@ static HRESULT LoadRuntime(
523 if (CSTR_EQUAL == CompareString(LOCALE_NEUTRAL, 0, L"v4.0.30319", -1, pwzVersion, cchVersion)) 522 if (CSTR_EQUAL == CompareString(LOCALE_NEUTRAL, 0, L"v4.0.30319", -1, pwzVersion, cchVersion))
524 { 523 {
525 hr = VerifyNET4RuntimeIsSupported(); 524 hr = VerifyNET4RuntimeIsSupported();
526 ExitOnFailure(hr, "Found unsupported .NET 4 Runtime."); 525 BalExitOnFailure(hr, "Found unsupported .NET 4 Runtime.");
527 } 526 }
528 527
529 if (METAHOST_CONFIG_FLAGS_LEGACY_V2_ACTIVATION_POLICY_TRUE == (METAHOST_CONFIG_FLAGS_LEGACY_V2_ACTIVATION_POLICY_MASK & dwConfigFlags)) 528 if (METAHOST_CONFIG_FLAGS_LEGACY_V2_ACTIVATION_POLICY_TRUE == (METAHOST_CONFIG_FLAGS_LEGACY_V2_ACTIVATION_POLICY_MASK & dwConfigFlags))
530 { 529 {
531 hr = pCLRRuntimeInfo->BindAsLegacyV2Runtime(); 530 hr = pCLRRuntimeInfo->BindAsLegacyV2Runtime();
532 ExitOnRootFailure(hr, "Failed to bind as legacy V2 runtime."); 531 BalExitOnRootFailure(hr, "Failed to bind as legacy V2 runtime.");
533 } 532 }
534 533
535 hr = pCLRRuntimeInfo->GetInterface(CLSID_CorRuntimeHost, IID_ICorRuntimeHost, reinterpret_cast<LPVOID*>(&pState->pCLRHost)); 534 hr = pCLRRuntimeInfo->GetInterface(CLSID_CorRuntimeHost, IID_ICorRuntimeHost, reinterpret_cast<LPVOID*>(&pState->pCLRHost));
536 ExitOnRootFailure(hr, "Failed to get instance of ICorRuntimeHost."); 535 BalExitOnRootFailure(hr, "Failed to get instance of ICorRuntimeHost.");
537 } 536 }
538 537
539 hr = pState->pCLRHost->Start(); 538 hr = pState->pCLRHost->Start();
540 ExitOnRootFailure(hr, "Failed to start the CLR host."); 539 BalExitOnRootFailure(hr, "Failed to start the CLR host.");
541 540
542LExit: 541LExit:
543 ReleaseStr(pwzVersion); 542 ReleaseStr(pwzVersion);
@@ -567,10 +566,10 @@ static HRESULT CreateManagedBootstrapperApplication(
567 IBootstrapperApplicationFactory* pAppFactory = NULL; 566 IBootstrapperApplicationFactory* pAppFactory = NULL;
568 567
569 hr = CreateManagedBootstrapperApplicationFactory(pAppDomain, &pAppFactory); 568 hr = CreateManagedBootstrapperApplicationFactory(pAppDomain, &pAppFactory);
570 ExitOnFailure(hr, "Failed to create the factory to create the bootstrapper application."); 569 BalExitOnFailure(hr, "Failed to create the factory to create the bootstrapper application.");
571 570
572 hr = pAppFactory->Create(pArgs, pResults); 571 hr = pAppFactory->Create(pArgs, pResults);
573 ExitOnFailure(hr, "Failed to create the bootstrapper application."); 572 BalExitOnFailure(hr, "Failed to create the bootstrapper application.");
574 573
575LExit: 574LExit:
576 ReleaseNullObject(pAppFactory); 575 ReleaseNullObject(pAppFactory);
@@ -593,20 +592,20 @@ static HRESULT CreateManagedBootstrapperApplicationFactory(
593 ::VariantInit(&vtBAFactory); 592 ::VariantInit(&vtBAFactory);
594 593
595 bstrAssemblyName = ::SysAllocString(MBA_ASSEMBLY_FULL_NAME); 594 bstrAssemblyName = ::SysAllocString(MBA_ASSEMBLY_FULL_NAME);
596 ExitOnNull(bstrAssemblyName, hr, E_OUTOFMEMORY, "Failed to allocate the full assembly name for the bootstrapper application factory."); 595 BalExitOnNull(bstrAssemblyName, hr, E_OUTOFMEMORY, "Failed to allocate the full assembly name for the bootstrapper application factory.");
597 596
598 bstrTypeName = ::SysAllocString(MBA_ENTRY_TYPE); 597 bstrTypeName = ::SysAllocString(MBA_ENTRY_TYPE);
599 ExitOnNull(bstrTypeName, hr, E_OUTOFMEMORY, "Failed to allocate the full type name for the BA factory."); 598 BalExitOnNull(bstrTypeName, hr, E_OUTOFMEMORY, "Failed to allocate the full type name for the BA factory.");
600 599
601 hr = pAppDomain->CreateInstance(bstrAssemblyName, bstrTypeName, &pObj); 600 hr = pAppDomain->CreateInstance(bstrAssemblyName, bstrTypeName, &pObj);
602 ExitOnRootFailure(hr, "Failed to create the BA factory object."); 601 BalExitOnRootFailure(hr, "Failed to create the BA factory object.");
603 602
604 hr = pObj->Unwrap(&vtBAFactory); 603 hr = pObj->Unwrap(&vtBAFactory);
605 ExitOnRootFailure(hr, "Failed to unwrap the BA factory object into the host domain."); 604 BalExitOnRootFailure(hr, "Failed to unwrap the BA factory object into the host domain.");
606 ExitOnNull(vtBAFactory.punkVal, hr, E_UNEXPECTED, "The variant did not contain the expected IUnknown pointer."); 605 BalExitOnNull(vtBAFactory.punkVal, hr, E_UNEXPECTED, "The variant did not contain the expected IUnknown pointer.");
607 606
608 hr = vtBAFactory.punkVal->QueryInterface(__uuidof(IBootstrapperApplicationFactory), reinterpret_cast<LPVOID*>(ppAppFactory)); 607 hr = vtBAFactory.punkVal->QueryInterface(__uuidof(IBootstrapperApplicationFactory), reinterpret_cast<LPVOID*>(ppAppFactory));
609 ExitOnRootFailure(hr, "Failed to query for the bootstrapper app factory interface."); 608 BalExitOnRootFailure(hr, "Failed to query for the bootstrapper app factory interface.");
610 609
611LExit: 610LExit:
612 ReleaseVariant(vtBAFactory); 611 ReleaseVariant(vtBAFactory);
@@ -632,13 +631,13 @@ static HRESULT CreatePrerequisiteBA(
632 BalExitOnFailure(hr, "Failed to get path to pre-requisite BA."); 631 BalExitOnFailure(hr, "Failed to get path to pre-requisite BA.");
633 632
634 hModule = ::LoadLibraryExW(sczMbapreqPath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); 633 hModule = ::LoadLibraryExW(sczMbapreqPath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
635 ExitOnNullWithLastError(hModule, hr, "Failed to load pre-requisite BA DLL."); 634 BalExitOnNullWithLastError(hModule, hr, "Failed to load pre-requisite BA DLL.");
636 635
637 PFN_PREQ_BOOTSTRAPPER_APPLICATION_CREATE pfnCreate = reinterpret_cast<PFN_PREQ_BOOTSTRAPPER_APPLICATION_CREATE>(::GetProcAddress(hModule, "PrereqBootstrapperApplicationCreate")); 636 PFN_PREQ_BOOTSTRAPPER_APPLICATION_CREATE pfnCreate = reinterpret_cast<PFN_PREQ_BOOTSTRAPPER_APPLICATION_CREATE>(::GetProcAddress(hModule, "PrereqBootstrapperApplicationCreate"));
638 ExitOnNullWithLastError(pfnCreate, hr, "Failed to get PrereqBootstrapperApplicationCreate entry-point from: %ls", sczMbapreqPath); 637 BalExitOnNullWithLastError(pfnCreate, hr, "Failed to get PrereqBootstrapperApplicationCreate entry-point from: %ls", sczMbapreqPath);
639 638
640 hr = pfnCreate(&pState->prereqData, pEngine, pArgs, pResults); 639 hr = pfnCreate(&pState->prereqData, pEngine, pArgs, pResults);
641 ExitOnFailure(hr, "Failed to create prequisite bootstrapper app."); 640 BalExitOnFailure(hr, "Failed to create prequisite bootstrapper app.");
642 641
643 pState->hMbapreqModule = hModule; 642 pState->hMbapreqModule = hModule;
644 hModule = NULL; 643 hModule = NULL;
@@ -672,14 +671,14 @@ static HRESULT VerifyNET4RuntimeIsSupported(
672 { 671 {
673 ExitFunction1(hr = S_OK); 672 ExitFunction1(hr = S_OK);
674 } 673 }
675 ExitOnFailure(hr, "Failed to open registry key for .NET 4."); 674 BalExitOnFailure(hr, "Failed to open registry key for .NET 4.");
676 675
677 er = ::RegQueryValueExW(hKey, L"Release", NULL, NULL, reinterpret_cast<LPBYTE>(&dwRelease), &cchRelease); 676 er = ::RegQueryValueExW(hKey, L"Release", NULL, NULL, reinterpret_cast<LPBYTE>(&dwRelease), &cchRelease);
678 if (ERROR_FILE_NOT_FOUND == er) 677 if (ERROR_FILE_NOT_FOUND == er)
679 { 678 {
680 ExitFunction1(hr = S_OK); 679 ExitFunction1(hr = S_OK);
681 } 680 }
682 ExitOnWin32Error(er, hr, "Failed to get Release value."); 681 BalExitOnWin32Error(er, hr, "Failed to get Release value.");
683 682
684 if (NET452_RELEASE <= dwRelease) 683 if (NET452_RELEASE <= dwRelease)
685 { 684 {
diff --git a/src/ext/Dependency/ca/wixdepca.cpp b/src/ext/Dependency/ca/wixdepca.cpp
index e9278e04..87610420 100644
--- a/src/ext/Dependency/ca/wixdepca.cpp
+++ b/src/ext/Dependency/ca/wixdepca.cpp
@@ -277,6 +277,7 @@ static HRESULT EnsureAbsentDependents(
277 DEPENDENCY* rgDependents = NULL; 277 DEPENDENCY* rgDependents = NULL;
278 UINT cDependents = 0; 278 UINT cDependents = 0;
279 PMSIHANDLE hDependencyRec = NULL; 279 PMSIHANDLE hDependencyRec = NULL;
280 BOOL fExists = FALSE;
280 281
281 // Skip the dependent check if the Wix4DependencyProvider table is missing (no dependency providers). 282 // Skip the dependent check if the Wix4DependencyProvider table is missing (no dependency providers).
282 hr = WcaTableExists(L"Wix4DependencyProvider"); 283 hr = WcaTableExists(L"Wix4DependencyProvider");
@@ -338,11 +339,7 @@ static HRESULT EnsureAbsentDependents(
338 339
339 // Check the registry to see if the provider has any dependents registered. 340 // Check the registry to see if the provider has any dependents registered.
340 hr = DepCheckDependents(hkHive, sczProviderKey, iAttributes, sdIgnoredDependents, &rgDependents, &cDependents); 341 hr = DepCheckDependents(hkHive, sczProviderKey, iAttributes, sdIgnoredDependents, &rgDependents, &cDependents);
341 if (E_FILENOTFOUND == hr) 342 ExitOnPathFailure(hr, fExists, "Failed dependents check for %ls.", sczId);
342 {
343 hr = S_OK;
344 }
345 ExitOnFailure(hr, "Failed dependents check for %ls.", sczId);
346 } 343 }
347 344
348 if (E_NOMOREITEMS != hr) 345 if (E_NOMOREITEMS != hr)
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: