diff options
Diffstat (limited to 'src/engine/EngineForApplication.cpp')
| -rw-r--r-- | src/engine/EngineForApplication.cpp | 118 |
1 files changed, 60 insertions, 58 deletions
diff --git a/src/engine/EngineForApplication.cpp b/src/engine/EngineForApplication.cpp index 81eec2fc..d034c2bf 100644 --- a/src/engine/EngineForApplication.cpp +++ b/src/engine/EngineForApplication.cpp | |||
| @@ -2,6 +2,13 @@ | |||
| 2 | 2 | ||
| 3 | #include "precomp.h" | 3 | #include "precomp.h" |
| 4 | 4 | ||
| 5 | |||
| 6 | static HRESULT CopyStringToBA( | ||
| 7 | __in LPWSTR wzValue, | ||
| 8 | __in LPWSTR wzBuffer, | ||
| 9 | __inout DWORD* pcchBuffer | ||
| 10 | ); | ||
| 11 | |||
| 5 | static HRESULT BAEngineGetPackageCount( | 12 | static HRESULT BAEngineGetPackageCount( |
| 6 | __in BOOTSTRAPPER_ENGINE_CONTEXT* pContext, | 13 | __in BOOTSTRAPPER_ENGINE_CONTEXT* pContext, |
| 7 | __in BAENGINE_GETPACKAGECOUNT_ARGS* /*pArgs*/, | 14 | __in BAENGINE_GETPACKAGECOUNT_ARGS* /*pArgs*/, |
| @@ -46,7 +53,6 @@ static HRESULT BAEngineGetVariableString( | |||
| 46 | { | 53 | { |
| 47 | HRESULT hr = S_OK; | 54 | HRESULT hr = S_OK; |
| 48 | LPWSTR sczValue = NULL; | 55 | LPWSTR sczValue = NULL; |
| 49 | size_t cchRemaining = 0; | ||
| 50 | LPCWSTR wzVariable = pArgs->wzVariable; | 56 | LPCWSTR wzVariable = pArgs->wzVariable; |
| 51 | LPWSTR wzValue = pResults->wzValue; | 57 | LPWSTR wzValue = pResults->wzValue; |
| 52 | DWORD* pcchValue = &pResults->cchValue; | 58 | DWORD* pcchValue = &pResults->cchValue; |
| @@ -56,24 +62,7 @@ static HRESULT BAEngineGetVariableString( | |||
| 56 | hr = VariableGetString(&pContext->pEngineState->variables, wzVariable, &sczValue); | 62 | hr = VariableGetString(&pContext->pEngineState->variables, wzVariable, &sczValue); |
| 57 | if (SUCCEEDED(hr)) | 63 | if (SUCCEEDED(hr)) |
| 58 | { | 64 | { |
| 59 | if (wzValue) | 65 | hr = CopyStringToBA(sczValue, wzValue, pcchValue); |
| 60 | { | ||
| 61 | hr = ::StringCchCopyExW(wzValue, *pcchValue, sczValue, NULL, &cchRemaining, STRSAFE_FILL_BEHIND_NULL); | ||
| 62 | if (STRSAFE_E_INSUFFICIENT_BUFFER == hr) | ||
| 63 | { | ||
| 64 | hr = E_MOREDATA; | ||
| 65 | |||
| 66 | ::StringCchLengthW(sczValue, STRSAFE_MAX_CCH, &cchRemaining); | ||
| 67 | *pcchValue = cchRemaining + 1; | ||
| 68 | } | ||
| 69 | } | ||
| 70 | else | ||
| 71 | { | ||
| 72 | hr = E_MOREDATA; | ||
| 73 | |||
| 74 | ::StringCchLengthW(sczValue, STRSAFE_MAX_CCH, &cchRemaining); | ||
| 75 | *pcchValue = cchRemaining + 1; | ||
| 76 | } | ||
| 77 | } | 66 | } |
| 78 | } | 67 | } |
| 79 | else | 68 | else |
| @@ -92,18 +81,26 @@ static HRESULT BAEngineGetVariableVersion( | |||
| 92 | ) | 81 | ) |
| 93 | { | 82 | { |
| 94 | HRESULT hr = S_OK; | 83 | HRESULT hr = S_OK; |
| 84 | VERUTIL_VERSION* pVersion = NULL; | ||
| 95 | LPCWSTR wzVariable = pArgs->wzVariable; | 85 | LPCWSTR wzVariable = pArgs->wzVariable; |
| 96 | DWORD64* pqwValue = &pResults->qwValue; | 86 | LPWSTR wzValue = pResults->wzValue; |
| 87 | DWORD* pcchValue = &pResults->cchValue; | ||
| 97 | 88 | ||
| 98 | if (wzVariable && *wzVariable) | 89 | if (wzVariable && *wzVariable) |
| 99 | { | 90 | { |
| 100 | hr = VariableGetVersion(&pContext->pEngineState->variables, wzVariable, pqwValue); | 91 | hr = VariableGetVersion(&pContext->pEngineState->variables, wzVariable, &pVersion); |
| 92 | if (SUCCEEDED(hr)) | ||
| 93 | { | ||
| 94 | hr = CopyStringToBA(pVersion->sczVersion, wzValue, pcchValue); | ||
| 95 | } | ||
| 101 | } | 96 | } |
| 102 | else | 97 | else |
| 103 | { | 98 | { |
| 104 | hr = E_INVALIDARG; | 99 | hr = E_INVALIDARG; |
| 105 | } | 100 | } |
| 106 | 101 | ||
| 102 | ReleaseVerutilVersion(pVersion); | ||
| 103 | |||
| 107 | return hr; | 104 | return hr; |
| 108 | } | 105 | } |
| 109 | 106 | ||
| @@ -115,33 +112,16 @@ static HRESULT BAEngineFormatString( | |||
| 115 | { | 112 | { |
| 116 | HRESULT hr = S_OK; | 113 | HRESULT hr = S_OK; |
| 117 | LPWSTR sczValue = NULL; | 114 | LPWSTR sczValue = NULL; |
| 118 | DWORD cchValue = 0; | ||
| 119 | LPCWSTR wzIn = pArgs->wzIn; | 115 | LPCWSTR wzIn = pArgs->wzIn; |
| 120 | LPWSTR wzOut = pResults->wzOut; | 116 | LPWSTR wzOut = pResults->wzOut; |
| 121 | DWORD* pcchOut = &pResults->cchOut; | 117 | DWORD* pcchOut = &pResults->cchOut; |
| 122 | 118 | ||
| 123 | if (wzIn && *wzIn) | 119 | if (wzIn && *wzIn) |
| 124 | { | 120 | { |
| 125 | hr = VariableFormatString(&pContext->pEngineState->variables, wzIn, &sczValue, &cchValue); | 121 | hr = VariableFormatString(&pContext->pEngineState->variables, wzIn, &sczValue, NULL); |
| 126 | if (SUCCEEDED(hr)) | 122 | if (SUCCEEDED(hr)) |
| 127 | { | 123 | { |
| 128 | if (wzOut) | 124 | hr = CopyStringToBA(sczValue, wzOut, pcchOut); |
| 129 | { | ||
| 130 | hr = ::StringCchCopyExW(wzOut, *pcchOut, sczValue, NULL, NULL, STRSAFE_FILL_BEHIND_NULL); | ||
| 131 | if (FAILED(hr)) | ||
| 132 | { | ||
| 133 | *pcchOut = cchValue; | ||
| 134 | if (STRSAFE_E_INSUFFICIENT_BUFFER == hr) | ||
| 135 | { | ||
| 136 | hr = E_MOREDATA; | ||
| 137 | } | ||
| 138 | } | ||
| 139 | } | ||
| 140 | else | ||
| 141 | { | ||
| 142 | hr = E_MOREDATA; | ||
| 143 | *pcchOut = cchValue; | ||
| 144 | } | ||
| 145 | } | 125 | } |
| 146 | } | 126 | } |
| 147 | else | 127 | else |
| @@ -161,7 +141,6 @@ static HRESULT BAEngineEscapeString( | |||
| 161 | { | 141 | { |
| 162 | HRESULT hr = S_OK; | 142 | HRESULT hr = S_OK; |
| 163 | LPWSTR sczValue = NULL; | 143 | LPWSTR sczValue = NULL; |
| 164 | size_t cchRemaining = 0; | ||
| 165 | LPCWSTR wzIn = pArgs->wzIn; | 144 | LPCWSTR wzIn = pArgs->wzIn; |
| 166 | LPWSTR wzOut = pResults->wzOut; | 145 | LPWSTR wzOut = pResults->wzOut; |
| 167 | DWORD* pcchOut = &pResults->cchOut; | 146 | DWORD* pcchOut = &pResults->cchOut; |
| @@ -171,21 +150,7 @@ static HRESULT BAEngineEscapeString( | |||
| 171 | hr = VariableEscapeString(wzIn, &sczValue); | 150 | hr = VariableEscapeString(wzIn, &sczValue); |
| 172 | if (SUCCEEDED(hr)) | 151 | if (SUCCEEDED(hr)) |
| 173 | { | 152 | { |
| 174 | if (wzOut) | 153 | hr = CopyStringToBA(sczValue, wzOut, pcchOut); |
| 175 | { | ||
| 176 | hr = ::StringCchCopyExW(wzOut, *pcchOut, sczValue, NULL, &cchRemaining, STRSAFE_FILL_BEHIND_NULL); | ||
| 177 | if (STRSAFE_E_INSUFFICIENT_BUFFER == hr) | ||
| 178 | { | ||
| 179 | hr = E_MOREDATA; | ||
| 180 | ::StringCchLengthW(sczValue, STRSAFE_MAX_CCH, &cchRemaining); | ||
| 181 | *pcchOut = cchRemaining; | ||
| 182 | } | ||
| 183 | } | ||
| 184 | else | ||
| 185 | { | ||
| 186 | ::StringCchLengthW(sczValue, STRSAFE_MAX_CCH, &cchRemaining); | ||
| 187 | *pcchOut = cchRemaining; | ||
| 188 | } | ||
| 189 | } | 154 | } |
| 190 | } | 155 | } |
| 191 | else | 156 | else |
| @@ -613,11 +578,15 @@ static HRESULT BAEngineSetVariableVersion( | |||
| 613 | { | 578 | { |
| 614 | HRESULT hr = S_OK; | 579 | HRESULT hr = S_OK; |
| 615 | LPCWSTR wzVariable = pArgs->wzVariable; | 580 | LPCWSTR wzVariable = pArgs->wzVariable; |
| 616 | DWORD64 qwValue = pArgs->qwValue; | 581 | LPCWSTR wzValue = pArgs->wzValue; |
| 582 | VERUTIL_VERSION* pVersion = NULL; | ||
| 617 | 583 | ||
| 618 | if (wzVariable && *wzVariable) | 584 | if (wzVariable && *wzVariable) |
| 619 | { | 585 | { |
| 620 | hr = VariableSetVersion(&pContext->pEngineState->variables, wzVariable, qwValue, FALSE); | 586 | hr = VerParseVersion(wzValue, 0, FALSE, &pVersion); |
| 587 | ExitOnFailure(hr, "Failed to parse new version value."); | ||
| 588 | |||
| 589 | hr = VariableSetVersion(&pContext->pEngineState->variables, wzVariable, pVersion, FALSE); | ||
| 621 | ExitOnFailure(hr, "Failed to set version variable."); | 590 | ExitOnFailure(hr, "Failed to set version variable."); |
| 622 | } | 591 | } |
| 623 | else | 592 | else |
| @@ -627,6 +596,8 @@ static HRESULT BAEngineSetVariableVersion( | |||
| 627 | } | 596 | } |
| 628 | 597 | ||
| 629 | LExit: | 598 | LExit: |
| 599 | ReleaseVerutilVersion(pVersion); | ||
| 600 | |||
| 630 | return hr; | 601 | return hr; |
| 631 | } | 602 | } |
| 632 | 603 | ||
| @@ -898,3 +869,34 @@ HRESULT WINAPI EngineForApplicationProc( | |||
| 898 | LExit: | 869 | LExit: |
| 899 | return hr; | 870 | return hr; |
| 900 | } | 871 | } |
| 872 | |||
| 873 | static HRESULT CopyStringToBA( | ||
| 874 | __in LPWSTR wzValue, | ||
| 875 | __in LPWSTR wzBuffer, | ||
| 876 | __inout DWORD* pcchBuffer | ||
| 877 | ) | ||
| 878 | { | ||
| 879 | HRESULT hr = S_OK; | ||
| 880 | BOOL fTooSmall = !wzBuffer; | ||
| 881 | |||
| 882 | if (!fTooSmall) | ||
| 883 | { | ||
| 884 | hr = ::StringCchCopyExW(wzBuffer, *pcchBuffer, wzValue, NULL, NULL, STRSAFE_FILL_BEHIND_NULL); | ||
| 885 | if (STRSAFE_E_INSUFFICIENT_BUFFER == hr) | ||
| 886 | { | ||
| 887 | fTooSmall = TRUE; | ||
| 888 | } | ||
| 889 | } | ||
| 890 | |||
| 891 | if (fTooSmall) | ||
| 892 | { | ||
| 893 | hr = ::StringCchLengthW(wzValue, STRSAFE_MAX_CCH, reinterpret_cast<size_t*>(pcchBuffer)); | ||
| 894 | if (SUCCEEDED(hr)) | ||
| 895 | { | ||
| 896 | hr = E_MOREDATA; | ||
| 897 | *pcchBuffer += 1; // null terminator. | ||
| 898 | } | ||
| 899 | } | ||
| 900 | |||
| 901 | return hr; | ||
| 902 | } | ||
