@joebigelow / wix / commits / 10ea1d3e

Use verutil for handling versions in WiuEnumRelatedProductCodes.

Sean Hall committed Apr 12, 2021 at 20:40 UTC 10ea1d3e52217ccd93dfa6830776a6be308ca1f6
1 file changed +24 -12
src/dutil/wiutil.cpp
+24 -12
@@ -674,8 +674,9 @@ extern "C" HRESULT DAPI WiuEnumRelatedProductCodes(
674 HRESULT hr = S_OK;
675 WCHAR wzCurrentProductCode[MAX_GUID_CHARS + 1] = { };
676 LPWSTR sczInstalledVersion = NULL;
677 - DWORD64 qwCurrentVersion = 0;
678 - DWORD64 qwHighestVersion = 0;
677 + VERUTIL_VERSION* pCurrentVersion = NULL;
678 + VERUTIL_VERSION* pHighestVersion = NULL;
679 + int nCompare = 0;
680
681 // make sure we start at zero
682 *pcRelatedProducts = 0;
@@ -702,31 +703,40 @@ extern "C" HRESULT DAPI WiuEnumRelatedProductCodes(
703 continue;
704 }
705
705 - // try to parse the product version but if it is corrupt (for whatever
706 - // reason), skip it
707 - hr = FileVersionFromStringEx(sczInstalledVersion, 0, &qwCurrentVersion);
708 - if (FAILED(hr))
706 + hr = VerParseVersion(sczInstalledVersion, 0, FALSE, &pCurrentVersion);
707 + WiuExitOnFailure(hr, "Failed to parse version: %ls for product code: %ls", sczInstalledVersion, wzCurrentProductCode);
708 +
709 + if (pCurrentVersion->fInvalid)
710 {
710 - WiuExitTrace(hr, "Could not convert version: %ls to DWORD64 for product code: %ls, skipping...", sczInstalledVersion, wzCurrentProductCode);
711 - continue;
711 + WiuExitTrace(E_INVALIDDATA, "Enumerated msi package with invalid version, product code: '%1!ls!', version: '%2!ls!'");
712 }
713
714 // if this is the first product found then it is the highest version (for now)
715 - if (0 == *pcRelatedProducts)
715 + if (!pHighestVersion)
716 {
717 - qwHighestVersion = qwCurrentVersion;
717 + pHighestVersion = pCurrentVersion;
718 + pCurrentVersion = NULL;
719 }
720 else
721 {
722 + hr = VerCompareParsedVersions(pCurrentVersion, pHighestVersion, &nCompare);
723 + WiuExitOnFailure(hr, "Failed to compare version '%ls' to highest version: '%ls'", pCurrentVersion->sczVersion, pHighestVersion->sczVersion);
724 +
725 // if this is the highest version encountered so far then overwrite
726 // the first item in the array (there will never be more than one item)
723 - if (qwCurrentVersion > qwHighestVersion)
727 + if (nCompare > 0)
728 {
725 - qwHighestVersion = qwCurrentVersion;
729 + ReleaseVerutilVersion(pHighestVersion);
730 + pHighestVersion = pCurrentVersion;
731 + pCurrentVersion = NULL;
732
733 hr = StrAllocString(prgsczProductCodes[0], wzCurrentProductCode, 0);
734 WiuExitOnFailure(hr, "Failed to update array with higher versioned product code.");
735 }
736 + else
737 + {
738 + ReleaseVerutilVersion(pCurrentVersion);
739 + }
740
741 // continue here as we don't want anything else added to the list
742 continue;
@@ -738,6 +748,8 @@ extern "C" HRESULT DAPI WiuEnumRelatedProductCodes(
748 }
749
750 LExit:
751 + ReleaseVerutilVersion(pCurrentVersion);
752 + ReleaseVerutilVersion(pHighestVersion);
753 ReleaseStr(sczInstalledVersion);
754 return hr;
755 }