diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2020-10-17 19:12:21 -0500 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2020-10-24 20:07:21 -0500 |
| commit | 273c69f34311f4f4e5f6b5896e71d0788f12d96a (patch) | |
| tree | 4cf8f42f3ecfa9341a41686b74aa5e48068ede87 /src/engine/condition.cpp | |
| parent | 3f8e35223216ebbe7f6683a5031a5a97bbc66d5a (diff) | |
| download | wix-273c69f34311f4f4e5f6b5896e71d0788f12d96a.tar.gz wix-273c69f34311f4f4e5f6b5896e71d0788f12d96a.tar.bz2 wix-273c69f34311f4f4e5f6b5896e71d0788f12d96a.zip | |
WIXFEAT:6210 Change data type of versions to strings.
Diffstat (limited to 'src/engine/condition.cpp')
| -rw-r--r-- | src/engine/condition.cpp | 88 |
1 files changed, 35 insertions, 53 deletions
diff --git a/src/engine/condition.cpp b/src/engine/condition.cpp index cd346680..32a7a0b8 100644 --- a/src/engine/condition.cpp +++ b/src/engine/condition.cpp | |||
| @@ -123,8 +123,8 @@ static HRESULT CompareIntegerValues( | |||
| 123 | ); | 123 | ); |
| 124 | static HRESULT CompareVersionValues( | 124 | static HRESULT CompareVersionValues( |
| 125 | __in BURN_SYMBOL_TYPE comparison, | 125 | __in BURN_SYMBOL_TYPE comparison, |
| 126 | __in DWORD64 qwLeftOperand, | 126 | __in VERUTIL_VERSION* pLeftOperand, |
| 127 | __in DWORD64 qwRightOperand, | 127 | __in VERUTIL_VERSION* pRightOperand, |
| 128 | __out BOOL* pfResult | 128 | __out BOOL* pfResult |
| 129 | ); | 129 | ); |
| 130 | 130 | ||
| @@ -379,7 +379,7 @@ static HRESULT ParseTerm( | |||
| 379 | { | 379 | { |
| 380 | LONGLONG llValue = 0; | 380 | LONGLONG llValue = 0; |
| 381 | LPWSTR sczValue = NULL; | 381 | LPWSTR sczValue = NULL; |
| 382 | DWORD64 qwValue = 0; | 382 | VERUTIL_VERSION* pVersion = NULL; |
| 383 | switch (firstValue.Type) | 383 | switch (firstValue.Type) |
| 384 | { | 384 | { |
| 385 | case BURN_VARIANT_TYPE_NONE: | 385 | case BURN_VARIANT_TYPE_NONE: |
| @@ -402,12 +402,12 @@ static HRESULT ParseTerm( | |||
| 402 | SecureZeroMemory(&llValue, sizeof(llValue)); | 402 | SecureZeroMemory(&llValue, sizeof(llValue)); |
| 403 | break; | 403 | break; |
| 404 | case BURN_VARIANT_TYPE_VERSION: | 404 | case BURN_VARIANT_TYPE_VERSION: |
| 405 | hr = BVariantGetVersion(&firstValue, &qwValue); | 405 | hr = BVariantGetVersion(&firstValue, &pVersion); |
| 406 | if (SUCCEEDED(hr)) | 406 | if (SUCCEEDED(hr)) |
| 407 | { | 407 | { |
| 408 | *pf = 0 != qwValue; | 408 | *pf = 0 != *pVersion->sczVersion; |
| 409 | } | 409 | } |
| 410 | SecureZeroMemory(&llValue, sizeof(qwValue)); | 410 | ReleaseVerutilVersion(pVersion); |
| 411 | break; | 411 | break; |
| 412 | default: | 412 | default: |
| 413 | ExitFunction1(hr = E_UNEXPECTED); | 413 | ExitFunction1(hr = E_UNEXPECTED); |
| @@ -689,33 +689,14 @@ static HRESULT NextSymbol( | |||
| 689 | if (L'v' == pContext->wzRead[0] && C1_DIGIT & charType) | 689 | if (L'v' == pContext->wzRead[0] && C1_DIGIT & charType) |
| 690 | { | 690 | { |
| 691 | // version | 691 | // version |
| 692 | DWORD cParts = 1; | 692 | do |
| 693 | for (;;) | ||
| 694 | { | 693 | { |
| 695 | ++n; | 694 | ++n; |
| 696 | if (L'.' == pContext->wzRead[n]) | 695 | ::GetStringTypeW(CT_CTYPE1, &pContext->wzRead[n], 1, &charType); |
| 697 | { | 696 | } while (L'\0' != pContext->wzRead[n] && C1_BLANK != (C1_BLANK & charType)); |
| 698 | ++cParts; | ||
| 699 | if (4 < cParts) | ||
| 700 | { | ||
| 701 | // error, too many parts in version | ||
| 702 | pContext->fError = TRUE; | ||
| 703 | hr = E_INVALIDDATA; | ||
| 704 | ExitOnRootFailure(hr, "Failed to parse condition \"%ls\". Version can have a maximum of 4 parts, at position %d.", pContext->wzCondition, iPosition); | ||
| 705 | } | ||
| 706 | } | ||
| 707 | else | ||
| 708 | { | ||
| 709 | ::GetStringTypeW(CT_CTYPE1, &pContext->wzRead[n], 1, &charType); | ||
| 710 | if (C1_DIGIT != (C1_DIGIT & charType)) | ||
| 711 | { | ||
| 712 | break; | ||
| 713 | } | ||
| 714 | } | ||
| 715 | } | ||
| 716 | 697 | ||
| 717 | // Symbols don't encrypt their value, so can access the value directly. | 698 | // Symbols don't encrypt their value, so can access the value directly. |
| 718 | hr = FileVersionFromStringEx(&pContext->wzRead[1], n - 1, &pContext->NextSymbol.Value.qwValue); | 699 | hr = VerParseVersion(&pContext->wzRead[1], n - 1, FALSE, &pContext->NextSymbol.Value.pValue); |
| 719 | if (FAILED(hr)) | 700 | if (FAILED(hr)) |
| 720 | { | 701 | { |
| 721 | pContext->fError = TRUE; | 702 | pContext->fError = TRUE; |
| @@ -785,10 +766,10 @@ static HRESULT CompareValues( | |||
| 785 | { | 766 | { |
| 786 | HRESULT hr = S_OK; | 767 | HRESULT hr = S_OK; |
| 787 | LONGLONG llLeft = 0; | 768 | LONGLONG llLeft = 0; |
| 788 | DWORD64 qwLeft = 0; | 769 | VERUTIL_VERSION* pVersionLeft = 0; |
| 789 | LPWSTR sczLeft = NULL; | 770 | LPWSTR sczLeft = NULL; |
| 790 | LONGLONG llRight = 0; | 771 | LONGLONG llRight = 0; |
| 791 | DWORD64 qwRight = 0; | 772 | VERUTIL_VERSION* pVersionRight = 0; |
| 792 | LPWSTR sczRight = NULL; | 773 | LPWSTR sczRight = NULL; |
| 793 | 774 | ||
| 794 | // get values to compare based on type | 775 | // get values to compare based on type |
| @@ -810,17 +791,17 @@ static HRESULT CompareValues( | |||
| 810 | } | 791 | } |
| 811 | else if (BURN_VARIANT_TYPE_VERSION == leftOperand.Type && BURN_VARIANT_TYPE_VERSION == rightOperand.Type) | 792 | else if (BURN_VARIANT_TYPE_VERSION == leftOperand.Type && BURN_VARIANT_TYPE_VERSION == rightOperand.Type) |
| 812 | { | 793 | { |
| 813 | hr = BVariantGetVersion(&leftOperand, &qwLeft); | 794 | hr = BVariantGetVersion(&leftOperand, &pVersionLeft); |
| 814 | ExitOnFailure(hr, "Failed to get the left version"); | 795 | ExitOnFailure(hr, "Failed to get the left version"); |
| 815 | hr = BVariantGetVersion(&rightOperand, &qwRight); | 796 | hr = BVariantGetVersion(&rightOperand, &pVersionRight); |
| 816 | ExitOnFailure(hr, "Failed to get the right version"); | 797 | ExitOnFailure(hr, "Failed to get the right version"); |
| 817 | hr = CompareVersionValues(comparison, qwLeft, qwRight, pfResult); | 798 | hr = CompareVersionValues(comparison, pVersionLeft, pVersionRight, pfResult); |
| 818 | } | 799 | } |
| 819 | else if (BURN_VARIANT_TYPE_VERSION == leftOperand.Type && BURN_VARIANT_TYPE_STRING == rightOperand.Type) | 800 | else if (BURN_VARIANT_TYPE_VERSION == leftOperand.Type && BURN_VARIANT_TYPE_STRING == rightOperand.Type) |
| 820 | { | 801 | { |
| 821 | hr = BVariantGetVersion(&leftOperand, &qwLeft); | 802 | hr = BVariantGetVersion(&leftOperand, &pVersionLeft); |
| 822 | ExitOnFailure(hr, "Failed to get the left version"); | 803 | ExitOnFailure(hr, "Failed to get the left version"); |
| 823 | hr = BVariantGetVersion(&rightOperand, &qwRight); | 804 | hr = BVariantGetVersion(&rightOperand, &pVersionRight); |
| 824 | if (FAILED(hr)) | 805 | if (FAILED(hr)) |
| 825 | { | 806 | { |
| 826 | if (DISP_E_TYPEMISMATCH != hr) | 807 | if (DISP_E_TYPEMISMATCH != hr) |
| @@ -832,14 +813,14 @@ static HRESULT CompareValues( | |||
| 832 | } | 813 | } |
| 833 | else | 814 | else |
| 834 | { | 815 | { |
| 835 | hr = CompareVersionValues(comparison, qwLeft, qwRight, pfResult); | 816 | hr = CompareVersionValues(comparison, pVersionLeft, pVersionRight, pfResult); |
| 836 | } | 817 | } |
| 837 | } | 818 | } |
| 838 | else if (BURN_VARIANT_TYPE_STRING == leftOperand.Type && BURN_VARIANT_TYPE_VERSION == rightOperand.Type) | 819 | else if (BURN_VARIANT_TYPE_STRING == leftOperand.Type && BURN_VARIANT_TYPE_VERSION == rightOperand.Type) |
| 839 | { | 820 | { |
| 840 | hr = BVariantGetVersion(&rightOperand, &qwRight); | 821 | hr = BVariantGetVersion(&rightOperand, &pVersionRight); |
| 841 | ExitOnFailure(hr, "Failed to get the right version"); | 822 | ExitOnFailure(hr, "Failed to get the right version"); |
| 842 | hr = BVariantGetVersion(&leftOperand, &qwLeft); | 823 | hr = BVariantGetVersion(&leftOperand, &pVersionLeft); |
| 843 | if (FAILED(hr)) | 824 | if (FAILED(hr)) |
| 844 | { | 825 | { |
| 845 | if (DISP_E_TYPEMISMATCH != hr) | 826 | if (DISP_E_TYPEMISMATCH != hr) |
| @@ -851,7 +832,7 @@ static HRESULT CompareValues( | |||
| 851 | } | 832 | } |
| 852 | else | 833 | else |
| 853 | { | 834 | { |
| 854 | hr = CompareVersionValues(comparison, qwLeft, qwRight, pfResult); | 835 | hr = CompareVersionValues(comparison, pVersionLeft, pVersionRight, pfResult); |
| 855 | } | 836 | } |
| 856 | } | 837 | } |
| 857 | else if (BURN_VARIANT_TYPE_NUMERIC == leftOperand.Type && BURN_VARIANT_TYPE_STRING == rightOperand.Type) | 838 | else if (BURN_VARIANT_TYPE_NUMERIC == leftOperand.Type && BURN_VARIANT_TYPE_STRING == rightOperand.Type) |
| @@ -899,10 +880,10 @@ static HRESULT CompareValues( | |||
| 899 | } | 880 | } |
| 900 | 881 | ||
| 901 | LExit: | 882 | LExit: |
| 902 | SecureZeroMemory(&qwLeft, sizeof(DWORD64)); | 883 | ReleaseVerutilVersion(pVersionLeft); |
| 903 | SecureZeroMemory(&llLeft, sizeof(LONGLONG)); | 884 | SecureZeroMemory(&llLeft, sizeof(LONGLONG)); |
| 904 | StrSecureZeroFreeString(sczLeft); | 885 | StrSecureZeroFreeString(sczLeft); |
| 905 | SecureZeroMemory(&qwRight, sizeof(DWORD64)); | 886 | ReleaseVerutilVersion(pVersionRight); |
| 906 | SecureZeroMemory(&llRight, sizeof(LONGLONG)); | 887 | SecureZeroMemory(&llRight, sizeof(LONGLONG)); |
| 907 | StrSecureZeroFreeString(sczRight); | 888 | StrSecureZeroFreeString(sczRight); |
| 908 | 889 | ||
| @@ -1010,24 +991,25 @@ LExit: | |||
| 1010 | // | 991 | // |
| 1011 | static HRESULT CompareVersionValues( | 992 | static HRESULT CompareVersionValues( |
| 1012 | __in BURN_SYMBOL_TYPE comparison, | 993 | __in BURN_SYMBOL_TYPE comparison, |
| 1013 | __in DWORD64 qwLeftOperand, | 994 | __in VERUTIL_VERSION* pLeftOperand, |
| 1014 | __in DWORD64 qwRightOperand, | 995 | __in VERUTIL_VERSION* pRightOperand, |
| 1015 | __out BOOL* pfResult | 996 | __out BOOL* pfResult |
| 1016 | ) | 997 | ) |
| 1017 | { | 998 | { |
| 1018 | HRESULT hr = S_OK; | 999 | HRESULT hr = S_OK; |
| 1000 | int nResult = 0; | ||
| 1001 | |||
| 1002 | hr = VerCompareParsedVersions(pLeftOperand, pRightOperand, &nResult); | ||
| 1003 | ExitOnFailure(hr, "Failed to compare condition versions: '%ls', '%ls'", pLeftOperand->sczVersion, pRightOperand->sczVersion); | ||
| 1019 | 1004 | ||
| 1020 | switch (comparison) | 1005 | switch (comparison) |
| 1021 | { | 1006 | { |
| 1022 | case BURN_SYMBOL_TYPE_LT: *pfResult = qwLeftOperand < qwRightOperand; break; | 1007 | case BURN_SYMBOL_TYPE_LT: *pfResult = nResult < 0; break; |
| 1023 | case BURN_SYMBOL_TYPE_GT: *pfResult = qwLeftOperand > qwRightOperand; break; | 1008 | case BURN_SYMBOL_TYPE_GT: *pfResult = nResult > 0; break; |
| 1024 | case BURN_SYMBOL_TYPE_LE: *pfResult = qwLeftOperand <= qwRightOperand; break; | 1009 | case BURN_SYMBOL_TYPE_LE: *pfResult = nResult <= 0; break; |
| 1025 | case BURN_SYMBOL_TYPE_GE: *pfResult = qwLeftOperand >= qwRightOperand; break; | 1010 | case BURN_SYMBOL_TYPE_GE: *pfResult = nResult >= 0; break; |
| 1026 | case BURN_SYMBOL_TYPE_EQ: *pfResult = qwLeftOperand == qwRightOperand; break; | 1011 | case BURN_SYMBOL_TYPE_EQ: *pfResult = nResult == 0; break; |
| 1027 | case BURN_SYMBOL_TYPE_NE: *pfResult = qwLeftOperand != qwRightOperand; break; | 1012 | case BURN_SYMBOL_TYPE_NE: *pfResult = nResult != 0; break; |
| 1028 | case BURN_SYMBOL_TYPE_BAND: *pfResult = (qwLeftOperand & qwRightOperand) ? TRUE : FALSE; break; | ||
| 1029 | case BURN_SYMBOL_TYPE_HIEQ: *pfResult = ((qwLeftOperand >> 16) & 0xFFFF) == qwRightOperand; break; | ||
| 1030 | case BURN_SYMBOL_TYPE_LOEQ: *pfResult = (qwLeftOperand & 0xFFFF) == qwRightOperand; break; | ||
| 1031 | default: | 1013 | default: |
| 1032 | ExitFunction1(hr = E_INVALIDARG); | 1014 | ExitFunction1(hr = E_INVALIDARG); |
| 1033 | } | 1015 | } |
