aboutsummaryrefslogtreecommitdiff
path: root/src/burn/engine/core.h
blob: c5d0a3704727bd5ec5c6194ba4cc8398a42d9bf7 (plain)
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
#pragma once
// 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.


#if defined(__cplusplus)
extern "C" {
#endif


// constants

const LPCWSTR BURN_POLICY_REGISTRY_PATH = L"WiX\\Burn";

const LPCWSTR BURN_COMMANDLINE_SWITCH_PARENT = L"parent";
const LPCWSTR BURN_COMMANDLINE_SWITCH_PARENT_NONE = L"parent:none";
const LPCWSTR BURN_COMMANDLINE_SWITCH_WORKING_DIRECTORY = L"burn.engine.working.directory";
const LPCWSTR BURN_COMMANDLINE_SWITCH_ELEVATED = L"burn.elevated";
const LPCWSTR BURN_COMMANDLINE_SWITCH_EMBEDDED = L"burn.embedded";
const LPCWSTR BURN_COMMANDLINE_SWITCH_RUNONCE = L"burn.runonce";
const LPCWSTR BURN_COMMANDLINE_SWITCH_LOG_APPEND = L"burn.log.append";
const LPCWSTR BURN_COMMANDLINE_SWITCH_LOG_MODE = L"burn.log.mode";
const LPCWSTR BURN_COMMANDLINE_SWITCH_RELATED_DETECT = L"burn.related.detect";
const LPCWSTR BURN_COMMANDLINE_SWITCH_RELATED_UPGRADE = L"burn.related.upgrade";
const LPCWSTR BURN_COMMANDLINE_SWITCH_RELATED_ADDON = L"burn.related.addon";
const LPCWSTR BURN_COMMANDLINE_SWITCH_RELATED_DEPENDENT_ADDON = L"burn.related.dependent.addon";
const LPCWSTR BURN_COMMANDLINE_SWITCH_RELATED_PATCH = L"burn.related.patch";
const LPCWSTR BURN_COMMANDLINE_SWITCH_RELATED_DEPENDENT_PATCH = L"burn.related.dependent.patch";
const LPCWSTR BURN_COMMANDLINE_SWITCH_RELATED_UPDATE = L"burn.related.update";
const LPCWSTR BURN_COMMANDLINE_SWITCH_RELATED_CHAIN_PACKAGE = L"burn.related.chain.package";
const LPCWSTR BURN_COMMANDLINE_SWITCH_PASSTHROUGH = L"burn.passthrough";
const LPCWSTR BURN_COMMANDLINE_SWITCH_DISABLE_UNELEVATE = L"burn.disable.unelevate";
const LPCWSTR BURN_COMMANDLINE_SWITCH_IGNOREDEPENDENCIES = L"burn.ignoredependencies";
const LPCWSTR BURN_COMMANDLINE_SWITCH_ANCESTORS = L"burn.ancestors";
const LPCWSTR BURN_COMMANDLINE_SWITCH_FILEHANDLE_ATTACHED = L"burn.filehandle.attached";
const LPCWSTR BURN_COMMANDLINE_SWITCH_FILEHANDLE_SELF = L"burn.filehandle.self";
const LPCWSTR BURN_COMMANDLINE_SWITCH_SPLASH_SCREEN = L"burn.splash.screen";
const LPCWSTR BURN_COMMANDLINE_SWITCH_SYSTEM_COMPONENT = L"burn.system.component";
const LPCWSTR BURN_COMMANDLINE_SWITCH_PREFIX = L"burn.";

const LPCWSTR BURN_BUNDLE_ACTION = L"WixBundleAction";
const LPCWSTR BURN_BUNDLE_ACTIVE_PARENT = L"WixBundleActiveParent";
const LPCWSTR BURN_BUNDLE_COMMAND_LINE_ACTION = L"WixBundleCommandLineAction";
const LPCWSTR BURN_BUNDLE_EXECUTE_PACKAGE_CACHE_FOLDER = L"WixBundleExecutePackageCacheFolder";
const LPCWSTR BURN_BUNDLE_EXECUTE_PACKAGE_ACTION = L"WixBundleExecutePackageAction";
const LPCWSTR BURN_BUNDLE_FORCED_RESTART_PACKAGE = L"WixBundleForcedRestartPackage";
const LPCWSTR BURN_BUNDLE_INSTALLED = L"WixBundleInstalled";
const LPCWSTR BURN_BUNDLE_ELEVATED = L"WixBundleElevated";
const LPCWSTR BURN_BUNDLE_PROVIDER_KEY = L"WixBundleProviderKey";
const LPCWSTR BURN_BUNDLE_TAG = L"WixBundleTag";
const LPCWSTR BURN_BUNDLE_UILEVEL = L"WixBundleUILevel";
const LPCWSTR BURN_BUNDLE_VERSION = L"WixBundleVersion";

// The following well-known variables are settable by the BA.
const LPCWSTR BURN_BUNDLE_LAYOUT_DIRECTORY = L"WixBundleLayoutDirectory";
const LPCWSTR BURN_BUNDLE_NAME = L"WixBundleName";
const LPCWSTR BURN_BUNDLE_INPROGRESS_NAME = L"WixBundleInProgressName";
const LPCWSTR BURN_BUNDLE_MANUFACTURER = L"WixBundleManufacturer";
const LPCWSTR BURN_BUNDLE_ORIGINAL_SOURCE = L"WixBundleOriginalSource";
const LPCWSTR BURN_BUNDLE_ORIGINAL_SOURCE_FOLDER = L"WixBundleOriginalSourceFolder";
const LPCWSTR BURN_BUNDLE_LAST_USED_SOURCE = L"WixBundleLastUsedSource";


// enums

enum BURN_MODE
{
    BURN_MODE_UNKNOWN,
    BURN_MODE_NORMAL,
    BURN_MODE_ELEVATED,
    BURN_MODE_EMBEDDED,
    BURN_MODE_RUNONCE,
};

enum BURN_AU_PAUSE_ACTION
{
    BURN_AU_PAUSE_ACTION_NONE,
    BURN_AU_PAUSE_ACTION_IFELEVATED,
    BURN_AU_PAUSE_ACTION_IFELEVATED_NORESUME,
};

enum BURN_RESTART_STATE
{
    BURN_RESTART_STATE_NONE,
    BURN_RESTART_STATE_REQUESTING,
    BURN_RESTART_STATE_REQUESTED,
    BURN_RESTART_STATE_INITIATING,
    BURN_RESTART_STATE_INITIATED,
    BURN_RESTART_STATE_BLOCKED,
};


// structs

typedef struct _BURN_ENGINE_COMMAND
{
    int argc;
    LPWSTR* argv;
    DWORD cSecretArgs;
    int* rgSecretArgs;
    DWORD cUnknownArgs;
    int* rgUnknownArgs;
    BOOL fInvalidCommandLine;

    BURN_MODE mode;
    BURN_AU_PAUSE_ACTION automaticUpdates;
    BOOL fArpSystemComponent;
    BOOL fDisableSystemRestore;
    BOOL fInitiallyElevated;

    LPWSTR sczActiveParent;
    LPWSTR sczAncestors;
    LPWSTR sczIgnoreDependencies;

    LPWSTR sczOriginalSource;
    LPWSTR sczEngineWorkingDirectory;

    DWORD dwLoggingAttributes;
    LPWSTR sczLogFile;
} BURN_ENGINE_COMMAND;

typedef struct _BURN_REDIRECTED_LOGGING_CONTEXT
{
    CRITICAL_SECTION csBuffer;
    LPSTR sczBuffer;
    HANDLE hPipe;
    HANDLE hLogEvent;
    HANDLE hFinishedEvent;
    HANDLE hThread;
} BURN_REDIRECTED_LOGGING_CONTEXT;

typedef struct _BURN_ENGINE_STATE
{
    // UX flow control
    BOOL fDetected;
    BOOL fPlanned;
    BOOL fQuit;
    //BOOL fSuspend;             // Is TRUE when UX made Suspend() call on core.
    //BOOL fForcedReboot;        // Is TRUE when UX made Reboot() call on core.
    //BOOL fCancelled;           // Is TRUE when UX return cancel on UX OnXXX() methods.
    //BOOL fReboot;              // Is TRUE when UX confirms OnRestartRequried().
    BOOL fRestart;               // Set TRUE when UX returns IDRESTART during Apply().

    // engine data
    BOOTSTRAPPER_COMMAND command;
    BURN_SECTION section;
    BURN_VARIABLES variables;
    BURN_CONDITION condition;
    BURN_SEARCHES searches;
    BURN_USER_EXPERIENCE userExperience;
    BURN_REGISTRATION registration;
    BURN_CONTAINERS containers;
    BURN_PAYLOADS payloads;
    BURN_PACKAGES packages;
    BURN_UPDATE update;
    BURN_APPROVED_EXES approvedExes;
    BURN_CACHE cache;
    BURN_DEPENDENCIES dependencies;
    BURN_EXTENSIONS extensions;

    HWND hMessageWindow;
    HANDLE hMessageWindowThread;

    BOOL fDisableRollback;
    BOOL fParallelCacheAndExecute;

    BURN_LOGGING log;

    BURN_PAYLOAD_GROUP layoutPayloads;

    BURN_PLAN plan;

    BURN_REDIRECTED_LOGGING_CONTEXT elevatedLoggingContext;
    HANDLE hUnelevatedLoggingThread;

    BURN_PIPE_CONNECTION companionConnection;
    BURN_PIPE_CONNECTION embeddedConnection;

    CRITICAL_SECTION csRestartState;
    BOOL fRestarting;
    BURN_RESTART_STATE restartState;

    BOOL fCriticalShutdownInitiated;
    BURN_RESUME_MODE resumeMode;
    LPCWSTR wzRestartInitiatedPackageId;

    BURN_ENGINE_COMMAND internalCommand;
} BURN_ENGINE_STATE;

typedef struct _BURN_APPLY_CONTEXT
{
    CRITICAL_SECTION csApply;
    DWORD cOverallProgressTicks;
    HANDLE hCacheThread;
    DWORD dwCacheCheckpoint;
} BURN_APPLY_CONTEXT;

typedef BOOL (STDAPICALLTYPE *PFN_CREATEPROCESSW)(
    __in_opt LPCWSTR lpApplicationName,
    __inout_opt LPWSTR lpCommandLine,
    __in_opt LPSECURITY_ATTRIBUTES lpProcessAttributes,
    __in_opt LPSECURITY_ATTRIBUTES lpThreadAttributes,
    __in BOOL bInheritHandles,
    __in DWORD dwCreationFlags,
    __in_opt LPVOID lpEnvironment,
    __in_opt LPCWSTR lpCurrentDirectory,
    __in LPSTARTUPINFOW lpStartupInfo,
    __out LPPROCESS_INFORMATION lpProcessInformation
    );

typedef HRESULT (DAPI *PFN_PROCWAITFORCOMPLETION)(
    __in HANDLE hProcess,
    __in DWORD dwTimeout,
    __out DWORD* pReturnCode
    );


// function declarations

HRESULT CoreInitialize(
    __in BURN_ENGINE_STATE* pEngineState
    );
HRESULT CoreInitializeConstants(
    __in BURN_ENGINE_STATE* pEngineState
    );
HRESULT CoreSerializeEngineState(
    __in BURN_ENGINE_STATE* pEngineState,
    __inout BYTE** ppbBuffer,
    __inout SIZE_T* piBuffer
    );
HRESULT CoreQueryRegistration(
    __in BURN_ENGINE_STATE* pEngineState
    );
//HRESULT CoreDeserializeEngineState(
//    __in BURN_ENGINE_STATE* pEngineState,
//    __in_bcount(cbBuffer) BYTE* pbBuffer,
//    __in SIZE_T cbBuffer
//    );
HRESULT CoreDetect(
    __in BURN_ENGINE_STATE* pEngineState,
    __in_opt HWND hwndParent
    );
HRESULT CorePlan(
    __in BURN_ENGINE_STATE* pEngineState,
    __in BOOTSTRAPPER_ACTION action
    );
HRESULT CoreElevate(
    __in BURN_ENGINE_STATE* pEngineState,
    __in WM_BURN reason,
    __in_opt HWND hwndParent
    );
HRESULT CoreApply(
    __in BURN_ENGINE_STATE* pEngineState,
    __in_opt HWND hwndParent
    );
HRESULT CoreLaunchApprovedExe(
    __in BURN_ENGINE_STATE* pEngineState,
    __in BURN_LAUNCH_APPROVED_EXE* pLaunchApprovedExe
    );
void CoreQuit(
    __in BAENGINE_CONTEXT* pEngineContext,
    __in DWORD dwExitCode
    );
HRESULT CoreSaveEngineState(
    __in BURN_ENGINE_STATE* pEngineState
    );
LPCWSTR CoreRelationTypeToCommandLineString(
    __in BOOTSTRAPPER_RELATION_TYPE relationType
    );
HRESULT CoreCreatePassthroughBundleCommandLine(
    __deref_inout_z LPWSTR* psczCommandLine,
    __in BURN_ENGINE_COMMAND* pInternalCommand,
    __in BOOTSTRAPPER_COMMAND* pCommand
    );
HRESULT CoreCreateResumeCommandLine(
    __deref_inout_z LPWSTR* psczCommandLine,
    __in BURN_PLAN* pPlan,
    __in BURN_LOGGING* pLog
    );
HRESULT CoreCreateUpdateBundleCommandLine(
    __deref_inout_z LPWSTR* psczCommandLine,
    __in BURN_ENGINE_COMMAND* pInternalCommand,
    __in BOOTSTRAPPER_COMMAND* pCommand
    );
HRESULT CoreAppendFileHandleAttachedToCommandLine(
    __in HANDLE hFileWithAttachedContainer,
    __out HANDLE* phExecutableFile,
    __deref_inout_z LPWSTR* psczCommandLine
    );
HRESULT CoreAppendFileHandleSelfToCommandLine(
    __in LPCWSTR wzExecutablePath,
    __out HANDLE* phExecutableFile,
    __deref_inout_z LPWSTR* psczCommandLine,
    __deref_inout_z_opt LPWSTR* psczObfuscatedCommandLine
    );
HRESULT CoreAppendLogToCommandLine(
    __deref_inout_z LPWSTR* psczCommandLine,
    __deref_inout_z_opt LPWSTR* psczObfuscatedCommandLine,
    __in BOOL fRollback,
    __in BURN_VARIABLES* pVariables,
    __in BURN_PACKAGE *pPackage
    );
HRESULT CoreAppendSplashScreenWindowToCommandLine(
    __in_opt HWND hwndSplashScreen,
    __deref_inout_z LPWSTR* psczCommandLine
    );
HRESULT CoreAppendEngineWorkingDirectoryToCommandLine(
    __in_z_opt LPCWSTR wzEngineWorkingDirectory,
    __deref_inout_z LPWSTR* psczCommandLine,
    __deref_inout_z_opt LPWSTR* psczObfuscatedCommandLine
    );
void CoreCleanup(
    __in BURN_ENGINE_STATE* pEngineState
    );
HRESULT CoreParseCommandLine(
    __in BURN_ENGINE_COMMAND* pInternalCommand,
    __in BOOTSTRAPPER_COMMAND* pCommand,
    __in BURN_PIPE_CONNECTION* pCompanionConnection,
    __in BURN_PIPE_CONNECTION* pEmbeddedConnection,
    __inout HANDLE* phSectionFile,
    __inout HANDLE* phSourceEngineFile
    );
void CoreUpdateRestartState(
    __in BURN_ENGINE_STATE* pEngineState,
    __in BURN_RESTART_STATE restartState
    );
void CoreFunctionOverride(
    __in_opt PFN_CREATEPROCESSW pfnCreateProcessW,
    __in_opt PFN_PROCWAITFORCOMPLETION pfnProcWaitForCompletion
    );
HRESULT CoreCreateProcess(
    __in_opt LPCWSTR wzApplicationName,
    __inout_opt LPWSTR sczCommandLine,
    __in BOOL fInheritHandles,
    __in DWORD dwCreationFlags,
    __in_opt LPCWSTR wzCurrentDirectory,
    __in WORD wShowWindow,
    __out LPPROCESS_INFORMATION pProcessInformation
    );
HRESULT DAPI CoreWaitForProcCompletion(
    __in HANDLE hProcess,
    __in DWORD dwTimeout,
    __out_opt DWORD* pdwReturnCode
    );
HRESULT DAPI CoreCloseElevatedLoggingThread(
    __in BURN_ENGINE_STATE* pEngineState
    );
HRESULT DAPI CoreWaitForUnelevatedLoggingThread(
    __in HANDLE hUnelevatedLoggingThread
    );

#if defined(__cplusplus)
}
#endif