From ed0ef472c76ac0d2a3d7a138e4f3b7ad950a56bc Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Tue, 30 Mar 2021 17:15:25 -0500 Subject: Add test for apuputil and fix descending sorting. --- src/dutil/apuputil.cpp | 27 +++++++++++++++------------ src/dutil/inc/verutil.h | 4 ++-- src/dutil/verutil.cpp | 16 ++++++++++++---- 3 files changed, 29 insertions(+), 18 deletions(-) (limited to 'src/dutil') diff --git a/src/dutil/apuputil.cpp b/src/dutil/apuputil.cpp index 07d591a7..6f5825bb 100644 --- a/src/dutil/apuputil.cpp +++ b/src/dutil/apuputil.cpp @@ -208,7 +208,6 @@ static HRESULT ProcessEntry( ) { HRESULT hr = S_OK; - BOOL fVersionFound = FALSE; int nCompareResult = 0; // First search the ATOM entry's custom elements to try and find the application update information. @@ -255,25 +254,26 @@ static HRESULT ProcessEntry( { hr = VerParseVersion(pElement->wzValue, 0, FALSE, &pApupEntry->pVersion); ApupExitOnFailure(hr, "Failed to parse version string '%ls' from ATOM entry.", pElement->wzValue); - - fVersionFound = TRUE; } } } // If there is no application identity or no version, skip the whole thing. - if ((!pApupEntry->wzApplicationId && !wzDefaultAppId) || !fVersionFound) + if ((!pApupEntry->wzApplicationId && !wzDefaultAppId) || !pApupEntry->pVersion) { ExitFunction1(hr = S_FALSE); // skip this update since it has no application id or version. } - hr = VerCompareParsedVersions(pApupEntry->pUpgradeVersion, pApupEntry->pVersion, &nCompareResult); - ApupExitOnFailure(hr, "Failed to compare version to upgrade version."); - - if (nCompareResult >= 0) + if (pApupEntry->pUpgradeVersion) { - hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); - ApupExitOnRootFailure(hr, "Upgrade version is greater than or equal to application version."); + hr = VerCompareParsedVersions(pApupEntry->pUpgradeVersion, pApupEntry->pVersion, &nCompareResult); + ApupExitOnFailure(hr, "Failed to compare version to upgrade version."); + + if (nCompareResult >= 0) + { + hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); + ApupExitOnRootFailure(hr, "Upgrade version is greater than or equal to application version."); + } } if (pAtomEntry->wzTitle) @@ -443,11 +443,14 @@ static __callback int __cdecl CompareEntries( VerCompareParsedVersions(pEntryLeft->pUpgradeVersion, pEntryRight->pUpgradeVersion, &ret); if (0 == ret) { - ret = (pEntryRight->dw64TotalSize < pEntryLeft->dw64TotalSize) ? -1 : - (pEntryRight->dw64TotalSize > pEntryLeft->dw64TotalSize) ? 1 : 0; + ret = (pEntryLeft->dw64TotalSize < pEntryRight->dw64TotalSize) ? -1 : + (pEntryLeft->dw64TotalSize > pEntryRight->dw64TotalSize) ? 1 : 0; } } + // Sort descending. + ret = -ret; + return ret; } diff --git a/src/dutil/inc/verutil.h b/src/dutil/inc/verutil.h index 30869aef..3caa17e1 100644 --- a/src/dutil/inc/verutil.h +++ b/src/dutil/inc/verutil.h @@ -34,8 +34,8 @@ typedef struct _VERUTIL_VERSION *******************************************************************/ HRESULT DAPI VerCompareParsedVersions( - __in VERUTIL_VERSION* pVersion1, - __in VERUTIL_VERSION* pVersion2, + __in_opt VERUTIL_VERSION* pVersion1, + __in_opt VERUTIL_VERSION* pVersion2, __out int* pnResult ); diff --git a/src/dutil/verutil.cpp b/src/dutil/verutil.cpp index 835dde81..fdb5a10a 100644 --- a/src/dutil/verutil.cpp +++ b/src/dutil/verutil.cpp @@ -40,8 +40,8 @@ static HRESULT CompareVersionSubstring( DAPI_(HRESULT) VerCompareParsedVersions( - __in VERUTIL_VERSION* pVersion1, - __in VERUTIL_VERSION* pVersion2, + __in_opt VERUTIL_VERSION* pVersion1, + __in_opt VERUTIL_VERSION* pVersion2, __out int* pnResult ) { @@ -50,8 +50,8 @@ DAPI_(HRESULT) VerCompareParsedVersions( DWORD cMaxReleaseLabels = 0; BOOL fCompareMetadata = FALSE; - if (!pVersion1 || !pVersion1->sczVersion || - !pVersion2 || !pVersion2->sczVersion) + if (pVersion1 && !pVersion1->sczVersion || + pVersion2 && !pVersion2->sczVersion) { ExitFunction1(hr = E_INVALIDARG); } @@ -60,6 +60,14 @@ DAPI_(HRESULT) VerCompareParsedVersions( { ExitFunction1(nResult = 0); } + else if (pVersion1 && !pVersion2) + { + ExitFunction1(nResult = 1); + } + else if (!pVersion1 && pVersion2) + { + ExitFunction1(nResult = -1); + } nResult = CompareDword(pVersion1->dwMajor, pVersion2->dwMajor); if (0 != nResult) -- cgit v1.2.3-55-g6feb