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 +++++++++++++++------------------ 8 files changed, 100 insertions(+), 136 deletions(-) (limited to 'src/burn') 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); -- cgit v1.2.3-55-g6feb