Skip logging errors in some places when they are due to missing files or registry keys or values.
Related to 6696
Sean Hall committed
Aug 8, 2022 at 18:02 UTC
240b663ad5fc94ed6d19c966b5c9105a176ecf40
24 files changed
+438
-425
src/burn/engine/apply.cpp
+5
-11
@@ -611,7 +611,7 @@ extern "C" HRESULT ApplyCache(
611
ExitOnFailure(hr, "Failed cache action: %ls", L"layout bundle");
612
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
616
break;
617
@@ -637,7 +637,7 @@ extern "C" HRESULT ApplyCache(
637
ExitOnFailure(hr, "Failed cache action: %ls", L"cache package");
638
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
642
break;
643
@@ -1038,7 +1038,7 @@ static HRESULT ApplyCachePackage(
1038
}
1039
else if (fCanceledBegin)
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
}
1043
1044
break;
@@ -1796,8 +1796,7 @@ static HRESULT AcquireContainerOrPayload(
1796
1797
break;
1798
default:
1799
- hr = E_FILENOTFOUND;
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);
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
}
1801
1802
// Send 100% complete here. This is sometimes the only progress sent to the BA.
@@ -1965,17 +1964,12 @@ static HRESULT PreparePayloadDestinationPath(
1964
dwFileAttributes &= ~FILE_ATTRIBUTE_READONLY;
1965
if (!::SetFileAttributes(wzDestinationPath, dwFileAttributes))
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);
1968
}
1969
}
1970
}
1971
1972
LExit:
1974
- if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr)
1975
- {
1976
- hr = S_OK;
1977
- }
1978
-
1973
return hr;
1974
}
1975
src/burn/engine/bundlepackageengine.cpp
+6
-8
@@ -1049,6 +1049,7 @@ static HRESULT DetectArpEntry(
1049
{
1050
HRESULT hr = S_OK;
1051
HKEY hKey = NULL;
1052
+ BOOL fExists = FALSE;
1053
HKEY hkRoot = pPackage->fPerMachine ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
1054
REG_KEY_BITNESS keyBitness = pPackage->Bundle.fWin64 ? REG_KEY_64BIT : REG_KEY_32BIT;
1055
@@ -1065,20 +1066,17 @@ static HRESULT DetectArpEntry(
1066
}
1067
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)
1072
{
1070
- ExitFunction1(hr = S_OK);
1073
+ ExitFunction();
1074
}
1072
- ExitOnFailure(hr, "Failed to open registry key: %ls.", pPackage->Bundle.sczArpKeyPath);
1075
1076
*pfRegistered = TRUE;
1077
1078
hr = RegReadString(hKey, L"QuietUninstallString", psczQuietUninstallString);
1077
- if (HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) == hr)
1078
- {
1079
- hr = S_OK;
1080
- }
1081
- ExitOnFailure(hr, "Failed to read QuietUninstallString.");
1079
+ ExitOnPathFailure(hr, fExists, "Failed to read QuietUninstallString.");
1080
1081
LExit:
1082
ReleaseRegKey(hKey);
src/burn/engine/cache.cpp
+1
-2
@@ -1144,8 +1144,7 @@ extern "C" HRESULT CacheCompletePayload(
1144
}
1145
else // if the working path and unverified path do not exist, nothing we can do.
1146
{
1147
- hr = E_FILENOTFOUND;
1148
- ExitOnFailure(hr, "Failed to find payload: %ls in working path: %ls and unverified path: %ls", pPayload->sczKey, wzWorkingPayloadPath, sczUnverifiedPayloadPath);
1147
+ ExitWithRootFailure(hr, E_FILENOTFOUND, "Failed to find payload: %ls in working path: %ls and unverified path: %ls", pPayload->sczKey, wzWorkingPayloadPath, sczUnverifiedPayloadPath);
1148
}
1149
1150
hr = ResetPathPermissions(fPerMachine, sczUnverifiedPayloadPath);
src/burn/engine/dependency.cpp
+17
-27
@@ -279,19 +279,13 @@ extern "C" HRESULT DependencyDetectBundle(
279
)
280
{
281
HRESULT hr = S_OK;
282
+ BOOL fExists = FALSE;
283
284
hr = DependencyDetectProviderKeyBundleId(pRegistration);
285
ExitOnFailure(hr, "Failed to detect provider key bundle id.");
286
287
hr = DepCheckDependents(pRegistration->hkRoot, pRegistration->sczProviderKey, 0, NULL, &pRegistration->rgDependents, &pRegistration->cDependents);
287
- if (E_FILENOTFOUND != hr)
288
- {
289
- ExitOnFailure(hr, "Failed dependents check on bundle.");
290
- }
291
- else
292
- {
293
- hr = S_OK;
294
- }
288
+ ExitOnPathFailure(hr, fExists, "Failed dependents check on bundle.");
289
290
if (pDependencies->fSelfDependent || pDependencies->fActiveParent)
291
{
@@ -813,6 +807,7 @@ extern "C" HRESULT DependencyProcessDependentRegistration(
807
)
808
{
809
HRESULT hr = S_OK;
810
+ BOOL fDeleted = FALSE;
811
812
switch (pAction->type)
813
{
@@ -823,12 +818,11 @@ extern "C" HRESULT DependencyProcessDependentRegistration(
818
819
case BURN_DEPENDENT_REGISTRATION_ACTION_TYPE_UNREGISTER:
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);
822
break;
823
824
default:
830
- hr = E_INVALIDARG;
831
- ExitOnRootFailure(hr, "Unrecognized registration action type: %d", pAction->type);
825
+ ExitWithRootFailure(hr, E_INVALIDARG, "Unrecognized registration action type: %d", pAction->type);
826
}
827
828
LExit:
@@ -848,11 +842,11 @@ extern "C" void DependencyUnregisterBundle(
842
{
843
// Remove the bundle provider key.
844
hr = DepUnregisterDependency(pRegistration->hkRoot, pRegistration->sczProviderKey);
851
- if (SUCCEEDED(hr))
845
+ if (SUCCEEDED(hr) || E_FILENOTFOUND == hr)
846
{
847
LogId(REPORT_VERBOSE, MSG_DEPENDENCY_BUNDLE_UNREGISTERED, pRegistration->sczProviderKey);
848
}
855
- else if (FAILED(hr) && E_FILENOTFOUND != hr)
849
+ else
850
{
851
LogId(REPORT_VERBOSE, MSG_DEPENDENCY_BUNDLE_UNREGISTERED_FAILED, pRegistration->sczProviderKey, hr);
852
}
@@ -961,13 +955,10 @@ static HRESULT DetectPackageDependents(
955
for (DWORD i = 0; i < pPackage->cDependencyProviders; ++i)
956
{
957
BURN_DEPENDENCY_PROVIDER* pProvider = &pPackage->rgDependencyProviders[i];
958
+ BOOL fExists = FALSE;
959
960
hr = DepCheckDependents(hkHive, pProvider->sczKey, 0, NULL, &pProvider->rgDependents, &pProvider->cDependents);
966
- if (E_FILENOTFOUND == hr)
967
- {
968
- hr = S_OK;
969
- }
970
- ExitOnFailure(hr, "Failed dependents check on package provider: %ls", pProvider->sczKey);
961
+ ExitOnPathFailure(hr, fExists, "Failed dependents check on package provider: %ls", pProvider->sczKey);
962
963
if (0 < pProvider->cDependents || GetProviderExists(hkHive, pProvider->sczKey))
964
{
@@ -1366,11 +1357,11 @@ static void UnregisterPackageProvider(
1357
HRESULT hr = S_OK;
1358
1359
hr = DepUnregisterDependency(hkRoot, pProvider->sczKey);
1369
- if (SUCCEEDED(hr))
1360
+ if (SUCCEEDED(hr) || E_FILENOTFOUND == hr)
1361
{
1362
LogId(REPORT_VERBOSE, MSG_DEPENDENCY_PACKAGE_UNREGISTERED, pProvider->sczKey, wzPackageId);
1363
}
1373
- else if (FAILED(hr) && E_FILENOTFOUND != hr)
1364
+ else
1365
{
1366
LogId(REPORT_VERBOSE, MSG_DEPENDENCY_PACKAGE_UNREGISTERED_FAILED, pProvider->sczKey, wzPackageId, hr);
1367
}
@@ -1390,15 +1381,14 @@ static HRESULT RegisterPackageProviderDependent(
1381
)
1382
{
1383
HRESULT hr = S_OK;
1384
+ BOOL fExists = FALSE;
1385
1386
LogId(REPORT_VERBOSE, MSG_DEPENDENCY_PACKAGE_REGISTER_DEPENDENCY, wzDependentProviderKey, pProvider->sczKey, wzPackageId);
1387
1388
hr = DepRegisterDependent(hkRoot, pProvider->sczKey, wzDependentProviderKey, NULL, NULL, 0);
1397
- if (E_FILENOTFOUND != hr)
1398
- {
1399
- ExitOnFailure(hr, "Failed to register the dependency on package dependency provider: %ls", pProvider->sczKey);
1400
- }
1401
- else
1389
+ ExitOnPathFailure(hr, fExists, "Failed to register the dependency on package dependency provider: %ls", pProvider->sczKey);
1390
+
1391
+ if (!fExists)
1392
{
1393
LogId(REPORT_VERBOSE, MSG_DEPENDENCY_PACKAGE_SKIP_MISSING, pProvider->sczKey, wzPackageId);
1394
}
@@ -1454,11 +1444,11 @@ static void UnregisterPackageProviderDependent(
1444
HRESULT hr = S_OK;
1445
1446
hr = DepUnregisterDependent(hkRoot, pProvider->sczKey, wzDependentProviderKey);
1457
- if (SUCCEEDED(hr))
1447
+ if (SUCCEEDED(hr) || E_FILENOTFOUND == hr)
1448
{
1449
LogId(REPORT_VERBOSE, MSG_DEPENDENCY_PACKAGE_UNREGISTERED_DEPENDENCY, wzDependentProviderKey, pProvider->sczKey, wzPackageId);
1450
}
1461
- else if (FAILED(hr) && E_FILENOTFOUND != hr)
1451
+ else
1452
{
1453
LogId(REPORT_VERBOSE, MSG_DEPENDENCY_PACKAGE_UNREGISTERED_DEPENDENCY_FAILED, wzDependentProviderKey, pProvider->sczKey, wzPackageId, hr);
1454
}
src/burn/engine/exeengine.cpp
+10
-11
@@ -1040,6 +1040,7 @@ static HRESULT DetectArpEntry(
1040
{
1041
HRESULT hr = S_OK;
1042
HKEY hKey = NULL;
1043
+ BOOL fExists = FALSE;
1044
VERUTIL_VERSION* pVersion = NULL;
1045
int nCompareResult = 0;
1046
HKEY hkRoot = pPackage->fPerMachine ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
@@ -1052,18 +1053,20 @@ static HRESULT DetectArpEntry(
1053
}
1054
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)
1059
{
1057
- ExitFunction1(hr = S_OK);
1060
+ ExitFunction();
1061
}
1059
- ExitOnFailure(hr, "Failed to open registry key: %ls.", pPackage->Exe.sczArpKeyPath);
1062
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)
1067
{
1064
- ExitFunction1(hr = S_OK);
1068
+ ExitFunction();
1069
}
1066
- ExitOnFailure(hr, "Failed to read DisplayVersion.");
1070
1071
if (pVersion->fInvalid)
1072
{
@@ -1089,11 +1092,7 @@ static HRESULT DetectArpEntry(
1092
if (psczQuietUninstallString)
1093
{
1094
hr = RegReadString(hKey, L"QuietUninstallString", psczQuietUninstallString);
1092
- if (HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) == hr)
1093
- {
1094
- hr = S_OK;
1095
- }
1096
- ExitOnFailure(hr, "Failed to read QuietUninstallString.");
1095
+ ExitOnPathFailure(hr, fExists, "Failed to read QuietUninstallString.");
1096
}
1097
1098
LExit:
src/burn/engine/registration.cpp
+17
-15
@@ -492,25 +492,28 @@ extern "C" HRESULT RegistrationDetectResumeType(
492
{
493
HRESULT hr = S_OK;
494
HKEY hkRegistration = NULL;
495
+ BOOL fExists = FALSE;
496
DWORD dwResume = 0;
497
498
// open registration key
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)
503
{
504
*pResumeType = BOOTSTRAPPER_RESUME_TYPE_NONE;
502
- ExitFunction1(hr = S_OK);
505
+ ExitFunction();
506
}
504
- ExitOnFailure(hr, "Failed to open registration key.");
507
508
// read Resume value
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)
513
{
514
*pResumeType = BOOTSTRAPPER_RESUME_TYPE_INVALID;
511
- ExitFunction1(hr = S_OK);
515
+ ExitFunction();
516
}
513
- ExitOnFailure(hr, "Failed to read Resume value.");
517
518
switch (dwResume)
519
{
@@ -855,6 +858,7 @@ extern "C" HRESULT RegistrationSessionEnd(
858
{
859
HRESULT hr = S_OK;
860
HKEY hkRegistration = NULL;
861
+ BOOL fDeleted = FALSE;
862
863
// If no resume mode, then remove the bundle registration.
864
if (BURN_RESUME_MODE_NONE == resumeMode)
@@ -874,10 +878,7 @@ extern "C" HRESULT RegistrationSessionEnd(
878
879
// Delete registration key.
880
hr = RegDelete(pRegistration->hkRoot, pRegistration->sczRegistrationKey, REG_KEY_DEFAULT, TRUE);
877
- if (E_FILENOTFOUND != hr)
878
- {
879
- ExitOnFailure(hr, "Failed to delete registration key: %ls", pRegistration->sczRegistrationKey);
880
- }
881
+ ExitOnPathFailure(hr, fDeleted, "Failed to delete registration key: %ls", pRegistration->sczRegistrationKey);
882
883
CacheRemoveBundle(pCache, pRegistration->fPerMachine, pRegistration->sczId);
884
}
@@ -967,7 +968,10 @@ extern "C" HRESULT RegistrationSaveState(
968
ExitOnFailure(hr, "Failed to enumerate value %u", i);
969
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
+ }
975
}
976
977
// Write variables.
@@ -1486,6 +1490,7 @@ static HRESULT RemoveUpdateRegistration(
1490
LPWSTR sczPackageVersion = NULL;
1491
HKEY hkKey = NULL;
1492
BOOL fDeleteRegKey = TRUE;
1493
+ BOOL fDeleted = FALSE;
1494
1495
hr = FormatUpdateRegistrationKey(pRegistration, &sczKey);
1496
ExitOnFailure(hr, "Failed to format key for update registration.");
@@ -1513,10 +1518,7 @@ static HRESULT RemoveUpdateRegistration(
1518
if (fDeleteRegKey)
1519
{
1520
hr = RegDelete(pRegistration->hkRoot, sczKey, REG_KEY_DEFAULT, FALSE);
1516
- if (E_FILENOTFOUND != hr)
1517
- {
1518
- ExitOnFailure(hr, "Failed to remove update registration key: %ls", sczKey);
1519
- }
1521
+ ExitOnPathFailure(hr, fDeleted, "Failed to remove update registration key: %ls", sczKey);
1522
}
1523
1524
LExit:
src/burn/engine/relatedbundle.cpp
+4
-13
@@ -322,6 +322,7 @@ static HRESULT LoadRelatedBundleFromKey(
322
LPWSTR sczCachePath = NULL;
323
BOOL fCached = FALSE;
324
DWORD64 qwFileSize = 0;
325
+ BOOL fExists = FALSE;
326
BURN_DEPENDENCY_PROVIDER dependencyProvider = { };
327
BURN_DEPENDENCY_PROVIDER* pBundleDependencyProvider = NULL;
328
@@ -369,10 +370,7 @@ static HRESULT LoadRelatedBundleFromKey(
370
pRelatedBundle->fPlannable = fCached;
371
372
hr = RegReadString(hkBundleId, BURN_REGISTRATION_REGISTRY_BUNDLE_PROVIDER_KEY, &dependencyProvider.sczKey);
372
- if (E_FILENOTFOUND != hr)
373
- {
374
- ExitOnFailure(hr, "Failed to read provider key from registry for bundle: %ls", wzRelatedBundleId);
375
- }
373
+ ExitOnPathFailure(hr, fExists, "Failed to read provider key from registry for bundle: %ls", wzRelatedBundleId);
374
375
if (dependencyProvider.sczKey && *dependencyProvider.sczKey)
376
{
@@ -384,18 +382,11 @@ static HRESULT LoadRelatedBundleFromKey(
382
ExitOnFailure(hr, "Failed to copy version for bundle: %ls", wzRelatedBundleId);
383
384
hr = RegReadString(hkBundleId, BURN_REGISTRATION_REGISTRY_BUNDLE_DISPLAY_NAME, &dependencyProvider.sczDisplayName);
387
- if (E_FILENOTFOUND != hr)
388
- {
389
- ExitOnFailure(hr, "Failed to copy display name for bundle: %ls", wzRelatedBundleId);
390
- }
385
+ ExitOnPathFailure(hr, fExists, "Failed to copy display name for bundle: %ls", wzRelatedBundleId);
386
}
387
388
hr = RegReadString(hkBundleId, BURN_REGISTRATION_REGISTRY_BUNDLE_TAG, &pRelatedBundle->sczTag);
394
- if (E_FILENOTFOUND == hr)
395
- {
396
- hr = S_OK;
397
- }
398
- ExitOnFailure(hr, "Failed to read tag from registry for bundle: %ls", wzRelatedBundleId);
389
+ ExitOnPathFailure(hr, fExists, "Failed to read tag from registry for bundle: %ls", wzRelatedBundleId);
390
391
pRelatedBundle->detectRelationType = relationType;
392
src/burn/engine/search.cpp
+40
-49
@@ -610,6 +610,7 @@ static HRESULT DirectorySearchExists(
610
)
611
{
612
HRESULT hr = S_OK;
613
+ DWORD er = ERROR_SUCCESS;
614
LPWSTR sczPath = NULL;
615
BOOL fExists = FALSE;
616
@@ -629,21 +630,25 @@ static HRESULT DirectorySearchExists(
630
DWORD dwAttributes = ::GetFileAttributesW(sczPath);
631
if (INVALID_FILE_ATTRIBUTES == dwAttributes)
632
{
632
- hr = HRESULT_FROM_WIN32(::GetLastError());
633
- if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr)
633
+ er = ::GetLastError();
634
+ if (ERROR_FILE_NOT_FOUND == er || ERROR_PATH_NOT_FOUND == er)
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);
641
}
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
648
{
649
fExists = TRUE;
650
}
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
-
652
// set variable
653
hr = VariableSetNumeric(pVariables, pSearch->sczVariable, fExists, FALSE);
654
ExitOnFailure(hr, "Failed to set variable.");
@@ -694,13 +699,12 @@ static HRESULT DirectorySearchPath(
699
hr = E_PATHNOTFOUND;
700
}
701
697
- // What if there is a hidden variable in sczPath?
702
if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr)
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);
705
ExitFunction1(hr = S_OK);
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);
708
709
LExit:
710
#if !defined(_WIN64)
@@ -742,15 +746,18 @@ static HRESULT FileSearchExists(
746
er = ::GetLastError();
747
if (ERROR_FILE_NOT_FOUND == er || ERROR_PATH_NOT_FOUND == er)
748
{
745
- // What if there is a hidden variable in sczPath?
746
- LogStringLine(REPORT_STANDARD, "File search: %ls, did not find path: %ls", pSearch->sczKey, sczPath);
749
+ LogStringLine(REPORT_STANDARD, "File search: %ls, did not find path: %ls", pSearch->sczKey, pSearch->FileSearch.sczPath);
750
}
751
else
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);
754
}
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
761
{
762
fExists = TRUE;
763
}
@@ -795,8 +802,7 @@ static HRESULT FileSearchVersion(
802
hr = FileVersion(sczPath, &uliVersion.HighPart, &uliVersion.LowPart);
803
if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr)
804
{
798
- // What if there is a hidden variable in sczPath?
799
- LogStringLine(REPORT_STANDARD, "File search: %ls, did not find path: %ls", pSearch->sczKey, sczPath);
805
+ LogStringLine(REPORT_STANDARD, "File search: %ls, did not find path: %ls", pSearch->sczKey, pSearch->FileSearch.sczPath);
806
ExitFunction1(hr = S_OK);
807
}
808
ExitOnFailure(hr, "Failed to get file version.");
@@ -854,13 +860,12 @@ static HRESULT FileSearchPath(
860
ExitOnFailure(hr, "Failed to set variable to file search path.");
861
}
862
857
- // What if there is a hidden variable in sczPath?
863
if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr)
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);
866
ExitFunction1(hr = S_OK);
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);
869
870
LExit:
871
#if !defined(_WIN64)
@@ -891,24 +896,13 @@ static HRESULT RegistrySearchExists(
896
897
// open key
898
hr = RegOpenEx(pSearch->RegistrySearch.hRoot, sczKey, KEY_QUERY_VALUE, pSearch->RegistrySearch.fWin64 ? REG_KEY_64BIT : REG_KEY_32BIT, &hKey);
894
- if (SUCCEEDED(hr))
895
- {
896
- fExists = TRUE;
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
899
+ ExitOnPathFailure(hr, fExists, "Failed to open registry key. Key = '%ls'", pSearch->RegistrySearch.sczKey);
900
+
901
+ if (!fExists)
902
{
907
- // What if there is a hidden variable in sczKey?
908
- ExitOnFailure(hr, "Failed to open registry key. Key = '%ls'", sczKey);
903
+ LogStringLine(REPORT_STANDARD, "Registry key not found. Key = '%ls'", pSearch->RegistrySearch.sczKey);
904
}
910
-
911
- if (fExists && pSearch->RegistrySearch.sczValue)
905
+ else if (pSearch->RegistrySearch.sczValue)
906
{
907
// format value string
908
hr = VariableFormatString(pVariables, pSearch->RegistrySearch.sczValue, &sczValue, NULL);
@@ -922,8 +916,7 @@ static HRESULT RegistrySearchExists(
916
fExists = TRUE;
917
break;
918
case ERROR_FILE_NOT_FOUND:
925
- // What if there is a hidden variable in sczKey or sczValue?
926
- LogStringLine(REPORT_STANDARD, "Registry value not found. Key = '%ls', Value = '%ls'", sczKey, sczValue);
919
+ LogStringLine(REPORT_STANDARD, "Registry value not found. Key = '%ls', Value = '%ls'", pSearch->RegistrySearch.sczKey, pSearch->RegistrySearch.sczValue);
920
fExists = FALSE;
921
break;
922
default:
@@ -938,8 +931,7 @@ static HRESULT RegistrySearchExists(
931
LExit:
932
if (FAILED(hr))
933
{
941
- // What if there is a hidden variable in sczKey?
942
- LogStringLine(REPORT_STANDARD, "RegistrySearchExists failed: ID '%ls', HRESULT 0x%x", sczKey, hr);
934
+ LogStringLine(REPORT_STANDARD, "RegistrySearchExists failed: ID '%ls', HRESULT 0x%x", pSearch->sczKey, hr);
935
}
936
937
StrSecureZeroFreeString(sczKey);
@@ -958,6 +950,7 @@ static HRESULT RegistrySearchValue(
950
LPWSTR sczKey = NULL;
951
LPWSTR sczValue = NULL;
952
HKEY hKey = NULL;
953
+ BOOL fExists = FALSE;
954
DWORD dwType = 0;
955
SIZE_T cbData = 0;
956
LPBYTE pData = NULL;
@@ -978,21 +971,20 @@ static HRESULT RegistrySearchValue(
971
972
// open key
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)
977
{
983
- // What if there is a hidden variable in sczKey?
984
- LogStringLine(REPORT_STANDARD, "Registry key not found. Key = '%ls'", sczKey);
978
+ LogStringLine(REPORT_STANDARD, "Registry key not found. Key = '%ls'", pSearch->RegistrySearch.sczKey);
979
986
- ExitFunction1(hr = S_OK);
980
+ ExitFunction();
981
}
988
- ExitOnFailure(hr, "Failed to open registry key.");
982
983
// get value
984
hr = RegReadValue(hKey, sczValue, pSearch->RegistrySearch.fExpandEnvironment, &pData, &cbData, &dwType);
985
if (E_FILENOTFOUND == hr)
986
{
994
- // What if there is a hidden variable in sczKey or sczValue?
995
- LogStringLine(REPORT_STANDARD, "Registry value not found. Key = '%ls', Value = '%ls'", sczKey, sczValue);
987
+ LogStringLine(REPORT_STANDARD, "Registry value not found. Key = '%ls', Value = '%ls'", pSearch->RegistrySearch.sczKey, pSearch->RegistrySearch.sczValue);
988
989
ExitFunction1(hr = S_OK);
990
}
@@ -1034,8 +1026,7 @@ static HRESULT RegistrySearchValue(
1026
LExit:
1027
if (FAILED(hr))
1028
{
1037
- // What if there is a hidden variable in sczKey?
1038
- LogStringLine(REPORT_STANDARD, "RegistrySearchValue failed: ID '%ls', HRESULT 0x%x", sczKey, hr);
1029
+ LogStringLine(REPORT_STANDARD, "RegistrySearchValue failed: ID '%ls', HRESULT 0x%x", pSearch->sczKey, hr);
1030
}
1031
1032
StrSecureZeroFreeString(sczKey);
src/ext/Bal/dnchost/dncutil.cpp
+1
-1
@@ -338,7 +338,7 @@ static HRESULT InitializeCoreClrPre5(
338
{
339
BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "%ls: %ls", rgPropertyKeys[i], rgPropertyValues[i]);
340
}
341
- BalExitOnFailure(hr = E_FILENOTFOUND, "Failed to locate coreclr.dll.");
341
+ BalExitWithRootFailure(hr, E_FILENOTFOUND, "Failed to locate coreclr.dll.");
342
}
343
344
hr = LoadCoreClr(pState, sczCoreClrPath);
src/ext/Bal/mbahost/mbahost.cpp
+49
-50
@@ -228,31 +228,31 @@ static HRESULT GetAppDomain(
228
229
// Create the setup information for a new AppDomain to set the app base and config.
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
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);
236
237
// Set properties on the AppDomainSetup object.
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
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
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
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
250
// Create the AppDomain to load the factory type.
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
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
257
LExit:
258
ReleaseBSTR(bstrConfigPath);
@@ -270,13 +270,13 @@ static HRESULT LoadModulePaths(
270
LPWSTR sczFullPath = NULL;
271
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
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
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
281
LExit:
282
ReleaseStr(sczFullPath);
@@ -332,23 +332,23 @@ static HRESULT CheckSupportedFrameworks(
332
BOOL fUpdatedManifest = FALSE;
333
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
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
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
343
if (cSupportedFrameworks)
344
{
345
while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, NULL)))
346
{
347
hr = XmlGetAttributeEx(pNode, L"version", &sczSupportedFrameworkVersion);
348
- ExitOnRequiredXmlQueryFailure(hr, "Failed to get supportedFramework/@version.");
348
+ BalExitOnRequiredXmlQueryFailure(hr, "Failed to get supportedFramework/@version.");
349
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
353
hr = RegOpen(HKEY_LOCAL_MACHINE, sczFrameworkRegistryKey, KEY_READ, &hkFramework);
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.
368
if (S_FALSE == hr)
369
{
370
- hr = E_NOTFOUND;
371
- ExitOnRootFailure(hr, "Failed to find a supported framework.");
370
+ BalExitWithRootFailure(hr, E_NOTFOUND, "Failed to find a supported framework.");
371
}
372
373
hr = UpdateSupportedRuntime(pixdManifest, pNode, &fUpdatedManifest);
375
- ExitOnFailure(hr, "Failed to update supportedRuntime.");
374
+ BalExitOnFailure(hr, "Failed to update supportedRuntime.");
375
}
376
// else no supported frameworks specified, so the startup/supportedRuntime must be enough.
377
378
if (fUpdatedManifest)
379
{
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);
382
}
383
384
LExit:
@@ -410,7 +409,7 @@ static HRESULT UpdateSupportedRuntime(
409
410
// If the runtime version attribute is not specified, don't update the manifest.
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.");
413
414
if (!fXmlFound)
415
{
@@ -420,17 +419,17 @@ static HRESULT UpdateSupportedRuntime(
419
// Get the startup element. Fail if we can't find it since it'll be necessary to load the
420
// correct runtime.
421
hr = XmlSelectSingleNode(pixdManifest, L"/configuration/startup", &pixnStartup);
423
- ExitOnRequiredXmlQueryFailure(hr, "Failed to get startup element.");
422
+ BalExitOnRequiredXmlQueryFailure(hr, "Failed to get startup element.");
423
424
// Remove any pre-existing supported runtimes because they'll just get in the way and create our new one.
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.");
427
428
hr = XmlCreateChild(pixnStartup, L"supportedRuntime", &pixnSupportedRuntime);
430
- ExitOnFailure(hr, "Failed to create supportedRuntime element.");
429
+ BalExitOnFailure(hr, "Failed to create supportedRuntime element.");
430
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);
433
434
*pfUpdatedManifest = TRUE;
435
@@ -465,14 +464,14 @@ static HRESULT LoadRuntime(
464
465
// Check that the supported framework is installed.
466
hr = CheckSupportedFrameworks(pState->sczConfigPath);
468
- ExitOnFailure(hr, "Failed to find supported framework.");
467
+ BalExitOnFailure(hr, "Failed to find supported framework.");
468
469
// Cache the CLR host to be shutdown later. This can occur on a different thread.
470
// Disable message boxes from being displayed on error and blocking execution.
471
::SetErrorMode(uiMode | SEM_FAILCRITICALERRORS);
472
473
hr = LoadSystemLibrary(L"mscoree.dll", &hModule);
475
- ExitOnFailure(hr, "Failed to load mscoree.dll");
474
+ BalExitOnFailure(hr, "Failed to load mscoree.dll");
475
476
pfnCLRCreateInstance = reinterpret_cast<CLRCreateInstanceFnPtr>(::GetProcAddress(hModule, "CLRCreateInstance"));
477
@@ -481,7 +480,7 @@ static HRESULT LoadRuntime(
480
hr = pfnCLRCreateInstance(CLSID_CLRMetaHostPolicy, IID_ICLRMetaHostPolicy, reinterpret_cast<LPVOID*>(&pCLRMetaHostPolicy));
481
if (E_NOTIMPL != hr)
482
{
484
- ExitOnRootFailure(hr, "Failed to create instance of ICLRMetaHostPolicy.");
483
+ BalExitOnRootFailure(hr, "Failed to create instance of ICLRMetaHostPolicy.");
484
485
fFallbackToCorBindToCurrentRuntime = FALSE;
486
}
@@ -490,19 +489,19 @@ static HRESULT LoadRuntime(
489
if (fFallbackToCorBindToCurrentRuntime)
490
{
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.");
493
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.");
496
}
497
else
498
{
499
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);
502
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.");
505
506
// .NET 4 RTM had a bug where it wouldn't set pcchVersion if pwzVersion was NULL.
507
if (!cchVersion)
@@ -510,7 +509,7 @@ static HRESULT LoadRuntime(
509
hr = pCLRRuntimeInfo->GetVersionString(NULL, &cchVersion);
510
if (HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) != hr)
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.");
513
}
514
}
515
@@ -523,21 +522,21 @@ static HRESULT LoadRuntime(
522
if (CSTR_EQUAL == CompareString(LOCALE_NEUTRAL, 0, L"v4.0.30319", -1, pwzVersion, cchVersion))
523
{
524
hr = VerifyNET4RuntimeIsSupported();
526
- ExitOnFailure(hr, "Found unsupported .NET 4 Runtime.");
525
+ BalExitOnFailure(hr, "Found unsupported .NET 4 Runtime.");
526
}
527
528
if (METAHOST_CONFIG_FLAGS_LEGACY_V2_ACTIVATION_POLICY_TRUE == (METAHOST_CONFIG_FLAGS_LEGACY_V2_ACTIVATION_POLICY_MASK & dwConfigFlags))
529
{
530
hr = pCLRRuntimeInfo->BindAsLegacyV2Runtime();
532
- ExitOnRootFailure(hr, "Failed to bind as legacy V2 runtime.");
531
+ BalExitOnRootFailure(hr, "Failed to bind as legacy V2 runtime.");
532
}
533
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.");
536
}
537
538
hr = pState->pCLRHost->Start();
540
- ExitOnRootFailure(hr, "Failed to start the CLR host.");
539
+ BalExitOnRootFailure(hr, "Failed to start the CLR host.");
540
541
LExit:
542
ReleaseStr(pwzVersion);
@@ -567,10 +566,10 @@ static HRESULT CreateManagedBootstrapperApplication(
566
IBootstrapperApplicationFactory* pAppFactory = NULL;
567
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.");
570
571
hr = pAppFactory->Create(pArgs, pResults);
573
- ExitOnFailure(hr, "Failed to create the bootstrapper application.");
572
+ BalExitOnFailure(hr, "Failed to create the bootstrapper application.");
573
574
LExit:
575
ReleaseNullObject(pAppFactory);
@@ -593,20 +592,20 @@ static HRESULT CreateManagedBootstrapperApplicationFactory(
592
::VariantInit(&vtBAFactory);
593
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.");
596
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.");
599
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.");
602
603
hr = pObj->Unwrap(&vtBAFactory);
605
- ExitOnRootFailure(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.");
604
+ BalExitOnRootFailure(hr, "Failed to unwrap the BA factory object into the host domain.");
605
+ BalExitOnNull(vtBAFactory.punkVal, hr, E_UNEXPECTED, "The variant did not contain the expected IUnknown pointer.");
606
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.");
609
610
LExit:
611
ReleaseVariant(vtBAFactory);
@@ -632,13 +631,13 @@ static HRESULT CreatePrerequisiteBA(
631
BalExitOnFailure(hr, "Failed to get path to pre-requisite BA.");
632
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.");
635
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);
638
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.");
641
642
pState->hMbapreqModule = hModule;
643
hModule = NULL;
@@ -672,14 +671,14 @@ static HRESULT VerifyNET4RuntimeIsSupported(
671
{
672
ExitFunction1(hr = S_OK);
673
}
675
- ExitOnFailure(hr, "Failed to open registry key for .NET 4.");
674
+ BalExitOnFailure(hr, "Failed to open registry key for .NET 4.");
675
676
er = ::RegQueryValueExW(hKey, L"Release", NULL, NULL, reinterpret_cast<LPBYTE>(&dwRelease), &cchRelease);
677
if (ERROR_FILE_NOT_FOUND == er)
678
{
679
ExitFunction1(hr = S_OK);
680
}
682
- ExitOnWin32Error(er, hr, "Failed to get Release value.");
681
+ BalExitOnWin32Error(er, hr, "Failed to get Release value.");
682
683
if (NET452_RELEASE <= dwRelease)
684
{
src/ext/Dependency/ca/wixdepca.cpp
+2
-5
@@ -277,6 +277,7 @@ static HRESULT EnsureAbsentDependents(
277
DEPENDENCY* rgDependents = NULL;
278
UINT cDependents = 0;
279
PMSIHANDLE hDependencyRec = NULL;
280
+ BOOL fExists = FALSE;
281
282
// Skip the dependent check if the Wix4DependencyProvider table is missing (no dependency providers).
283
hr = WcaTableExists(L"Wix4DependencyProvider");
@@ -338,11 +339,7 @@ static HRESULT EnsureAbsentDependents(
339
340
// Check the registry to see if the provider has any dependents registered.
341
hr = DepCheckDependents(hkHive, sczProviderKey, iAttributes, sdIgnoredDependents, &rgDependents, &cDependents);
341
- if (E_FILENOTFOUND == hr)
342
- {
343
- hr = S_OK;
344
- }
345
- ExitOnFailure(hr, "Failed dependents check for %ls.", sczId);
342
+ ExitOnPathFailure(hr, fExists, "Failed dependents check for %ls.", sczId);
343
}
344
345
if (E_NOMOREITEMS != hr)
src/libs/dutil/WixToolset.DUtil/butil.cpp
+45
-82
@@ -15,6 +15,7 @@
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__)
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__)
19
20
// constants
21
// From engine/registration.h
@@ -82,19 +83,6 @@ static HRESULT LocateAndQueryBundleValue(
83
__inout DWORD* pdwType,
84
__out INTERNAL_BUNDLE_STATUS* pStatus
85
);
85
-
86
-/********************************************************************
87
-OpenBundleKey - Opens the bundle uninstallation key for a given bundle
88
-
89
-NOTE: caller is responsible for closing key
90
-********************************************************************/
91
-static 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
- );
86
static HRESULT CopyStringToBuffer(
87
__in_z LPWSTR wzValue,
88
__in_z_opt LPWSTR wzBuffer,
@@ -389,12 +377,12 @@ DAPI_(HRESULT) BundleQueryRelatedBundles(
377
queryContext.regBitness = REG_KEY_32BIT;
378
379
hr = QueryRelatedBundlesForScopeAndBitness(&queryContext);
392
- ExitOnFailure(hr, "Failed to query 32-bit related bundles.");
380
+ ButilExitOnFailure(hr, "Failed to query 32-bit related bundles.");
381
382
queryContext.regBitness = REG_KEY_64BIT;
383
384
hr = QueryRelatedBundlesForScopeAndBitness(&queryContext);
397
- ExitOnFailure(hr, "Failed to query 64-bit related bundles.");
385
+ ButilExitOnFailure(hr, "Failed to query 64-bit related bundles.");
386
387
LExit:
388
return hr;
@@ -407,15 +395,17 @@ static HRESULT QueryRelatedBundlesForScopeAndBitness(
395
HRESULT hr = S_OK;
396
HKEY hkRoot = BUNDLE_INSTALL_CONTEXT_USER == pQueryContext->installContext ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
397
HKEY hkUninstallKey = NULL;
398
+ BOOL fExists = FALSE;
399
LPWSTR sczRelatedBundleId = NULL;
400
BUNDLE_QUERY_CALLBACK_RESULT result = BUNDLE_QUERY_CALLBACK_RESULT_CONTINUE;
401
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)
406
{
407
ExitFunction1(hr = S_OK);
408
}
418
- ExitOnFailure(hr, "Failed to open uninstall registry key.");
409
410
for (DWORD dwIndex = 0; /* exit via break below */; ++dwIndex)
411
{
@@ -425,7 +415,7 @@ static HRESULT QueryRelatedBundlesForScopeAndBitness(
415
hr = S_OK;
416
break;
417
}
428
- ExitOnFailure(hr, "Failed to enumerate uninstall key for related bundles.");
418
+ ButilExitOnFailure(hr, "Failed to enumerate uninstall key for related bundles.");
419
420
// Ignore failures here since we'll often find products that aren't actually
421
// related bundles (or even bundles at all).
@@ -456,7 +446,7 @@ static HRESULT QueryPotentialRelatedBundle(
446
BUNDLE_QUERY_RELATED_BUNDLE_RESULT bundle = { };
447
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);
450
451
hr = DetermineRelationType(pQueryContext, hkBundleId, &relationType);
452
if (FAILED(hr))
@@ -506,7 +496,7 @@ static HRESULT DetermineRelationType(
496
TraceError(hr, "Failed to read upgrade codes as REG_MULTI_SZ. Trying again as REG_SZ in case of older bundles.");
497
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.");
500
501
hr = RegReadString(hkBundleId, BUNDLE_REGISTRATION_REGISTRY_BUNDLE_UPGRADE_CODE, &rgsczUpgradeCodes[0]);
502
if (SUCCEEDED(hr))
@@ -519,7 +509,7 @@ static HRESULT DetermineRelationType(
509
if (SUCCEEDED(hr))
510
{
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");
513
514
// Upgrade relationship: when their upgrade codes match our upgrade codes.
515
hr = DictCompareStringListToArray(sdUpgradeCodes, const_cast<LPCWSTR*>(pQueryContext->rgwzUpgradeCodes), pQueryContext->cUpgradeCodes);
@@ -529,7 +519,7 @@ static HRESULT DetermineRelationType(
519
}
520
else
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.");
523
524
*pRelationType = BUNDLE_RELATION_UPGRADE;
525
ExitFunction();
@@ -543,7 +533,7 @@ static HRESULT DetermineRelationType(
533
}
534
else
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.");
537
538
*pRelationType = BUNDLE_RELATION_DETECT;
539
ExitFunction();
@@ -557,7 +547,7 @@ static HRESULT DetermineRelationType(
547
}
548
else
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.");
551
552
*pRelationType = BUNDLE_RELATION_DEPENDENT_ADDON;
553
ExitFunction();
@@ -571,7 +561,7 @@ static HRESULT DetermineRelationType(
561
}
562
else
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.");
565
566
*pRelationType = BUNDLE_RELATION_DEPENDENT_PATCH;
567
ExitFunction();
@@ -586,7 +576,7 @@ static HRESULT DetermineRelationType(
576
if (SUCCEEDED(hr))
577
{
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");
580
581
// Addon relationship: when their addon codes match our detect codes.
582
hr = DictCompareStringListToArray(sdAddonCodes, const_cast<LPCWSTR*>(pQueryContext->rgwzDetectCodes), pQueryContext->cDetectCodes);
@@ -596,7 +586,7 @@ static HRESULT DetermineRelationType(
586
}
587
else
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.");
590
591
*pRelationType = BUNDLE_RELATION_ADDON;
592
ExitFunction();
@@ -610,7 +600,7 @@ static HRESULT DetermineRelationType(
600
}
601
else
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.");
604
605
*pRelationType = BUNDLE_RELATION_ADDON;
606
ExitFunction();
@@ -625,7 +615,7 @@ static HRESULT DetermineRelationType(
615
if (SUCCEEDED(hr))
616
{
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");
619
620
// Patch relationship: when their patch codes match our detect codes.
621
hr = DictCompareStringListToArray(sdPatchCodes, const_cast<LPCWSTR*>(pQueryContext->rgwzDetectCodes), pQueryContext->cDetectCodes);
@@ -635,7 +625,7 @@ static HRESULT DetermineRelationType(
625
}
626
else
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.");
629
630
*pRelationType = BUNDLE_RELATION_PATCH;
631
ExitFunction();
@@ -649,7 +639,7 @@ static HRESULT DetermineRelationType(
639
}
640
else
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.");
643
644
*pRelationType = BUNDLE_RELATION_PATCH;
645
ExitFunction();
@@ -664,7 +654,7 @@ static HRESULT DetermineRelationType(
654
if (SUCCEEDED(hr))
655
{
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");
658
659
// Detect relationship: when their detect codes match our detect codes.
660
hr = DictCompareStringListToArray(sdDetectCodes, const_cast<LPCWSTR*>(pQueryContext->rgwzDetectCodes), pQueryContext->cDetectCodes);
@@ -674,7 +664,7 @@ static HRESULT DetermineRelationType(
664
}
665
else
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.");
668
669
*pRelationType = BUNDLE_RELATION_DETECT;
670
ExitFunction();
@@ -688,7 +678,7 @@ static HRESULT DetermineRelationType(
678
}
679
else
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.");
682
683
*pRelationType = BUNDLE_RELATION_DEPENDENT_ADDON;
684
ExitFunction();
@@ -702,7 +692,7 @@ static HRESULT DetermineRelationType(
692
}
693
else
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.");
696
697
*pRelationType = BUNDLE_RELATION_DEPENDENT_PATCH;
698
ExitFunction();
@@ -740,54 +730,11 @@ static HRESULT LocateAndQueryBundleValue(
730
)
731
{
732
HRESULT hr = S_OK;
733
+ LPWSTR sczKeypath = NULL;
734
+ BOOL fExists = TRUE;
735
736
*pStatus = INTERNAL_BUNDLE_STATUS_SUCCESS;
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
-
772
-LExit:
773
- return hr;
774
-}
775
-
776
-static 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
-
738
if (wzSubKey)
739
{
740
hr = StrAllocFormatted(&sczKeypath, L"%ls\\%ls\\%ls", BUNDLE_REGISTRATION_REGISTRY_UNINSTALL_KEY, wzBundleId, wzSubKey);
@@ -798,8 +745,24 @@ static HRESULT OpenBundleKey(
745
}
746
ButilExitOnFailure(hr, "Failed to allocate bundle uninstall key path.");
747
801
- hr = RegOpenEx(hkRoot, sczKeypath, KEY_READ, kbKeyBitness, phKey);
802
- ButilExitOnFailure(hr, "Failed to open bundle uninstall key path.");
748
+ if (FAILED(hr = RegOpenEx(HKEY_LOCAL_MACHINE, sczKeypath, KEY_READ, REG_KEY_32BIT, phKey)) &&
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
+ }
766
767
LExit:
768
ReleaseStr(sczKeypath);
src/libs/dutil/WixToolset.DUtil/deputil.cpp
+73
-72
@@ -16,6 +16,7 @@
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__)
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__)
20
21
#define ARRAY_GROWTH_SIZE 5
22
@@ -54,6 +55,7 @@ DAPI_(HRESULT) DepGetProviderInformation(
55
HRESULT hr = S_OK;
56
LPWSTR sczKey = NULL;
57
HKEY hkKey = NULL;
58
+ BOOL fExists = FALSE;
59
60
// Format the provider dependency registry key.
61
hr = AllocDependencyKeyName(wzProviderKey, &sczKey);
@@ -61,43 +63,32 @@ DAPI_(HRESULT) DepGetProviderInformation(
63
64
// Try to open the dependency key.
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)
69
{
70
ExitFunction1(hr = E_NOTFOUND);
71
}
68
- DepExitOnFailure(hr, "Failed to open the registry key for the dependency \"%ls\".", wzProviderKey);
72
73
// Get the Id if requested and available.
74
if (psczId)
75
{
76
hr = RegReadString(hkKey, NULL, psczId);
74
- if (E_FILENOTFOUND == hr)
75
- {
76
- hr = S_OK;
77
- }
78
- DepExitOnFailure(hr, "Failed to get the id for the dependency \"%ls\".", wzProviderKey);
77
+ DepExitOnPathFailure(hr, fExists, "Failed to get the id for the dependency \"%ls\".", wzProviderKey);
78
}
79
80
// Get the DisplayName if requested and available.
81
if (psczName)
82
{
83
hr = RegReadString(hkKey, vcszDisplayNameValue, psczName);
85
- if (E_FILENOTFOUND == hr)
86
- {
87
- hr = S_OK;
88
- }
89
- DepExitOnFailure(hr, "Failed to get the name for the dependency \"%ls\".", wzProviderKey);
84
+ DepExitOnPathFailure(hr, fExists, "Failed to get the name for the dependency \"%ls\".", wzProviderKey);
85
}
86
87
// Get the Version if requested and available.
88
if (psczVersion)
89
{
90
hr = RegReadString(hkKey, vcszVersionValue, psczVersion);
96
- if (E_FILENOTFOUND == hr)
97
- {
98
- hr = S_OK;
99
- }
100
- DepExitOnFailure(hr, "Failed to get the version for the dependency \"%ls\".", wzProviderKey);
91
+ DepExitOnPathFailure(hr, fExists, "Failed to get the version for the dependency \"%ls\".", wzProviderKey);
92
}
93
94
LExit:
@@ -121,6 +112,7 @@ DAPI_(HRESULT) DepCheckDependency(
112
HRESULT hr = S_OK;
113
LPWSTR sczKey = NULL;
114
HKEY hkKey = NULL;
115
+ BOOL fExists = FALSE;
116
VERUTIL_VERSION* pVersion = NULL;
117
VERUTIL_VERSION* pMinVersion = NULL;
118
VERUTIL_VERSION* pMaxVersion = NULL;
@@ -134,20 +126,17 @@ DAPI_(HRESULT) DepCheckDependency(
126
127
// Try to open the key. If that fails, add the missing dependency key to the dependency array if it doesn't already exist.
128
hr = RegOpen(hkHive, sczKey, KEY_READ, &hkKey);
137
- if (E_FILENOTFOUND != hr)
138
- {
139
- DepExitOnFailure(hr, "Failed to open the registry key for dependency \"%ls\".", wzProviderKey);
129
+ DepExitOnPathFailure(hr, fExists, "Failed to open the registry key for dependency \"%ls\".", wzProviderKey);
130
131
+ if (fExists)
132
+ {
133
// If there are no registry values, consider the key orphaned and treat it as missing.
134
hr = RegReadWixVersion(hkKey, vcszVersionValue, &pVersion);
143
- if (E_FILENOTFOUND != hr)
144
- {
145
- DepExitOnFailure(hr, "Failed to read the %ls registry value for dependency \"%ls\".", vcszVersionValue, wzProviderKey);
146
- }
135
+ DepExitOnPathFailure(hr, fExists, "Failed to read the %ls registry value for dependency \"%ls\".", vcszVersionValue, wzProviderKey);
136
}
137
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)
140
{
141
hr = DictKeyExists(sdDependencies, wzProviderKey);
142
if (E_NOTFOUND != hr)
@@ -190,7 +179,7 @@ DAPI_(HRESULT) DepCheckDependency(
179
else
180
{
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);
183
184
hr = DepDependencyArrayAlloc(prgDependencies, pcDependencies, wzProviderKey, sczName);
185
DepExitOnFailure(hr, "Failed to add the older dependency \"%ls\" to the dependencies array.", wzProviderKey);
@@ -228,7 +217,7 @@ DAPI_(HRESULT) DepCheckDependency(
217
else
218
{
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);
221
222
hr = DepDependencyArrayAlloc(prgDependencies, pcDependencies, wzProviderKey, sczName);
223
DepExitOnFailure(hr, "Failed to add the newer dependency \"%ls\" to the dependencies array.", wzProviderKey);
@@ -267,6 +256,7 @@ DAPI_(HRESULT) DepCheckDependents(
256
LPWSTR sczKey = NULL;
257
HKEY hkProviderKey = NULL;
258
HKEY hkDependentsKey = NULL;
259
+ BOOL fExists = FALSE;
260
LPWSTR sczDependentKey = NULL;
261
LPWSTR sczDependentName = NULL;
262
BOOL fIgnore = FALSE;
@@ -277,15 +267,18 @@ DAPI_(HRESULT) DepCheckDependents(
267
268
// Try to open the key. If that fails, the dependency information is corrupt.
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);
271
282
- // Try to open the dependencies key. If that does not exist, there are no dependents.
283
- hr = RegOpen(hkProviderKey, vsczRegistryDependents, KEY_READ, &hkDependentsKey);
284
- if (E_FILENOTFOUND != hr)
272
+ if (!fExists)
273
{
286
- DepExitOnFailure(hr, "Failed to open the registry key for dependents of \"%ls\".", wzProviderKey);
274
+ ExitFunction1(hr = S_OK);
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)
282
{
283
ExitFunction1(hr = S_OK);
284
}
@@ -399,15 +392,18 @@ DAPI_(HRESULT) DepDependentExists(
392
HRESULT hr = S_OK;
393
LPWSTR sczDependentKey = NULL;
394
HKEY hkDependentKey = NULL;
395
+ BOOL fExists = FALSE;
396
397
// Format the provider dependents registry key.
398
hr = StrAllocFormatted(&sczDependentKey, L"%ls%ls\\%ls\\%ls", vsczRegistryRoot, wzDependencyProviderKey, vsczRegistryDependents, wzProviderKey);
399
DepExitOnFailure(hr, "Failed to format registry key to dependent.");
400
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)
405
{
410
- DepExitOnFailure(hr, "Failed to open the dependent registry key at: \"%ls\".", sczDependentKey);
406
+ hr = E_FILENOTFOUND;
407
}
408
409
LExit:
@@ -480,6 +476,7 @@ DAPI_(HRESULT) DepUnregisterDependency(
476
HRESULT hr = S_OK;
477
LPWSTR sczKey = NULL;
478
HKEY hkKey = NULL;
479
+ BOOL fExists = FALSE;
480
481
// Format the provider dependency registry key.
482
hr = AllocDependencyKeyName(wzProviderKey, &sczKey);
@@ -487,9 +484,11 @@ DAPI_(HRESULT) DepUnregisterDependency(
484
485
// Delete the entire key including all sub-keys.
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)
490
{
492
- DepExitOnFailure(hr, "Failed to delete the key \"%ls\".", sczKey);
491
+ hr = E_FILENOTFOUND;
492
}
493
494
LExit:
@@ -506,6 +505,7 @@ DAPI_(HRESULT) DepUnregisterDependent(
505
)
506
{
507
HRESULT hr = S_OK;
508
+ BOOL fExists = FALSE;
509
HKEY hkRegistryRoot = NULL;
510
HKEY hkDependencyProviderKey = NULL;
511
HKEY hkRegistryDependents = NULL;
@@ -514,40 +514,39 @@ DAPI_(HRESULT) DepUnregisterDependent(
514
515
// Open the root key. We may delete the wzDependencyProviderKey during clean up.
516
hr = RegOpen(hkHive, vsczRegistryRoot, KEY_READ, &hkRegistryRoot);
517
- if (E_FILENOTFOUND != hr)
518
- {
519
- DepExitOnFailure(hr, "Failed to open root registry key \"%ls\".", vsczRegistryRoot);
520
- }
521
- else
517
+ DepExitOnPathFailure(hr, fExists, "Failed to open root registry key \"%ls\".", vsczRegistryRoot);
518
+
519
+ if (!fExists)
520
{
523
- ExitFunction();
521
+ ExitFunction1(hr = E_FILENOTFOUND);
522
}
523
524
// Try to open the dependency key. If that does not exist, simply return.
525
hr = RegOpen(hkRegistryRoot, wzDependencyProviderKey, KEY_READ, &hkDependencyProviderKey);
528
- if (E_FILENOTFOUND != hr)
529
- {
530
- DepExitOnFailure(hr, "Failed to open the registry key for the dependency \"%ls\".", wzDependencyProviderKey);
531
- }
532
- else
526
+ DepExitOnPathFailure(hr, fExists, "Failed to open the registry key for the dependency \"%ls\".", wzDependencyProviderKey);
527
+
528
+ if (!fExists)
529
{
534
- ExitFunction();
530
+ ExitFunction1(hr = E_FILENOTFOUND);
531
}
532
533
// Try to open the dependents subkey to enumerate.
534
hr = RegOpen(hkDependencyProviderKey, vsczRegistryDependents, KEY_READ, &hkRegistryDependents);
539
- if (E_FILENOTFOUND != hr)
540
- {
541
- DepExitOnFailure(hr, "Failed to open the dependents subkey under the dependency \"%ls\".", wzDependencyProviderKey);
542
- }
543
- else
535
+ DepExitOnPathFailure(hr, fExists, "Failed to open the dependents subkey under the dependency \"%ls\".", wzDependencyProviderKey);
536
+
537
+ if (!fExists)
538
{
545
- ExitFunction();
539
+ ExitFunction1(hr = E_FILENOTFOUND);
540
}
541
542
// Delete the wzProviderKey dependent sub-key.
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
+ }
550
551
// If there are no remaining dependents, delete the Dependents subkey.
552
hr = RegQueryKey(hkRegistryDependents, &cSubKeys, NULL);
@@ -563,7 +562,12 @@ DAPI_(HRESULT) DepUnregisterDependent(
562
563
// Fail if there are any subkeys since we just checked.
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
+ }
571
572
// If there are no values, delete the provider dependency key.
573
hr = RegQueryKey(hkDependencyProviderKey, NULL, &cValues);
@@ -576,7 +580,12 @@ DAPI_(HRESULT) DepUnregisterDependent(
580
581
// Fail if there are any subkeys since we just checked.
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
+ }
589
}
590
591
LExit:
@@ -685,6 +694,7 @@ static HRESULT GetDependencyNameFromKey(
694
HRESULT hr = S_OK;
695
LPWSTR sczKey = NULL;
696
HKEY hkKey = NULL;
697
+ BOOL fExists = FALSE;
698
699
// Format the provider dependency registry key.
700
hr = AllocDependencyKeyName(wzProviderKey, &sczKey);
@@ -692,25 +702,16 @@ static HRESULT GetDependencyNameFromKey(
702
703
// Try to open the dependency key.
704
hr = RegOpen(hkHive, sczKey, KEY_READ, &hkKey);
695
- if (E_FILENOTFOUND != hr)
696
- {
697
- DepExitOnFailure(hr, "Failed to open the registry key for the dependency \"%ls\".", wzProviderKey);
698
- }
699
- else
705
+ DepExitOnPathFailure(hr, fExists, "Failed to open the registry key for the dependency \"%ls\".", wzProviderKey);
706
+
707
+ if (!fExists)
708
{
701
- ExitFunction1(hr = S_OK);
709
+ ExitFunction();
710
}
711
712
// Get the DisplayName if available.
713
hr = RegReadString(hkKey, vcszDisplayNameValue, psczName);
706
- if (E_FILENOTFOUND != hr)
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
+ DepExitOnPathFailure(hr, fExists, "Failed to get the dependency name for the dependency \"%ls\".", wzProviderKey);
715
716
LExit:
717
ReleaseRegKey(hkKey);
src/libs/dutil/WixToolset.DUtil/dirutil.cpp
+27
-15
@@ -17,6 +17,8 @@
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__)
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__)
22
23
24
/*******************************************************************
@@ -184,13 +186,9 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx(
186
187
if (-1 == (dwAttrib = ::GetFileAttributesW(wzPath)))
188
{
187
- er = ::GetLastError();
188
- if (ERROR_FILE_NOT_FOUND == er) // change "file not found" to "path not found" since we were looking for a directory.
189
- {
190
- er = ERROR_PATH_NOT_FOUND;
191
- }
192
- hr = HRESULT_FROM_WIN32(er);
193
- DirExitOnRootFailure(hr, "Failed to get attributes for path: %ls", wzPath);
189
+ DirExitWithPathLastError(hr, "Failed to get attributes for path: %ls", wzPath);
190
+
191
+ ExitFunction1(hr = E_PATHNOTFOUND);
192
}
193
194
if (dwAttrib & FILE_ATTRIBUTE_DIRECTORY)
@@ -199,7 +197,9 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx(
197
{
198
if (!::SetFileAttributesW(wzPath, FILE_ATTRIBUTE_NORMAL))
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
}
204
}
205
@@ -245,9 +245,12 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx(
245
hr = DirEnsureDeleteEx(sczDelete, dwFlags); // recursive call
246
if (FAILED(hr))
247
{
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);
250
- hr = S_OK;
248
+ // if we failed to delete a subdirectory, keep trying to finish any remaining files
249
+ if (E_PATHNOTFOUND != hr)
250
+ {
251
+ ExitTraceSource(DUTIL_SOURCE_DIRUTIL, hr, "Failed to delete subdirectory; continuing: %ls", sczDelete);
252
+ }
253
+ hr = S_OK;
254
}
255
}
256
else if (fDeleteFiles) // this is a file, just delete it
@@ -256,7 +259,8 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx(
259
{
260
if (!::SetFileAttributesW(sczDelete, FILE_ATTRIBUTE_NORMAL))
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;
264
}
265
}
266
@@ -280,7 +284,7 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx(
284
}
285
else
286
{
283
- DirExitWithLastError(hr, "Failed to delete file: %ls", sczDelete);
287
+ DirExitWithPathLastError(hr, "Failed to delete file: %ls", sczDelete);
288
}
289
}
290
}
@@ -308,13 +312,21 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx(
312
}
313
}
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
+
324
DirExitOnRootFailure(hr, "Failed to remove directory: %ls", wzPath);
325
}
326
}
327
else
328
{
316
- hr = E_UNEXPECTED;
317
- DirExitOnFailure(hr, "Directory delete cannot delete file: %ls", wzPath);
329
+ DirExitWithRootFailure(hr, E_UNEXPECTED, "Directory delete cannot delete file: %ls", wzPath);
330
}
331
332
Assert(S_OK == hr);
src/libs/dutil/WixToolset.DUtil/file2utl.cpp
+19
-12
@@ -16,6 +16,7 @@
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__)
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__)
20
21
// constants
22
@@ -35,6 +36,7 @@ extern "C" BOOL DAPI FileExistsAfterRestart(
36
{
37
HRESULT hr = S_OK;
38
BOOL fExists = FALSE;
39
+ BOOL fRegExists = FALSE;
40
HKEY hkPendingFileRename = NULL;
41
LPWSTR* rgsczRenames = NULL;
42
DWORD cRenames = 0;
@@ -44,18 +46,20 @@ extern "C" BOOL DAPI FileExistsAfterRestart(
46
if (fExists)
47
{
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)
52
{
49
- ExitFunction1(hr = S_OK);
53
+ ExitFunction();
54
}
51
- FileExitOnFailure(hr, "Failed to open pending file rename registry key.");
55
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)
60
{
56
- ExitFunction1(hr = S_OK);
61
+ ExitFunction();
62
}
58
- FileExitOnFailure(hr, "Failed to read pending file renames.");
63
64
// The pending file renames array is pairs of source and target paths. We only care
65
// about checking the source paths so skip the target paths (i += 2).
@@ -95,6 +99,7 @@ extern "C" HRESULT DAPI FileRemoveFromPendingRename(
99
{
100
HRESULT hr = S_OK;
101
HKEY hkPendingFileRename = NULL;
102
+ BOOL fExists = FALSE;
103
LPWSTR* rgsczRenames = NULL;
104
DWORD cRenames = 0;
105
BOOL fPathEqual = FALSE;
@@ -102,18 +107,20 @@ extern "C" HRESULT DAPI FileRemoveFromPendingRename(
107
DWORD cNewRenames = 0;
108
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)
113
{
107
- ExitFunction1(hr = S_OK);
114
+ ExitFunction();
115
}
109
- FileExitOnFailure(hr, "Failed to open pending file rename registry key.");
116
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)
121
{
114
- ExitFunction1(hr = S_OK);
122
+ ExitFunction();
123
}
116
- FileExitOnFailure(hr, "Failed to read pending file renames.");
124
125
// The pending file renames array is pairs of source and target paths. We only care
126
// about checking the source paths so skip the target paths (i += 2).
src/libs/dutil/WixToolset.DUtil/fileutil.cpp
+9
-3
@@ -443,6 +443,7 @@ extern "C" HRESULT DAPI FileSize(
443
)
444
{
445
HRESULT hr = S_OK;
446
+ DWORD er = ERROR_SUCCESS;
447
HANDLE hFile = INVALID_HANDLE_VALUE;
448
449
FileExitOnNull(pwzFileName, hr, E_INVALIDARG, "Attempted to check filename, but no filename was provided");
@@ -450,6 +451,11 @@ extern "C" HRESULT DAPI FileSize(
451
hFile = ::CreateFileW(pwzFileName, FILE_READ_ATTRIBUTES, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
452
if (INVALID_HANDLE_VALUE == hFile)
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
+ }
459
FileExitWithLastError(hr, "Failed to open file %ls while checking file size", pwzFileName);
460
}
461
@@ -617,11 +623,11 @@ extern "C" HRESULT DAPI FileReadPartialEx(
623
if (INVALID_HANDLE_VALUE == hFile)
624
{
625
er = ::GetLastError();
620
- if (E_FILENOTFOUND == HRESULT_FROM_WIN32(er))
626
+ if (ERROR_PATH_NOT_FOUND == er || ERROR_FILE_NOT_FOUND == er)
627
{
622
- ExitFunction1(hr = E_FILENOTFOUND);
628
+ ExitFunction1(hr = HRESULT_FROM_WIN32(er));
629
}
624
- FileExitOnWin32Error(er, hr, "Failed to open file: %ls", wzSrcPath);
630
+ FileExitWithLastError(hr, "Failed to open file: %ls", wzSrcPath);
631
}
632
633
if (!::GetFileSizeEx(hFile, &liFileSize))
src/libs/dutil/WixToolset.DUtil/inc/dutil.h
+4
@@ -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__); }
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__); }
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__); }
136
137
#define ExitOnLastError(x, s, ...) ExitOnLastErrorSource(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
149
#define ExitOnOptionalXmlQueryFailure(x, b, s, ...) ExitOnOptionalXmlQueryFailureSource(DUTIL_SOURCE_DEFAULT, x, b, s, __VA_ARGS__)
150
#define ExitOnRequiredXmlQueryFailure(x, s, ...) ExitOnRequiredXmlQueryFailureSource(DUTIL_SOURCE_DEFAULT, x, 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__)
154
155
// release macros
156
#define ReleaseObject(x) if (x) { x->Release(); }
src/libs/dutil/WixToolset.DUtil/inc/logutil.h
+2
@@ -8,9 +8,11 @@ extern "C" {
8
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; }
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; }
12
13
#define LogExitOnFailure(x, i, f, ...) LogExitOnFailureSource(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__)
16
17
typedef HRESULT (DAPI *PFN_LOGSTRINGWORKRAW)(
18
__in_z LPCSTR szString,
src/libs/dutil/WixToolset.DUtil/monutil.cpp
+7
-7
@@ -17,6 +17,7 @@
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__)
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__)
21
22
const int MON_THREAD_GROWTH = 5;
23
const int MON_ARRAY_GROWTH = 40;
@@ -982,6 +983,7 @@ static HRESULT InitiateWait(
983
DWORD dwIndex = 0;
984
HKEY hk = NULL;
985
HANDLE hTemp = INVALID_HANDLE_VALUE;
986
+ BOOL fExists = FALSE;
987
988
if (pRequest->hNotify)
989
{
@@ -1025,11 +1027,12 @@ static HRESULT InitiateWait(
1027
case MON_REGKEY:
1028
ReleaseRegKey(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)
1033
{
1034
continue;
1035
}
1032
- MonExitOnFailure(hr, "Failed to open regkey %ls", pRequest->rgsczPathHierarchy[dwIndex]);
1036
1037
er = ::RegNotifyChangeKeyValue(pRequest->regkey.hkSubKey, GetRecursiveFlag(pRequest, dwIndex), REG_NOTIFY_CHANGE_NAME | REG_NOTIFY_CHANGE_LAST_SET | REG_NOTIFY_CHANGE_SECURITY, *pHandle, TRUE);
1038
ReleaseRegKey(hk);
@@ -1038,12 +1041,9 @@ static HRESULT InitiateWait(
1041
{
1042
continue;
1043
}
1041
- else
1042
- {
1043
- MonExitOnWin32Error(er, hr, "Failed to wait on subkey %ls", pRequest->rgsczPathHierarchy[dwIndex]);
1044
+ MonExitOnFailure(hr, "Failed to wait on subkey %ls", pRequest->rgsczPathHierarchy[dwIndex]);
1045
1045
- fHandleFound = TRUE;
1046
- }
1046
+ fHandleFound = TRUE;
1047
1048
break;
1049
default:
src/libs/dutil/WixToolset.DUtil/osutil.cpp
+10
-6
@@ -16,6 +16,7 @@
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__)
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__)
20
21
typedef NTSTATUS(NTAPI* PFN_RTL_GET_VERSION)(_Out_ PRTL_OSVERSIONINFOEXW lpVersionInformation);
22
@@ -186,23 +187,26 @@ extern "C" HRESULT DAPI OsIsUacEnabled(
187
{
188
HRESULT hr = S_OK;
189
HKEY hk = NULL;
190
+ BOOL fExists = FALSE;
191
DWORD dwUacEnabled = 0;
192
193
*pfUacEnabled = FALSE; // assume UAC not enabled.
194
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)
199
{
196
- ExitFunction1(hr = S_OK);
200
+ ExitFunction();
201
}
198
- OsExitOnFailure(hr, "Failed to open system policy key to detect UAC.");
202
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)
207
{
203
- ExitFunction1(hr = S_OK);
208
+ ExitFunction();
209
}
205
- OsExitOnFailure(hr, "Failed to read registry value to detect UAC.");
210
211
*pfUacEnabled = (0 != dwUacEnabled);
212
src/libs/dutil/WixToolset.DUtil/path3utl.cpp
+9
-5
@@ -17,6 +17,7 @@
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__)
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__)
21
22
static HRESULT GetTempPathFromSystemEnvironmentVariable(
23
__in HKEY hKey,
@@ -32,6 +33,7 @@ DAPI_(HRESULT) PathGetSystemTempPaths(
33
HRESULT hr = S_OK;
34
HMODULE hModule = NULL;
35
BOOL fSystem = FALSE;
36
+ BOOL fExists = FALSE;
37
HKEY hKey = NULL;
38
LPWSTR sczTemp = NULL;
39
@@ -61,10 +63,10 @@ DAPI_(HRESULT) PathGetSystemTempPaths(
63
64
// There is no documented API to get system environment variables, so read them from the registry.
65
hr = RegOpen(HKEY_LOCAL_MACHINE, L"System\\CurrentControlSet\\Control\\Session Manager\\Environment", KEY_READ, &hKey);
64
- if (E_FILENOTFOUND != hr)
65
- {
66
- PathExitOnFailure(hr, "Failed to open system environment registry key.");
66
+ PathExitOnPathFailure(hr, fExists, "Failed to open system environment registry key.");
67
68
+ if (fExists)
69
+ {
70
hr = GetTempPathFromSystemEnvironmentVariable(hKey, L"TMP", &sczTemp);
71
PathExitOnFailure(hr, "Failed to get temp path from system TMP.");
72
@@ -118,14 +120,16 @@ static HRESULT GetTempPathFromSystemEnvironmentVariable(
120
HRESULT hr = S_OK;
121
LPWSTR sczValue = NULL;
122
BOOL fNeedsExpansion = FALSE;
123
+ BOOL fExists = FALSE;
124
125
// Read the value unexpanded so that it can be expanded with system environment variables.
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)
130
{
131
ExitFunction1(hr = S_FALSE);
132
}
128
- PathExitOnFailure(hr, "Failed to get system '%ls' value.", wzName);
133
134
if (fNeedsExpansion)
135
{
src/libs/dutil/WixToolset.DUtil/polcutil.cpp
+32
-16
@@ -16,6 +16,7 @@
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__)
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__)
20
21
const LPCWSTR REGISTRY_POLICIES_KEY = L"SOFTWARE\\Policies\\";
22
@@ -34,25 +35,28 @@ extern "C" HRESULT DAPI PolcReadNumber(
35
{
36
HRESULT hr = S_OK;
37
HKEY hk = NULL;
38
+ BOOL fExists = FALSE;
39
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)
44
{
45
ExitFunction1(hr = S_FALSE);
46
}
43
- PolcExitOnFailure(hr, "Failed to open policy key: %ls", wzPolicyPath);
47
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)
52
{
53
ExitFunction1(hr = S_FALSE);
54
}
50
- PolcExitOnFailure(hr, "Failed to open policy key: %ls, name: %ls", wzPolicyPath, wzPolicyName);
55
56
LExit:
57
ReleaseRegKey(hk);
58
55
- if (S_FALSE == hr || FAILED(hr))
59
+ if (!fExists)
60
{
61
*pdw = dwDefault;
62
}
@@ -69,25 +73,28 @@ extern "C" HRESULT DAPI PolcReadString(
73
{
74
HRESULT hr = S_OK;
75
HKEY hk = NULL;
76
+ BOOL fExists = FALSE;
77
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)
82
{
83
ExitFunction1(hr = S_FALSE);
84
}
78
- PolcExitOnFailure(hr, "Failed to open policy key: %ls", wzPolicyPath);
85
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)
90
{
91
ExitFunction1(hr = S_FALSE);
92
}
85
- PolcExitOnFailure(hr, "Failed to open policy key: %ls, name: %ls", wzPolicyPath, wzPolicyName);
93
94
LExit:
95
ReleaseRegKey(hk);
96
90
- if (S_FALSE == hr || FAILED(hr))
97
+ if (!fExists)
98
{
99
if (NULL == wzDefault)
100
{
@@ -112,25 +119,28 @@ extern "C" HRESULT DAPI PolcReadUnexpandedString(
119
{
120
HRESULT hr = S_OK;
121
HKEY hk = NULL;
122
+ BOOL fExists = FALSE;
123
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)
128
{
129
ExitFunction1(hr = S_FALSE);
130
}
121
- PolcExitOnFailure(hr, "Failed to open policy key: %ls", wzPolicyPath);
131
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)
136
{
137
ExitFunction1(hr = S_FALSE);
138
}
128
- PolcExitOnFailure(hr, "Failed to open policy key: %ls, name: %ls", wzPolicyPath, wzPolicyName);
139
140
LExit:
141
ReleaseRegKey(hk);
142
133
- if (S_FALSE == hr || FAILED(hr))
143
+ if (!fExists)
144
{
145
if (NULL == wzDefault)
146
{
@@ -155,12 +165,18 @@ static HRESULT OpenPolicyKey(
165
{
166
HRESULT hr = S_OK;
167
LPWSTR sczPath = NULL;
168
+ BOOL fExists = FALSE;
169
170
hr = PathConcat(REGISTRY_POLICIES_KEY, wzPolicyPath, &sczPath);
171
PolcExitOnFailure(hr, "Failed to combine logging path with root path.");
172
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
+ }
180
181
LExit:
182
ReleaseStr(sczPath);
src/libs/dutil/WixToolset.DUtil/regutil.cpp
+35
-14
@@ -17,6 +17,7 @@
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__)
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__)
21
22
static PFN_REGCREATEKEYEXW vpfnRegCreateKeyExW = ::RegCreateKeyExW;
23
static PFN_REGOPENKEYEXW vpfnRegOpenKeyExW = ::RegOpenKeyExW;
@@ -179,7 +180,7 @@ DAPI_(HRESULT) RegOpen(
180
__in_z LPCWSTR wzSubKey,
181
__in DWORD dwAccess,
182
__out HKEY* phk
182
-)
183
+ )
184
{
185
return RegOpenEx(hkRoot, wzSubKey, dwAccess, REG_KEY_DEFAULT, phk);
186
}
@@ -191,18 +192,18 @@ DAPI_(HRESULT) RegOpenEx(
192
__in DWORD dwAccess,
193
__in REG_KEY_BITNESS kbKeyBitness,
194
__out HKEY* phk
194
-)
195
+ )
196
{
197
HRESULT hr = S_OK;
198
DWORD er = ERROR_SUCCESS;
199
200
REGSAM samDesired = RegTranslateKeyBitness(kbKeyBitness);
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)
203
{
203
- ExitFunction1(hr = E_FILENOTFOUND);
204
+ ExitFunction1(hr = HRESULT_FROM_WIN32(er));
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);
207
208
LExit:
209
return hr;
@@ -221,6 +222,7 @@ DAPI_(HRESULT) RegDelete(
222
LPWSTR pszEnumeratedSubKey = NULL;
223
LPWSTR pszRecursiveSubKey = NULL;
224
HKEY hkKey = NULL;
225
+ BOOL fExists = FALSE;
226
227
if (!vfRegInitialized && REG_KEY_DEFAULT != kbKeyBitness)
228
{
@@ -231,9 +233,9 @@ DAPI_(HRESULT) RegDelete(
233
if (fDeleteTree)
234
{
235
hr = RegOpenEx(hkRoot, wzSubKey, KEY_READ, kbKeyBitness, &hkKey);
234
- if (E_FILENOTFOUND == hr)
236
+ if (E_PATHNOTFOUND == hr || E_FILENOTFOUND == hr)
237
{
236
- ExitFunction1(hr = S_OK);
238
+ ExitFunction();
239
}
240
RegExitOnFailure(hr, "Failed to open this key for enumerating subkeys: %ls", wzSubKey);
241
@@ -246,28 +248,31 @@ DAPI_(HRESULT) RegDelete(
248
RegExitOnFailure(hr, "Failed to concatenate paths while recursively deleting subkeys. Path1: %ls, Path2: %ls", wzSubKey, pszEnumeratedSubKey);
249
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);
252
}
253
254
hr = S_OK;
255
+
256
+ // Release the handle to make sure it's deleted immediately.
257
+ ReleaseRegKey(hkKey);
258
}
259
260
if (NULL != vpfnRegDeleteKeyExW)
261
{
262
REGSAM samDesired = RegTranslateKeyBitness(kbKeyBitness);
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)
265
{
261
- ExitFunction1(hr = E_FILENOTFOUND);
266
+ ExitFunction1(hr = HRESULT_FROM_WIN32(er));
267
}
268
RegExitOnWin32Error(er, hr, "Failed to delete registry key (ex).");
269
}
270
else
271
{
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)
274
{
270
- ExitFunction1(hr = E_FILENOTFOUND);
275
+ ExitFunction1(hr = HRESULT_FROM_WIN32(er));
276
}
277
RegExitOnWin32Error(er, hr, "Failed to delete registry key.");
278
}
@@ -772,7 +777,7 @@ DAPI_(HRESULT) RegReadNumber(
777
DWORD cb = sizeof(DWORD);
778
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)
781
{
782
ExitFunction1(hr = E_FILENOTFOUND);
783
}
@@ -801,7 +806,7 @@ DAPI_(HRESULT) RegReadQword(
806
DWORD cb = sizeof(DWORD64);
807
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)
810
{
811
ExitFunction1(hr = E_FILENOTFOUND);
812
}
@@ -1015,9 +1020,17 @@ DAPI_(HRESULT) RegKeyReadNumber(
1020
HKEY hkKey = NULL;
1021
1022
hr = RegOpenEx(hk, wzSubKey, KEY_READ, kbKeyBitness, &hkKey);
1023
+ if (E_PATHNOTFOUND == hr || E_FILENOTFOUND == hr)
1024
+ {
1025
+ ExitFunction();
1026
+ }
1027
RegExitOnFailure(hr, "Failed to open key: %ls", wzSubKey);
1028
1029
hr = RegReadNumber(hkKey, wzName, pdwValue);
1030
+ if (E_FILENOTFOUND == hr)
1031
+ {
1032
+ ExitFunction();
1033
+ }
1034
RegExitOnFailure(hr, "Failed to read value: %ls/@%ls", wzSubKey, wzName);
1035
1036
LExit:
@@ -1038,9 +1051,17 @@ DAPI_(BOOL) RegValueExists(
1051
DWORD dwType = 0;
1052
1053
hr = RegOpenEx(hk, wzSubKey, KEY_READ, kbKeyBitness, &hkKey);
1054
+ if (E_PATHNOTFOUND == hr || E_FILENOTFOUND == hr)
1055
+ {
1056
+ ExitFunction();
1057
+ }
1058
RegExitOnFailure(hr, "Failed to open key: %ls", wzSubKey);
1059
1060
hr = RegGetType(hkKey, wzName, &dwType);
1061
+ if (E_FILENOTFOUND == hr)
1062
+ {
1063
+ ExitFunction();
1064
+ }
1065
RegExitOnFailure(hr, "Failed to read value type: %ls/@%ls", wzSubKey, wzName);
1066
1067
LExit:
src/libs/dutil/WixToolset.DUtil/wiutil.cpp
+14
-1
@@ -427,6 +427,11 @@ extern "C" HRESULT DAPI WiuGetProductInfo(
427
428
er = vpfnMsiGetProductInfoW(wzProductCode, wzProperty, *psczValue, &cch);
429
}
430
+
431
+ if (ERROR_UNKNOWN_PRODUCT == er || ERROR_UNKNOWN_PROPERTY == er)
432
+ {
433
+ ExitFunction1(hr = HRESULT_FROM_WIN32(er));
434
+ }
435
WiuExitOnWin32Error(er, hr, "Failed to get product info.");
436
437
LExit:
@@ -449,7 +454,10 @@ extern "C" HRESULT DAPI WiuGetProductInfoEx(
454
if (!vpfnMsiGetProductInfoExW)
455
{
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
+ }
461
462
ExitFunction();
463
}
@@ -466,6 +474,11 @@ extern "C" HRESULT DAPI WiuGetProductInfoEx(
474
475
er = vpfnMsiGetProductInfoExW(wzProductCode, wzUserSid, dwContext, wzProperty, *psczValue, &cch);
476
}
477
+
478
+ if (ERROR_UNKNOWN_PRODUCT == er || ERROR_UNKNOWN_PROPERTY == er)
479
+ {
480
+ ExitFunction1(hr = HRESULT_FROM_WIN32(er));
481
+ }
482
WiuExitOnWin32Error(er, hr, "Failed to get extended product info.");
483
484
LExit: