1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
|
// 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.
#include "precomp.h"
static HRESULT BEEngineEscapeString(
__in BURN_EXTENSION_ENGINE_CONTEXT* /*pContext*/,
__in BUNDLE_EXTENSION_ENGINE_ESCAPESTRING_ARGS* pArgs,
__in BUNDLE_EXTENSION_ENGINE_ESCAPESTRING_RESULTS* pResults
)
{
HRESULT hr = S_OK;
LPWSTR sczValue = NULL;
size_t cchRemaining = 0;
LPCWSTR wzIn = pArgs->wzIn;
LPWSTR wzOut = pResults->wzOut;
DWORD* pcchOut = &pResults->cchOut;
if (wzIn && *wzIn)
{
hr = VariableEscapeString(wzIn, &sczValue);
if (SUCCEEDED(hr))
{
if (wzOut)
{
hr = ::StringCchCopyExW(wzOut, *pcchOut, sczValue, NULL, &cchRemaining, STRSAFE_FILL_BEHIND_NULL);
if (STRSAFE_E_INSUFFICIENT_BUFFER == hr)
{
hr = E_MOREDATA;
::StringCchLengthW(sczValue, STRSAFE_MAX_CCH, &cchRemaining);
*pcchOut = cchRemaining;
}
}
else
{
::StringCchLengthW(sczValue, STRSAFE_MAX_CCH, &cchRemaining);
*pcchOut = cchRemaining;
}
}
}
else
{
hr = E_INVALIDARG;
}
StrSecureZeroFreeString(sczValue);
return hr;
}
static HRESULT BEEngineEvaluateCondition(
__in BURN_EXTENSION_ENGINE_CONTEXT* pContext,
__in BUNDLE_EXTENSION_ENGINE_EVALUATECONDITION_ARGS* pArgs,
__in BUNDLE_EXTENSION_ENGINE_EVALUATECONDITION_RESULTS* pResults
)
{
HRESULT hr = S_OK;
LPCWSTR wzCondition = pArgs->wzCondition;
BOOL* pf = &pResults->f;
if (wzCondition && *wzCondition)
{
hr = ConditionEvaluate(&pContext->pEngineState->variables, wzCondition, pf);
}
else
{
hr = E_INVALIDARG;
}
return hr;
}
static HRESULT BEEngineFormatString(
__in BURN_EXTENSION_ENGINE_CONTEXT* pContext,
__in BUNDLE_EXTENSION_ENGINE_FORMATSTRING_ARGS* pArgs,
__in BUNDLE_EXTENSION_ENGINE_FORMATSTRING_RESULTS* pResults
)
{
HRESULT hr = S_OK;
LPWSTR sczValue = NULL;
DWORD cchValue = 0;
LPCWSTR wzIn = pArgs->wzIn;
LPWSTR wzOut = pResults->wzOut;
DWORD* pcchOut = &pResults->cchOut;
if (wzIn && *wzIn)
{
hr = VariableFormatString(&pContext->pEngineState->variables, wzIn, &sczValue, &cchValue);
if (SUCCEEDED(hr))
{
if (wzOut)
{
hr = ::StringCchCopyExW(wzOut, *pcchOut, sczValue, NULL, NULL, STRSAFE_FILL_BEHIND_NULL);
if (FAILED(hr))
{
*pcchOut = cchValue;
if (STRSAFE_E_INSUFFICIENT_BUFFER == hr)
{
hr = E_MOREDATA;
}
}
}
else
{
hr = E_MOREDATA;
*pcchOut = cchValue;
}
}
}
else
{
hr = E_INVALIDARG;
}
StrSecureZeroFreeString(sczValue);
return hr;
}
static HRESULT BEEngineGetVariableNumeric(
__in BURN_EXTENSION_ENGINE_CONTEXT* pContext,
__in BUNDLE_EXTENSION_ENGINE_GETVARIABLENUMERIC_ARGS* pArgs,
__in BUNDLE_EXTENSION_ENGINE_GETVARIABLENUMERIC_RESULTS* pResults
)
{
HRESULT hr = S_OK;
LPCWSTR wzVariable = pArgs->wzVariable;
LONGLONG* pllValue = &pResults->llValue;
if (wzVariable && *wzVariable)
{
hr = VariableGetNumeric(&pContext->pEngineState->variables, wzVariable, pllValue);
}
else
{
hr = E_INVALIDARG;
}
return hr;
}
static HRESULT BEEngineGetVariableString(
__in BURN_EXTENSION_ENGINE_CONTEXT* pContext,
__in BUNDLE_EXTENSION_ENGINE_GETVARIABLESTRING_ARGS* pArgs,
__in BUNDLE_EXTENSION_ENGINE_GETVARIABLESTRING_RESULTS* pResults
)
{
HRESULT hr = S_OK;
LPWSTR sczValue = NULL;
size_t cchRemaining = 0;
LPCWSTR wzVariable = pArgs->wzVariable;
LPWSTR wzValue = pResults->wzValue;
DWORD* pcchValue = &pResults->cchValue;
if (wzVariable && *wzVariable)
{
hr = VariableGetString(&pContext->pEngineState->variables, wzVariable, &sczValue);
if (SUCCEEDED(hr))
{
if (wzValue)
{
hr = ::StringCchCopyExW(wzValue, *pcchValue, sczValue, NULL, &cchRemaining, STRSAFE_FILL_BEHIND_NULL);
if (STRSAFE_E_INSUFFICIENT_BUFFER == hr)
{
hr = E_MOREDATA;
::StringCchLengthW(sczValue, STRSAFE_MAX_CCH, &cchRemaining);
*pcchValue = cchRemaining + 1;
}
}
else
{
hr = E_MOREDATA;
::StringCchLengthW(sczValue, STRSAFE_MAX_CCH, &cchRemaining);
*pcchValue = cchRemaining + 1;
}
}
}
else
{
hr = E_INVALIDARG;
}
StrSecureZeroFreeString(sczValue);
return hr;
}
static HRESULT BEEngineGetVariableVersion(
__in BURN_EXTENSION_ENGINE_CONTEXT* pContext,
__in BUNDLE_EXTENSION_ENGINE_GETVARIABLEVERSION_ARGS* pArgs,
__in BUNDLE_EXTENSION_ENGINE_GETVARIABLEVERSION_RESULTS* pResults
)
{
HRESULT hr = S_OK;
LPCWSTR wzVariable = pArgs->wzVariable;
DWORD64* pqwValue = &pResults->qwValue;
if (wzVariable && *wzVariable)
{
hr = VariableGetVersion(&pContext->pEngineState->variables, wzVariable, pqwValue);
}
else
{
hr = E_INVALIDARG;
}
return hr;
}
static HRESULT BEEngineLog(
__in BURN_EXTENSION_ENGINE_CONTEXT* /*pContext*/,
__in BUNDLE_EXTENSION_ENGINE_LOG_ARGS* pArgs,
__in BUNDLE_EXTENSION_ENGINE_LOG_RESULTS* /*pResults*/
)
{
HRESULT hr = S_OK;
REPORT_LEVEL rl = REPORT_NONE;
BUNDLE_EXTENSION_LOG_LEVEL level = pArgs->level;
LPCWSTR wzMessage = pArgs->wzMessage;
switch (level)
{
case BUNDLE_EXTENSION_LOG_LEVEL_STANDARD:
rl = REPORT_STANDARD;
break;
case BUNDLE_EXTENSION_LOG_LEVEL_VERBOSE:
rl = REPORT_VERBOSE;
break;
case BUNDLE_EXTENSION_LOG_LEVEL_DEBUG:
rl = REPORT_DEBUG;
break;
case BUNDLE_EXTENSION_LOG_LEVEL_ERROR:
rl = REPORT_ERROR;
break;
default:
ExitFunction1(hr = E_INVALIDARG);
}
hr = LogStringLine(rl, "%ls", wzMessage);
ExitOnFailure(hr, "Failed to log Bundle Extension message.");
LExit:
return hr;
}
static HRESULT BEEngineSetVariableLiteralString(
__in BURN_EXTENSION_ENGINE_CONTEXT* pContext,
__in const BUNDLE_EXTENSION_ENGINE_SETVARIABLELITERALSTRING_ARGS* pArgs,
__in BUNDLE_EXTENSION_ENGINE_SETVARIABLELITERALSTRING_RESULTS* /*pResults*/
)
{
HRESULT hr = S_OK;
LPCWSTR wzVariable = pArgs->wzVariable;
LPCWSTR wzValue = pArgs->wzValue;
if (wzVariable && *wzVariable)
{
hr = VariableSetLiteralString(&pContext->pEngineState->variables, wzVariable, wzValue, FALSE);
ExitOnFailure(hr, "Failed to set literal string variable.");
}
else
{
hr = E_INVALIDARG;
ExitOnFailure(hr, "Bundle Extension did not provide variable name.");
}
LExit:
return hr;
}
static HRESULT BEEngineSetVariableNumeric(
__in BURN_EXTENSION_ENGINE_CONTEXT* pContext,
__in const BUNDLE_EXTENSION_ENGINE_SETVARIABLENUMERIC_ARGS* pArgs,
__in BUNDLE_EXTENSION_ENGINE_SETVARIABLENUMERIC_RESULTS* /*pResults*/
)
{
HRESULT hr = S_OK;
LPCWSTR wzVariable = pArgs->wzVariable;
LONGLONG llValue = pArgs->llValue;
if (wzVariable && *wzVariable)
{
hr = VariableSetNumeric(&pContext->pEngineState->variables, wzVariable, llValue, FALSE);
ExitOnFailure(hr, "Failed to set numeric variable.");
}
else
{
hr = E_INVALIDARG;
ExitOnFailure(hr, "Bundle Extension did not provide variable name.");
}
LExit:
return hr;
}
static HRESULT BEEngineSetVariableString(
__in BURN_EXTENSION_ENGINE_CONTEXT* pContext,
__in const BUNDLE_EXTENSION_ENGINE_SETVARIABLESTRING_ARGS* pArgs,
__in BUNDLE_EXTENSION_ENGINE_SETVARIABLESTRING_RESULTS* /*pResults*/
)
{
HRESULT hr = S_OK;
LPCWSTR wzVariable = pArgs->wzVariable;
LPCWSTR wzValue = pArgs->wzValue;
if (wzVariable && *wzVariable)
{
hr = VariableSetString(&pContext->pEngineState->variables, wzVariable, wzValue, FALSE);
ExitOnFailure(hr, "Failed to set string variable.");
}
else
{
hr = E_INVALIDARG;
ExitOnFailure(hr, "Bundle Extension did not provide variable name.");
}
LExit:
return hr;
}
static HRESULT BEEngineSetVariableVersion(
__in BURN_EXTENSION_ENGINE_CONTEXT* pContext,
__in const BUNDLE_EXTENSION_ENGINE_SETVARIABLEVERSION_ARGS* pArgs,
__in BUNDLE_EXTENSION_ENGINE_SETVARIABLEVERSION_RESULTS* /*pResults*/
)
{
HRESULT hr = S_OK;
LPCWSTR wzVariable = pArgs->wzVariable;
DWORD64 qwValue = pArgs->qwValue;
if (wzVariable && *wzVariable)
{
hr = VariableSetVersion(&pContext->pEngineState->variables, wzVariable, qwValue, FALSE);
ExitOnFailure(hr, "Failed to set version variable.");
}
else
{
hr = E_INVALIDARG;
ExitOnFailure(hr, "Bundle Extension did not provide variable name.");
}
LExit:
return hr;
}
HRESULT WINAPI EngineForExtensionProc(
__in BUNDLE_EXTENSION_ENGINE_MESSAGE message,
__in const LPVOID pvArgs,
__inout LPVOID pvResults,
__in_opt LPVOID pvContext
)
{
HRESULT hr = S_OK;
BURN_EXTENSION_ENGINE_CONTEXT* pContext = reinterpret_cast<BURN_EXTENSION_ENGINE_CONTEXT*>(pvContext);
if (!pContext || !pvArgs || !pvResults)
{
ExitFunction1(hr = E_INVALIDARG);
}
switch (message)
{
case BUNDLE_EXTENSION_ENGINE_MESSAGE_ESCAPESTRING:
hr = BEEngineEscapeString(pContext, reinterpret_cast<BUNDLE_EXTENSION_ENGINE_ESCAPESTRING_ARGS*>(pvArgs), reinterpret_cast<BUNDLE_EXTENSION_ENGINE_ESCAPESTRING_RESULTS*>(pvResults));
break;
case BUNDLE_EXTENSION_ENGINE_MESSAGE_EVALUATECONDITION:
hr = BEEngineEvaluateCondition(pContext, reinterpret_cast<BUNDLE_EXTENSION_ENGINE_EVALUATECONDITION_ARGS*>(pvArgs), reinterpret_cast<BUNDLE_EXTENSION_ENGINE_EVALUATECONDITION_RESULTS*>(pvResults));
break;
case BUNDLE_EXTENSION_ENGINE_MESSAGE_FORMATSTRING:
hr = BEEngineFormatString(pContext, reinterpret_cast<BUNDLE_EXTENSION_ENGINE_FORMATSTRING_ARGS*>(pvArgs), reinterpret_cast<BUNDLE_EXTENSION_ENGINE_FORMATSTRING_RESULTS*>(pvResults));
break;
case BUNDLE_EXTENSION_ENGINE_MESSAGE_GETVARIABLENUMERIC:
hr = BEEngineGetVariableNumeric(pContext, reinterpret_cast<BUNDLE_EXTENSION_ENGINE_GETVARIABLENUMERIC_ARGS*>(pvArgs), reinterpret_cast<BUNDLE_EXTENSION_ENGINE_GETVARIABLENUMERIC_RESULTS*>(pvResults));
break;
case BUNDLE_EXTENSION_ENGINE_MESSAGE_GETVARIABLESTRING:
hr = BEEngineGetVariableString(pContext, reinterpret_cast<BUNDLE_EXTENSION_ENGINE_GETVARIABLESTRING_ARGS*>(pvArgs), reinterpret_cast<BUNDLE_EXTENSION_ENGINE_GETVARIABLESTRING_RESULTS*>(pvResults));
break;
case BUNDLE_EXTENSION_ENGINE_MESSAGE_GETVARIABLEVERSION:
hr = BEEngineGetVariableVersion(pContext, reinterpret_cast<BUNDLE_EXTENSION_ENGINE_GETVARIABLEVERSION_ARGS*>(pvArgs), reinterpret_cast<BUNDLE_EXTENSION_ENGINE_GETVARIABLEVERSION_RESULTS*>(pvResults));
break;
case BUNDLE_EXTENSION_ENGINE_MESSAGE_LOG:
hr = BEEngineLog(pContext, reinterpret_cast<BUNDLE_EXTENSION_ENGINE_LOG_ARGS*>(pvArgs), reinterpret_cast<BUNDLE_EXTENSION_ENGINE_LOG_RESULTS*>(pvResults));
break;
case BUNDLE_EXTENSION_ENGINE_MESSAGE_SETVARIABLELITERALSTRING:
hr = BEEngineSetVariableLiteralString(pContext, reinterpret_cast<BUNDLE_EXTENSION_ENGINE_SETVARIABLELITERALSTRING_ARGS*>(pvArgs), reinterpret_cast<BUNDLE_EXTENSION_ENGINE_SETVARIABLELITERALSTRING_RESULTS*>(pvResults));
break;
case BUNDLE_EXTENSION_ENGINE_MESSAGE_SETVARIABLENUMERIC:
hr = BEEngineSetVariableNumeric(pContext, reinterpret_cast<BUNDLE_EXTENSION_ENGINE_SETVARIABLENUMERIC_ARGS*>(pvArgs), reinterpret_cast<BUNDLE_EXTENSION_ENGINE_SETVARIABLENUMERIC_RESULTS*>(pvResults));
break;
case BUNDLE_EXTENSION_ENGINE_MESSAGE_SETVARIABLESTRING:
hr = BEEngineSetVariableString(pContext, reinterpret_cast<BUNDLE_EXTENSION_ENGINE_SETVARIABLESTRING_ARGS*>(pvArgs), reinterpret_cast<BUNDLE_EXTENSION_ENGINE_SETVARIABLESTRING_RESULTS*>(pvResults));
break;
case BUNDLE_EXTENSION_ENGINE_MESSAGE_SETVARIABLEVERSION:
hr = BEEngineSetVariableVersion(pContext, reinterpret_cast<BUNDLE_EXTENSION_ENGINE_SETVARIABLEVERSION_ARGS*>(pvArgs), reinterpret_cast<BUNDLE_EXTENSION_ENGINE_SETVARIABLEVERSION_RESULTS*>(pvResults));
break;
default:
hr = E_NOTIMPL;
break;
}
LExit:
return hr;
}
|