From 240b663ad5fc94ed6d19c966b5c9105a176ecf40 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Mon, 8 Aug 2022 18:02:15 -0500 Subject: Skip logging errors in some places when they are due to missing files or registry keys or values. Related to 6696 --- src/burn/engine/apply.cpp | 16 +-- src/burn/engine/bundlepackageengine.cpp | 14 ++- src/burn/engine/cache.cpp | 3 +- src/burn/engine/dependency.cpp | 44 +++----- src/burn/engine/exeengine.cpp | 21 ++-- src/burn/engine/registration.cpp | 32 +++--- src/burn/engine/relatedbundle.cpp | 17 +-- src/burn/engine/search.cpp | 89 +++++++--------- src/ext/Bal/dnchost/dncutil.cpp | 2 +- src/ext/Bal/mbahost/mbahost.cpp | 99 +++++++++--------- src/ext/Dependency/ca/wixdepca.cpp | 7 +- src/libs/dutil/WixToolset.DUtil/butil.cpp | 127 ++++++++-------------- src/libs/dutil/WixToolset.DUtil/deputil.cpp | 145 +++++++++++++------------- src/libs/dutil/WixToolset.DUtil/dirutil.cpp | 42 +++++--- src/libs/dutil/WixToolset.DUtil/file2utl.cpp | 31 +++--- src/libs/dutil/WixToolset.DUtil/fileutil.cpp | 12 ++- src/libs/dutil/WixToolset.DUtil/inc/dutil.h | 4 + src/libs/dutil/WixToolset.DUtil/inc/logutil.h | 2 + src/libs/dutil/WixToolset.DUtil/monutil.cpp | 14 +-- src/libs/dutil/WixToolset.DUtil/osutil.cpp | 16 +-- src/libs/dutil/WixToolset.DUtil/path3utl.cpp | 14 ++- src/libs/dutil/WixToolset.DUtil/polcutil.cpp | 48 ++++++--- src/libs/dutil/WixToolset.DUtil/regutil.cpp | 49 ++++++--- src/libs/dutil/WixToolset.DUtil/wiutil.cpp | 15 ++- 24 files changed, 438 insertions(+), 425 deletions(-) diff --git a/src/burn/engine/apply.cpp b/src/burn/engine/apply.cpp index 31d756a8..e67208b4 100644 --- a/src/burn/engine/apply.cpp +++ b/src/burn/engine/apply.cpp @@ -611,7 +611,7 @@ extern "C" HRESULT ApplyCache( ExitOnFailure(hr, "Failed cache action: %ls", L"layout bundle"); hr = ReportOverallProgressTicks(pUX, FALSE, pPlan->cOverallProgressTicksTotal, pContext); - LogExitOnFailure(hr, MSG_USER_CANCELED, "Cancel during cache: %ls", L"layout bundle"); + LogExitOnRootFailure(hr, MSG_USER_CANCELED, "Cancel during cache: %ls", L"layout bundle"); break; @@ -637,7 +637,7 @@ extern "C" HRESULT ApplyCache( ExitOnFailure(hr, "Failed cache action: %ls", L"cache package"); hr = ReportOverallProgressTicks(pUX, FALSE, pPlan->cOverallProgressTicksTotal, pContext); - LogExitOnFailure(hr, MSG_USER_CANCELED, "Cancel during cache: %ls", L"cache package"); + LogExitOnRootFailure(hr, MSG_USER_CANCELED, "Cancel during cache: %ls", L"cache package"); break; @@ -1038,7 +1038,7 @@ static HRESULT ApplyCachePackage( } else if (fCanceledBegin) { - LogExitOnFailure(hr, MSG_USER_CANCELED, "Cancel during cache: %ls: %ls", L"begin cache package", pPackage->sczId); + LogExitOnRootFailure(hr, MSG_USER_CANCELED, "Cancel during cache: %ls: %ls", L"begin cache package", pPackage->sczId); } break; @@ -1796,8 +1796,7 @@ static HRESULT AcquireContainerOrPayload( break; default: - hr = E_FILENOTFOUND; - 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); + 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); } // Send 100% complete here. This is sometimes the only progress sent to the BA. @@ -1965,17 +1964,12 @@ static HRESULT PreparePayloadDestinationPath( dwFileAttributes &= ~FILE_ATTRIBUTE_READONLY; if (!::SetFileAttributes(wzDestinationPath, dwFileAttributes)) { - ExitWithLastError(hr, "Failed to clear readonly bit on payload destination path: %ls", wzDestinationPath); + ExitWithPathLastError(hr, "Failed to clear readonly bit on payload destination path: %ls", wzDestinationPath); } } } LExit: - if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) - { - hr = S_OK; - } - return hr; } diff --git a/src/burn/engine/bundlepackageengine.cpp b/src/burn/engine/bundlepackageengine.cpp index dafe1967..8896fdd0 100644 --- a/src/burn/engine/bundlepackageengine.cpp +++ b/src/burn/engine/bundlepackageengine.cpp @@ -1049,6 +1049,7 @@ static HRESULT DetectArpEntry( { HRESULT hr = S_OK; HKEY hKey = NULL; + BOOL fExists = FALSE; HKEY hkRoot = pPackage->fPerMachine ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; REG_KEY_BITNESS keyBitness = pPackage->Bundle.fWin64 ? REG_KEY_64BIT : REG_KEY_32BIT; @@ -1065,20 +1066,17 @@ static HRESULT DetectArpEntry( } hr = RegOpenEx(hkRoot, pPackage->Bundle.sczArpKeyPath, KEY_READ, keyBitness, &hKey); - if (HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) == hr || HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) == hr) + ExitOnPathFailure(hr, fExists, "Failed to open registry key: %ls.", pPackage->Bundle.sczArpKeyPath); + + if (!fExists) { - ExitFunction1(hr = S_OK); + ExitFunction(); } - ExitOnFailure(hr, "Failed to open registry key: %ls.", pPackage->Bundle.sczArpKeyPath); *pfRegistered = TRUE; hr = RegReadString(hKey, L"QuietUninstallString", psczQuietUninstallString); - if (HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) == hr) - { - hr = S_OK; - } - ExitOnFailure(hr, "Failed to read QuietUninstallString."); + ExitOnPathFailure(hr, fExists, "Failed to read QuietUninstallString."); LExit: ReleaseRegKey(hKey); diff --git a/src/burn/engine/cache.cpp b/src/burn/engine/cache.cpp index a23ce9ed..01237162 100644 --- a/src/burn/engine/cache.cpp +++ b/src/burn/engine/cache.cpp @@ -1144,8 +1144,7 @@ extern "C" HRESULT CacheCompletePayload( } else // if the working path and unverified path do not exist, nothing we can do. { - hr = E_FILENOTFOUND; - ExitOnFailure(hr, "Failed to find payload: %ls in working path: %ls and unverified path: %ls", pPayload->sczKey, wzWorkingPayloadPath, sczUnverifiedPayloadPath); + ExitWithRootFailure(hr, E_FILENOTFOUND, "Failed to find payload: %ls in working path: %ls and unverified path: %ls", pPayload->sczKey, wzWorkingPayloadPath, sczUnverifiedPayloadPath); } hr = ResetPathPermissions(fPerMachine, sczUnverifiedPayloadPath); diff --git a/src/burn/engine/dependency.cpp b/src/burn/engine/dependency.cpp index 221c7bbf..d6698680 100644 --- a/src/burn/engine/dependency.cpp +++ b/src/burn/engine/dependency.cpp @@ -279,19 +279,13 @@ extern "C" HRESULT DependencyDetectBundle( ) { HRESULT hr = S_OK; + BOOL fExists = FALSE; hr = DependencyDetectProviderKeyBundleId(pRegistration); ExitOnFailure(hr, "Failed to detect provider key bundle id."); hr = DepCheckDependents(pRegistration->hkRoot, pRegistration->sczProviderKey, 0, NULL, &pRegistration->rgDependents, &pRegistration->cDependents); - if (E_FILENOTFOUND != hr) - { - ExitOnFailure(hr, "Failed dependents check on bundle."); - } - else - { - hr = S_OK; - } + ExitOnPathFailure(hr, fExists, "Failed dependents check on bundle."); if (pDependencies->fSelfDependent || pDependencies->fActiveParent) { @@ -813,6 +807,7 @@ extern "C" HRESULT DependencyProcessDependentRegistration( ) { HRESULT hr = S_OK; + BOOL fDeleted = FALSE; switch (pAction->type) { @@ -823,12 +818,11 @@ extern "C" HRESULT DependencyProcessDependentRegistration( case BURN_DEPENDENT_REGISTRATION_ACTION_TYPE_UNREGISTER: hr = DepUnregisterDependent(pRegistration->hkRoot, pRegistration->sczProviderKey, pAction->sczDependentProviderKey); - ExitOnFailure(hr, "Failed to unregister dependent: %ls", pAction->sczDependentProviderKey); + ExitOnPathFailure(hr, fDeleted, "Failed to unregister dependent: %ls", pAction->sczDependentProviderKey); break; default: - hr = E_INVALIDARG; - ExitOnRootFailure(hr, "Unrecognized registration action type: %d", pAction->type); + ExitWithRootFailure(hr, E_INVALIDARG, "Unrecognized registration action type: %d", pAction->type); } LExit: @@ -848,11 +842,11 @@ extern "C" void DependencyUnregisterBundle( { // Remove the bundle provider key. hr = DepUnregisterDependency(pRegistration->hkRoot, pRegistration->sczProviderKey); - if (SUCCEEDED(hr)) + if (SUCCEEDED(hr) || E_FILENOTFOUND == hr) { LogId(REPORT_VERBOSE, MSG_DEPENDENCY_BUNDLE_UNREGISTERED, pRegistration->sczProviderKey); } - else if (FAILED(hr) && E_FILENOTFOUND != hr) + else { LogId(REPORT_VERBOSE, MSG_DEPENDENCY_BUNDLE_UNREGISTERED_FAILED, pRegistration->sczProviderKey, hr); } @@ -961,13 +955,10 @@ static HRESULT DetectPackageDependents( for (DWORD i = 0; i < pPackage->cDependencyProviders; ++i) { BURN_DEPENDENCY_PROVIDER* pProvider = &pPackage->rgDependencyProviders[i]; + BOOL fExists = FALSE; hr = DepCheckDependents(hkHive, pProvider->sczKey, 0, NULL, &pProvider->rgDependents, &pProvider->cDependents); - if (E_FILENOTFOUND == hr) - { - hr = S_OK; - } - ExitOnFailure(hr, "Failed dependents check on package provider: %ls", pProvider->sczKey); + ExitOnPathFailure(hr, fExists, "Failed dependents check on package provider: %ls", pProvider->sczKey); if (0 < pProvider->cDependents || GetProviderExists(hkHive, pProvider->sczKey)) { @@ -1366,11 +1357,11 @@ static void UnregisterPackageProvider( HRESULT hr = S_OK; hr = DepUnregisterDependency(hkRoot, pProvider->sczKey); - if (SUCCEEDED(hr)) + if (SUCCEEDED(hr) || E_FILENOTFOUND == hr) { LogId(REPORT_VERBOSE, MSG_DEPENDENCY_PACKAGE_UNREGISTERED, pProvider->sczKey, wzPackageId); } - else if (FAILED(hr) && E_FILENOTFOUND != hr) + else { LogId(REPORT_VERBOSE, MSG_DEPENDENCY_PACKAGE_UNREGISTERED_FAILED, pProvider->sczKey, wzPackageId, hr); } @@ -1390,15 +1381,14 @@ static HRESULT RegisterPackageProviderDependent( ) { HRESULT hr = S_OK; + BOOL fExists = FALSE; LogId(REPORT_VERBOSE, MSG_DEPENDENCY_PACKAGE_REGISTER_DEPENDENCY, wzDependentProviderKey, pProvider->sczKey, wzPackageId); hr = DepRegisterDependent(hkRoot, pProvider->sczKey, wzDependentProviderKey, NULL, NULL, 0); - if (E_FILENOTFOUND != hr) - { - ExitOnFailure(hr, "Failed to register the dependency on package dependency provider: %ls", pProvider->sczKey); - } - else + ExitOnPathFailure(hr, fExists, "Failed to register the dependency on package dependency provider: %ls", pProvider->sczKey); + + if (!fExists) { LogId(REPORT_VERBOSE, MSG_DEPENDENCY_PACKAGE_SKIP_MISSING, pProvider->sczKey, wzPackageId); } @@ -1454,11 +1444,11 @@ static void UnregisterPackageProviderDependent( HRESULT hr = S_OK; hr = DepUnregisterDependent(hkRoot, pProvider->sczKey, wzDependentProviderKey); - if (SUCCEEDED(hr)) + if (SUCCEEDED(hr) || E_FILENOTFOUND == hr) { LogId(REPORT_VERBOSE, MSG_DEPENDENCY_PACKAGE_UNREGISTERED_DEPENDENCY, wzDependentProviderKey, pProvider->sczKey, wzPackageId); } - else if (FAILED(hr) && E_FILENOTFOUND != hr) + else { LogId(REPORT_VERBOSE, MSG_DEPENDENCY_PACKAGE_UNREGISTERED_DEPENDENCY_FAILED, wzDependentProviderKey, pProvider->sczKey, wzPackageId, hr); } diff --git a/src/burn/engine/exeengine.cpp b/src/burn/engine/exeengine.cpp index ef0015ac..b4898d42 100644 --- a/src/burn/engine/exeengine.cpp +++ b/src/burn/engine/exeengine.cpp @@ -1040,6 +1040,7 @@ static HRESULT DetectArpEntry( { HRESULT hr = S_OK; HKEY hKey = NULL; + BOOL fExists = FALSE; VERUTIL_VERSION* pVersion = NULL; int nCompareResult = 0; HKEY hkRoot = pPackage->fPerMachine ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; @@ -1052,18 +1053,20 @@ static HRESULT DetectArpEntry( } hr = RegOpenEx(hkRoot, pPackage->Exe.sczArpKeyPath, KEY_READ, keyBitness, &hKey); - if (HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) == hr || HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) == hr) + ExitOnPathFailure(hr, fExists, "Failed to open registry key: %ls.", pPackage->Exe.sczArpKeyPath); + + if (!fExists) { - ExitFunction1(hr = S_OK); + ExitFunction(); } - ExitOnFailure(hr, "Failed to open registry key: %ls.", pPackage->Exe.sczArpKeyPath); hr = RegReadWixVersion(hKey, L"DisplayVersion", &pVersion); - if (HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) == hr) + ExitOnPathFailure(hr, fExists, "Failed to read DisplayVersion."); + + if (!fExists) { - ExitFunction1(hr = S_OK); + ExitFunction(); } - ExitOnFailure(hr, "Failed to read DisplayVersion."); if (pVersion->fInvalid) { @@ -1089,11 +1092,7 @@ static HRESULT DetectArpEntry( if (psczQuietUninstallString) { hr = RegReadString(hKey, L"QuietUninstallString", psczQuietUninstallString); - if (HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) == hr) - { - hr = S_OK; - } - ExitOnFailure(hr, "Failed to read QuietUninstallString."); + ExitOnPathFailure(hr, fExists, "Failed to read QuietUninstallString."); } LExit: diff --git a/src/burn/engine/registration.cpp b/src/burn/engine/registration.cpp index 484c08ac..35100336 100644 --- a/src/burn/engine/registration.cpp +++ b/src/burn/engine/registration.cpp @@ -492,25 +492,28 @@ extern "C" HRESULT RegistrationDetectResumeType( { HRESULT hr = S_OK; HKEY hkRegistration = NULL; + BOOL fExists = FALSE; DWORD dwResume = 0; // open registration key hr = RegOpen(pRegistration->hkRoot, pRegistration->sczRegistrationKey, KEY_QUERY_VALUE, &hkRegistration); - if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) + ExitOnPathFailure(hr, fExists, "Failed to open registration key."); + + if (!fExists) { *pResumeType = BOOTSTRAPPER_RESUME_TYPE_NONE; - ExitFunction1(hr = S_OK); + ExitFunction(); } - ExitOnFailure(hr, "Failed to open registration key."); // read Resume value hr = RegReadNumber(hkRegistration, L"Resume", &dwResume); - if (E_FILENOTFOUND == hr) + ExitOnPathFailure(hr, fExists, "Failed to read Resume value."); + + if (!fExists) { *pResumeType = BOOTSTRAPPER_RESUME_TYPE_INVALID; - ExitFunction1(hr = S_OK); + ExitFunction(); } - ExitOnFailure(hr, "Failed to read Resume value."); switch (dwResume) { @@ -855,6 +858,7 @@ extern "C" HRESULT RegistrationSessionEnd( { HRESULT hr = S_OK; HKEY hkRegistration = NULL; + BOOL fDeleted = FALSE; // If no resume mode, then remove the bundle registration. if (BURN_RESUME_MODE_NONE == resumeMode) @@ -874,10 +878,7 @@ extern "C" HRESULT RegistrationSessionEnd( // Delete registration key. hr = RegDelete(pRegistration->hkRoot, pRegistration->sczRegistrationKey, REG_KEY_DEFAULT, TRUE); - if (E_FILENOTFOUND != hr) - { - ExitOnFailure(hr, "Failed to delete registration key: %ls", pRegistration->sczRegistrationKey); - } + ExitOnPathFailure(hr, fDeleted, "Failed to delete registration key: %ls", pRegistration->sczRegistrationKey); CacheRemoveBundle(pCache, pRegistration->fPerMachine, pRegistration->sczId); } @@ -967,7 +968,10 @@ extern "C" HRESULT RegistrationSaveState( ExitOnFailure(hr, "Failed to enumerate value %u", i); er = ::RegDeleteValueW(hkRegistration, sczValueName); - ExitOnWin32Error(er, hr, "Failed to delete registration variable value."); + if (ERROR_FILE_NOT_FOUND != er) + { + ExitOnWin32Error(er, hr, "Failed to delete registration variable value."); + } } // Write variables. @@ -1486,6 +1490,7 @@ static HRESULT RemoveUpdateRegistration( LPWSTR sczPackageVersion = NULL; HKEY hkKey = NULL; BOOL fDeleteRegKey = TRUE; + BOOL fDeleted = FALSE; hr = FormatUpdateRegistrationKey(pRegistration, &sczKey); ExitOnFailure(hr, "Failed to format key for update registration."); @@ -1513,10 +1518,7 @@ static HRESULT RemoveUpdateRegistration( if (fDeleteRegKey) { hr = RegDelete(pRegistration->hkRoot, sczKey, REG_KEY_DEFAULT, FALSE); - if (E_FILENOTFOUND != hr) - { - ExitOnFailure(hr, "Failed to remove update registration key: %ls", sczKey); - } + ExitOnPathFailure(hr, fDeleted, "Failed to remove update registration key: %ls", sczKey); } LExit: diff --git a/src/burn/engine/relatedbundle.cpp b/src/burn/engine/relatedbundle.cpp index 586446b1..23e0f352 100644 --- a/src/burn/engine/relatedbundle.cpp +++ b/src/burn/engine/relatedbundle.cpp @@ -322,6 +322,7 @@ static HRESULT LoadRelatedBundleFromKey( LPWSTR sczCachePath = NULL; BOOL fCached = FALSE; DWORD64 qwFileSize = 0; + BOOL fExists = FALSE; BURN_DEPENDENCY_PROVIDER dependencyProvider = { }; BURN_DEPENDENCY_PROVIDER* pBundleDependencyProvider = NULL; @@ -369,10 +370,7 @@ static HRESULT LoadRelatedBundleFromKey( pRelatedBundle->fPlannable = fCached; hr = RegReadString(hkBundleId, BURN_REGISTRATION_REGISTRY_BUNDLE_PROVIDER_KEY, &dependencyProvider.sczKey); - if (E_FILENOTFOUND != hr) - { - ExitOnFailure(hr, "Failed to read provider key from registry for bundle: %ls", wzRelatedBundleId); - } + ExitOnPathFailure(hr, fExists, "Failed to read provider key from registry for bundle: %ls", wzRelatedBundleId); if (dependencyProvider.sczKey && *dependencyProvider.sczKey) { @@ -384,18 +382,11 @@ static HRESULT LoadRelatedBundleFromKey( ExitOnFailure(hr, "Failed to copy version for bundle: %ls", wzRelatedBundleId); hr = RegReadString(hkBundleId, BURN_REGISTRATION_REGISTRY_BUNDLE_DISPLAY_NAME, &dependencyProvider.sczDisplayName); - if (E_FILENOTFOUND != hr) - { - ExitOnFailure(hr, "Failed to copy display name for bundle: %ls", wzRelatedBundleId); - } + ExitOnPathFailure(hr, fExists, "Failed to copy display name for bundle: %ls", wzRelatedBundleId); } hr = RegReadString(hkBundleId, BURN_REGISTRATION_REGISTRY_BUNDLE_TAG, &pRelatedBundle->sczTag); - if (E_FILENOTFOUND == hr) - { - hr = S_OK; - } - ExitOnFailure(hr, "Failed to read tag from registry for bundle: %ls", wzRelatedBundleId); + ExitOnPathFailure(hr, fExists, "Failed to read tag from registry for bundle: %ls", wzRelatedBundleId); pRelatedBundle->detectRelationType = relationType; diff --git a/src/burn/engine/search.cpp b/src/burn/engine/search.cpp index b37dc9bd..a1b6b74a 100644 --- a/src/burn/engine/search.cpp +++ b/src/burn/engine/search.cpp @@ -610,6 +610,7 @@ static HRESULT DirectorySearchExists( ) { HRESULT hr = S_OK; + DWORD er = ERROR_SUCCESS; LPWSTR sczPath = NULL; BOOL fExists = FALSE; @@ -629,21 +630,25 @@ static HRESULT DirectorySearchExists( DWORD dwAttributes = ::GetFileAttributesW(sczPath); if (INVALID_FILE_ATTRIBUTES == dwAttributes) { - hr = HRESULT_FROM_WIN32(::GetLastError()); - if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) + er = ::GetLastError(); + if (ERROR_FILE_NOT_FOUND == er || ERROR_PATH_NOT_FOUND == er) { - hr = S_OK; // didn't find file, fExists still is false. + LogStringLine(REPORT_STANDARD, "Directory search: %ls, did not find path: %ls", pSearch->sczKey, pSearch->DirectorySearch.sczPath); + } + else + { + ExitOnWin32Error(er, hr, "Directory search: %ls, failed get to directory attributes. '%ls'", pSearch->sczKey, pSearch->DirectorySearch.sczPath); } } - else if (dwAttributes & FILE_ATTRIBUTE_DIRECTORY) + else if (FILE_ATTRIBUTE_DIRECTORY != (dwAttributes & FILE_ATTRIBUTE_DIRECTORY)) + { + LogStringLine(REPORT_STANDARD, "Directory search: %ls, found file at path: %ls", pSearch->sczKey, pSearch->DirectorySearch.sczPath); + } + else { fExists = TRUE; } - // else must have found a file. - // What if there is a hidden variable in sczPath? - ExitOnFailure(hr, "Failed while searching directory search: %ls, for path: %ls", pSearch->sczKey, sczPath); - // set variable hr = VariableSetNumeric(pVariables, pSearch->sczVariable, fExists, FALSE); ExitOnFailure(hr, "Failed to set variable."); @@ -694,13 +699,12 @@ static HRESULT DirectorySearchPath( hr = E_PATHNOTFOUND; } - // What if there is a hidden variable in sczPath? if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) { - LogStringLine(REPORT_STANDARD, "Directory search: %ls, did not find path: %ls, reason: 0x%x", pSearch->sczKey, sczPath, hr); + LogStringLine(REPORT_STANDARD, "Directory search: %ls, did not find path: %ls, reason: 0x%x", pSearch->sczKey, pSearch->DirectorySearch.sczPath, hr); ExitFunction1(hr = S_OK); } - ExitOnFailure(hr, "Failed while searching directory search: %ls, for path: %ls", pSearch->sczKey, sczPath); + ExitOnFailure(hr, "Failed while searching directory search: %ls, for path: %ls", pSearch->sczKey, pSearch->DirectorySearch.sczPath); LExit: #if !defined(_WIN64) @@ -742,15 +746,18 @@ static HRESULT FileSearchExists( er = ::GetLastError(); if (ERROR_FILE_NOT_FOUND == er || ERROR_PATH_NOT_FOUND == er) { - // What if there is a hidden variable in sczPath? - LogStringLine(REPORT_STANDARD, "File search: %ls, did not find path: %ls", pSearch->sczKey, sczPath); + LogStringLine(REPORT_STANDARD, "File search: %ls, did not find path: %ls", pSearch->sczKey, pSearch->FileSearch.sczPath); } else { - ExitOnWin32Error(er, hr, "Failed get to file attributes. '%ls'", pSearch->FileSearch.sczPath); + ExitOnWin32Error(er, hr, "File search: %ls, failed get to file attributes. '%ls'", pSearch->sczKey, pSearch->FileSearch.sczPath); } } - else if (FILE_ATTRIBUTE_DIRECTORY != (dwAttributes & FILE_ATTRIBUTE_DIRECTORY)) + else if (FILE_ATTRIBUTE_DIRECTORY == (dwAttributes & FILE_ATTRIBUTE_DIRECTORY)) + { + LogStringLine(REPORT_STANDARD, "File search: %ls, found directory at path: %ls", pSearch->sczKey, pSearch->FileSearch.sczPath); + } + else { fExists = TRUE; } @@ -795,8 +802,7 @@ static HRESULT FileSearchVersion( hr = FileVersion(sczPath, &uliVersion.HighPart, &uliVersion.LowPart); if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) { - // What if there is a hidden variable in sczPath? - LogStringLine(REPORT_STANDARD, "File search: %ls, did not find path: %ls", pSearch->sczKey, sczPath); + LogStringLine(REPORT_STANDARD, "File search: %ls, did not find path: %ls", pSearch->sczKey, pSearch->FileSearch.sczPath); ExitFunction1(hr = S_OK); } ExitOnFailure(hr, "Failed to get file version."); @@ -854,13 +860,12 @@ static HRESULT FileSearchPath( ExitOnFailure(hr, "Failed to set variable to file search path."); } - // What if there is a hidden variable in sczPath? if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) { - LogStringLine(REPORT_STANDARD, "File search: %ls, did not find path: %ls", pSearch->sczKey, sczPath); + LogStringLine(REPORT_STANDARD, "File search: %ls, did not find path: %ls", pSearch->sczKey, pSearch->FileSearch.sczPath); ExitFunction1(hr = S_OK); } - ExitOnFailure(hr, "Failed while searching file search: %ls, for path: %ls", pSearch->sczKey, sczPath); + ExitOnFailure(hr, "Failed while searching file search: %ls, for path: %ls", pSearch->sczKey, pSearch->FileSearch.sczPath); LExit: #if !defined(_WIN64) @@ -891,24 +896,13 @@ static HRESULT RegistrySearchExists( // open key hr = RegOpenEx(pSearch->RegistrySearch.hRoot, sczKey, KEY_QUERY_VALUE, pSearch->RegistrySearch.fWin64 ? REG_KEY_64BIT : REG_KEY_32BIT, &hKey); - if (SUCCEEDED(hr)) - { - fExists = TRUE; - } - else if (E_FILENOTFOUND == hr) - { - // What if there is a hidden variable in sczKey? - LogStringLine(REPORT_STANDARD, "Registry key not found. Key = '%ls'", sczKey); - fExists = FALSE; - hr = S_OK; - } - else + ExitOnPathFailure(hr, fExists, "Failed to open registry key. Key = '%ls'", pSearch->RegistrySearch.sczKey); + + if (!fExists) { - // What if there is a hidden variable in sczKey? - ExitOnFailure(hr, "Failed to open registry key. Key = '%ls'", sczKey); + LogStringLine(REPORT_STANDARD, "Registry key not found. Key = '%ls'", pSearch->RegistrySearch.sczKey); } - - if (fExists && pSearch->RegistrySearch.sczValue) + else if (pSearch->RegistrySearch.sczValue) { // format value string hr = VariableFormatString(pVariables, pSearch->RegistrySearch.sczValue, &sczValue, NULL); @@ -922,8 +916,7 @@ static HRESULT RegistrySearchExists( fExists = TRUE; break; case ERROR_FILE_NOT_FOUND: - // What if there is a hidden variable in sczKey or sczValue? - LogStringLine(REPORT_STANDARD, "Registry value not found. Key = '%ls', Value = '%ls'", sczKey, sczValue); + LogStringLine(REPORT_STANDARD, "Registry value not found. Key = '%ls', Value = '%ls'", pSearch->RegistrySearch.sczKey, pSearch->RegistrySearch.sczValue); fExists = FALSE; break; default: @@ -938,8 +931,7 @@ static HRESULT RegistrySearchExists( LExit: if (FAILED(hr)) { - // What if there is a hidden variable in sczKey? - LogStringLine(REPORT_STANDARD, "RegistrySearchExists failed: ID '%ls', HRESULT 0x%x", sczKey, hr); + LogStringLine(REPORT_STANDARD, "RegistrySearchExists failed: ID '%ls', HRESULT 0x%x", pSearch->sczKey, hr); } StrSecureZeroFreeString(sczKey); @@ -958,6 +950,7 @@ static HRESULT RegistrySearchValue( LPWSTR sczKey = NULL; LPWSTR sczValue = NULL; HKEY hKey = NULL; + BOOL fExists = FALSE; DWORD dwType = 0; SIZE_T cbData = 0; LPBYTE pData = NULL; @@ -978,21 +971,20 @@ static HRESULT RegistrySearchValue( // open key hr = RegOpenEx(pSearch->RegistrySearch.hRoot, sczKey, KEY_QUERY_VALUE, pSearch->RegistrySearch.fWin64 ? REG_KEY_64BIT : REG_KEY_32BIT, &hKey); - if (E_FILENOTFOUND == hr) + ExitOnPathFailure(hr, fExists, "Failed to open registry key."); + + if (!fExists) { - // What if there is a hidden variable in sczKey? - LogStringLine(REPORT_STANDARD, "Registry key not found. Key = '%ls'", sczKey); + LogStringLine(REPORT_STANDARD, "Registry key not found. Key = '%ls'", pSearch->RegistrySearch.sczKey); - ExitFunction1(hr = S_OK); + ExitFunction(); } - ExitOnFailure(hr, "Failed to open registry key."); // get value hr = RegReadValue(hKey, sczValue, pSearch->RegistrySearch.fExpandEnvironment, &pData, &cbData, &dwType); if (E_FILENOTFOUND == hr) { - // What if there is a hidden variable in sczKey or sczValue? - LogStringLine(REPORT_STANDARD, "Registry value not found. Key = '%ls', Value = '%ls'", sczKey, sczValue); + LogStringLine(REPORT_STANDARD, "Registry value not found. Key = '%ls', Value = '%ls'", pSearch->RegistrySearch.sczKey, pSearch->RegistrySearch.sczValue); ExitFunction1(hr = S_OK); } @@ -1034,8 +1026,7 @@ static HRESULT RegistrySearchValue( LExit: if (FAILED(hr)) { - // What if there is a hidden variable in sczKey? - LogStringLine(REPORT_STANDARD, "RegistrySearchValue failed: ID '%ls', HRESULT 0x%x", sczKey, hr); + LogStringLine(REPORT_STANDARD, "RegistrySearchValue failed: ID '%ls', HRESULT 0x%x", pSearch->sczKey, hr); } StrSecureZeroFreeString(sczKey); diff --git a/src/ext/Bal/dnchost/dncutil.cpp b/src/ext/Bal/dnchost/dncutil.cpp index 6486e6e9..a8d4f4ff 100644 --- a/src/ext/Bal/dnchost/dncutil.cpp +++ b/src/ext/Bal/dnchost/dncutil.cpp @@ -338,7 +338,7 @@ static HRESULT InitializeCoreClrPre5( { BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "%ls: %ls", rgPropertyKeys[i], rgPropertyValues[i]); } - BalExitOnFailure(hr = E_FILENOTFOUND, "Failed to locate coreclr.dll."); + BalExitWithRootFailure(hr, E_FILENOTFOUND, "Failed to locate coreclr.dll."); } hr = LoadCoreClr(pState, sczCoreClrPath); diff --git a/src/ext/Bal/mbahost/mbahost.cpp b/src/ext/Bal/mbahost/mbahost.cpp index 5edbe376..9d8acc8a 100644 --- a/src/ext/Bal/mbahost/mbahost.cpp +++ b/src/ext/Bal/mbahost/mbahost.cpp @@ -228,31 +228,31 @@ static HRESULT GetAppDomain( // Create the setup information for a new AppDomain to set the app base and config. hr = pState->pCLRHost->CreateDomainSetup(&pUnk); - ExitOnRootFailure(hr, "Failed to create the AppDomainSetup object."); + BalExitOnRootFailure(hr, "Failed to create the AppDomainSetup object."); hr = pUnk->QueryInterface(__uuidof(IAppDomainSetup), reinterpret_cast(&pAppDomainSetup)); - ExitOnRootFailure(hr, "Failed to query for the IAppDomainSetup interface."); + BalExitOnRootFailure(hr, "Failed to query for the IAppDomainSetup interface."); ReleaseNullObject(pUnk); // Set properties on the AppDomainSetup object. bstrAppBase = ::SysAllocString(pState->sczAppBase); - ExitOnNull(bstrAppBase, hr, E_OUTOFMEMORY, "Failed to allocate the application base path for the AppDomainSetup."); + BalExitOnNull(bstrAppBase, hr, E_OUTOFMEMORY, "Failed to allocate the application base path for the AppDomainSetup."); hr = pAppDomainSetup->put_ApplicationBase(bstrAppBase); - ExitOnRootFailure(hr, "Failed to set the application base path for the AppDomainSetup."); + BalExitOnRootFailure(hr, "Failed to set the application base path for the AppDomainSetup."); bstrConfigPath = ::SysAllocString(pState->sczConfigPath); - ExitOnNull(bstrConfigPath, hr, E_OUTOFMEMORY, "Failed to allocate the application configuration file for the AppDomainSetup."); + BalExitOnNull(bstrConfigPath, hr, E_OUTOFMEMORY, "Failed to allocate the application configuration file for the AppDomainSetup."); hr = pAppDomainSetup->put_ConfigurationFile(bstrConfigPath); - ExitOnRootFailure(hr, "Failed to set the configuration file path for the AppDomainSetup."); + BalExitOnRootFailure(hr, "Failed to set the configuration file path for the AppDomainSetup."); // Create the AppDomain to load the factory type. hr = pState->pCLRHost->CreateDomainEx(L"MBA", pAppDomainSetup, NULL, &pUnk); - ExitOnRootFailure(hr, "Failed to create the MBA AppDomain."); + BalExitOnRootFailure(hr, "Failed to create the MBA AppDomain."); hr = pUnk->QueryInterface(__uuidof(_AppDomain), reinterpret_cast(&pState->pAppDomain)); - ExitOnRootFailure(hr, "Failed to query for the _AppDomain interface."); + BalExitOnRootFailure(hr, "Failed to query for the _AppDomain interface."); LExit: ReleaseBSTR(bstrConfigPath); @@ -270,13 +270,13 @@ static HRESULT LoadModulePaths( LPWSTR sczFullPath = NULL; hr = PathForCurrentProcess(&sczFullPath, pState->hInstance); - ExitOnFailure(hr, "Failed to get the full host path."); + BalExitOnFailure(hr, "Failed to get the full host path."); hr = PathGetDirectory(sczFullPath, &pState->sczAppBase); - ExitOnFailure(hr, "Failed to get the directory of the full process path."); + BalExitOnFailure(hr, "Failed to get the directory of the full process path."); hr = PathConcat(pState->sczAppBase, MBA_CONFIG_FILE_NAME, &pState->sczConfigPath); - ExitOnFailure(hr, "Failed to get the full path to the application configuration file."); + BalExitOnFailure(hr, "Failed to get the full path to the application configuration file."); LExit: ReleaseStr(sczFullPath); @@ -332,23 +332,23 @@ static HRESULT CheckSupportedFrameworks( BOOL fUpdatedManifest = FALSE; hr = XmlLoadDocumentFromFile(wzConfigPath, &pixdManifest); - ExitOnFailure(hr, "Failed to load bootstrapper config file from path: %ls", wzConfigPath); + BalExitOnFailure(hr, "Failed to load bootstrapper config file from path: %ls", wzConfigPath); hr = XmlSelectNodes(pixdManifest, L"/configuration/wix.bootstrapper/host/supportedFramework", &pNodeList); - ExitOnFailure(hr, "Failed to select all supportedFramework elements."); + BalExitOnFailure(hr, "Failed to select all supportedFramework elements."); hr = pNodeList->get_length(reinterpret_cast(&cSupportedFrameworks)); - ExitOnFailure(hr, "Failed to get the supported framework count."); + BalExitOnFailure(hr, "Failed to get the supported framework count."); if (cSupportedFrameworks) { while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, NULL))) { hr = XmlGetAttributeEx(pNode, L"version", &sczSupportedFrameworkVersion); - ExitOnRequiredXmlQueryFailure(hr, "Failed to get supportedFramework/@version."); + BalExitOnRequiredXmlQueryFailure(hr, "Failed to get supportedFramework/@version."); hr = StrAllocFormatted(&sczFrameworkRegistryKey, L"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\%ls", sczSupportedFrameworkVersion); - ExitOnFailure(hr, "Failed to allocate path to supported framework Install registry key."); + BalExitOnFailure(hr, "Failed to allocate path to supported framework Install registry key."); hr = RegOpen(HKEY_LOCAL_MACHINE, sczFrameworkRegistryKey, KEY_READ, &hkFramework); if (SUCCEEDED(hr)) @@ -367,19 +367,18 @@ static HRESULT CheckSupportedFrameworks( // If we looped through all the supported frameworks but didn't find anything, ensure we return a failure. if (S_FALSE == hr) { - hr = E_NOTFOUND; - ExitOnRootFailure(hr, "Failed to find a supported framework."); + BalExitWithRootFailure(hr, E_NOTFOUND, "Failed to find a supported framework."); } hr = UpdateSupportedRuntime(pixdManifest, pNode, &fUpdatedManifest); - ExitOnFailure(hr, "Failed to update supportedRuntime."); + BalExitOnFailure(hr, "Failed to update supportedRuntime."); } // else no supported frameworks specified, so the startup/supportedRuntime must be enough. if (fUpdatedManifest) { hr = XmlSaveDocument(pixdManifest, wzConfigPath); - ExitOnFailure(hr, "Failed to save updated manifest over config file: %ls", wzConfigPath); + BalExitOnFailure(hr, "Failed to save updated manifest over config file: %ls", wzConfigPath); } LExit: @@ -410,7 +409,7 @@ static HRESULT UpdateSupportedRuntime( // If the runtime version attribute is not specified, don't update the manifest. hr = XmlGetAttributeEx(pixnSupportedFramework, L"runtimeVersion", &sczSupportedRuntimeVersion); - ExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get supportedFramework/@runtimeVersion."); + BalExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get supportedFramework/@runtimeVersion."); if (!fXmlFound) { @@ -420,17 +419,17 @@ static HRESULT UpdateSupportedRuntime( // Get the startup element. Fail if we can't find it since it'll be necessary to load the // correct runtime. hr = XmlSelectSingleNode(pixdManifest, L"/configuration/startup", &pixnStartup); - ExitOnRequiredXmlQueryFailure(hr, "Failed to get startup element."); + BalExitOnRequiredXmlQueryFailure(hr, "Failed to get startup element."); // Remove any pre-existing supported runtimes because they'll just get in the way and create our new one. hr = XmlRemoveChildren(pixnStartup, L"supportedRuntime"); - ExitOnFailure(hr, "Failed to remove pre-existing supportedRuntime elements."); + BalExitOnFailure(hr, "Failed to remove pre-existing supportedRuntime elements."); hr = XmlCreateChild(pixnStartup, L"supportedRuntime", &pixnSupportedRuntime); - ExitOnFailure(hr, "Failed to create supportedRuntime element."); + BalExitOnFailure(hr, "Failed to create supportedRuntime element."); hr = XmlSetAttribute(pixnSupportedRuntime, L"version", sczSupportedRuntimeVersion); - ExitOnFailure(hr, "Failed to set supportedRuntime/@version to '%ls'.", sczSupportedRuntimeVersion); + BalExitOnFailure(hr, "Failed to set supportedRuntime/@version to '%ls'.", sczSupportedRuntimeVersion); *pfUpdatedManifest = TRUE; @@ -465,14 +464,14 @@ static HRESULT LoadRuntime( // Check that the supported framework is installed. hr = CheckSupportedFrameworks(pState->sczConfigPath); - ExitOnFailure(hr, "Failed to find supported framework."); + BalExitOnFailure(hr, "Failed to find supported framework."); // Cache the CLR host to be shutdown later. This can occur on a different thread. // Disable message boxes from being displayed on error and blocking execution. ::SetErrorMode(uiMode | SEM_FAILCRITICALERRORS); hr = LoadSystemLibrary(L"mscoree.dll", &hModule); - ExitOnFailure(hr, "Failed to load mscoree.dll"); + BalExitOnFailure(hr, "Failed to load mscoree.dll"); pfnCLRCreateInstance = reinterpret_cast(::GetProcAddress(hModule, "CLRCreateInstance")); @@ -481,7 +480,7 @@ static HRESULT LoadRuntime( hr = pfnCLRCreateInstance(CLSID_CLRMetaHostPolicy, IID_ICLRMetaHostPolicy, reinterpret_cast(&pCLRMetaHostPolicy)); if (E_NOTIMPL != hr) { - ExitOnRootFailure(hr, "Failed to create instance of ICLRMetaHostPolicy."); + BalExitOnRootFailure(hr, "Failed to create instance of ICLRMetaHostPolicy."); fFallbackToCorBindToCurrentRuntime = FALSE; } @@ -490,19 +489,19 @@ static HRESULT LoadRuntime( if (fFallbackToCorBindToCurrentRuntime) { pfnCorBindToCurrentRuntime = reinterpret_cast(::GetProcAddress(hModule, "CorBindToCurrentRuntime")); - ExitOnNullWithLastError(pfnCorBindToCurrentRuntime, hr, "Failed to get procedure address for CorBindToCurrentRuntime."); + BalExitOnNullWithLastError(pfnCorBindToCurrentRuntime, hr, "Failed to get procedure address for CorBindToCurrentRuntime."); hr = pfnCorBindToCurrentRuntime(pState->sczConfigPath, CLSID_CorRuntimeHost, IID_ICorRuntimeHost, reinterpret_cast(&pState->pCLRHost)); - ExitOnRootFailure(hr, "Failed to create the CLR host using the application configuration file path."); + BalExitOnRootFailure(hr, "Failed to create the CLR host using the application configuration file path."); } else { hr = SHCreateStreamOnFileEx(pState->sczConfigPath, STGM_READ | STGM_SHARE_DENY_WRITE, 0, FALSE, NULL, &pCfgStream); - ExitOnFailure(hr, "Failed to load bootstrapper config file from path: %ls", pState->sczConfigPath); + BalExitOnFailure(hr, "Failed to load bootstrapper config file from path: %ls", pState->sczConfigPath); hr = pCLRMetaHostPolicy->GetRequestedRuntime(METAHOST_POLICY_HIGHCOMPAT, NULL, pCfgStream, NULL, &cchVersion, NULL, NULL, &dwConfigFlags, IID_ICLRRuntimeInfo, reinterpret_cast(&pCLRRuntimeInfo)); - ExitOnRootFailure(hr, "Failed to get the CLR runtime info using the application configuration file path."); + BalExitOnRootFailure(hr, "Failed to get the CLR runtime info using the application configuration file path."); // .NET 4 RTM had a bug where it wouldn't set pcchVersion if pwzVersion was NULL. if (!cchVersion) @@ -510,7 +509,7 @@ static HRESULT LoadRuntime( hr = pCLRRuntimeInfo->GetVersionString(NULL, &cchVersion); if (HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) != hr) { - ExitOnFailure(hr, "Failed to get the length of the CLR version string."); + BalExitOnFailure(hr, "Failed to get the length of the CLR version string."); } } @@ -523,21 +522,21 @@ static HRESULT LoadRuntime( if (CSTR_EQUAL == CompareString(LOCALE_NEUTRAL, 0, L"v4.0.30319", -1, pwzVersion, cchVersion)) { hr = VerifyNET4RuntimeIsSupported(); - ExitOnFailure(hr, "Found unsupported .NET 4 Runtime."); + BalExitOnFailure(hr, "Found unsupported .NET 4 Runtime."); } if (METAHOST_CONFIG_FLAGS_LEGACY_V2_ACTIVATION_POLICY_TRUE == (METAHOST_CONFIG_FLAGS_LEGACY_V2_ACTIVATION_POLICY_MASK & dwConfigFlags)) { hr = pCLRRuntimeInfo->BindAsLegacyV2Runtime(); - ExitOnRootFailure(hr, "Failed to bind as legacy V2 runtime."); + BalExitOnRootFailure(hr, "Failed to bind as legacy V2 runtime."); } hr = pCLRRuntimeInfo->GetInterface(CLSID_CorRuntimeHost, IID_ICorRuntimeHost, reinterpret_cast(&pState->pCLRHost)); - ExitOnRootFailure(hr, "Failed to get instance of ICorRuntimeHost."); + BalExitOnRootFailure(hr, "Failed to get instance of ICorRuntimeHost."); } hr = pState->pCLRHost->Start(); - ExitOnRootFailure(hr, "Failed to start the CLR host."); + BalExitOnRootFailure(hr, "Failed to start the CLR host."); LExit: ReleaseStr(pwzVersion); @@ -567,10 +566,10 @@ static HRESULT CreateManagedBootstrapperApplication( IBootstrapperApplicationFactory* pAppFactory = NULL; hr = CreateManagedBootstrapperApplicationFactory(pAppDomain, &pAppFactory); - ExitOnFailure(hr, "Failed to create the factory to create the bootstrapper application."); + BalExitOnFailure(hr, "Failed to create the factory to create the bootstrapper application."); hr = pAppFactory->Create(pArgs, pResults); - ExitOnFailure(hr, "Failed to create the bootstrapper application."); + BalExitOnFailure(hr, "Failed to create the bootstrapper application."); LExit: ReleaseNullObject(pAppFactory); @@ -593,20 +592,20 @@ static HRESULT CreateManagedBootstrapperApplicationFactory( ::VariantInit(&vtBAFactory); bstrAssemblyName = ::SysAllocString(MBA_ASSEMBLY_FULL_NAME); - ExitOnNull(bstrAssemblyName, hr, E_OUTOFMEMORY, "Failed to allocate the full assembly name for the bootstrapper application factory."); + BalExitOnNull(bstrAssemblyName, hr, E_OUTOFMEMORY, "Failed to allocate the full assembly name for the bootstrapper application factory."); bstrTypeName = ::SysAllocString(MBA_ENTRY_TYPE); - ExitOnNull(bstrTypeName, hr, E_OUTOFMEMORY, "Failed to allocate the full type name for the BA factory."); + BalExitOnNull(bstrTypeName, hr, E_OUTOFMEMORY, "Failed to allocate the full type name for the BA factory."); hr = pAppDomain->CreateInstance(bstrAssemblyName, bstrTypeName, &pObj); - ExitOnRootFailure(hr, "Failed to create the BA factory object."); + BalExitOnRootFailure(hr, "Failed to create the BA factory object."); hr = pObj->Unwrap(&vtBAFactory); - ExitOnRootFailure(hr, "Failed to unwrap the BA factory object into the host domain."); - ExitOnNull(vtBAFactory.punkVal, hr, E_UNEXPECTED, "The variant did not contain the expected IUnknown pointer."); + BalExitOnRootFailure(hr, "Failed to unwrap the BA factory object into the host domain."); + BalExitOnNull(vtBAFactory.punkVal, hr, E_UNEXPECTED, "The variant did not contain the expected IUnknown pointer."); hr = vtBAFactory.punkVal->QueryInterface(__uuidof(IBootstrapperApplicationFactory), reinterpret_cast(ppAppFactory)); - ExitOnRootFailure(hr, "Failed to query for the bootstrapper app factory interface."); + BalExitOnRootFailure(hr, "Failed to query for the bootstrapper app factory interface."); LExit: ReleaseVariant(vtBAFactory); @@ -632,13 +631,13 @@ static HRESULT CreatePrerequisiteBA( BalExitOnFailure(hr, "Failed to get path to pre-requisite BA."); hModule = ::LoadLibraryExW(sczMbapreqPath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); - ExitOnNullWithLastError(hModule, hr, "Failed to load pre-requisite BA DLL."); + BalExitOnNullWithLastError(hModule, hr, "Failed to load pre-requisite BA DLL."); PFN_PREQ_BOOTSTRAPPER_APPLICATION_CREATE pfnCreate = reinterpret_cast(::GetProcAddress(hModule, "PrereqBootstrapperApplicationCreate")); - ExitOnNullWithLastError(pfnCreate, hr, "Failed to get PrereqBootstrapperApplicationCreate entry-point from: %ls", sczMbapreqPath); + BalExitOnNullWithLastError(pfnCreate, hr, "Failed to get PrereqBootstrapperApplicationCreate entry-point from: %ls", sczMbapreqPath); hr = pfnCreate(&pState->prereqData, pEngine, pArgs, pResults); - ExitOnFailure(hr, "Failed to create prequisite bootstrapper app."); + BalExitOnFailure(hr, "Failed to create prequisite bootstrapper app."); pState->hMbapreqModule = hModule; hModule = NULL; @@ -672,14 +671,14 @@ static HRESULT VerifyNET4RuntimeIsSupported( { ExitFunction1(hr = S_OK); } - ExitOnFailure(hr, "Failed to open registry key for .NET 4."); + BalExitOnFailure(hr, "Failed to open registry key for .NET 4."); er = ::RegQueryValueExW(hKey, L"Release", NULL, NULL, reinterpret_cast(&dwRelease), &cchRelease); if (ERROR_FILE_NOT_FOUND == er) { ExitFunction1(hr = S_OK); } - ExitOnWin32Error(er, hr, "Failed to get Release value."); + BalExitOnWin32Error(er, hr, "Failed to get Release value."); if (NET452_RELEASE <= dwRelease) { diff --git a/src/ext/Dependency/ca/wixdepca.cpp b/src/ext/Dependency/ca/wixdepca.cpp index e9278e04..87610420 100644 --- a/src/ext/Dependency/ca/wixdepca.cpp +++ b/src/ext/Dependency/ca/wixdepca.cpp @@ -277,6 +277,7 @@ static HRESULT EnsureAbsentDependents( DEPENDENCY* rgDependents = NULL; UINT cDependents = 0; PMSIHANDLE hDependencyRec = NULL; + BOOL fExists = FALSE; // Skip the dependent check if the Wix4DependencyProvider table is missing (no dependency providers). hr = WcaTableExists(L"Wix4DependencyProvider"); @@ -338,11 +339,7 @@ static HRESULT EnsureAbsentDependents( // Check the registry to see if the provider has any dependents registered. hr = DepCheckDependents(hkHive, sczProviderKey, iAttributes, sdIgnoredDependents, &rgDependents, &cDependents); - if (E_FILENOTFOUND == hr) - { - hr = S_OK; - } - ExitOnFailure(hr, "Failed dependents check for %ls.", sczId); + ExitOnPathFailure(hr, fExists, "Failed dependents check for %ls.", sczId); } if (E_NOMOREITEMS != hr) diff --git a/src/libs/dutil/WixToolset.DUtil/butil.cpp b/src/libs/dutil/WixToolset.DUtil/butil.cpp index 175903ad..47f206ea 100644 --- a/src/libs/dutil/WixToolset.DUtil/butil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/butil.cpp @@ -15,6 +15,7 @@ #define ButilExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_BUTIL, p, x, e, s, __VA_ARGS__) #define ButilExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_BUTIL, p, x, s, __VA_ARGS__) #define ButilExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_BUTIL, e, x, s, __VA_ARGS__) +#define ButilExitOnPathFailure(x, b, s, ...) ExitOnPathFailureSource(DUTIL_SOURCE_BUTIL, x, b, s, __VA_ARGS__) // constants // From engine/registration.h @@ -82,19 +83,6 @@ static HRESULT LocateAndQueryBundleValue( __inout DWORD* pdwType, __out INTERNAL_BUNDLE_STATUS* pStatus ); - -/******************************************************************** -OpenBundleKey - Opens the bundle uninstallation key for a given bundle - -NOTE: caller is responsible for closing key -********************************************************************/ -static HRESULT OpenBundleKey( - __in_z LPCWSTR wzBundleId, - __in BUNDLE_INSTALL_CONTEXT context, - __in_opt LPCWSTR wzSubKey, - __in REG_KEY_BITNESS kbKeyBitness, - __inout HKEY* phKey - ); static HRESULT CopyStringToBuffer( __in_z LPWSTR wzValue, __in_z_opt LPWSTR wzBuffer, @@ -389,12 +377,12 @@ DAPI_(HRESULT) BundleQueryRelatedBundles( queryContext.regBitness = REG_KEY_32BIT; hr = QueryRelatedBundlesForScopeAndBitness(&queryContext); - ExitOnFailure(hr, "Failed to query 32-bit related bundles."); + ButilExitOnFailure(hr, "Failed to query 32-bit related bundles."); queryContext.regBitness = REG_KEY_64BIT; hr = QueryRelatedBundlesForScopeAndBitness(&queryContext); - ExitOnFailure(hr, "Failed to query 64-bit related bundles."); + ButilExitOnFailure(hr, "Failed to query 64-bit related bundles."); LExit: return hr; @@ -407,15 +395,17 @@ static HRESULT QueryRelatedBundlesForScopeAndBitness( HRESULT hr = S_OK; HKEY hkRoot = BUNDLE_INSTALL_CONTEXT_USER == pQueryContext->installContext ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; HKEY hkUninstallKey = NULL; + BOOL fExists = FALSE; LPWSTR sczRelatedBundleId = NULL; BUNDLE_QUERY_CALLBACK_RESULT result = BUNDLE_QUERY_CALLBACK_RESULT_CONTINUE; hr = RegOpenEx(hkRoot, BUNDLE_REGISTRATION_REGISTRY_UNINSTALL_KEY, KEY_READ, pQueryContext->regBitness, &hkUninstallKey); - if (HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) == hr || HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) == hr) + ButilExitOnPathFailure(hr, fExists, "Failed to open uninstall registry key."); + + if (!fExists) { ExitFunction1(hr = S_OK); } - ExitOnFailure(hr, "Failed to open uninstall registry key."); for (DWORD dwIndex = 0; /* exit via break below */; ++dwIndex) { @@ -425,7 +415,7 @@ static HRESULT QueryRelatedBundlesForScopeAndBitness( hr = S_OK; break; } - ExitOnFailure(hr, "Failed to enumerate uninstall key for related bundles."); + ButilExitOnFailure(hr, "Failed to enumerate uninstall key for related bundles."); // Ignore failures here since we'll often find products that aren't actually // related bundles (or even bundles at all). @@ -456,7 +446,7 @@ static HRESULT QueryPotentialRelatedBundle( BUNDLE_QUERY_RELATED_BUNDLE_RESULT bundle = { }; hr = RegOpenEx(hkUninstallKey, wzRelatedBundleId, KEY_READ, pQueryContext->regBitness, &hkBundleId); - ExitOnFailure(hr, "Failed to open uninstall key for potential related bundle: %ls", wzRelatedBundleId); + ButilExitOnFailure(hr, "Failed to open uninstall key for potential related bundle: %ls", wzRelatedBundleId); hr = DetermineRelationType(pQueryContext, hkBundleId, &relationType); if (FAILED(hr)) @@ -506,7 +496,7 @@ static HRESULT DetermineRelationType( TraceError(hr, "Failed to read upgrade codes as REG_MULTI_SZ. Trying again as REG_SZ in case of older bundles."); rgsczUpgradeCodes = reinterpret_cast(MemAlloc(sizeof(LPWSTR), TRUE)); - ExitOnNull(rgsczUpgradeCodes, hr, E_OUTOFMEMORY, "Failed to allocate list for a single upgrade code from older bundle."); + ButilExitOnNull(rgsczUpgradeCodes, hr, E_OUTOFMEMORY, "Failed to allocate list for a single upgrade code from older bundle."); hr = RegReadString(hkBundleId, BUNDLE_REGISTRATION_REGISTRY_BUNDLE_UPGRADE_CODE, &rgsczUpgradeCodes[0]); if (SUCCEEDED(hr)) @@ -519,7 +509,7 @@ static HRESULT DetermineRelationType( if (SUCCEEDED(hr)) { hr = DictCreateStringListFromArray(&sdUpgradeCodes, rgsczUpgradeCodes, cUpgradeCodes, DICT_FLAG_CASEINSENSITIVE); - ExitOnFailure(hr, "Failed to create string dictionary for %hs.", "upgrade codes"); + ButilExitOnFailure(hr, "Failed to create string dictionary for %hs.", "upgrade codes"); // Upgrade relationship: when their upgrade codes match our upgrade codes. hr = DictCompareStringListToArray(sdUpgradeCodes, const_cast(pQueryContext->rgwzUpgradeCodes), pQueryContext->cUpgradeCodes); @@ -529,7 +519,7 @@ static HRESULT DetermineRelationType( } else { - ExitOnFailure(hr, "Failed to do array search for upgrade code match."); + ButilExitOnFailure(hr, "Failed to do array search for upgrade code match."); *pRelationType = BUNDLE_RELATION_UPGRADE; ExitFunction(); @@ -543,7 +533,7 @@ static HRESULT DetermineRelationType( } else { - ExitOnFailure(hr, "Failed to do array search for detect code match."); + ButilExitOnFailure(hr, "Failed to do array search for detect code match."); *pRelationType = BUNDLE_RELATION_DETECT; ExitFunction(); @@ -557,7 +547,7 @@ static HRESULT DetermineRelationType( } else { - ExitOnFailure(hr, "Failed to do array search for addon code match."); + ButilExitOnFailure(hr, "Failed to do array search for addon code match."); *pRelationType = BUNDLE_RELATION_DEPENDENT_ADDON; ExitFunction(); @@ -571,7 +561,7 @@ static HRESULT DetermineRelationType( } else { - ExitOnFailure(hr, "Failed to do array search for patch code match."); + ButilExitOnFailure(hr, "Failed to do array search for patch code match."); *pRelationType = BUNDLE_RELATION_DEPENDENT_PATCH; ExitFunction(); @@ -586,7 +576,7 @@ static HRESULT DetermineRelationType( if (SUCCEEDED(hr)) { hr = DictCreateStringListFromArray(&sdAddonCodes, rgsczAddonCodes, cAddonCodes, DICT_FLAG_CASEINSENSITIVE); - ExitOnFailure(hr, "Failed to create string dictionary for %hs.", "addon codes"); + ButilExitOnFailure(hr, "Failed to create string dictionary for %hs.", "addon codes"); // Addon relationship: when their addon codes match our detect codes. hr = DictCompareStringListToArray(sdAddonCodes, const_cast(pQueryContext->rgwzDetectCodes), pQueryContext->cDetectCodes); @@ -596,7 +586,7 @@ static HRESULT DetermineRelationType( } else { - ExitOnFailure(hr, "Failed to do array search for addon code match."); + ButilExitOnFailure(hr, "Failed to do array search for addon code match."); *pRelationType = BUNDLE_RELATION_ADDON; ExitFunction(); @@ -610,7 +600,7 @@ static HRESULT DetermineRelationType( } else { - ExitOnFailure(hr, "Failed to do array search for addon code match."); + ButilExitOnFailure(hr, "Failed to do array search for addon code match."); *pRelationType = BUNDLE_RELATION_ADDON; ExitFunction(); @@ -625,7 +615,7 @@ static HRESULT DetermineRelationType( if (SUCCEEDED(hr)) { hr = DictCreateStringListFromArray(&sdPatchCodes, rgsczPatchCodes, cPatchCodes, DICT_FLAG_CASEINSENSITIVE); - ExitOnFailure(hr, "Failed to create string dictionary for %hs.", "patch codes"); + ButilExitOnFailure(hr, "Failed to create string dictionary for %hs.", "patch codes"); // Patch relationship: when their patch codes match our detect codes. hr = DictCompareStringListToArray(sdPatchCodes, const_cast(pQueryContext->rgwzDetectCodes), pQueryContext->cDetectCodes); @@ -635,7 +625,7 @@ static HRESULT DetermineRelationType( } else { - ExitOnFailure(hr, "Failed to do array search for patch code match."); + ButilExitOnFailure(hr, "Failed to do array search for patch code match."); *pRelationType = BUNDLE_RELATION_PATCH; ExitFunction(); @@ -649,7 +639,7 @@ static HRESULT DetermineRelationType( } else { - ExitOnFailure(hr, "Failed to do array search for patch code match."); + ButilExitOnFailure(hr, "Failed to do array search for patch code match."); *pRelationType = BUNDLE_RELATION_PATCH; ExitFunction(); @@ -664,7 +654,7 @@ static HRESULT DetermineRelationType( if (SUCCEEDED(hr)) { hr = DictCreateStringListFromArray(&sdDetectCodes, rgsczDetectCodes, cDetectCodes, DICT_FLAG_CASEINSENSITIVE); - ExitOnFailure(hr, "Failed to create string dictionary for %hs.", "detect codes"); + ButilExitOnFailure(hr, "Failed to create string dictionary for %hs.", "detect codes"); // Detect relationship: when their detect codes match our detect codes. hr = DictCompareStringListToArray(sdDetectCodes, const_cast(pQueryContext->rgwzDetectCodes), pQueryContext->cDetectCodes); @@ -674,7 +664,7 @@ static HRESULT DetermineRelationType( } else { - ExitOnFailure(hr, "Failed to do array search for detect code match."); + ButilExitOnFailure(hr, "Failed to do array search for detect code match."); *pRelationType = BUNDLE_RELATION_DETECT; ExitFunction(); @@ -688,7 +678,7 @@ static HRESULT DetermineRelationType( } else { - ExitOnFailure(hr, "Failed to do array search for addon code match."); + ButilExitOnFailure(hr, "Failed to do array search for addon code match."); *pRelationType = BUNDLE_RELATION_DEPENDENT_ADDON; ExitFunction(); @@ -702,7 +692,7 @@ static HRESULT DetermineRelationType( } else { - ExitOnFailure(hr, "Failed to do array search for patch code match."); + ButilExitOnFailure(hr, "Failed to do array search for patch code match."); *pRelationType = BUNDLE_RELATION_DEPENDENT_PATCH; ExitFunction(); @@ -740,54 +730,11 @@ static HRESULT LocateAndQueryBundleValue( ) { HRESULT hr = S_OK; + LPWSTR sczKeypath = NULL; + BOOL fExists = TRUE; *pStatus = INTERNAL_BUNDLE_STATUS_SUCCESS; - if (FAILED(hr = OpenBundleKey(wzBundleId, BUNDLE_INSTALL_CONTEXT_MACHINE, wzSubKey, REG_KEY_32BIT, phKey)) && - FAILED(hr = OpenBundleKey(wzBundleId, BUNDLE_INSTALL_CONTEXT_MACHINE, wzSubKey, REG_KEY_64BIT, phKey)) && - FAILED(hr = OpenBundleKey(wzBundleId, BUNDLE_INSTALL_CONTEXT_USER, wzSubKey, REG_KEY_DEFAULT, phKey))) - { - if (E_FILENOTFOUND == hr) - { - *pStatus = INTERNAL_BUNDLE_STATUS_UNKNOWN_BUNDLE; - ExitFunction1(hr = S_OK); - } - - ButilExitOnFailure(hr, "Failed to open bundle key."); - } - - // If the bundle doesn't have the value defined, return ERROR_UNKNOWN_PROPERTY - hr = RegGetType(*phKey, wzValueName, pdwType); - if (FAILED(hr)) - { - if (E_FILENOTFOUND == hr) - { - *pStatus = INTERNAL_BUNDLE_STATUS_UNKNOWN_PROPERTY; - ExitFunction1(hr = S_OK); - } - - ButilExitOnFailure(hr, "Failed to read bundle value."); - } - -LExit: - return hr; -} - -static HRESULT OpenBundleKey( - __in_z LPCWSTR wzBundleId, - __in BUNDLE_INSTALL_CONTEXT context, - __in_opt LPCWSTR wzSubKey, - __in REG_KEY_BITNESS kbKeyBitness, - __inout HKEY* phKey - ) -{ - Assert(phKey && wzBundleId); - AssertSz(NULL == *phKey, "*key should be null"); - - HRESULT hr = S_OK; - HKEY hkRoot = BUNDLE_INSTALL_CONTEXT_USER == context ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; - LPWSTR sczKeypath = NULL; - if (wzSubKey) { hr = StrAllocFormatted(&sczKeypath, L"%ls\\%ls\\%ls", BUNDLE_REGISTRATION_REGISTRY_UNINSTALL_KEY, wzBundleId, wzSubKey); @@ -798,8 +745,24 @@ static HRESULT OpenBundleKey( } ButilExitOnFailure(hr, "Failed to allocate bundle uninstall key path."); - hr = RegOpenEx(hkRoot, sczKeypath, KEY_READ, kbKeyBitness, phKey); - ButilExitOnFailure(hr, "Failed to open bundle uninstall key path."); + if (FAILED(hr = RegOpenEx(HKEY_LOCAL_MACHINE, sczKeypath, KEY_READ, REG_KEY_32BIT, phKey)) && + FAILED(hr = RegOpenEx(HKEY_LOCAL_MACHINE, sczKeypath, KEY_READ, REG_KEY_64BIT, phKey)) && + FAILED(hr = RegOpenEx(HKEY_CURRENT_USER, sczKeypath, KEY_READ, REG_KEY_DEFAULT, phKey))) + { + ButilExitOnPathFailure(hr, fExists, "Failed to open bundle key."); + + *pStatus = INTERNAL_BUNDLE_STATUS_UNKNOWN_BUNDLE; + ExitFunction1(hr = S_OK); + } + + hr = RegGetType(*phKey, wzValueName, pdwType); + ButilExitOnPathFailure(hr, fExists, "Failed to read bundle value."); + + if (!fExists) + { + *pStatus = INTERNAL_BUNDLE_STATUS_UNKNOWN_PROPERTY; + ExitFunction1(hr = S_OK); + } LExit: ReleaseStr(sczKeypath); diff --git a/src/libs/dutil/WixToolset.DUtil/deputil.cpp b/src/libs/dutil/WixToolset.DUtil/deputil.cpp index 4de85199..f92c7d18 100644 --- a/src/libs/dutil/WixToolset.DUtil/deputil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/deputil.cpp @@ -16,6 +16,7 @@ #define DepExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_DEPUTIL, p, x, s, __VA_ARGS__) #define DepExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_DEPUTIL, e, x, s, __VA_ARGS__) #define DepExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_DEPUTIL, g, x, s, __VA_ARGS__) +#define DepExitOnPathFailure(x, b, s, ...) ExitOnPathFailureSource(DUTIL_SOURCE_DEPUTIL, x, b, s, __VA_ARGS__) #define ARRAY_GROWTH_SIZE 5 @@ -54,6 +55,7 @@ DAPI_(HRESULT) DepGetProviderInformation( HRESULT hr = S_OK; LPWSTR sczKey = NULL; HKEY hkKey = NULL; + BOOL fExists = FALSE; // Format the provider dependency registry key. hr = AllocDependencyKeyName(wzProviderKey, &sczKey); @@ -61,43 +63,32 @@ DAPI_(HRESULT) DepGetProviderInformation( // Try to open the dependency key. hr = RegOpen(hkHive, sczKey, KEY_READ, &hkKey); - if (E_FILENOTFOUND == hr) + DepExitOnPathFailure(hr, fExists, "Failed to open the registry key for the dependency \"%ls\".", wzProviderKey); + + if (!fExists) { ExitFunction1(hr = E_NOTFOUND); } - DepExitOnFailure(hr, "Failed to open the registry key for the dependency \"%ls\".", wzProviderKey); // Get the Id if requested and available. if (psczId) { hr = RegReadString(hkKey, NULL, psczId); - if (E_FILENOTFOUND == hr) - { - hr = S_OK; - } - DepExitOnFailure(hr, "Failed to get the id for the dependency \"%ls\".", wzProviderKey); + DepExitOnPathFailure(hr, fExists, "Failed to get the id for the dependency \"%ls\".", wzProviderKey); } // Get the DisplayName if requested and available. if (psczName) { hr = RegReadString(hkKey, vcszDisplayNameValue, psczName); - if (E_FILENOTFOUND == hr) - { - hr = S_OK; - } - DepExitOnFailure(hr, "Failed to get the name for the dependency \"%ls\".", wzProviderKey); + DepExitOnPathFailure(hr, fExists, "Failed to get the name for the dependency \"%ls\".", wzProviderKey); } // Get the Version if requested and available. if (psczVersion) { hr = RegReadString(hkKey, vcszVersionValue, psczVersion); - if (E_FILENOTFOUND == hr) - { - hr = S_OK; - } - DepExitOnFailure(hr, "Failed to get the version for the dependency \"%ls\".", wzProviderKey); + DepExitOnPathFailure(hr, fExists, "Failed to get the version for the dependency \"%ls\".", wzProviderKey); } LExit: @@ -121,6 +112,7 @@ DAPI_(HRESULT) DepCheckDependency( HRESULT hr = S_OK; LPWSTR sczKey = NULL; HKEY hkKey = NULL; + BOOL fExists = FALSE; VERUTIL_VERSION* pVersion = NULL; VERUTIL_VERSION* pMinVersion = NULL; VERUTIL_VERSION* pMaxVersion = NULL; @@ -134,20 +126,17 @@ DAPI_(HRESULT) DepCheckDependency( // Try to open the key. If that fails, add the missing dependency key to the dependency array if it doesn't already exist. hr = RegOpen(hkHive, sczKey, KEY_READ, &hkKey); - if (E_FILENOTFOUND != hr) - { - DepExitOnFailure(hr, "Failed to open the registry key for dependency \"%ls\".", wzProviderKey); + DepExitOnPathFailure(hr, fExists, "Failed to open the registry key for dependency \"%ls\".", wzProviderKey); + if (fExists) + { // If there are no registry values, consider the key orphaned and treat it as missing. hr = RegReadWixVersion(hkKey, vcszVersionValue, &pVersion); - if (E_FILENOTFOUND != hr) - { - DepExitOnFailure(hr, "Failed to read the %ls registry value for dependency \"%ls\".", vcszVersionValue, wzProviderKey); - } + DepExitOnPathFailure(hr, fExists, "Failed to read the %ls registry value for dependency \"%ls\".", vcszVersionValue, wzProviderKey); } // If the key was not found or the Version value was not found, add the missing dependency key to the dependency array. - if (E_FILENOTFOUND == hr) + if (!fExists) { hr = DictKeyExists(sdDependencies, wzProviderKey); if (E_NOTFOUND != hr) @@ -190,7 +179,7 @@ DAPI_(HRESULT) DepCheckDependency( else { hr = RegReadString(hkKey, vcszDisplayNameValue, &sczName); - DepExitOnFailure(hr, "Failed to get the display name of the older dependency \"%ls\".", wzProviderKey); + DepExitOnPathFailure(hr, fExists, "Failed to get the display name of the older dependency \"%ls\".", wzProviderKey); hr = DepDependencyArrayAlloc(prgDependencies, pcDependencies, wzProviderKey, sczName); DepExitOnFailure(hr, "Failed to add the older dependency \"%ls\" to the dependencies array.", wzProviderKey); @@ -228,7 +217,7 @@ DAPI_(HRESULT) DepCheckDependency( else { hr = RegReadString(hkKey, vcszDisplayNameValue, &sczName); - DepExitOnFailure(hr, "Failed to get the display name of the newer dependency \"%ls\".", wzProviderKey); + DepExitOnPathFailure(hr, fExists, "Failed to get the display name of the newer dependency \"%ls\".", wzProviderKey); hr = DepDependencyArrayAlloc(prgDependencies, pcDependencies, wzProviderKey, sczName); DepExitOnFailure(hr, "Failed to add the newer dependency \"%ls\" to the dependencies array.", wzProviderKey); @@ -267,6 +256,7 @@ DAPI_(HRESULT) DepCheckDependents( LPWSTR sczKey = NULL; HKEY hkProviderKey = NULL; HKEY hkDependentsKey = NULL; + BOOL fExists = FALSE; LPWSTR sczDependentKey = NULL; LPWSTR sczDependentName = NULL; BOOL fIgnore = FALSE; @@ -277,15 +267,18 @@ DAPI_(HRESULT) DepCheckDependents( // Try to open the key. If that fails, the dependency information is corrupt. hr = RegOpen(hkHive, sczKey, KEY_READ, &hkProviderKey); - DepExitOnFailure(hr, "Failed to open the registry key \"%ls\". The dependency store is corrupt.", sczKey); + DepExitOnPathFailure(hr, fExists, "Failed to open the registry key \"%ls\". The dependency store is corrupt.", sczKey); - // Try to open the dependencies key. If that does not exist, there are no dependents. - hr = RegOpen(hkProviderKey, vsczRegistryDependents, KEY_READ, &hkDependentsKey); - if (E_FILENOTFOUND != hr) + if (!fExists) { - DepExitOnFailure(hr, "Failed to open the registry key for dependents of \"%ls\".", wzProviderKey); + ExitFunction1(hr = S_OK); } - else + + // Try to open the dependencies key. If that does not exist, there are no dependents. + hr = RegOpen(hkProviderKey, vsczRegistryDependents, KEY_READ, &hkDependentsKey); + DepExitOnPathFailure(hr, fExists, "Failed to open the registry key for dependents of \"%ls\".", wzProviderKey); + + if (!fExists) { ExitFunction1(hr = S_OK); } @@ -399,15 +392,18 @@ DAPI_(HRESULT) DepDependentExists( HRESULT hr = S_OK; LPWSTR sczDependentKey = NULL; HKEY hkDependentKey = NULL; + BOOL fExists = FALSE; // Format the provider dependents registry key. hr = StrAllocFormatted(&sczDependentKey, L"%ls%ls\\%ls\\%ls", vsczRegistryRoot, wzDependencyProviderKey, vsczRegistryDependents, wzProviderKey); DepExitOnFailure(hr, "Failed to format registry key to dependent."); hr = RegOpen(hkHive, sczDependentKey, KEY_READ, &hkDependentKey); - if (E_FILENOTFOUND != hr) + DepExitOnPathFailure(hr, fExists, "Failed to open the dependent registry key at: \"%ls\".", sczDependentKey); + + if (!fExists) { - DepExitOnFailure(hr, "Failed to open the dependent registry key at: \"%ls\".", sczDependentKey); + hr = E_FILENOTFOUND; } LExit: @@ -480,6 +476,7 @@ DAPI_(HRESULT) DepUnregisterDependency( HRESULT hr = S_OK; LPWSTR sczKey = NULL; HKEY hkKey = NULL; + BOOL fExists = FALSE; // Format the provider dependency registry key. hr = AllocDependencyKeyName(wzProviderKey, &sczKey); @@ -487,9 +484,11 @@ DAPI_(HRESULT) DepUnregisterDependency( // Delete the entire key including all sub-keys. hr = RegDelete(hkHive, sczKey, REG_KEY_DEFAULT, TRUE); - if (E_FILENOTFOUND != hr) + DepExitOnPathFailure(hr, fExists, "Failed to delete the key \"%ls\".", sczKey); + + if (!fExists) { - DepExitOnFailure(hr, "Failed to delete the key \"%ls\".", sczKey); + hr = E_FILENOTFOUND; } LExit: @@ -506,6 +505,7 @@ DAPI_(HRESULT) DepUnregisterDependent( ) { HRESULT hr = S_OK; + BOOL fExists = FALSE; HKEY hkRegistryRoot = NULL; HKEY hkDependencyProviderKey = NULL; HKEY hkRegistryDependents = NULL; @@ -514,40 +514,39 @@ DAPI_(HRESULT) DepUnregisterDependent( // Open the root key. We may delete the wzDependencyProviderKey during clean up. hr = RegOpen(hkHive, vsczRegistryRoot, KEY_READ, &hkRegistryRoot); - if (E_FILENOTFOUND != hr) - { - DepExitOnFailure(hr, "Failed to open root registry key \"%ls\".", vsczRegistryRoot); - } - else + DepExitOnPathFailure(hr, fExists, "Failed to open root registry key \"%ls\".", vsczRegistryRoot); + + if (!fExists) { - ExitFunction(); + ExitFunction1(hr = E_FILENOTFOUND); } // Try to open the dependency key. If that does not exist, simply return. hr = RegOpen(hkRegistryRoot, wzDependencyProviderKey, KEY_READ, &hkDependencyProviderKey); - if (E_FILENOTFOUND != hr) - { - DepExitOnFailure(hr, "Failed to open the registry key for the dependency \"%ls\".", wzDependencyProviderKey); - } - else + DepExitOnPathFailure(hr, fExists, "Failed to open the registry key for the dependency \"%ls\".", wzDependencyProviderKey); + + if (!fExists) { - ExitFunction(); + ExitFunction1(hr = E_FILENOTFOUND); } // Try to open the dependents subkey to enumerate. hr = RegOpen(hkDependencyProviderKey, vsczRegistryDependents, KEY_READ, &hkRegistryDependents); - if (E_FILENOTFOUND != hr) - { - DepExitOnFailure(hr, "Failed to open the dependents subkey under the dependency \"%ls\".", wzDependencyProviderKey); - } - else + DepExitOnPathFailure(hr, fExists, "Failed to open the dependents subkey under the dependency \"%ls\".", wzDependencyProviderKey); + + if (!fExists) { - ExitFunction(); + ExitFunction1(hr = E_FILENOTFOUND); } // Delete the wzProviderKey dependent sub-key. hr = RegDelete(hkRegistryDependents, wzProviderKey, REG_KEY_DEFAULT, TRUE); - DepExitOnFailure(hr, "Failed to delete the dependent \"%ls\" under the dependency \"%ls\".", wzProviderKey, wzDependencyProviderKey); + DepExitOnPathFailure(hr, fExists, "Failed to delete the dependent \"%ls\" under the dependency \"%ls\".", wzProviderKey, wzDependencyProviderKey); + + if (!fExists) + { + ExitFunction1(hr = E_FILENOTFOUND); + } // If there are no remaining dependents, delete the Dependents subkey. hr = RegQueryKey(hkRegistryDependents, &cSubKeys, NULL); @@ -563,7 +562,12 @@ DAPI_(HRESULT) DepUnregisterDependent( // Fail if there are any subkeys since we just checked. hr = RegDelete(hkDependencyProviderKey, vsczRegistryDependents, REG_KEY_DEFAULT, FALSE); - DepExitOnFailure(hr, "Failed to delete the dependents subkey under the dependency \"%ls\".", wzDependencyProviderKey); + DepExitOnPathFailure(hr, fExists, "Failed to delete the dependents subkey under the dependency \"%ls\".", wzDependencyProviderKey); + + if (!fExists) + { + ExitFunction1(hr = E_FILENOTFOUND); + } // If there are no values, delete the provider dependency key. hr = RegQueryKey(hkDependencyProviderKey, NULL, &cValues); @@ -576,7 +580,12 @@ DAPI_(HRESULT) DepUnregisterDependent( // Fail if there are any subkeys since we just checked. hr = RegDelete(hkRegistryRoot, wzDependencyProviderKey, REG_KEY_DEFAULT, FALSE); - DepExitOnFailure(hr, "Failed to delete the dependency \"%ls\".", wzDependencyProviderKey); + DepExitOnPathFailure(hr, fExists, "Failed to delete the dependency \"%ls\".", wzDependencyProviderKey); + + if (!fExists) + { + ExitFunction1(hr = E_FILENOTFOUND); + } } LExit: @@ -685,6 +694,7 @@ static HRESULT GetDependencyNameFromKey( HRESULT hr = S_OK; LPWSTR sczKey = NULL; HKEY hkKey = NULL; + BOOL fExists = FALSE; // Format the provider dependency registry key. hr = AllocDependencyKeyName(wzProviderKey, &sczKey); @@ -692,25 +702,16 @@ static HRESULT GetDependencyNameFromKey( // Try to open the dependency key. hr = RegOpen(hkHive, sczKey, KEY_READ, &hkKey); - if (E_FILENOTFOUND != hr) - { - DepExitOnFailure(hr, "Failed to open the registry key for the dependency \"%ls\".", wzProviderKey); - } - else + DepExitOnPathFailure(hr, fExists, "Failed to open the registry key for the dependency \"%ls\".", wzProviderKey); + + if (!fExists) { - ExitFunction1(hr = S_OK); + ExitFunction(); } // Get the DisplayName if available. hr = RegReadString(hkKey, vcszDisplayNameValue, psczName); - if (E_FILENOTFOUND != hr) - { - DepExitOnFailure(hr, "Failed to get the dependency name for the dependency \"%ls\".", wzProviderKey); - } - else - { - ExitFunction1(hr = S_OK); - } + DepExitOnPathFailure(hr, fExists, "Failed to get the dependency name for the dependency \"%ls\".", wzProviderKey); LExit: ReleaseRegKey(hkKey); diff --git a/src/libs/dutil/WixToolset.DUtil/dirutil.cpp b/src/libs/dutil/WixToolset.DUtil/dirutil.cpp index 2c02225d..8c7ef461 100644 --- a/src/libs/dutil/WixToolset.DUtil/dirutil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/dirutil.cpp @@ -17,6 +17,8 @@ #define DirExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_DIRUTIL, p, x, s, __VA_ARGS__) #define DirExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_DIRUTIL, e, x, s, __VA_ARGS__) #define DirExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_DIRUTIL, g, x, s, __VA_ARGS__) +#define DirExitOnPathFailure(x, b, s, ...) ExitOnPathFailureSource(DUTIL_SOURCE_DIRUTIL, x, b, s, __VA_ARGS__) +#define DirExitWithPathLastError(x, s, ...) ExitWithPathLastErrorSource(DUTIL_SOURCE_DIRUTIL, x, s, __VA_ARGS__) /******************************************************************* @@ -184,13 +186,9 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx( if (-1 == (dwAttrib = ::GetFileAttributesW(wzPath))) { - er = ::GetLastError(); - if (ERROR_FILE_NOT_FOUND == er) // change "file not found" to "path not found" since we were looking for a directory. - { - er = ERROR_PATH_NOT_FOUND; - } - hr = HRESULT_FROM_WIN32(er); - DirExitOnRootFailure(hr, "Failed to get attributes for path: %ls", wzPath); + DirExitWithPathLastError(hr, "Failed to get attributes for path: %ls", wzPath); + + ExitFunction1(hr = E_PATHNOTFOUND); } if (dwAttrib & FILE_ATTRIBUTE_DIRECTORY) @@ -199,7 +197,9 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx( { if (!::SetFileAttributesW(wzPath, FILE_ATTRIBUTE_NORMAL)) { - DirExitWithLastError(hr, "Failed to remove read-only attribute from path: %ls", wzPath); + DirExitWithPathLastError(hr, "Failed to remove read-only attribute from path: %ls", wzPath); + + ExitFunction1(hr = E_PATHNOTFOUND); } } @@ -245,9 +245,12 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx( hr = DirEnsureDeleteEx(sczDelete, dwFlags); // recursive call if (FAILED(hr)) { - // if we failed to delete a subdirectory, keep trying to finish any remaining files - ExitTraceSource(DUTIL_SOURCE_DIRUTIL, hr, "Failed to delete subdirectory; continuing: %ls", sczDelete); - hr = S_OK; + // if we failed to delete a subdirectory, keep trying to finish any remaining files + if (E_PATHNOTFOUND != hr) + { + ExitTraceSource(DUTIL_SOURCE_DIRUTIL, hr, "Failed to delete subdirectory; continuing: %ls", sczDelete); + } + hr = S_OK; } } else if (fDeleteFiles) // this is a file, just delete it @@ -256,7 +259,8 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx( { if (!::SetFileAttributesW(sczDelete, FILE_ATTRIBUTE_NORMAL)) { - DirExitWithLastError(hr, "Failed to remove attributes from file: %ls", sczDelete); + DirExitWithPathLastError(hr, "Failed to remove attributes from file: %ls", sczDelete); + continue; } } @@ -280,7 +284,7 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx( } else { - DirExitWithLastError(hr, "Failed to delete file: %ls", sczDelete); + DirExitWithPathLastError(hr, "Failed to delete file: %ls", sczDelete); } } } @@ -308,13 +312,21 @@ extern "C" HRESULT DAPI DirEnsureDeleteEx( } } + if (E_PATHNOTFOUND == hr || E_FILENOTFOUND == hr) + { + ExitFunction1(hr = E_PATHNOTFOUND); + } + else if (HRESULT_FROM_WIN32(ERROR_DIR_NOT_EMPTY) == hr && !fDeleteFiles && !fRecurse) + { + ExitFunction(); + } + DirExitOnRootFailure(hr, "Failed to remove directory: %ls", wzPath); } } else { - hr = E_UNEXPECTED; - DirExitOnFailure(hr, "Directory delete cannot delete file: %ls", wzPath); + DirExitWithRootFailure(hr, E_UNEXPECTED, "Directory delete cannot delete file: %ls", wzPath); } Assert(S_OK == hr); diff --git a/src/libs/dutil/WixToolset.DUtil/file2utl.cpp b/src/libs/dutil/WixToolset.DUtil/file2utl.cpp index 88f8377c..3ab47f59 100644 --- a/src/libs/dutil/WixToolset.DUtil/file2utl.cpp +++ b/src/libs/dutil/WixToolset.DUtil/file2utl.cpp @@ -16,6 +16,7 @@ #define FileExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_FILEUTIL, p, x, s, __VA_ARGS__) #define FileExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_FILEUTIL, e, x, s, __VA_ARGS__) #define FileExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_FILEUTIL, g, x, s, __VA_ARGS__) +#define FileExitOnPathFailure(x, b, s, ...) ExitOnPathFailureSource(DUTIL_SOURCE_FILEUTIL, x, b, s, __VA_ARGS__) // constants @@ -35,6 +36,7 @@ extern "C" BOOL DAPI FileExistsAfterRestart( { HRESULT hr = S_OK; BOOL fExists = FALSE; + BOOL fRegExists = FALSE; HKEY hkPendingFileRename = NULL; LPWSTR* rgsczRenames = NULL; DWORD cRenames = 0; @@ -44,18 +46,20 @@ extern "C" BOOL DAPI FileExistsAfterRestart( if (fExists) { hr = RegOpen(HKEY_LOCAL_MACHINE, REGISTRY_PENDING_FILE_RENAME_KEY, KEY_QUERY_VALUE, &hkPendingFileRename); - if (E_FILENOTFOUND == hr) + FileExitOnPathFailure(hr, fRegExists, "Failed to open pending file rename registry key."); + + if (!fRegExists) { - ExitFunction1(hr = S_OK); + ExitFunction(); } - FileExitOnFailure(hr, "Failed to open pending file rename registry key."); hr = RegReadStringArray(hkPendingFileRename, REGISTRY_PENDING_FILE_RENAME_VALUE, &rgsczRenames, &cRenames); - if (E_FILENOTFOUND == hr) + FileExitOnPathFailure(hr, fRegExists, "Failed to read pending file renames."); + + if (!fRegExists) { - ExitFunction1(hr = S_OK); + ExitFunction(); } - FileExitOnFailure(hr, "Failed to read pending file renames."); // The pending file renames array is pairs of source and target paths. We only care // about checking the source paths so skip the target paths (i += 2). @@ -95,6 +99,7 @@ extern "C" HRESULT DAPI FileRemoveFromPendingRename( { HRESULT hr = S_OK; HKEY hkPendingFileRename = NULL; + BOOL fExists = FALSE; LPWSTR* rgsczRenames = NULL; DWORD cRenames = 0; BOOL fPathEqual = FALSE; @@ -102,18 +107,20 @@ extern "C" HRESULT DAPI FileRemoveFromPendingRename( DWORD cNewRenames = 0; hr = RegOpen(HKEY_LOCAL_MACHINE, REGISTRY_PENDING_FILE_RENAME_KEY, KEY_QUERY_VALUE | KEY_SET_VALUE, &hkPendingFileRename); - if (E_FILENOTFOUND == hr) + FileExitOnPathFailure(hr, fExists, "Failed to open pending file rename registry key."); + + if (!fExists) { - ExitFunction1(hr = S_OK); + ExitFunction(); } - FileExitOnFailure(hr, "Failed to open pending file rename registry key."); hr = RegReadStringArray(hkPendingFileRename, REGISTRY_PENDING_FILE_RENAME_VALUE, &rgsczRenames, &cRenames); - if (E_FILENOTFOUND == hr) + FileExitOnPathFailure(hr, fExists, "Failed to read pending file renames."); + + if (!fExists) { - ExitFunction1(hr = S_OK); + ExitFunction(); } - FileExitOnFailure(hr, "Failed to read pending file renames."); // The pending file renames array is pairs of source and target paths. We only care // about checking the source paths so skip the target paths (i += 2). diff --git a/src/libs/dutil/WixToolset.DUtil/fileutil.cpp b/src/libs/dutil/WixToolset.DUtil/fileutil.cpp index ac407916..a9369ea1 100644 --- a/src/libs/dutil/WixToolset.DUtil/fileutil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/fileutil.cpp @@ -443,6 +443,7 @@ extern "C" HRESULT DAPI FileSize( ) { HRESULT hr = S_OK; + DWORD er = ERROR_SUCCESS; HANDLE hFile = INVALID_HANDLE_VALUE; FileExitOnNull(pwzFileName, hr, E_INVALIDARG, "Attempted to check filename, but no filename was provided"); @@ -450,6 +451,11 @@ extern "C" HRESULT DAPI FileSize( hFile = ::CreateFileW(pwzFileName, FILE_READ_ATTRIBUTES, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (INVALID_HANDLE_VALUE == hFile) { + er = ::GetLastError(); + if (ERROR_PATH_NOT_FOUND == er || ERROR_FILE_NOT_FOUND == er) + { + ExitFunction1(hr = HRESULT_FROM_WIN32(er)); + } FileExitWithLastError(hr, "Failed to open file %ls while checking file size", pwzFileName); } @@ -617,11 +623,11 @@ extern "C" HRESULT DAPI FileReadPartialEx( if (INVALID_HANDLE_VALUE == hFile) { er = ::GetLastError(); - if (E_FILENOTFOUND == HRESULT_FROM_WIN32(er)) + if (ERROR_PATH_NOT_FOUND == er || ERROR_FILE_NOT_FOUND == er) { - ExitFunction1(hr = E_FILENOTFOUND); + ExitFunction1(hr = HRESULT_FROM_WIN32(er)); } - FileExitOnWin32Error(er, hr, "Failed to open file: %ls", wzSrcPath); + FileExitWithLastError(hr, "Failed to open file: %ls", wzSrcPath); } if (!::GetFileSizeEx(hFile, &liFileSize)) diff --git a/src/libs/dutil/WixToolset.DUtil/inc/dutil.h b/src/libs/dutil/WixToolset.DUtil/inc/dutil.h index 2db64812..4a172f46 100644 --- a/src/libs/dutil/WixToolset.DUtil/inc/dutil.h +++ b/src/libs/dutil/WixToolset.DUtil/inc/dutil.h @@ -131,6 +131,8 @@ void DAPI Dutil_RootFailure(__in_z LPCSTR szFile, __in int iLine, __in HRESULT h #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__); } #define ExitOnRequiredXmlQueryFailureSource(d, x, s, ...) { if (S_FALSE == x) { x = E_NOTFOUND; } ExitOnRootFailureSource(d, x, s, __VA_ARGS__); } #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__); } +#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__); } +#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__); } #define ExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_DEFAULT, x, s, __VA_ARGS__) #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 #define ExitOnOptionalXmlQueryFailure(x, b, s, ...) ExitOnOptionalXmlQueryFailureSource(DUTIL_SOURCE_DEFAULT, x, b, s, __VA_ARGS__) #define ExitOnRequiredXmlQueryFailure(x, s, ...) ExitOnRequiredXmlQueryFailureSource(DUTIL_SOURCE_DEFAULT, x, s, __VA_ARGS__) #define ExitOnWaitObjectFailure(x, b, s, ...) ExitOnWaitObjectFailureSource(DUTIL_SOURCE_DEFAULT, x, b, s, __VA_ARGS__) +#define ExitOnPathFailure(x, b, s, ...) ExitOnPathFailureSource(DUTIL_SOURCE_DEFAULT, x, b, s, __VA_ARGS__) +#define ExitWithPathLastError(x, s, ...) ExitWithPathLastErrorSource(DUTIL_SOURCE_DEFAULT, x, s, __VA_ARGS__) // release macros #define ReleaseObject(x) if (x) { x->Release(); } diff --git a/src/libs/dutil/WixToolset.DUtil/inc/logutil.h b/src/libs/dutil/WixToolset.DUtil/inc/logutil.h index 1636e297..8f38e0ce 100644 --- a/src/libs/dutil/WixToolset.DUtil/inc/logutil.h +++ b/src/libs/dutil/WixToolset.DUtil/inc/logutil.h @@ -8,9 +8,11 @@ extern "C" { #define LogExitOnFailureSource(d, x, i, f, ...) if (FAILED(x)) { LogErrorId(x, i, __VA_ARGS__); ExitTraceSource(d, x, f, __VA_ARGS__); goto LExit; } #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; } +#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; } #define LogExitOnFailure(x, i, f, ...) LogExitOnFailureSource(DUTIL_SOURCE_DEFAULT, x, i, f, __VA_ARGS__) #define LogExitOnRootFailure(x, i, f, ...) LogExitOnRootFailureSource(DUTIL_SOURCE_DEFAULT, x, i, f, __VA_ARGS__) +#define LogExitWithRootFailure(x, e, i, f, ...) LogExitWithRootFailureSource(DUTIL_SOURCE_DEFAULT, x, e, i, f, __VA_ARGS__) typedef HRESULT (DAPI *PFN_LOGSTRINGWORKRAW)( __in_z LPCSTR szString, diff --git a/src/libs/dutil/WixToolset.DUtil/monutil.cpp b/src/libs/dutil/WixToolset.DUtil/monutil.cpp index 10954164..d7bcfa52 100644 --- a/src/libs/dutil/WixToolset.DUtil/monutil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/monutil.cpp @@ -17,6 +17,7 @@ #define MonExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_MONUTIL, e, x, s, __VA_ARGS__) #define MonExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_MONUTIL, g, x, s, __VA_ARGS__) #define MonExitOnWaitObjectFailure(x, b, s, ...) ExitOnWaitObjectFailureSource(DUTIL_SOURCE_MONUTIL, x, b, s, __VA_ARGS__) +#define MonExitOnPathFailure(x, b, s, ...) ExitOnPathFailureSource(DUTIL_SOURCE_MONUTIL, x, b, s, __VA_ARGS__) const int MON_THREAD_GROWTH = 5; const int MON_ARRAY_GROWTH = 40; @@ -982,6 +983,7 @@ static HRESULT InitiateWait( DWORD dwIndex = 0; HKEY hk = NULL; HANDLE hTemp = INVALID_HANDLE_VALUE; + BOOL fExists = FALSE; if (pRequest->hNotify) { @@ -1025,11 +1027,12 @@ static HRESULT InitiateWait( case MON_REGKEY: ReleaseRegKey(pRequest->regkey.hkSubKey); hr = RegOpen(pRequest->regkey.hkRoot, pRequest->rgsczPathHierarchy[dwIndex], KEY_NOTIFY | GetRegKeyBitness(pRequest), &pRequest->regkey.hkSubKey); - if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) + MonExitOnPathFailure(hr, fExists, "Failed to open regkey %ls", pRequest->rgsczPathHierarchy[dwIndex]); + + if (!fExists) { continue; } - MonExitOnFailure(hr, "Failed to open regkey %ls", pRequest->rgsczPathHierarchy[dwIndex]); er = ::RegNotifyChangeKeyValue(pRequest->regkey.hkSubKey, GetRecursiveFlag(pRequest, dwIndex), REG_NOTIFY_CHANGE_NAME | REG_NOTIFY_CHANGE_LAST_SET | REG_NOTIFY_CHANGE_SECURITY, *pHandle, TRUE); ReleaseRegKey(hk); @@ -1038,12 +1041,9 @@ static HRESULT InitiateWait( { continue; } - else - { - MonExitOnWin32Error(er, hr, "Failed to wait on subkey %ls", pRequest->rgsczPathHierarchy[dwIndex]); + MonExitOnFailure(hr, "Failed to wait on subkey %ls", pRequest->rgsczPathHierarchy[dwIndex]); - fHandleFound = TRUE; - } + fHandleFound = TRUE; break; default: diff --git a/src/libs/dutil/WixToolset.DUtil/osutil.cpp b/src/libs/dutil/WixToolset.DUtil/osutil.cpp index 880ec3ea..4798dc58 100644 --- a/src/libs/dutil/WixToolset.DUtil/osutil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/osutil.cpp @@ -16,6 +16,7 @@ #define OsExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_OSUTIL, p, x, s, __VA_ARGS__) #define OsExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_OSUTIL, e, x, s, __VA_ARGS__) #define OsExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_OSUTIL, g, x, s, __VA_ARGS__) +#define OsExitOnPathFailure(x, b, s, ...) ExitOnPathFailureSource(DUTIL_SOURCE_OSUTIL, x, b, s, __VA_ARGS__) typedef NTSTATUS(NTAPI* PFN_RTL_GET_VERSION)(_Out_ PRTL_OSVERSIONINFOEXW lpVersionInformation); @@ -186,23 +187,26 @@ extern "C" HRESULT DAPI OsIsUacEnabled( { HRESULT hr = S_OK; HKEY hk = NULL; + BOOL fExists = FALSE; DWORD dwUacEnabled = 0; *pfUacEnabled = FALSE; // assume UAC not enabled. hr = RegOpen(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", KEY_READ, &hk); - if (E_FILENOTFOUND == hr) + OsExitOnPathFailure(hr, fExists, "Failed to open system policy key to detect UAC."); + + if (!fExists) { - ExitFunction1(hr = S_OK); + ExitFunction(); } - OsExitOnFailure(hr, "Failed to open system policy key to detect UAC."); hr = RegReadNumber(hk, L"EnableLUA", &dwUacEnabled); - if (E_FILENOTFOUND == hr) + OsExitOnPathFailure(hr, fExists, "Failed to read registry value to detect UAC."); + + if (!fExists) { - ExitFunction1(hr = S_OK); + ExitFunction(); } - OsExitOnFailure(hr, "Failed to read registry value to detect UAC."); *pfUacEnabled = (0 != dwUacEnabled); diff --git a/src/libs/dutil/WixToolset.DUtil/path3utl.cpp b/src/libs/dutil/WixToolset.DUtil/path3utl.cpp index cb6ce6d5..844cbfbb 100644 --- a/src/libs/dutil/WixToolset.DUtil/path3utl.cpp +++ b/src/libs/dutil/WixToolset.DUtil/path3utl.cpp @@ -17,6 +17,7 @@ #define PathExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_PATHUTIL, p, x, s, __VA_ARGS__) #define PathExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_PATHUTIL, e, x, s, __VA_ARGS__) #define PathExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_PATHUTIL, g, x, s, __VA_ARGS__) +#define PathExitOnPathFailure(x, b, s, ...) ExitOnPathFailureSource(DUTIL_SOURCE_PATHUTIL, x, b, s, __VA_ARGS__) static HRESULT GetTempPathFromSystemEnvironmentVariable( __in HKEY hKey, @@ -32,6 +33,7 @@ DAPI_(HRESULT) PathGetSystemTempPaths( HRESULT hr = S_OK; HMODULE hModule = NULL; BOOL fSystem = FALSE; + BOOL fExists = FALSE; HKEY hKey = NULL; LPWSTR sczTemp = NULL; @@ -61,10 +63,10 @@ DAPI_(HRESULT) PathGetSystemTempPaths( // There is no documented API to get system environment variables, so read them from the registry. hr = RegOpen(HKEY_LOCAL_MACHINE, L"System\\CurrentControlSet\\Control\\Session Manager\\Environment", KEY_READ, &hKey); - if (E_FILENOTFOUND != hr) - { - PathExitOnFailure(hr, "Failed to open system environment registry key."); + PathExitOnPathFailure(hr, fExists, "Failed to open system environment registry key."); + if (fExists) + { hr = GetTempPathFromSystemEnvironmentVariable(hKey, L"TMP", &sczTemp); PathExitOnFailure(hr, "Failed to get temp path from system TMP."); @@ -118,14 +120,16 @@ static HRESULT GetTempPathFromSystemEnvironmentVariable( HRESULT hr = S_OK; LPWSTR sczValue = NULL; BOOL fNeedsExpansion = FALSE; + BOOL fExists = FALSE; // Read the value unexpanded so that it can be expanded with system environment variables. hr = RegReadUnexpandedString(hKey, wzName, &fNeedsExpansion, &sczValue); - if (E_FILENOTFOUND == hr) + PathExitOnPathFailure(hr, fExists, "Failed to get system '%ls' value.", wzName); + + if (!fExists) { ExitFunction1(hr = S_FALSE); } - PathExitOnFailure(hr, "Failed to get system '%ls' value.", wzName); if (fNeedsExpansion) { diff --git a/src/libs/dutil/WixToolset.DUtil/polcutil.cpp b/src/libs/dutil/WixToolset.DUtil/polcutil.cpp index c2247bc1..a56c380b 100644 --- a/src/libs/dutil/WixToolset.DUtil/polcutil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/polcutil.cpp @@ -16,6 +16,7 @@ #define PolcExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_POLCUTIL, p, x, s, __VA_ARGS__) #define PolcExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_POLCUTIL, e, x, s, __VA_ARGS__) #define PolcExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_POLCUTIL, g, x, s, __VA_ARGS__) +#define PolcExitOnPathFailure(x, b, s, ...) ExitOnPathFailureSource(DUTIL_SOURCE_POLCUTIL, x, b, s, __VA_ARGS__) const LPCWSTR REGISTRY_POLICIES_KEY = L"SOFTWARE\\Policies\\"; @@ -34,25 +35,28 @@ extern "C" HRESULT DAPI PolcReadNumber( { HRESULT hr = S_OK; HKEY hk = NULL; + BOOL fExists = FALSE; hr = OpenPolicyKey(wzPolicyPath, &hk); - if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) + PolcExitOnFailure(hr, "Failed to open policy key: %ls", wzPolicyPath); + + if (!hk) { ExitFunction1(hr = S_FALSE); } - PolcExitOnFailure(hr, "Failed to open policy key: %ls", wzPolicyPath); hr = RegReadNumber(hk, wzPolicyName, pdw); - if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) + PolcExitOnPathFailure(hr, fExists, "Failed to open policy key: %ls, name: %ls", wzPolicyPath, wzPolicyName); + + if (!fExists) { ExitFunction1(hr = S_FALSE); } - PolcExitOnFailure(hr, "Failed to open policy key: %ls, name: %ls", wzPolicyPath, wzPolicyName); LExit: ReleaseRegKey(hk); - if (S_FALSE == hr || FAILED(hr)) + if (!fExists) { *pdw = dwDefault; } @@ -69,25 +73,28 @@ extern "C" HRESULT DAPI PolcReadString( { HRESULT hr = S_OK; HKEY hk = NULL; + BOOL fExists = FALSE; hr = OpenPolicyKey(wzPolicyPath, &hk); - if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) + PolcExitOnFailure(hr, "Failed to open policy key: %ls", wzPolicyPath); + + if (!hk) { ExitFunction1(hr = S_FALSE); } - PolcExitOnFailure(hr, "Failed to open policy key: %ls", wzPolicyPath); hr = RegReadString(hk, wzPolicyName, pscz); - if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) + PolcExitOnPathFailure(hr, fExists, "Failed to open policy key: %ls, name: %ls", wzPolicyPath, wzPolicyName); + + if (!fExists) { ExitFunction1(hr = S_FALSE); } - PolcExitOnFailure(hr, "Failed to open policy key: %ls, name: %ls", wzPolicyPath, wzPolicyName); LExit: ReleaseRegKey(hk); - if (S_FALSE == hr || FAILED(hr)) + if (!fExists) { if (NULL == wzDefault) { @@ -112,25 +119,28 @@ extern "C" HRESULT DAPI PolcReadUnexpandedString( { HRESULT hr = S_OK; HKEY hk = NULL; + BOOL fExists = FALSE; hr = OpenPolicyKey(wzPolicyPath, &hk); - if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) + PolcExitOnFailure(hr, "Failed to open policy key: %ls", wzPolicyPath); + + if (!hk) { ExitFunction1(hr = S_FALSE); } - PolcExitOnFailure(hr, "Failed to open policy key: %ls", wzPolicyPath); hr = RegReadUnexpandedString(hk, wzPolicyName, pfNeedsExpansion, pscz); - if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) + PolcExitOnPathFailure(hr, fExists, "Failed to open policy key: %ls, name: %ls", wzPolicyPath, wzPolicyName); + + if (!fExists) { ExitFunction1(hr = S_FALSE); } - PolcExitOnFailure(hr, "Failed to open policy key: %ls, name: %ls", wzPolicyPath, wzPolicyName); LExit: ReleaseRegKey(hk); - if (S_FALSE == hr || FAILED(hr)) + if (!fExists) { if (NULL == wzDefault) { @@ -155,12 +165,18 @@ static HRESULT OpenPolicyKey( { HRESULT hr = S_OK; LPWSTR sczPath = NULL; + BOOL fExists = FALSE; hr = PathConcat(REGISTRY_POLICIES_KEY, wzPolicyPath, &sczPath); PolcExitOnFailure(hr, "Failed to combine logging path with root path."); hr = RegOpen(HKEY_LOCAL_MACHINE, sczPath, KEY_READ, phk); - PolcExitOnFailure(hr, "Failed to open policy registry key."); + PolcExitOnPathFailure(hr, fExists, "Failed to open policy registry key."); + + if (!fExists) + { + ReleaseRegKey(*phk); + } LExit: ReleaseStr(sczPath); diff --git a/src/libs/dutil/WixToolset.DUtil/regutil.cpp b/src/libs/dutil/WixToolset.DUtil/regutil.cpp index 9a1b9ced..744e7a3f 100644 --- a/src/libs/dutil/WixToolset.DUtil/regutil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/regutil.cpp @@ -17,6 +17,7 @@ #define RegExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_REGUTIL, p, x, s, __VA_ARGS__) #define RegExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_REGUTIL, e, x, s, __VA_ARGS__) #define RegExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_REGUTIL, g, x, s, __VA_ARGS__) +#define RegExitOnPathFailure(x, b, s, ...) ExitOnPathFailureSource(DUTIL_SOURCE_REGUTIL, x, b, s, __VA_ARGS__) static PFN_REGCREATEKEYEXW vpfnRegCreateKeyExW = ::RegCreateKeyExW; static PFN_REGOPENKEYEXW vpfnRegOpenKeyExW = ::RegOpenKeyExW; @@ -179,7 +180,7 @@ DAPI_(HRESULT) RegOpen( __in_z LPCWSTR wzSubKey, __in DWORD dwAccess, __out HKEY* phk -) + ) { return RegOpenEx(hkRoot, wzSubKey, dwAccess, REG_KEY_DEFAULT, phk); } @@ -191,18 +192,18 @@ DAPI_(HRESULT) RegOpenEx( __in DWORD dwAccess, __in REG_KEY_BITNESS kbKeyBitness, __out HKEY* phk -) + ) { HRESULT hr = S_OK; DWORD er = ERROR_SUCCESS; REGSAM samDesired = RegTranslateKeyBitness(kbKeyBitness); er = vpfnRegOpenKeyExW(hkRoot, wzSubKey, 0, dwAccess | samDesired, phk); - if (E_FILENOTFOUND == HRESULT_FROM_WIN32(er)) + if (ERROR_PATH_NOT_FOUND == er || ERROR_FILE_NOT_FOUND == er) { - ExitFunction1(hr = E_FILENOTFOUND); + ExitFunction1(hr = HRESULT_FROM_WIN32(er)); } - RegExitOnWin32Error(er, hr, "Failed to open registry key."); + RegExitOnWin32Error(er, hr, "Failed to open registry key, root: %x, subkey: %ls.", hkRoot, wzSubKey); LExit: return hr; @@ -221,6 +222,7 @@ DAPI_(HRESULT) RegDelete( LPWSTR pszEnumeratedSubKey = NULL; LPWSTR pszRecursiveSubKey = NULL; HKEY hkKey = NULL; + BOOL fExists = FALSE; if (!vfRegInitialized && REG_KEY_DEFAULT != kbKeyBitness) { @@ -231,9 +233,9 @@ DAPI_(HRESULT) RegDelete( if (fDeleteTree) { hr = RegOpenEx(hkRoot, wzSubKey, KEY_READ, kbKeyBitness, &hkKey); - if (E_FILENOTFOUND == hr) + if (E_PATHNOTFOUND == hr || E_FILENOTFOUND == hr) { - ExitFunction1(hr = S_OK); + ExitFunction(); } RegExitOnFailure(hr, "Failed to open this key for enumerating subkeys: %ls", wzSubKey); @@ -246,28 +248,31 @@ DAPI_(HRESULT) RegDelete( RegExitOnFailure(hr, "Failed to concatenate paths while recursively deleting subkeys. Path1: %ls, Path2: %ls", wzSubKey, pszEnumeratedSubKey); hr = RegDelete(hkRoot, pszRecursiveSubKey, kbKeyBitness, fDeleteTree); - RegExitOnFailure(hr, "Failed to recursively delete subkey: %ls", pszRecursiveSubKey); + RegExitOnPathFailure(hr, fExists, "Failed to recursively delete subkey: %ls", pszRecursiveSubKey); } hr = S_OK; + + // Release the handle to make sure it's deleted immediately. + ReleaseRegKey(hkKey); } if (NULL != vpfnRegDeleteKeyExW) { REGSAM samDesired = RegTranslateKeyBitness(kbKeyBitness); er = vpfnRegDeleteKeyExW(hkRoot, wzSubKey, samDesired, 0); - if (E_FILENOTFOUND == HRESULT_FROM_WIN32(er)) + if (ERROR_PATH_NOT_FOUND == er || ERROR_FILE_NOT_FOUND == er) { - ExitFunction1(hr = E_FILENOTFOUND); + ExitFunction1(hr = HRESULT_FROM_WIN32(er)); } RegExitOnWin32Error(er, hr, "Failed to delete registry key (ex)."); } else { er = vpfnRegDeleteKeyW(hkRoot, wzSubKey); - if (E_FILENOTFOUND == HRESULT_FROM_WIN32(er)) + if (ERROR_PATH_NOT_FOUND == er || ERROR_FILE_NOT_FOUND == er) { - ExitFunction1(hr = E_FILENOTFOUND); + ExitFunction1(hr = HRESULT_FROM_WIN32(er)); } RegExitOnWin32Error(er, hr, "Failed to delete registry key."); } @@ -772,7 +777,7 @@ DAPI_(HRESULT) RegReadNumber( DWORD cb = sizeof(DWORD); er = vpfnRegQueryValueExW(hk, wzName, NULL, &dwType, reinterpret_cast(pdwValue), &cb); - if (E_FILENOTFOUND == HRESULT_FROM_WIN32(er)) + if (ERROR_FILE_NOT_FOUND == er) { ExitFunction1(hr = E_FILENOTFOUND); } @@ -801,7 +806,7 @@ DAPI_(HRESULT) RegReadQword( DWORD cb = sizeof(DWORD64); er = vpfnRegQueryValueExW(hk, wzName, NULL, &dwType, reinterpret_cast(pqwValue), &cb); - if (E_FILENOTFOUND == HRESULT_FROM_WIN32(er)) + if (ERROR_FILE_NOT_FOUND == er) { ExitFunction1(hr = E_FILENOTFOUND); } @@ -1015,9 +1020,17 @@ DAPI_(HRESULT) RegKeyReadNumber( HKEY hkKey = NULL; hr = RegOpenEx(hk, wzSubKey, KEY_READ, kbKeyBitness, &hkKey); + if (E_PATHNOTFOUND == hr || E_FILENOTFOUND == hr) + { + ExitFunction(); + } RegExitOnFailure(hr, "Failed to open key: %ls", wzSubKey); hr = RegReadNumber(hkKey, wzName, pdwValue); + if (E_FILENOTFOUND == hr) + { + ExitFunction(); + } RegExitOnFailure(hr, "Failed to read value: %ls/@%ls", wzSubKey, wzName); LExit: @@ -1038,9 +1051,17 @@ DAPI_(BOOL) RegValueExists( DWORD dwType = 0; hr = RegOpenEx(hk, wzSubKey, KEY_READ, kbKeyBitness, &hkKey); + if (E_PATHNOTFOUND == hr || E_FILENOTFOUND == hr) + { + ExitFunction(); + } RegExitOnFailure(hr, "Failed to open key: %ls", wzSubKey); hr = RegGetType(hkKey, wzName, &dwType); + if (E_FILENOTFOUND == hr) + { + ExitFunction(); + } RegExitOnFailure(hr, "Failed to read value type: %ls/@%ls", wzSubKey, wzName); LExit: diff --git a/src/libs/dutil/WixToolset.DUtil/wiutil.cpp b/src/libs/dutil/WixToolset.DUtil/wiutil.cpp index da7cffe7..5f81cf3a 100644 --- a/src/libs/dutil/WixToolset.DUtil/wiutil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/wiutil.cpp @@ -427,6 +427,11 @@ extern "C" HRESULT DAPI WiuGetProductInfo( er = vpfnMsiGetProductInfoW(wzProductCode, wzProperty, *psczValue, &cch); } + + if (ERROR_UNKNOWN_PRODUCT == er || ERROR_UNKNOWN_PROPERTY == er) + { + ExitFunction1(hr = HRESULT_FROM_WIN32(er)); + } WiuExitOnWin32Error(er, hr, "Failed to get product info."); LExit: @@ -449,7 +454,10 @@ extern "C" HRESULT DAPI WiuGetProductInfoEx( if (!vpfnMsiGetProductInfoExW) { hr = WiuGetProductInfo(wzProductCode, wzProperty, psczValue); - WiuExitOnFailure(hr, "Failed to get product info when extended info was not available."); + if (HRESULT_FROM_WIN32(ERROR_UNKNOWN_PRODUCT) != hr && HRESULT_FROM_WIN32(ERROR_UNKNOWN_PROPERTY) != hr) + { + WiuExitOnFailure(hr, "Failed to get product info when extended info was not available."); + } ExitFunction(); } @@ -466,6 +474,11 @@ extern "C" HRESULT DAPI WiuGetProductInfoEx( er = vpfnMsiGetProductInfoExW(wzProductCode, wzUserSid, dwContext, wzProperty, *psczValue, &cch); } + + if (ERROR_UNKNOWN_PRODUCT == er || ERROR_UNKNOWN_PROPERTY == er) + { + ExitFunction1(hr = HRESULT_FROM_WIN32(er)); + } WiuExitOnWin32Error(er, hr, "Failed to get extended product info."); LExit: -- cgit v1.2.3-55-g6feb