From 0c2b4cf3a439eda3e19d20fadfc65ddc7d0394c0 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Sat, 10 Apr 2021 16:05:23 -0700 Subject: Integrate fixes that make dutil a little more robust to failure --- src/dutil/wiutil.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src/dutil/wiutil.cpp') diff --git a/src/dutil/wiutil.cpp b/src/dutil/wiutil.cpp index ffbfe85a..f1984266 100644 --- a/src/dutil/wiutil.cpp +++ b/src/dutil/wiutil.cpp @@ -4,6 +4,7 @@ // Exit macros +#define WiuExitTrace(x, s, ...) ExitTraceSource(DUTIL_SOURCE_WIUTIL, x, s, __VA_ARGS__) #define WiuExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_WIUTIL, x, s, __VA_ARGS__) #define WiuExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_WIUTIL, x, s, __VA_ARGS__) #define WiuExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_WIUTIL, x, s, __VA_ARGS__) @@ -692,12 +693,23 @@ extern "C" HRESULT DAPI WiuEnumRelatedProductCodes( if (fReturnHighestVersionOnly) { - // get the version + // try to get the version but if the product registration is broken + // (for whatever reason), skip this product hr = WiuGetProductInfo(wzCurrentProductCode, L"VersionString", &sczInstalledVersion); - WiuExitOnFailure(hr, "Failed to get version for product code: %ls", wzCurrentProductCode); + if (FAILED(hr)) + { + WiuExitTrace(hr, "Could not get product version for product code: %ls, skipping...", wzCurrentProductCode); + continue; + } + // try to parse the product version but if it is corrupt (for whatever + // reason), skip it hr = FileVersionFromStringEx(sczInstalledVersion, 0, &qwCurrentVersion); - WiuExitOnFailure(hr, "Failed to convert version: %ls to DWORD64 for product code: %ls", sczInstalledVersion, wzCurrentProductCode); + if (FAILED(hr)) + { + WiuExitTrace(hr, "Could not convert version: %ls to DWORD64 for product code: %ls, skipping...", sczInstalledVersion, wzCurrentProductCode); + continue; + } // if this is the first product found then it is the highest version (for now) if (0 == *pcRelatedProducts) -- cgit v1.2.3-55-g6feb