diff options
Diffstat (limited to 'src/api/burn/bextutil/BextBundleExtensionEngine.cpp')
| -rw-r--r-- | src/api/burn/bextutil/BextBundleExtensionEngine.cpp | 344 |
1 files changed, 344 insertions, 0 deletions
diff --git a/src/api/burn/bextutil/BextBundleExtensionEngine.cpp b/src/api/burn/bextutil/BextBundleExtensionEngine.cpp new file mode 100644 index 00000000..6043e2db --- /dev/null +++ b/src/api/burn/bextutil/BextBundleExtensionEngine.cpp | |||
| @@ -0,0 +1,344 @@ | |||
| 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
| 2 | |||
| 3 | #include "precomp.h" | ||
| 4 | |||
| 5 | |||
| 6 | class CBextBundleExtensionEngine : public IBundleExtensionEngine | ||
| 7 | { | ||
| 8 | public: // IUnknown | ||
| 9 | virtual STDMETHODIMP QueryInterface( | ||
| 10 | __in REFIID riid, | ||
| 11 | __out LPVOID *ppvObject | ||
| 12 | ) | ||
| 13 | { | ||
| 14 | if (!ppvObject) | ||
| 15 | { | ||
| 16 | return E_INVALIDARG; | ||
| 17 | } | ||
| 18 | |||
| 19 | *ppvObject = NULL; | ||
| 20 | |||
| 21 | if (::IsEqualIID(__uuidof(IBundleExtensionEngine), riid)) | ||
| 22 | { | ||
| 23 | *ppvObject = static_cast<IBundleExtensionEngine*>(this); | ||
| 24 | } | ||
| 25 | else if (::IsEqualIID(IID_IUnknown, riid)) | ||
| 26 | { | ||
| 27 | *ppvObject = reinterpret_cast<IUnknown*>(this); | ||
| 28 | } | ||
| 29 | else // no interface for requested iid | ||
| 30 | { | ||
| 31 | return E_NOINTERFACE; | ||
| 32 | } | ||
| 33 | |||
| 34 | AddRef(); | ||
| 35 | return S_OK; | ||
| 36 | } | ||
| 37 | |||
| 38 | virtual STDMETHODIMP_(ULONG) AddRef() | ||
| 39 | { | ||
| 40 | return ::InterlockedIncrement(&this->m_cReferences); | ||
| 41 | } | ||
| 42 | |||
| 43 | virtual STDMETHODIMP_(ULONG) Release() | ||
| 44 | { | ||
| 45 | long l = ::InterlockedDecrement(&this->m_cReferences); | ||
| 46 | if (0 < l) | ||
| 47 | { | ||
| 48 | return l; | ||
| 49 | } | ||
| 50 | |||
| 51 | delete this; | ||
| 52 | return 0; | ||
| 53 | } | ||
| 54 | |||
| 55 | public: // IBundleExtensionEngine | ||
| 56 | virtual STDMETHODIMP EscapeString( | ||
| 57 | __in_z LPCWSTR wzIn, | ||
| 58 | __out_ecount_opt(*pcchOut) LPWSTR wzOut, | ||
| 59 | __inout SIZE_T* pcchOut | ||
| 60 | ) | ||
| 61 | { | ||
| 62 | HRESULT hr = S_OK; | ||
| 63 | BUNDLE_EXTENSION_ENGINE_ESCAPESTRING_ARGS args = { }; | ||
| 64 | BUNDLE_EXTENSION_ENGINE_ESCAPESTRING_RESULTS results = { }; | ||
| 65 | |||
| 66 | ExitOnNull(pcchOut, hr, E_INVALIDARG, "pcchOut is required"); | ||
| 67 | |||
| 68 | args.cbSize = sizeof(args); | ||
| 69 | args.wzIn = wzIn; | ||
| 70 | |||
| 71 | results.cbSize = sizeof(results); | ||
| 72 | results.wzOut = wzOut; | ||
| 73 | results.cchOut = *pcchOut; | ||
| 74 | |||
| 75 | hr = m_pfnBundleExtensionEngineProc(BUNDLE_EXTENSION_ENGINE_MESSAGE_ESCAPESTRING, &args, &results, m_pvBundleExtensionEngineProcContext); | ||
| 76 | |||
| 77 | *pcchOut = results.cchOut; | ||
| 78 | |||
| 79 | LExit: | ||
| 80 | return hr; | ||
| 81 | } | ||
| 82 | |||
| 83 | virtual STDMETHODIMP EvaluateCondition( | ||
| 84 | __in_z LPCWSTR wzCondition, | ||
| 85 | __out BOOL* pf | ||
| 86 | ) | ||
| 87 | { | ||
| 88 | HRESULT hr = S_OK; | ||
| 89 | BUNDLE_EXTENSION_ENGINE_EVALUATECONDITION_ARGS args = { }; | ||
| 90 | BUNDLE_EXTENSION_ENGINE_EVALUATECONDITION_RESULTS results = { }; | ||
| 91 | |||
| 92 | ExitOnNull(pf, hr, E_INVALIDARG, "pf is required"); | ||
| 93 | |||
| 94 | args.cbSize = sizeof(args); | ||
| 95 | args.wzCondition = wzCondition; | ||
| 96 | |||
| 97 | results.cbSize = sizeof(results); | ||
| 98 | |||
| 99 | hr = m_pfnBundleExtensionEngineProc(BUNDLE_EXTENSION_ENGINE_MESSAGE_EVALUATECONDITION, &args, &results, m_pvBundleExtensionEngineProcContext); | ||
| 100 | |||
| 101 | *pf = results.f; | ||
| 102 | |||
| 103 | LExit: | ||
| 104 | return hr; | ||
| 105 | } | ||
| 106 | |||
| 107 | virtual STDMETHODIMP FormatString( | ||
| 108 | __in_z LPCWSTR wzIn, | ||
| 109 | __out_ecount_opt(*pcchOut) LPWSTR wzOut, | ||
| 110 | __inout SIZE_T* pcchOut | ||
| 111 | ) | ||
| 112 | { | ||
| 113 | HRESULT hr = S_OK; | ||
| 114 | BUNDLE_EXTENSION_ENGINE_FORMATSTRING_ARGS args = { }; | ||
| 115 | BUNDLE_EXTENSION_ENGINE_FORMATSTRING_RESULTS results = { }; | ||
| 116 | |||
| 117 | ExitOnNull(pcchOut, hr, E_INVALIDARG, "pcchOut is required"); | ||
| 118 | |||
| 119 | args.cbSize = sizeof(args); | ||
| 120 | args.wzIn = wzIn; | ||
| 121 | |||
| 122 | results.cbSize = sizeof(results); | ||
| 123 | results.wzOut = wzOut; | ||
| 124 | results.cchOut = *pcchOut; | ||
| 125 | |||
| 126 | hr = m_pfnBundleExtensionEngineProc(BUNDLE_EXTENSION_ENGINE_MESSAGE_FORMATSTRING, &args, &results, m_pvBundleExtensionEngineProcContext); | ||
| 127 | |||
| 128 | *pcchOut = results.cchOut; | ||
| 129 | |||
| 130 | LExit: | ||
| 131 | return hr; | ||
| 132 | } | ||
| 133 | |||
| 134 | virtual STDMETHODIMP GetVariableNumeric( | ||
| 135 | __in_z LPCWSTR wzVariable, | ||
| 136 | __out LONGLONG* pllValue | ||
| 137 | ) | ||
| 138 | { | ||
| 139 | HRESULT hr = S_OK; | ||
| 140 | BUNDLE_EXTENSION_ENGINE_GETVARIABLENUMERIC_ARGS args = { }; | ||
| 141 | BUNDLE_EXTENSION_ENGINE_GETVARIABLENUMERIC_RESULTS results = { }; | ||
| 142 | |||
| 143 | ExitOnNull(pllValue, hr, E_INVALIDARG, "pllValue is required"); | ||
| 144 | |||
| 145 | args.cbSize = sizeof(args); | ||
| 146 | args.wzVariable = wzVariable; | ||
| 147 | |||
| 148 | results.cbSize = sizeof(results); | ||
| 149 | |||
| 150 | hr = m_pfnBundleExtensionEngineProc(BUNDLE_EXTENSION_ENGINE_MESSAGE_GETVARIABLENUMERIC, &args, &results, m_pvBundleExtensionEngineProcContext); | ||
| 151 | |||
| 152 | *pllValue = results.llValue; | ||
| 153 | |||
| 154 | LExit: | ||
| 155 | SecureZeroMemory(&results, sizeof(results)); | ||
| 156 | return hr; | ||
| 157 | } | ||
| 158 | |||
| 159 | virtual STDMETHODIMP GetVariableString( | ||
| 160 | __in_z LPCWSTR wzVariable, | ||
| 161 | __out_ecount_opt(*pcchValue) LPWSTR wzValue, | ||
| 162 | __inout SIZE_T* pcchValue | ||
| 163 | ) | ||
| 164 | { | ||
| 165 | HRESULT hr = S_OK; | ||
| 166 | BUNDLE_EXTENSION_ENGINE_GETVARIABLESTRING_ARGS args = { }; | ||
| 167 | BUNDLE_EXTENSION_ENGINE_GETVARIABLESTRING_RESULTS results = { }; | ||
| 168 | |||
| 169 | ExitOnNull(pcchValue, hr, E_INVALIDARG, "pcchValue is required"); | ||
| 170 | |||
| 171 | args.cbSize = sizeof(args); | ||
| 172 | args.wzVariable = wzVariable; | ||
| 173 | |||
| 174 | results.cbSize = sizeof(results); | ||
| 175 | results.wzValue = wzValue; | ||
| 176 | results.cchValue = *pcchValue; | ||
| 177 | |||
| 178 | hr = m_pfnBundleExtensionEngineProc(BUNDLE_EXTENSION_ENGINE_MESSAGE_GETVARIABLESTRING, &args, &results, m_pvBundleExtensionEngineProcContext); | ||
| 179 | |||
| 180 | *pcchValue = results.cchValue; | ||
| 181 | |||
| 182 | LExit: | ||
| 183 | return hr; | ||
| 184 | } | ||
| 185 | |||
| 186 | virtual STDMETHODIMP GetVariableVersion( | ||
| 187 | __in_z LPCWSTR wzVariable, | ||
| 188 | __out_ecount_opt(*pcchValue) LPWSTR wzValue, | ||
| 189 | __inout SIZE_T* pcchValue | ||
| 190 | ) | ||
| 191 | { | ||
| 192 | HRESULT hr = S_OK; | ||
| 193 | BUNDLE_EXTENSION_ENGINE_GETVARIABLEVERSION_ARGS args = { }; | ||
| 194 | BUNDLE_EXTENSION_ENGINE_GETVARIABLEVERSION_RESULTS results = { }; | ||
| 195 | |||
| 196 | ExitOnNull(pcchValue, hr, E_INVALIDARG, "pcchValue is required"); | ||
| 197 | |||
| 198 | args.cbSize = sizeof(args); | ||
| 199 | args.wzVariable = wzVariable; | ||
| 200 | |||
| 201 | results.cbSize = sizeof(results); | ||
| 202 | results.wzValue = wzValue; | ||
| 203 | results.cchValue = *pcchValue; | ||
| 204 | |||
| 205 | hr = m_pfnBundleExtensionEngineProc(BUNDLE_EXTENSION_ENGINE_MESSAGE_GETVARIABLEVERSION, &args, &results, m_pvBundleExtensionEngineProcContext); | ||
| 206 | |||
| 207 | *pcchValue = results.cchValue; | ||
| 208 | |||
| 209 | LExit: | ||
| 210 | return hr; | ||
| 211 | } | ||
| 212 | |||
| 213 | virtual STDMETHODIMP Log( | ||
| 214 | __in BUNDLE_EXTENSION_LOG_LEVEL level, | ||
| 215 | __in_z LPCWSTR wzMessage | ||
| 216 | ) | ||
| 217 | { | ||
| 218 | BUNDLE_EXTENSION_ENGINE_LOG_ARGS args = { }; | ||
| 219 | BUNDLE_EXTENSION_ENGINE_LOG_RESULTS results = { }; | ||
| 220 | |||
| 221 | args.cbSize = sizeof(args); | ||
| 222 | args.level = level; | ||
| 223 | args.wzMessage = wzMessage; | ||
| 224 | |||
| 225 | results.cbSize = sizeof(results); | ||
| 226 | |||
| 227 | return m_pfnBundleExtensionEngineProc(BUNDLE_EXTENSION_ENGINE_MESSAGE_LOG, &args, &results, m_pvBundleExtensionEngineProcContext); | ||
| 228 | } | ||
| 229 | |||
| 230 | virtual STDMETHODIMP SetVariableNumeric( | ||
| 231 | __in_z LPCWSTR wzVariable, | ||
| 232 | __in LONGLONG llValue | ||
| 233 | ) | ||
| 234 | { | ||
| 235 | BUNDLE_EXTENSION_ENGINE_SETVARIABLENUMERIC_ARGS args = { }; | ||
| 236 | BUNDLE_EXTENSION_ENGINE_SETVARIABLENUMERIC_RESULTS results = { }; | ||
| 237 | |||
| 238 | args.cbSize = sizeof(args); | ||
| 239 | args.wzVariable = wzVariable; | ||
| 240 | args.llValue = llValue; | ||
| 241 | |||
| 242 | results.cbSize = sizeof(results); | ||
| 243 | |||
| 244 | return m_pfnBundleExtensionEngineProc(BUNDLE_EXTENSION_ENGINE_MESSAGE_SETVARIABLENUMERIC, &args, &results, m_pvBundleExtensionEngineProcContext); | ||
| 245 | } | ||
| 246 | |||
| 247 | virtual STDMETHODIMP SetVariableString( | ||
| 248 | __in_z LPCWSTR wzVariable, | ||
| 249 | __in_z_opt LPCWSTR wzValue, | ||
| 250 | __in BOOL fFormatted | ||
| 251 | ) | ||
| 252 | { | ||
| 253 | BUNDLE_EXTENSION_ENGINE_SETVARIABLESTRING_ARGS args = { }; | ||
| 254 | BUNDLE_EXTENSION_ENGINE_SETVARIABLESTRING_RESULTS results = { }; | ||
| 255 | |||
| 256 | args.cbSize = sizeof(args); | ||
| 257 | args.wzVariable = wzVariable; | ||
| 258 | args.wzValue = wzValue; | ||
| 259 | args.fFormatted = fFormatted; | ||
| 260 | |||
| 261 | results.cbSize = sizeof(results); | ||
| 262 | |||
| 263 | return m_pfnBundleExtensionEngineProc(BUNDLE_EXTENSION_ENGINE_MESSAGE_SETVARIABLESTRING, &args, &results, m_pvBundleExtensionEngineProcContext); | ||
| 264 | } | ||
| 265 | |||
| 266 | virtual STDMETHODIMP SetVariableVersion( | ||
| 267 | __in_z LPCWSTR wzVariable, | ||
| 268 | __in_z_opt LPCWSTR wzValue | ||
| 269 | ) | ||
| 270 | { | ||
| 271 | BUNDLE_EXTENSION_ENGINE_SETVARIABLEVERSION_ARGS args = { }; | ||
| 272 | BUNDLE_EXTENSION_ENGINE_SETVARIABLEVERSION_RESULTS results = { }; | ||
| 273 | |||
| 274 | args.cbSize = sizeof(args); | ||
| 275 | args.wzVariable = wzVariable; | ||
| 276 | args.wzValue = wzValue; | ||
| 277 | |||
| 278 | results.cbSize = sizeof(results); | ||
| 279 | |||
| 280 | return m_pfnBundleExtensionEngineProc(BUNDLE_EXTENSION_ENGINE_MESSAGE_SETVARIABLEVERSION, &args, &results, m_pvBundleExtensionEngineProcContext); | ||
| 281 | } | ||
| 282 | |||
| 283 | virtual STDMETHODIMP CompareVersions( | ||
| 284 | __in_z LPCWSTR wzVersion1, | ||
| 285 | __in_z LPCWSTR wzVersion2, | ||
| 286 | __out int* pnResult | ||
| 287 | ) | ||
| 288 | { | ||
| 289 | HRESULT hr = S_OK; | ||
| 290 | BUNDLE_EXTENSION_ENGINE_COMPAREVERSIONS_ARGS args = { }; | ||
| 291 | BUNDLE_EXTENSION_ENGINE_COMPAREVERSIONS_RESULTS results = { }; | ||
| 292 | |||
| 293 | ExitOnNull(pnResult, hr, E_INVALIDARG, "pnResult is required"); | ||
| 294 | |||
| 295 | args.cbSize = sizeof(args); | ||
| 296 | args.wzVersion1 = wzVersion1; | ||
| 297 | args.wzVersion2 = wzVersion2; | ||
| 298 | |||
| 299 | results.cbSize = sizeof(results); | ||
| 300 | |||
| 301 | hr = m_pfnBundleExtensionEngineProc(BUNDLE_EXTENSION_ENGINE_MESSAGE_COMPAREVERSIONS, &args, &results, m_pvBundleExtensionEngineProcContext); | ||
| 302 | |||
| 303 | *pnResult = results.nResult; | ||
| 304 | |||
| 305 | LExit: | ||
| 306 | return hr; | ||
| 307 | } | ||
| 308 | |||
| 309 | public: | ||
| 310 | CBextBundleExtensionEngine( | ||
| 311 | __in PFN_BUNDLE_EXTENSION_ENGINE_PROC pfnBundleExtensionEngineProc, | ||
| 312 | __in_opt LPVOID pvBundleExtensionEngineProcContext | ||
| 313 | ) | ||
| 314 | { | ||
| 315 | m_cReferences = 1; | ||
| 316 | m_pfnBundleExtensionEngineProc = pfnBundleExtensionEngineProc; | ||
| 317 | m_pvBundleExtensionEngineProcContext = pvBundleExtensionEngineProcContext; | ||
| 318 | } | ||
| 319 | |||
| 320 | private: | ||
| 321 | long m_cReferences; | ||
| 322 | PFN_BUNDLE_EXTENSION_ENGINE_PROC m_pfnBundleExtensionEngineProc; | ||
| 323 | LPVOID m_pvBundleExtensionEngineProcContext; | ||
| 324 | }; | ||
| 325 | |||
| 326 | HRESULT BextBundleExtensionEngineCreate( | ||
| 327 | __in PFN_BUNDLE_EXTENSION_ENGINE_PROC pfnBundleExtensionEngineProc, | ||
| 328 | __in_opt LPVOID pvBundleExtensionEngineProcContext, | ||
| 329 | __out IBundleExtensionEngine** ppEngineForExtension | ||
| 330 | ) | ||
| 331 | { | ||
| 332 | HRESULT hr = S_OK; | ||
| 333 | CBextBundleExtensionEngine* pBundleExtensionEngine = NULL; | ||
| 334 | |||
| 335 | pBundleExtensionEngine = new CBextBundleExtensionEngine(pfnBundleExtensionEngineProc, pvBundleExtensionEngineProcContext); | ||
| 336 | ExitOnNull(pBundleExtensionEngine, hr, E_OUTOFMEMORY, "Failed to allocate new BextBundleExtensionEngine object."); | ||
| 337 | |||
| 338 | hr = pBundleExtensionEngine->QueryInterface(IID_PPV_ARGS(ppEngineForExtension)); | ||
| 339 | ExitOnFailure(hr, "Failed to QI for IBundleExtensionEngine from BextBundleExtensionEngine object."); | ||
| 340 | |||
| 341 | LExit: | ||
| 342 | ReleaseObject(pBundleExtensionEngine); | ||
| 343 | return hr; | ||
| 344 | } | ||
