diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2021-04-12 20:40:20 -0500 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2021-04-12 20:44:35 -0500 |
| commit | 10ea1d3e52217ccd93dfa6830776a6be308ca1f6 (patch) | |
| tree | bd8987321e244edea7ae5964c9c45782e54089f1 /src | |
| parent | 2113f2bedbdf5c2f8fb21fc5dfacc6ddc7379fe7 (diff) | |
| download | wix-10ea1d3e52217ccd93dfa6830776a6be308ca1f6.tar.gz wix-10ea1d3e52217ccd93dfa6830776a6be308ca1f6.tar.bz2 wix-10ea1d3e52217ccd93dfa6830776a6be308ca1f6.zip | |
Use verutil for handling versions in WiuEnumRelatedProductCodes.
Diffstat (limited to 'src')
| -rw-r--r-- | src/dutil/wiutil.cpp | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/src/dutil/wiutil.cpp b/src/dutil/wiutil.cpp index f1984266..7414ac42 100644 --- a/src/dutil/wiutil.cpp +++ b/src/dutil/wiutil.cpp | |||
| @@ -674,8 +674,9 @@ extern "C" HRESULT DAPI WiuEnumRelatedProductCodes( | |||
| 674 | HRESULT hr = S_OK; | 674 | HRESULT hr = S_OK; |
| 675 | WCHAR wzCurrentProductCode[MAX_GUID_CHARS + 1] = { }; | 675 | WCHAR wzCurrentProductCode[MAX_GUID_CHARS + 1] = { }; |
| 676 | LPWSTR sczInstalledVersion = NULL; | 676 | LPWSTR sczInstalledVersion = NULL; |
| 677 | DWORD64 qwCurrentVersion = 0; | 677 | VERUTIL_VERSION* pCurrentVersion = NULL; |
| 678 | DWORD64 qwHighestVersion = 0; | 678 | VERUTIL_VERSION* pHighestVersion = NULL; |
| 679 | int nCompare = 0; | ||
| 679 | 680 | ||
| 680 | // make sure we start at zero | 681 | // make sure we start at zero |
| 681 | *pcRelatedProducts = 0; | 682 | *pcRelatedProducts = 0; |
| @@ -702,31 +703,40 @@ extern "C" HRESULT DAPI WiuEnumRelatedProductCodes( | |||
| 702 | continue; | 703 | continue; |
| 703 | } | 704 | } |
| 704 | 705 | ||
| 705 | // try to parse the product version but if it is corrupt (for whatever | 706 | hr = VerParseVersion(sczInstalledVersion, 0, FALSE, &pCurrentVersion); |
| 706 | // reason), skip it | 707 | WiuExitOnFailure(hr, "Failed to parse version: %ls for product code: %ls", sczInstalledVersion, wzCurrentProductCode); |
| 707 | hr = FileVersionFromStringEx(sczInstalledVersion, 0, &qwCurrentVersion); | 708 | |
| 708 | if (FAILED(hr)) | 709 | if (pCurrentVersion->fInvalid) |
| 709 | { | 710 | { |
| 710 | WiuExitTrace(hr, "Could not convert version: %ls to DWORD64 for product code: %ls, skipping...", sczInstalledVersion, wzCurrentProductCode); | 711 | WiuExitTrace(E_INVALIDDATA, "Enumerated msi package with invalid version, product code: '%1!ls!', version: '%2!ls!'"); |
| 711 | continue; | ||
| 712 | } | 712 | } |
| 713 | 713 | ||
| 714 | // if this is the first product found then it is the highest version (for now) | 714 | // if this is the first product found then it is the highest version (for now) |
| 715 | if (0 == *pcRelatedProducts) | 715 | if (!pHighestVersion) |
| 716 | { | 716 | { |
| 717 | qwHighestVersion = qwCurrentVersion; | 717 | pHighestVersion = pCurrentVersion; |
| 718 | pCurrentVersion = NULL; | ||
| 718 | } | 719 | } |
| 719 | else | 720 | else |
| 720 | { | 721 | { |
| 722 | hr = VerCompareParsedVersions(pCurrentVersion, pHighestVersion, &nCompare); | ||
| 723 | WiuExitOnFailure(hr, "Failed to compare version '%ls' to highest version: '%ls'", pCurrentVersion->sczVersion, pHighestVersion->sczVersion); | ||
| 724 | |||
| 721 | // if this is the highest version encountered so far then overwrite | 725 | // if this is the highest version encountered so far then overwrite |
| 722 | // the first item in the array (there will never be more than one item) | 726 | // the first item in the array (there will never be more than one item) |
| 723 | if (qwCurrentVersion > qwHighestVersion) | 727 | if (nCompare > 0) |
| 724 | { | 728 | { |
| 725 | qwHighestVersion = qwCurrentVersion; | 729 | ReleaseVerutilVersion(pHighestVersion); |
| 730 | pHighestVersion = pCurrentVersion; | ||
| 731 | pCurrentVersion = NULL; | ||
| 726 | 732 | ||
| 727 | hr = StrAllocString(prgsczProductCodes[0], wzCurrentProductCode, 0); | 733 | hr = StrAllocString(prgsczProductCodes[0], wzCurrentProductCode, 0); |
| 728 | WiuExitOnFailure(hr, "Failed to update array with higher versioned product code."); | 734 | WiuExitOnFailure(hr, "Failed to update array with higher versioned product code."); |
| 729 | } | 735 | } |
| 736 | else | ||
| 737 | { | ||
| 738 | ReleaseVerutilVersion(pCurrentVersion); | ||
| 739 | } | ||
| 730 | 740 | ||
| 731 | // continue here as we don't want anything else added to the list | 741 | // continue here as we don't want anything else added to the list |
| 732 | continue; | 742 | continue; |
| @@ -738,6 +748,8 @@ extern "C" HRESULT DAPI WiuEnumRelatedProductCodes( | |||
| 738 | } | 748 | } |
| 739 | 749 | ||
| 740 | LExit: | 750 | LExit: |
| 751 | ReleaseVerutilVersion(pCurrentVersion); | ||
| 752 | ReleaseVerutilVersion(pHighestVersion); | ||
| 741 | ReleaseStr(sczInstalledVersion); | 753 | ReleaseStr(sczInstalledVersion); |
| 742 | return hr; | 754 | return hr; |
| 743 | } | 755 | } |
