@joebigelow / wix / commits / d3bd9187

Update apuputil and deputil to not use DWORD64 for versions.

Sean Hall committed Aug 29, 2020 at 21:30 UTC d3bd9187857fb42218925c4b9192b25f82e81db6
5 files changed +56 -46
src/dutil/apuputil.cpp
+48 -38
@@ -22,7 +22,7 @@ static __callback int __cdecl CompareEntries(
22 static HRESULT FilterEntries(
23 __in APPLICATION_UPDATE_ENTRY* rgEntries,
24 __in DWORD cEntries,
25 - __in DWORD64 dw64CurrentVersion,
25 + __in VERUTIL_VERSION* pCurrentVersion,
26 __inout APPLICATION_UPDATE_ENTRY** prgFilteredEntries,
27 __inout DWORD* pcFilteredEntries
28 );
@@ -128,7 +128,7 @@ LExit:
128 //
129 HRESULT DAPI ApupFilterChain(
130 __in APPLICATION_UPDATE_CHAIN* pChain,
131 - __in DWORD64 dw64Version,
131 + __in VERUTIL_VERSION* pVersion,
132 __out APPLICATION_UPDATE_CHAIN** ppFilteredChain
133 )
134 {
@@ -140,7 +140,7 @@ HRESULT DAPI ApupFilterChain(
140 pNewChain = static_cast<APPLICATION_UPDATE_CHAIN*>(MemAlloc(sizeof(APPLICATION_UPDATE_CHAIN), TRUE));
141 ExitOnNull(pNewChain, hr, E_OUTOFMEMORY, "Failed to allocate filtered chain.");
142
143 - hr = FilterEntries(pChain->rgEntries, pChain->cEntries, dw64Version, &prgEntries, &cEntries);
143 + hr = FilterEntries(pChain->rgEntries, pChain->cEntries, pVersion, &prgEntries, &cEntries);
144 ExitOnFailure(hr, "Failed to filter entries by version.");
145
146 if (pChain->wzDefaultApplicationId)
@@ -197,6 +197,7 @@ static HRESULT ProcessEntry(
197 {
198 HRESULT hr = S_OK;
199 BOOL fVersionFound = FALSE;
200 + int nCompareResult = 0;
201
202 // First search the ATOM entry's custom elements to try and find the application update information.
203 for (ATOM_UNKNOWN_ELEMENT* pElement = pAtomEntry->pUnknownElements; pElement; pElement = pElement->pNext)
@@ -226,13 +227,8 @@ static HRESULT ProcessEntry(
227 {
228 if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pAttribute->wzAttribute, -1, L"version", -1))
229 {
229 - DWORD dwMajor = 0;
230 - DWORD dwMinor = 0;
231 -
232 - hr = FileVersionFromString(pAttribute->wzValue, &dwMajor, &dwMinor);
233 - ExitOnFailure(hr, "Failed to parse version string from ATOM entry.");
234 -
235 - pApupEntry->dw64UpgradeVersion = static_cast<DWORD64>(dwMajor) << 32 | dwMinor;
230 + hr = VerParseVersion(pAttribute->wzValue, 0, FALSE, &pApupEntry->pUpgradeVersion);
231 + ExitOnFailure(hr, "Failed to parse upgrade version string '%ls' from ATOM entry.", pAttribute->wzValue);
232 }
233 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pAttribute->wzAttribute, -1, L"exclusive", -1))
234 {
@@ -245,13 +241,9 @@ static HRESULT ProcessEntry(
241 }
242 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pElement->wzElement, -1, L"version", -1))
243 {
248 - DWORD dwMajor = 0;
249 - DWORD dwMinor = 0;
250 -
251 - hr = FileVersionFromString(pElement->wzValue, &dwMajor, &dwMinor);
252 - ExitOnFailure(hr, "Failed to parse version string from ATOM entry.");
244 + hr = VerParseVersion(pElement->wzValue, 0, FALSE, &pApupEntry->pVersion);
245 + ExitOnFailure(hr, "Failed to parse version string '%ls' from ATOM entry.", pElement->wzValue);
246
254 - pApupEntry->dw64Version = static_cast<DWORD64>(dwMajor) << 32 | dwMinor;
247 fVersionFound = TRUE;
248 }
249 }
@@ -263,7 +255,10 @@ static HRESULT ProcessEntry(
255 ExitFunction1(hr = S_FALSE); // skip this update since it has no application id or version.
256 }
257
266 - if (pApupEntry->dw64UpgradeVersion >= pApupEntry->dw64Version)
258 + hr = VerCompareParsedVersions(pApupEntry->pUpgradeVersion, pApupEntry->pVersion, &nCompareResult);
259 + ExitOnFailure(hr, "Failed to compare version to upgrade version.");
260 +
261 + if (nCompareResult >= 0)
262 {
263 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
264 ExitOnRootFailure(hr, "Upgrade version is greater than or equal to application version.");
@@ -404,31 +399,24 @@ LExit:
399
400
401 static __callback int __cdecl CompareEntries(
407 - void* pvContext,
402 + void* /*pvContext*/,
403 const void* pvLeft,
404 const void* pvRight
405 )
406 {
412 - UNREFERENCED_PARAMETER(pvContext);
413 -
407 int ret = 0;
408 const APPLICATION_UPDATE_ENTRY* pEntryLeft = static_cast<const APPLICATION_UPDATE_ENTRY*>(pvLeft);
409 const APPLICATION_UPDATE_ENTRY* pEntryRight = static_cast<const APPLICATION_UPDATE_ENTRY*>(pvRight);
410
418 - if (pEntryLeft->dw64Version == pEntryRight->dw64Version)
411 + VerCompareParsedVersions(pEntryLeft->pVersion, pEntryRight->pVersion, &ret);
412 + if (0 == ret)
413 {
420 - if (pEntryLeft->dw64UpgradeVersion == pEntryRight->dw64UpgradeVersion)
414 + VerCompareParsedVersions(pEntryLeft->pUpgradeVersion, pEntryRight->pUpgradeVersion, &ret);
415 + if (0 == ret)
416 {
422 - ret = (pEntryRight->dw64TotalSize < pEntryLeft->dw64TotalSize) ? -1 : 1;
417 + ret = (pEntryRight->dw64TotalSize < pEntryLeft->dw64TotalSize) ? -1 :
418 + (pEntryRight->dw64TotalSize > pEntryLeft->dw64TotalSize) ? 1 : 0;
419 }
424 - else
425 - {
426 - ret = (pEntryLeft->dw64UpgradeVersion > pEntryRight->dw64UpgradeVersion) ? -1 : 1;
427 - }
428 - }
429 - else
430 - {
431 - ret = (pEntryLeft->dw64Version > pEntryRight->dw64Version) ? -1 : 1;
420 }
421
422 return ret;
@@ -438,12 +426,13 @@ static __callback int __cdecl CompareEntries(
426 static HRESULT FilterEntries(
427 __in APPLICATION_UPDATE_ENTRY* rgEntries,
428 __in DWORD cEntries,
441 - __in DWORD64 dw64CurrentVersion,
429 + __in VERUTIL_VERSION* pCurrentVersion,
430 __inout APPLICATION_UPDATE_ENTRY** prgFilteredEntries,
431 __inout DWORD* pcFilteredEntries
432 )
433 {
434 HRESULT hr = S_OK;
435 + int nCompareResult = 0;
436 size_t cbAllocSize = 0;
437 const APPLICATION_UPDATE_ENTRY* pRequired = NULL;;
438 LPVOID pv = NULL;
@@ -453,8 +442,19 @@ static HRESULT FilterEntries(
442 for (DWORD i = 0; i < cEntries; ++i)
443 {
444 const APPLICATION_UPDATE_ENTRY* pEntry = rgEntries + i;
456 - if (((pEntry->fUpgradeExclusive && dw64CurrentVersion > pEntry->dw64UpgradeVersion) || (!pEntry->fUpgradeExclusive && dw64CurrentVersion >= pEntry->dw64UpgradeVersion)) &&
457 - dw64CurrentVersion < pEntry->dw64Version)
445 +
446 + hr = VerCompareParsedVersions(pCurrentVersion, pEntry->pVersion, &nCompareResult);
447 + ExitOnFailure(hr, "Failed to compare versions.");
448 +
449 + if (nCompareResult >= 0)
450 + {
451 + continue;
452 + }
453 +
454 + hr = VerCompareParsedVersions(pCurrentVersion, pEntry->pUpgradeVersion, &nCompareResult);
455 + ExitOnFailure(hr, "Failed to compare upgrade versions.");
456 +
457 + if (nCompareResult > 0 || (!pEntry->fUpgradeExclusive && nCompareResult == 0))
458 {
459 pRequired = pEntry;
460 break;
@@ -486,9 +486,12 @@ static HRESULT FilterEntries(
486 hr = CopyEntry(pRequired, *prgFilteredEntries + *pcFilteredEntries - 1);
487 ExitOnFailure(hr, "Failed to deep copy entry.");
488
489 - if (pRequired->dw64Version < rgEntries[0].dw64Version)
489 + hr = VerCompareParsedVersions(pRequired->pVersion, rgEntries[0].pVersion, &nCompareResult);
490 + ExitOnFailure(hr, "Failed to compare required version.");
491 +
492 + if (nCompareResult < 0)
493 {
491 - FilterEntries(rgEntries, cEntries, pRequired->dw64Version, prgFilteredEntries, pcFilteredEntries);
494 + FilterEntries(rgEntries, cEntries, pRequired->pVersion, prgFilteredEntries, pcFilteredEntries);
495 }
496 }
497 }
@@ -552,8 +555,13 @@ static HRESULT CopyEntry(
555 }
556
557 pDest->dw64TotalSize = pSrc->dw64TotalSize;
555 - pDest->dw64UpgradeVersion = pSrc->dw64UpgradeVersion;
556 - pDest->dw64Version = pSrc->dw64Version;
558 +
559 + hr = VerCopyVersion(pSrc->pUpgradeVersion, &pDest->pUpgradeVersion);
560 + ExitOnFailure(hr, "Failed to copy upgrade version.");
561 +
562 + hr = VerCopyVersion(pSrc->pVersion, &pDest->pVersion);
563 + ExitOnFailure(hr, "Failed to copy version.");
564 +
565 pDest->fUpgradeExclusive = pSrc->fUpgradeExclusive;
566
567 hr = ::SizeTMult(sizeof(APPLICATION_UPDATE_ENCLOSURE), pSrc->cEnclosures, &cbAllocSize);
@@ -641,6 +649,8 @@ static void FreeEntry(
649 ReleaseStr(pEntry->wzSummary);
650 ReleaseStr(pEntry->wzContentType);
651 ReleaseStr(pEntry->wzContent);
652 + ReleaseVerutilVersion(pEntry->pVersion);
653 + ReleaseVerutilVersion(pEntry->pUpgradeVersion);
654 }
655 }
656
src/dutil/deputil.cpp
+3 -3
@@ -33,7 +33,7 @@ DAPI_(HRESULT) DepGetProviderInformation(
33 __in_z LPCWSTR wzProviderKey,
34 __deref_out_z_opt LPWSTR* psczId,
35 __deref_out_z_opt LPWSTR* psczName,
36 - __out_opt DWORD64* pqwVersion
36 + __deref_out_z_opt LPWSTR* psczVersion
37 )
38 {
39 HRESULT hr = S_OK;
@@ -75,9 +75,9 @@ DAPI_(HRESULT) DepGetProviderInformation(
75 }
76
77 // Get the Version if requested and available.
78 - if (pqwVersion)
78 + if (psczVersion)
79 {
80 - hr = RegReadVersion(hkKey, vcszVersionValue, pqwVersion);
80 + hr = RegReadString(hkKey, vcszVersionValue, psczVersion);
81 if (E_FILENOTFOUND == hr)
82 {
83 hr = S_OK;
src/dutil/inc/apuputil.h
+3 -3
@@ -46,8 +46,8 @@ struct APPLICATION_UPDATE_ENTRY
46
47 LPWSTR wzUpgradeId;
48 BOOL fUpgradeExclusive;
49 - DWORD64 dw64Version;
50 - DWORD64 dw64UpgradeVersion;
49 + VERUTIL_VERSION* pVersion;
50 + VERUTIL_VERSION* pUpgradeVersion;
51
52 DWORD64 dw64TotalSize;
53
@@ -73,7 +73,7 @@ HRESULT DAPI ApupAllocChainFromAtom(
73
74 HRESULT DAPI ApupFilterChain(
75 __in APPLICATION_UPDATE_CHAIN* pChain,
76 - __in DWORD64 dw64Version,
76 + __in VERUTIL_VERSION* pVersion,
77 __out APPLICATION_UPDATE_CHAIN** ppFilteredChain
78 );
79
src/dutil/inc/deputil.h
+1 -1
@@ -27,7 +27,7 @@ DAPI_(HRESULT) DepGetProviderInformation(
27 __in_z LPCWSTR wzProviderKey,
28 __deref_out_z_opt LPWSTR* psczId,
29 __deref_out_z_opt LPWSTR* psczName,
30 - __out_opt DWORD64* pqwVersion
30 + __deref_out_z_opt LPWSTR* psczVersion
31 );
32
33 /***************************************************************************
src/dutil/precomp.h
+1 -1
@@ -43,6 +43,7 @@
43
44 #include "dutilsources.h"
45 #include "dutil.h"
46 +#include "verutil.h"
47 #include "aclutil.h"
48 #include "atomutil.h"
49 #include "buffutil.h"
@@ -89,7 +90,6 @@
90 #include "uncutil.h"
91 #include "uriutil.h"
92 #include "userutil.h"
92 -#include "verutil.h"
93 #include "wiutil.h"
94 #include "wuautil.h"
95 #include <comutil.h> // This header is needed for msxml2.h to compile correctly