diff options
Diffstat (limited to 'src/ext/Bal/wixiuiba')
-rw-r--r-- | src/ext/Bal/wixiuiba/WixInternalUIBootstrapperApplication.cpp | 918 | ||||
-rw-r--r-- | src/ext/Bal/wixiuiba/WixInternalUIBootstrapperApplication.h | 18 | ||||
-rw-r--r-- | src/ext/Bal/wixiuiba/precomp.h | 8 | ||||
-rw-r--r-- | src/ext/Bal/wixiuiba/wixiuiba.cpp | 186 | ||||
-rw-r--r-- | src/ext/Bal/wixiuiba/wixiuiba.def | 6 | ||||
-rw-r--r-- | src/ext/Bal/wixiuiba/wixiuiba.h | 13 | ||||
-rw-r--r-- | src/ext/Bal/wixiuiba/wixiuiba.rc | 1 | ||||
-rw-r--r-- | src/ext/Bal/wixiuiba/wixiuiba.vcxproj | 43 |
8 files changed, 46 insertions, 1147 deletions
diff --git a/src/ext/Bal/wixiuiba/WixInternalUIBootstrapperApplication.cpp b/src/ext/Bal/wixiuiba/WixInternalUIBootstrapperApplication.cpp deleted file mode 100644 index 6ff6559b..00000000 --- a/src/ext/Bal/wixiuiba/WixInternalUIBootstrapperApplication.cpp +++ /dev/null | |||
@@ -1,918 +0,0 @@ | |||
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 | #include "BalBaseBootstrapperApplicationProc.h" | ||
5 | #include "BalBaseBootstrapperApplication.h" | ||
6 | |||
7 | static const LPCWSTR WIXIUIBA_WINDOW_CLASS = L"WixInternalUIBA"; | ||
8 | |||
9 | enum WM_WIXIUIBA | ||
10 | { | ||
11 | WM_WIXIUIBA_DETECT_PACKAGES = WM_APP + 100, | ||
12 | WM_WIXIUIBA_PLAN_PACKAGES, | ||
13 | WM_WIXIUIBA_APPLY_PACKAGES, | ||
14 | WM_WIXIUIBA_DETECT_FOR_CLEANUP, | ||
15 | WM_WIXIUIBA_PLAN_PACKAGES_FOR_CLEANUP, | ||
16 | }; | ||
17 | |||
18 | |||
19 | class CWixInternalUIBootstrapperApplication : public CBalBaseBootstrapperApplication | ||
20 | { | ||
21 | public: // IBootstrapperApplication | ||
22 | virtual STDMETHODIMP OnStartup() | ||
23 | { | ||
24 | HRESULT hr = S_OK; | ||
25 | DWORD dwUIThreadId = 0; | ||
26 | |||
27 | // create UI thread | ||
28 | m_hUiThread = ::CreateThread(NULL, 0, UiThreadProc, this, 0, &dwUIThreadId); | ||
29 | if (!m_hUiThread) | ||
30 | { | ||
31 | BalExitWithLastError(hr, "Failed to create UI thread."); | ||
32 | } | ||
33 | |||
34 | LExit: | ||
35 | return hr; | ||
36 | } | ||
37 | |||
38 | |||
39 | virtual STDMETHODIMP OnShutdown( | ||
40 | __inout BOOTSTRAPPER_SHUTDOWN_ACTION* pAction | ||
41 | ) | ||
42 | { | ||
43 | // wait for UI thread to terminate | ||
44 | if (m_hUiThread) | ||
45 | { | ||
46 | ::WaitForSingleObject(m_hUiThread, INFINITE); | ||
47 | ReleaseHandle(m_hUiThread); | ||
48 | } | ||
49 | |||
50 | if (m_fFailedToLoadPackage) | ||
51 | { | ||
52 | Assert(FAILED(m_hrFinal)); | ||
53 | m_pPrereqData->hrFatalError = m_hrFinal; | ||
54 | BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Failed to load primary package as the BA. The bootstrapper application will be reloaded to show the error."); | ||
55 | *pAction = BOOTSTRAPPER_SHUTDOWN_ACTION_RELOAD_BOOTSTRAPPER; | ||
56 | } | ||
57 | |||
58 | return S_OK; | ||
59 | } | ||
60 | |||
61 | |||
62 | virtual STDMETHODIMP OnDetectPackageComplete( | ||
63 | __in_z LPCWSTR wzPackageId, | ||
64 | __in HRESULT hrStatus, | ||
65 | __in BOOTSTRAPPER_PACKAGE_STATE state, | ||
66 | __in BOOL fCached | ||
67 | ) | ||
68 | { | ||
69 | BAL_INFO_PACKAGE* pPackage = NULL; | ||
70 | |||
71 | if (SUCCEEDED(hrStatus) && SUCCEEDED(BalInfoFindPackageById(&m_Bundle.packages, wzPackageId, &pPackage)) && | ||
72 | BAL_INFO_PRIMARY_PACKAGE_TYPE_DEFAULT == pPackage->primaryPackageType) | ||
73 | { | ||
74 | BOOL fInstalled = BOOTSTRAPPER_PACKAGE_STATE_ABSENT < state; | ||
75 | |||
76 | // Maybe modify the action state if the primary package is or is not already installed. | ||
77 | if (fInstalled && BOOTSTRAPPER_ACTION_INSTALL == m_command.action) | ||
78 | { | ||
79 | m_command.action = BOOTSTRAPPER_ACTION_MODIFY; | ||
80 | } | ||
81 | else if (!fInstalled && (BOOTSTRAPPER_ACTION_MODIFY == m_command.action || BOOTSTRAPPER_ACTION_REPAIR == m_command.action)) | ||
82 | { | ||
83 | m_command.action = BOOTSTRAPPER_ACTION_INSTALL; | ||
84 | } | ||
85 | |||
86 | if (m_fApplied && !fInstalled && fCached) | ||
87 | { | ||
88 | m_fAutomaticRemoval = TRUE; | ||
89 | } | ||
90 | } | ||
91 | |||
92 | return __super::OnDetectPackageComplete(wzPackageId, hrStatus, state, fCached); | ||
93 | } | ||
94 | |||
95 | |||
96 | virtual STDMETHODIMP OnDetectComplete( | ||
97 | __in HRESULT hrStatus, | ||
98 | __in BOOL fEligibleForCleanup | ||
99 | ) | ||
100 | { | ||
101 | if (m_fAutomaticRemoval && SUCCEEDED(hrStatus)) | ||
102 | { | ||
103 | ::PostMessageW(m_hWnd, WM_WIXIUIBA_PLAN_PACKAGES_FOR_CLEANUP, 0, BOOTSTRAPPER_ACTION_UNINSTALL); | ||
104 | ExitFunction(); | ||
105 | } | ||
106 | else if (m_fApplied) | ||
107 | { | ||
108 | ::PostMessageW(m_hWnd, WM_CLOSE, 0, 0); | ||
109 | ExitFunction(); | ||
110 | } | ||
111 | |||
112 | // If we're performing an action that modifies machine state then evaluate conditions. | ||
113 | BOOL fEvaluateConditions = SUCCEEDED(hrStatus) && | ||
114 | (BOOTSTRAPPER_ACTION_LAYOUT < m_command.action && BOOTSTRAPPER_ACTION_UPDATE_REPLACE > m_command.action); | ||
115 | |||
116 | if (fEvaluateConditions) | ||
117 | { | ||
118 | hrStatus = EvaluateConditions(); | ||
119 | } | ||
120 | |||
121 | if (SUCCEEDED(hrStatus)) | ||
122 | { | ||
123 | ::PostMessageW(m_hWnd, WM_WIXIUIBA_PLAN_PACKAGES, 0, m_command.action); | ||
124 | } | ||
125 | else | ||
126 | { | ||
127 | SetLoadPackageFailure(hrStatus); | ||
128 | } | ||
129 | |||
130 | LExit: | ||
131 | return __super::OnDetectComplete(hrStatus, fEligibleForCleanup); | ||
132 | } | ||
133 | |||
134 | |||
135 | virtual STDMETHODIMP OnPlanPackageBegin( | ||
136 | __in_z LPCWSTR wzPackageId, | ||
137 | __in BOOTSTRAPPER_PACKAGE_STATE state, | ||
138 | __in BOOL fCached, | ||
139 | __in BOOTSTRAPPER_PACKAGE_CONDITION_RESULT installCondition, | ||
140 | __in BOOTSTRAPPER_PACKAGE_CONDITION_RESULT repairCondition, | ||
141 | __in BOOTSTRAPPER_REQUEST_STATE recommendedState, | ||
142 | __in BOOTSTRAPPER_CACHE_TYPE recommendedCacheType, | ||
143 | __inout BOOTSTRAPPER_REQUEST_STATE* pRequestState, | ||
144 | __inout BOOTSTRAPPER_CACHE_TYPE* pRequestedCacheType, | ||
145 | __inout BOOL* pfCancel | ||
146 | ) | ||
147 | { | ||
148 | HRESULT hr = S_OK; | ||
149 | BAL_INFO_PACKAGE* pPackage = NULL; | ||
150 | |||
151 | hr = BalInfoFindPackageById(&m_Bundle.packages, wzPackageId, &pPackage); | ||
152 | if (FAILED(hr)) | ||
153 | { | ||
154 | // Non-chain package, keep default. | ||
155 | } | ||
156 | else if (BAL_INFO_PRIMARY_PACKAGE_TYPE_DEFAULT != pPackage->primaryPackageType) | ||
157 | { | ||
158 | // Only the primary package should be cached or executed. | ||
159 | if (BOOTSTRAPPER_CACHE_TYPE_FORCE == *pRequestedCacheType) | ||
160 | { | ||
161 | *pRequestedCacheType = BOOTSTRAPPER_CACHE_TYPE_KEEP; | ||
162 | } | ||
163 | |||
164 | *pRequestState = BOOTSTRAPPER_REQUEST_STATE_NONE; | ||
165 | } | ||
166 | else if (BOOTSTRAPPER_DISPLAY_FULL == m_command.display && !m_fAutomaticRemoval) | ||
167 | { | ||
168 | // Make sure the MSI UI is shown regardless of the current state of the package. | ||
169 | *pRequestState = BOOTSTRAPPER_REQUEST_STATE_FORCE_PRESENT; | ||
170 | } | ||
171 | |||
172 | return __super::OnPlanPackageBegin(wzPackageId, state, fCached, installCondition, repairCondition, recommendedState, recommendedCacheType, pRequestState, pRequestedCacheType, pfCancel); | ||
173 | } | ||
174 | |||
175 | |||
176 | virtual STDMETHODIMP OnPlanMsiPackage( | ||
177 | __in_z LPCWSTR wzPackageId, | ||
178 | __in BOOL fExecute, | ||
179 | __in BOOTSTRAPPER_ACTION_STATE action, | ||
180 | __in BOOTSTRAPPER_MSI_FILE_VERSIONING recommendedFileVersioning, | ||
181 | __inout BOOL* pfCancel, | ||
182 | __inout BURN_MSI_PROPERTY* pActionMsiProperty, | ||
183 | __inout INSTALLUILEVEL* pUiLevel, | ||
184 | __inout BOOL* pfDisableExternalUiHandler, | ||
185 | __inout BOOTSTRAPPER_MSI_FILE_VERSIONING* pFileVersioning | ||
186 | ) | ||
187 | { | ||
188 | INSTALLUILEVEL uiLevel = INSTALLUILEVEL_NOCHANGE; | ||
189 | |||
190 | if (m_fAutomaticRemoval) | ||
191 | { | ||
192 | ExitFunction(); | ||
193 | } | ||
194 | |||
195 | switch (m_command.display) | ||
196 | { | ||
197 | case BOOTSTRAPPER_DISPLAY_FULL: | ||
198 | uiLevel = INSTALLUILEVEL_FULL; | ||
199 | break; | ||
200 | |||
201 | case BOOTSTRAPPER_DISPLAY_PASSIVE: | ||
202 | uiLevel = INSTALLUILEVEL_REDUCED; | ||
203 | break; | ||
204 | } | ||
205 | |||
206 | if (INSTALLUILEVEL_NOCHANGE != uiLevel) | ||
207 | { | ||
208 | *pUiLevel = uiLevel; | ||
209 | } | ||
210 | |||
211 | *pActionMsiProperty = BURN_MSI_PROPERTY_NONE; | ||
212 | *pfDisableExternalUiHandler = TRUE; | ||
213 | |||
214 | LExit: | ||
215 | return __super::OnPlanMsiPackage(wzPackageId, fExecute, action, recommendedFileVersioning, pfCancel, pActionMsiProperty, pUiLevel, pfDisableExternalUiHandler, pFileVersioning); | ||
216 | } | ||
217 | |||
218 | |||
219 | virtual STDMETHODIMP OnPlanComplete( | ||
220 | __in HRESULT hrStatus | ||
221 | ) | ||
222 | { | ||
223 | if (SUCCEEDED(hrStatus)) | ||
224 | { | ||
225 | ::PostMessageW(m_hWnd, WM_WIXIUIBA_APPLY_PACKAGES, 0, 0); | ||
226 | } | ||
227 | else if (m_fAutomaticRemoval) | ||
228 | { | ||
229 | ::PostMessageW(m_hWnd, WM_CLOSE, 0, 0); | ||
230 | } | ||
231 | else | ||
232 | { | ||
233 | SetLoadPackageFailure(hrStatus); | ||
234 | } | ||
235 | |||
236 | return __super::OnPlanComplete(hrStatus); | ||
237 | } | ||
238 | |||
239 | |||
240 | virtual STDMETHODIMP OnApplyBegin( | ||
241 | __in DWORD dwPhaseCount, | ||
242 | __inout BOOL* pfCancel | ||
243 | ) | ||
244 | { | ||
245 | m_fApplying = TRUE; | ||
246 | return __super::OnApplyBegin(dwPhaseCount, pfCancel); | ||
247 | } | ||
248 | |||
249 | |||
250 | virtual STDMETHODIMP OnCacheComplete( | ||
251 | __in HRESULT hrStatus | ||
252 | ) | ||
253 | { | ||
254 | if (FAILED(hrStatus) && !m_fAutomaticRemoval) | ||
255 | { | ||
256 | SetLoadPackageFailure(hrStatus); | ||
257 | } | ||
258 | |||
259 | return __super::OnCacheComplete(hrStatus); | ||
260 | } | ||
261 | |||
262 | |||
263 | virtual STDMETHODIMP OnExecuteBegin( | ||
264 | __in DWORD cExecutingPackages, | ||
265 | __in BOOL* pfCancel | ||
266 | ) | ||
267 | { | ||
268 | m_pEngine->CloseSplashScreen(); | ||
269 | |||
270 | return __super::OnExecuteBegin(cExecutingPackages, pfCancel); | ||
271 | } | ||
272 | |||
273 | |||
274 | virtual STDMETHODIMP OnApplyComplete( | ||
275 | __in HRESULT hrStatus, | ||
276 | __in BOOTSTRAPPER_APPLY_RESTART restart, | ||
277 | __in BOOTSTRAPPER_APPLYCOMPLETE_ACTION recommendation, | ||
278 | __inout BOOTSTRAPPER_APPLYCOMPLETE_ACTION* pAction | ||
279 | ) | ||
280 | { | ||
281 | HRESULT hr = __super::OnApplyComplete(hrStatus, restart, recommendation, pAction); | ||
282 | |||
283 | *pAction = BOOTSTRAPPER_APPLYCOMPLETE_ACTION_NONE; | ||
284 | m_fApplying = FALSE; | ||
285 | |||
286 | if (m_fAutomaticRemoval) | ||
287 | { | ||
288 | ::PostMessageW(m_hWnd, WM_CLOSE, 0, 0); | ||
289 | } | ||
290 | else | ||
291 | { | ||
292 | m_restartResult = restart; // remember the restart result so we return the correct error code. | ||
293 | m_fApplied = TRUE; | ||
294 | |||
295 | if (FAILED(hrStatus)) | ||
296 | { | ||
297 | m_hrFinal = hrStatus; | ||
298 | } | ||
299 | |||
300 | ::PostMessageW(m_hWnd, WM_WIXIUIBA_DETECT_FOR_CLEANUP, 0, 0); | ||
301 | } | ||
302 | |||
303 | return hr; | ||
304 | } | ||
305 | |||
306 | |||
307 | public: //CBalBaseBootstrapperApplication | ||
308 | virtual STDMETHODIMP Initialize( | ||
309 | __in const BOOTSTRAPPER_CREATE_ARGS* pCreateArgs | ||
310 | ) | ||
311 | { | ||
312 | HRESULT hr = S_OK; | ||
313 | |||
314 | hr = __super::Initialize(pCreateArgs); | ||
315 | BalExitOnFailure(hr, "CBalBaseBootstrapperApplication initialization failed."); | ||
316 | |||
317 | memcpy_s(&m_command, sizeof(m_command), pCreateArgs->pCommand, sizeof(BOOTSTRAPPER_COMMAND)); | ||
318 | memcpy_s(&m_createArgs, sizeof(m_createArgs), pCreateArgs, sizeof(BOOTSTRAPPER_CREATE_ARGS)); | ||
319 | m_createArgs.pCommand = &m_command; | ||
320 | |||
321 | LExit: | ||
322 | return hr; | ||
323 | } | ||
324 | |||
325 | void Uninitialize( | ||
326 | __in const BOOTSTRAPPER_DESTROY_ARGS* /*pArgs*/, | ||
327 | __in BOOTSTRAPPER_DESTROY_RESULTS* /*pResults*/ | ||
328 | ) | ||
329 | { | ||
330 | } | ||
331 | |||
332 | |||
333 | private: | ||
334 | // | ||
335 | // UiThreadProc - entrypoint for UI thread. | ||
336 | // | ||
337 | static DWORD WINAPI UiThreadProc( | ||
338 | __in LPVOID pvContext | ||
339 | ) | ||
340 | { | ||
341 | HRESULT hr = S_OK; | ||
342 | CWixInternalUIBootstrapperApplication* pThis = (CWixInternalUIBootstrapperApplication*)pvContext; | ||
343 | BOOL fComInitialized = FALSE; | ||
344 | BOOL fRet = FALSE; | ||
345 | MSG msg = { }; | ||
346 | DWORD dwQuit = 0; | ||
347 | |||
348 | // Initialize COM and theme. | ||
349 | hr = ::CoInitialize(NULL); | ||
350 | BalExitOnFailure(hr, "Failed to initialize COM."); | ||
351 | fComInitialized = TRUE; | ||
352 | |||
353 | hr = pThis->InitializeData(); | ||
354 | BalExitOnFailure(hr, "Failed to initialize data in bootstrapper application."); | ||
355 | |||
356 | // Create main window. | ||
357 | hr = pThis->CreateMainWindow(); | ||
358 | BalExitOnFailure(hr, "Failed to create main window."); | ||
359 | |||
360 | ::PostMessageW(pThis->m_hWnd, WM_WIXIUIBA_DETECT_PACKAGES, 0, 0); | ||
361 | |||
362 | // message pump | ||
363 | while (0 != (fRet = ::GetMessageW(&msg, NULL, 0, 0))) | ||
364 | { | ||
365 | if (-1 == fRet) | ||
366 | { | ||
367 | hr = E_UNEXPECTED; | ||
368 | BalExitOnFailure(hr, "Unexpected return value from message pump."); | ||
369 | } | ||
370 | else if (!::IsDialogMessageW(pThis->m_hWnd, &msg)) | ||
371 | { | ||
372 | ::TranslateMessage(&msg); | ||
373 | ::DispatchMessageW(&msg); | ||
374 | } | ||
375 | } | ||
376 | |||
377 | // Succeeded thus far, check to see if anything went wrong while actually | ||
378 | // executing changes. | ||
379 | if (FAILED(pThis->m_hrFinal)) | ||
380 | { | ||
381 | hr = pThis->m_hrFinal; | ||
382 | } | ||
383 | else if (pThis->CheckCanceled()) | ||
384 | { | ||
385 | hr = HRESULT_FROM_WIN32(ERROR_INSTALL_USEREXIT); | ||
386 | } | ||
387 | |||
388 | LExit: | ||
389 | // destroy main window | ||
390 | pThis->DestroyMainWindow(); | ||
391 | |||
392 | if (BOOTSTRAPPER_APPLY_RESTART_INITIATED == pThis->m_restartResult) | ||
393 | { | ||
394 | dwQuit = SUCCEEDED(hr) ? ERROR_SUCCESS_REBOOT_INITIATED : ERROR_FAIL_REBOOT_INITIATED; | ||
395 | } | ||
396 | else if (BOOTSTRAPPER_APPLY_RESTART_REQUIRED == pThis->m_restartResult) | ||
397 | { | ||
398 | dwQuit = SUCCEEDED(hr) ? ERROR_SUCCESS_REBOOT_REQUIRED : ERROR_FAIL_REBOOT_REQUIRED; | ||
399 | } | ||
400 | else if (SEVERITY_ERROR == HRESULT_SEVERITY(hr) && FACILITY_WIN32 == HRESULT_FACILITY(hr)) | ||
401 | { | ||
402 | // Convert Win32 HRESULTs back to the error code. | ||
403 | dwQuit = HRESULT_CODE(hr); | ||
404 | } | ||
405 | else | ||
406 | { | ||
407 | dwQuit = hr; | ||
408 | } | ||
409 | |||
410 | // initiate engine shutdown | ||
411 | pThis->m_pEngine->Quit(dwQuit); | ||
412 | |||
413 | // uninitialize COM | ||
414 | if (fComInitialized) | ||
415 | { | ||
416 | ::CoUninitialize(); | ||
417 | } | ||
418 | |||
419 | return hr; | ||
420 | } | ||
421 | |||
422 | |||
423 | // | ||
424 | // InitializeData - initializes all the package and prerequisite information. | ||
425 | // | ||
426 | HRESULT InitializeData() | ||
427 | { | ||
428 | HRESULT hr = S_OK; | ||
429 | IXMLDOMDocument* pixdManifest = NULL; | ||
430 | |||
431 | hr = BalManifestLoad(m_hModule, &pixdManifest); | ||
432 | BalExitOnFailure(hr, "Failed to load bootstrapper application manifest."); | ||
433 | |||
434 | hr = BalInfoParseFromXml(&m_Bundle, pixdManifest); | ||
435 | BalExitOnFailure(hr, "Failed to load bundle information."); | ||
436 | |||
437 | hr = EnsureSinglePrimaryPackage(); | ||
438 | BalExitOnFailure(hr, "Failed to ensure single primary package."); | ||
439 | |||
440 | hr = ProcessCommandLine(); | ||
441 | ExitOnFailure(hr, "Unknown commandline parameters."); | ||
442 | |||
443 | hr = BalConditionsParseFromXml(&m_Conditions, pixdManifest, NULL); | ||
444 | BalExitOnFailure(hr, "Failed to load conditions from XML."); | ||
445 | |||
446 | LExit: | ||
447 | ReleaseObject(pixdManifest); | ||
448 | |||
449 | return hr; | ||
450 | } | ||
451 | |||
452 | |||
453 | // | ||
454 | // ProcessCommandLine - process the provided command line arguments. | ||
455 | // | ||
456 | HRESULT ProcessCommandLine() | ||
457 | { | ||
458 | HRESULT hr = S_OK; | ||
459 | int argc = 0; | ||
460 | LPWSTR* argv = NULL; | ||
461 | |||
462 | argc = m_BalInfoCommand.cUnknownArgs; | ||
463 | argv = m_BalInfoCommand.rgUnknownArgs; | ||
464 | |||
465 | for (int i = 0; i < argc; ++i) | ||
466 | { | ||
467 | BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Ignoring unknown argument: %ls", argv[i]); | ||
468 | } | ||
469 | |||
470 | hr = BalSetOverridableVariablesFromEngine(&m_Bundle.overridableVariables, &m_BalInfoCommand, m_pEngine); | ||
471 | BalExitOnFailure(hr, "Failed to set overridable variables from the command line."); | ||
472 | |||
473 | LExit: | ||
474 | return hr; | ||
475 | } | ||
476 | |||
477 | HRESULT EnsureSinglePrimaryPackage() | ||
478 | { | ||
479 | HRESULT hr = S_OK; | ||
480 | BAL_INFO_PACKAGE* pDefaultPackage = NULL; | ||
481 | BOOL fPrimaryArchSpecific = FALSE; | ||
482 | USHORT usNativeMachine = 0; | ||
483 | BAL_INFO_PRIMARY_PACKAGE_TYPE nativeType = BAL_INFO_PRIMARY_PACKAGE_TYPE_NONE; | ||
484 | |||
485 | hr = ProcNativeMachine(::GetCurrentProcess(), &usNativeMachine); | ||
486 | BalExitOnFailure(hr, "Failed to get native machine value."); | ||
487 | |||
488 | if (S_FALSE != hr) | ||
489 | { | ||
490 | switch (usNativeMachine) | ||
491 | { | ||
492 | case IMAGE_FILE_MACHINE_I386: | ||
493 | nativeType = BAL_INFO_PRIMARY_PACKAGE_TYPE_X86; | ||
494 | break; | ||
495 | case IMAGE_FILE_MACHINE_AMD64: | ||
496 | nativeType = BAL_INFO_PRIMARY_PACKAGE_TYPE_X64; | ||
497 | break; | ||
498 | case IMAGE_FILE_MACHINE_ARM64: | ||
499 | nativeType = BAL_INFO_PRIMARY_PACKAGE_TYPE_ARM64; | ||
500 | break; | ||
501 | } | ||
502 | } | ||
503 | else | ||
504 | { | ||
505 | #if !defined(_WIN64) | ||
506 | BOOL fIsWow64 = FALSE; | ||
507 | |||
508 | ProcWow64(::GetCurrentProcess(), &fIsWow64); | ||
509 | if (!fIsWow64) | ||
510 | { | ||
511 | nativeType = BAL_INFO_PRIMARY_PACKAGE_TYPE_X86; | ||
512 | } | ||
513 | else | ||
514 | #endif | ||
515 | { | ||
516 | nativeType = BAL_INFO_PRIMARY_PACKAGE_TYPE_X64; | ||
517 | } | ||
518 | } | ||
519 | |||
520 | for (DWORD i = 0; i < m_Bundle.packages.cPackages; ++i) | ||
521 | { | ||
522 | BAL_INFO_PACKAGE* pPackage = m_Bundle.packages.rgPackages + i; | ||
523 | |||
524 | if (BAL_INFO_PRIMARY_PACKAGE_TYPE_NONE == pPackage->primaryPackageType) | ||
525 | { | ||
526 | // Skip. | ||
527 | } | ||
528 | else if (nativeType == pPackage->primaryPackageType) | ||
529 | { | ||
530 | if (fPrimaryArchSpecific) | ||
531 | { | ||
532 | BalExitWithRootFailure(hr, E_INVALIDDATA, "Bundle contains multiple primary packages for same architecture: %u.", nativeType); | ||
533 | } | ||
534 | |||
535 | pPackage->primaryPackageType = BAL_INFO_PRIMARY_PACKAGE_TYPE_DEFAULT; | ||
536 | fPrimaryArchSpecific = TRUE; | ||
537 | } | ||
538 | else if (BAL_INFO_PRIMARY_PACKAGE_TYPE_DEFAULT == pPackage->primaryPackageType) | ||
539 | { | ||
540 | if (pDefaultPackage) | ||
541 | { | ||
542 | BalExitWithRootFailure(hr, E_INVALIDDATA, "Bundle contains multiple default primary packages."); | ||
543 | } | ||
544 | |||
545 | pDefaultPackage = pPackage; | ||
546 | } | ||
547 | } | ||
548 | |||
549 | BalExitOnNull(pDefaultPackage, hr, E_INVALIDSTATE, "Bundle did not contain default primary package."); | ||
550 | |||
551 | if (fPrimaryArchSpecific) | ||
552 | { | ||
553 | pDefaultPackage->primaryPackageType = BAL_INFO_PRIMARY_PACKAGE_TYPE_NONE; | ||
554 | } | ||
555 | |||
556 | LExit: | ||
557 | return hr; | ||
558 | } | ||
559 | |||
560 | |||
561 | // | ||
562 | // CreateMainWindow - creates the main install window. | ||
563 | // | ||
564 | HRESULT CreateMainWindow() | ||
565 | { | ||
566 | HRESULT hr = S_OK; | ||
567 | WNDCLASSW wc = { }; | ||
568 | DWORD dwWindowStyle = WS_POPUP; | ||
569 | |||
570 | wc.lpfnWndProc = CWixInternalUIBootstrapperApplication::WndProc; | ||
571 | wc.hInstance = m_hModule; | ||
572 | wc.lpszClassName = WIXIUIBA_WINDOW_CLASS; | ||
573 | |||
574 | if (!::RegisterClassW(&wc)) | ||
575 | { | ||
576 | ExitWithLastError(hr, "Failed to register window."); | ||
577 | } | ||
578 | |||
579 | m_fRegistered = TRUE; | ||
580 | |||
581 | // If the UI should be visible, allow it to be visible and activated so we are the foreground window. | ||
582 | // This allows the UAC prompt and MSI UI to automatically be activated. | ||
583 | if (BOOTSTRAPPER_DISPLAY_NONE < m_command.display) | ||
584 | { | ||
585 | dwWindowStyle |= WS_VISIBLE; | ||
586 | } | ||
587 | |||
588 | m_hWnd = ::CreateWindowExW(WS_EX_TOOLWINDOW, wc.lpszClassName, NULL, dwWindowStyle, 0, 0, 0, 0, HWND_DESKTOP, NULL, m_hModule, this); | ||
589 | ExitOnNullWithLastError(m_hWnd, hr, "Failed to create window."); | ||
590 | |||
591 | LExit: | ||
592 | return hr; | ||
593 | } | ||
594 | |||
595 | // | ||
596 | // DestroyMainWindow - clean up all the window registration. | ||
597 | // | ||
598 | void DestroyMainWindow() | ||
599 | { | ||
600 | if (::IsWindow(m_hWnd)) | ||
601 | { | ||
602 | ::DestroyWindow(m_hWnd); | ||
603 | m_hWnd = NULL; | ||
604 | } | ||
605 | |||
606 | if (m_fRegistered) | ||
607 | { | ||
608 | ::UnregisterClassW(WIXIUIBA_WINDOW_CLASS, m_hModule); | ||
609 | m_fRegistered = FALSE; | ||
610 | } | ||
611 | } | ||
612 | |||
613 | // | ||
614 | // WndProc - standard windows message handler. | ||
615 | // | ||
616 | static LRESULT CALLBACK WndProc( | ||
617 | __in HWND hWnd, | ||
618 | __in UINT uMsg, | ||
619 | __in WPARAM wParam, | ||
620 | __in LPARAM lParam | ||
621 | ) | ||
622 | { | ||
623 | #pragma warning(suppress:4312) | ||
624 | CWixInternalUIBootstrapperApplication* pBA = reinterpret_cast<CWixInternalUIBootstrapperApplication*>(::GetWindowLongPtrW(hWnd, GWLP_USERDATA)); | ||
625 | |||
626 | switch (uMsg) | ||
627 | { | ||
628 | case WM_NCCREATE: | ||
629 | { | ||
630 | LPCREATESTRUCT lpcs = reinterpret_cast<LPCREATESTRUCT>(lParam); | ||
631 | pBA = reinterpret_cast<CWixInternalUIBootstrapperApplication*>(lpcs->lpCreateParams); | ||
632 | #pragma warning(suppress:4244) | ||
633 | ::SetWindowLongPtrW(hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(pBA)); | ||
634 | } | ||
635 | break; | ||
636 | |||
637 | case WM_NCDESTROY: | ||
638 | { | ||
639 | LRESULT lres = ::DefWindowProcW(hWnd, uMsg, wParam, lParam); | ||
640 | ::SetWindowLongPtrW(hWnd, GWLP_USERDATA, 0); | ||
641 | ::PostQuitMessage(0); | ||
642 | return lres; | ||
643 | } | ||
644 | |||
645 | case WM_CLOSE: | ||
646 | // If the user chose not to close, do *not* let the default window proc handle the message. | ||
647 | if (!pBA->OnClose()) | ||
648 | { | ||
649 | return 0; | ||
650 | } | ||
651 | break; | ||
652 | |||
653 | case WM_WIXIUIBA_DETECT_PACKAGES: __fallthrough; | ||
654 | case WM_WIXIUIBA_DETECT_FOR_CLEANUP: | ||
655 | pBA->OnDetect(); | ||
656 | return 0; | ||
657 | |||
658 | case WM_WIXIUIBA_PLAN_PACKAGES: | ||
659 | case WM_WIXIUIBA_PLAN_PACKAGES_FOR_CLEANUP: | ||
660 | pBA->OnPlan(static_cast<BOOTSTRAPPER_ACTION>(lParam)); | ||
661 | return 0; | ||
662 | |||
663 | case WM_WIXIUIBA_APPLY_PACKAGES: | ||
664 | pBA->OnApply(); | ||
665 | return 0; | ||
666 | } | ||
667 | |||
668 | return ::DefWindowProcW(hWnd, uMsg, wParam, lParam); | ||
669 | } | ||
670 | |||
671 | |||
672 | // | ||
673 | // OnDetect - start the processing of packages. | ||
674 | // | ||
675 | void OnDetect() | ||
676 | { | ||
677 | HRESULT hr = S_OK; | ||
678 | |||
679 | hr = m_pEngine->Detect(); | ||
680 | BalExitOnFailure(hr, "Failed to start detecting chain."); | ||
681 | |||
682 | LExit: | ||
683 | if (FAILED(hr)) | ||
684 | { | ||
685 | SetLoadPackageFailure(hr); | ||
686 | } | ||
687 | } | ||
688 | |||
689 | |||
690 | // | ||
691 | // OnPlan - plan the detected changes. | ||
692 | // | ||
693 | void OnPlan( | ||
694 | __in BOOTSTRAPPER_ACTION action | ||
695 | ) | ||
696 | { | ||
697 | HRESULT hr = S_OK; | ||
698 | |||
699 | m_plannedAction = action; | ||
700 | |||
701 | hr = m_pEngine->Plan(action); | ||
702 | BalExitOnFailure(hr, "Failed to start planning packages."); | ||
703 | |||
704 | LExit: | ||
705 | if (FAILED(hr)) | ||
706 | { | ||
707 | SetLoadPackageFailure(hr); | ||
708 | } | ||
709 | } | ||
710 | |||
711 | |||
712 | // | ||
713 | // OnApply - apply the packages. | ||
714 | // | ||
715 | void OnApply() | ||
716 | { | ||
717 | HRESULT hr = S_OK; | ||
718 | |||
719 | hr = m_pEngine->Apply(m_hWnd); | ||
720 | BalExitOnFailure(hr, "Failed to start applying packages."); | ||
721 | |||
722 | LExit: | ||
723 | if (FAILED(hr)) | ||
724 | { | ||
725 | SetLoadPackageFailure(hr); | ||
726 | } | ||
727 | } | ||
728 | |||
729 | |||
730 | // | ||
731 | // OnClose - called when the window is trying to be closed. | ||
732 | // | ||
733 | BOOL OnClose() | ||
734 | { | ||
735 | BOOL fClose = FALSE; | ||
736 | |||
737 | // If we've already applied, just close. | ||
738 | if (m_fApplied) | ||
739 | { | ||
740 | fClose = TRUE; | ||
741 | } | ||
742 | else | ||
743 | { | ||
744 | PromptCancel(m_hWnd, TRUE, NULL, NULL); | ||
745 | |||
746 | // If we're inside Apply then we never close, we just cancel to let rollback occur. | ||
747 | fClose = !m_fApplying; | ||
748 | } | ||
749 | |||
750 | return fClose; | ||
751 | } | ||
752 | |||
753 | |||
754 | HRESULT EvaluateConditions() | ||
755 | { | ||
756 | HRESULT hr = S_OK; | ||
757 | BOOL fResult = FALSE; | ||
758 | |||
759 | for (DWORD i = 0; i < m_Conditions.cConditions; ++i) | ||
760 | { | ||
761 | BAL_CONDITION* pCondition = m_Conditions.rgConditions + i; | ||
762 | |||
763 | hr = BalConditionEvaluate(pCondition, m_pEngine, &fResult, &m_sczFailedMessage); | ||
764 | BalExitOnFailure(hr, "Failed to evaluate condition."); | ||
765 | |||
766 | if (!fResult) | ||
767 | { | ||
768 | hr = E_WIXSTDBA_CONDITION_FAILED; | ||
769 | BalExitOnFailure(hr, "%ls", m_sczFailedMessage); | ||
770 | } | ||
771 | } | ||
772 | |||
773 | ReleaseNullStrSecure(m_sczFailedMessage); | ||
774 | |||
775 | LExit: | ||
776 | return hr; | ||
777 | } | ||
778 | |||
779 | |||
780 | void SetLoadPackageFailure( | ||
781 | __in HRESULT hrStatus | ||
782 | ) | ||
783 | { | ||
784 | Assert(FAILED(hrStatus)); | ||
785 | |||
786 | if (!m_fApplied) | ||
787 | { | ||
788 | m_hrFinal = hrStatus; | ||
789 | m_fFailedToLoadPackage = TRUE; | ||
790 | } | ||
791 | |||
792 | // Quietly exit. | ||
793 | ::PostMessageW(m_hWnd, WM_CLOSE, 0, 0); | ||
794 | } | ||
795 | |||
796 | |||
797 | public: | ||
798 | // | ||
799 | // Constructor - initialize member variables. | ||
800 | // | ||
801 | CWixInternalUIBootstrapperApplication( | ||
802 | __in HMODULE hModule, | ||
803 | __in_opt PREQBA_DATA* pPrereqData, | ||
804 | __in IBootstrapperEngine* pEngine | ||
805 | ) : CBalBaseBootstrapperApplication(pEngine, 3, 3000) | ||
806 | { | ||
807 | m_hModule = hModule; | ||
808 | m_command = { }; | ||
809 | m_createArgs = { }; | ||
810 | |||
811 | m_plannedAction = BOOTSTRAPPER_ACTION_UNKNOWN; | ||
812 | |||
813 | m_Bundle = { }; | ||
814 | m_Conditions = { }; | ||
815 | m_sczConfirmCloseMessage = NULL; | ||
816 | m_sczFailedMessage = NULL; | ||
817 | |||
818 | m_hUiThread = NULL; | ||
819 | m_fRegistered = FALSE; | ||
820 | m_hWnd = NULL; | ||
821 | |||
822 | m_hrFinal = S_OK; | ||
823 | |||
824 | m_restartResult = BOOTSTRAPPER_APPLY_RESTART_NONE; | ||
825 | |||
826 | m_fApplying = FALSE; | ||
827 | m_fApplied = FALSE; | ||
828 | m_fAutomaticRemoval = FALSE; | ||
829 | m_fFailedToLoadPackage = FALSE; | ||
830 | m_pPrereqData = pPrereqData; | ||
831 | |||
832 | pEngine->AddRef(); | ||
833 | m_pEngine = pEngine; | ||
834 | } | ||
835 | |||
836 | |||
837 | // | ||
838 | // Destructor - release member variables. | ||
839 | // | ||
840 | ~CWixInternalUIBootstrapperApplication() | ||
841 | { | ||
842 | ReleaseStr(m_sczFailedMessage); | ||
843 | ReleaseStr(m_sczConfirmCloseMessage); | ||
844 | BalConditionsUninitialize(&m_Conditions); | ||
845 | BalInfoUninitialize(&m_Bundle); | ||
846 | |||
847 | ReleaseNullObject(m_pEngine); | ||
848 | } | ||
849 | |||
850 | private: | ||
851 | HMODULE m_hModule; | ||
852 | BOOTSTRAPPER_CREATE_ARGS m_createArgs; | ||
853 | BOOTSTRAPPER_COMMAND m_command; | ||
854 | IBootstrapperEngine* m_pEngine; | ||
855 | BOOTSTRAPPER_ACTION m_plannedAction; | ||
856 | |||
857 | BAL_INFO_BUNDLE m_Bundle; | ||
858 | BAL_CONDITIONS m_Conditions; | ||
859 | LPWSTR m_sczFailedMessage; | ||
860 | LPWSTR m_sczConfirmCloseMessage; | ||
861 | |||
862 | HANDLE m_hUiThread; | ||
863 | BOOL m_fRegistered; | ||
864 | HWND m_hWnd; | ||
865 | |||
866 | HRESULT m_hrFinal; | ||
867 | |||
868 | BOOTSTRAPPER_APPLY_RESTART m_restartResult; | ||
869 | |||
870 | BOOL m_fApplying; | ||
871 | BOOL m_fApplied; | ||
872 | BOOL m_fAutomaticRemoval; | ||
873 | BOOL m_fFailedToLoadPackage; | ||
874 | PREQBA_DATA* m_pPrereqData; | ||
875 | }; | ||
876 | |||
877 | |||
878 | // | ||
879 | // CreateBootstrapperApplication - creates a new IBootstrapperApplication object. | ||
880 | // | ||
881 | HRESULT CreateBootstrapperApplication( | ||
882 | __in HMODULE hModule, | ||
883 | __in_opt PREQBA_DATA* pPrereqData, | ||
884 | __in IBootstrapperEngine* pEngine, | ||
885 | __in const BOOTSTRAPPER_CREATE_ARGS* pArgs, | ||
886 | __inout BOOTSTRAPPER_CREATE_RESULTS* pResults, | ||
887 | __out IBootstrapperApplication** ppApplication | ||
888 | ) | ||
889 | { | ||
890 | HRESULT hr = S_OK; | ||
891 | CWixInternalUIBootstrapperApplication* pApplication = NULL; | ||
892 | |||
893 | pApplication = new CWixInternalUIBootstrapperApplication(hModule, pPrereqData, pEngine); | ||
894 | BalExitOnNull(pApplication, hr, E_OUTOFMEMORY, "Failed to create new InternalUI bootstrapper application object."); | ||
895 | |||
896 | hr = pApplication->Initialize(pArgs); | ||
897 | ExitOnFailure(hr, "CWixInternalUIBootstrapperApplication initialization failed."); | ||
898 | |||
899 | pResults->pfnBootstrapperApplicationProc = BalBaseBootstrapperApplicationProc; | ||
900 | pResults->pvBootstrapperApplicationProcContext = pApplication; | ||
901 | *ppApplication = pApplication; | ||
902 | pApplication = NULL; | ||
903 | |||
904 | LExit: | ||
905 | ReleaseObject(pApplication); | ||
906 | return hr; | ||
907 | } | ||
908 | |||
909 | |||
910 | void DestroyBootstrapperApplication( | ||
911 | __in IBootstrapperApplication* pApplication, | ||
912 | __in const BOOTSTRAPPER_DESTROY_ARGS* pArgs, | ||
913 | __inout BOOTSTRAPPER_DESTROY_RESULTS* pResults | ||
914 | ) | ||
915 | { | ||
916 | CWixInternalUIBootstrapperApplication* pBA = (CWixInternalUIBootstrapperApplication*)pApplication; | ||
917 | pBA->Uninitialize(pArgs, pResults); | ||
918 | } | ||
diff --git a/src/ext/Bal/wixiuiba/WixInternalUIBootstrapperApplication.h b/src/ext/Bal/wixiuiba/WixInternalUIBootstrapperApplication.h deleted file mode 100644 index b0b782dd..00000000 --- a/src/ext/Bal/wixiuiba/WixInternalUIBootstrapperApplication.h +++ /dev/null | |||
@@ -1,18 +0,0 @@ | |||
1 | #pragma once | ||
2 | // 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. | ||
3 | |||
4 | |||
5 | HRESULT CreateBootstrapperApplication( | ||
6 | __in HMODULE hModule, | ||
7 | __in_opt PREQBA_DATA* pPrereqData, | ||
8 | __in IBootstrapperEngine* pEngine, | ||
9 | __in const BOOTSTRAPPER_CREATE_ARGS* pArgs, | ||
10 | __inout BOOTSTRAPPER_CREATE_RESULTS* pResults, | ||
11 | __out IBootstrapperApplication** ppApplication | ||
12 | ); | ||
13 | |||
14 | void DestroyBootstrapperApplication( | ||
15 | __in IBootstrapperApplication* pApplication, | ||
16 | __in const BOOTSTRAPPER_DESTROY_ARGS* pArgs, | ||
17 | __inout BOOTSTRAPPER_DESTROY_RESULTS* pResults | ||
18 | ); | ||
diff --git a/src/ext/Bal/wixiuiba/precomp.h b/src/ext/Bal/wixiuiba/precomp.h index 89ec6eab..cb6730fd 100644 --- a/src/ext/Bal/wixiuiba/precomp.h +++ b/src/ext/Bal/wixiuiba/precomp.h | |||
@@ -15,8 +15,9 @@ | |||
15 | #include <strutil.h> | 15 | #include <strutil.h> |
16 | #include <xmlutil.h> | 16 | #include <xmlutil.h> |
17 | 17 | ||
18 | #include <BootstrapperEngine.h> | 18 | #include <baenginetypes.h> |
19 | #include <BootstrapperApplication.h> | 19 | #include <batypes.h> |
20 | |||
20 | #include <IBootstrapperEngine.h> | 21 | #include <IBootstrapperEngine.h> |
21 | #include <IBootstrapperApplication.h> | 22 | #include <IBootstrapperApplication.h> |
22 | 23 | ||
@@ -24,7 +25,4 @@ | |||
24 | #include <balinfo.h> | 25 | #include <balinfo.h> |
25 | #include <balcondition.h> | 26 | #include <balcondition.h> |
26 | 27 | ||
27 | #include <preqba.h> | ||
28 | |||
29 | #include "WixInternalUIBootstrapperApplication.h" | 28 | #include "WixInternalUIBootstrapperApplication.h" |
30 | #include "wixiuiba.h" | ||
diff --git a/src/ext/Bal/wixiuiba/wixiuiba.cpp b/src/ext/Bal/wixiuiba/wixiuiba.cpp index 3e751893..92261e9b 100644 --- a/src/ext/Bal/wixiuiba/wixiuiba.cpp +++ b/src/ext/Bal/wixiuiba/wixiuiba.cpp | |||
@@ -2,191 +2,27 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | static INTERNAL_UI_BA_STATE vstate = { }; | ||
6 | |||
7 | |||
8 | // internal function declarations | ||
9 | |||
10 | static HRESULT LoadModulePaths( | ||
11 | __in INTERNAL_UI_BA_STATE* pState | ||
12 | ); | ||
13 | static HRESULT LoadInternalUIBAConfiguration( | ||
14 | __in INTERNAL_UI_BA_STATE* pState, | ||
15 | __in const BOOTSTRAPPER_CREATE_ARGS* pArgs | ||
16 | ); | ||
17 | static HRESULT CreatePrerequisiteBA( | ||
18 | __in INTERNAL_UI_BA_STATE* pState, | ||
19 | __in IBootstrapperEngine* pEngine, | ||
20 | __in const BOOTSTRAPPER_CREATE_ARGS* pArgs, | ||
21 | __inout BOOTSTRAPPER_CREATE_RESULTS* pResults | ||
22 | ); | ||
23 | |||
24 | 5 | ||
25 | // function definitions | 6 | // function definitions |
26 | 7 | ||
27 | extern "C" BOOL WINAPI DllMain( | 8 | EXTERN_C int WINAPI wWinMain( |
28 | __in HINSTANCE hInstance, | 9 | __in HINSTANCE hInstance, |
29 | __in DWORD dwReason, | 10 | __in_opt HINSTANCE /* hPrevInstance */, |
30 | __in LPVOID /*pvReserved*/ | 11 | __in_z_opt LPWSTR /*lpCmdLine*/, |
31 | ) | 12 | __in int /*nCmdShow*/ |
32 | { | ||
33 | switch (dwReason) | ||
34 | { | ||
35 | case DLL_PROCESS_ATTACH: | ||
36 | ::DisableThreadLibraryCalls(hInstance); | ||
37 | vstate.hInstance = hInstance; | ||
38 | break; | ||
39 | |||
40 | case DLL_PROCESS_DETACH: | ||
41 | vstate.hInstance = NULL; | ||
42 | break; | ||
43 | } | ||
44 | |||
45 | return TRUE; | ||
46 | } | ||
47 | |||
48 | // Note: This function assumes that COM was already initialized on the thread. | ||
49 | extern "C" HRESULT WINAPI BootstrapperApplicationCreate( | ||
50 | __in const BOOTSTRAPPER_CREATE_ARGS* pArgs, | ||
51 | __inout BOOTSTRAPPER_CREATE_RESULTS* pResults | ||
52 | ) | ||
53 | { | ||
54 | HRESULT hr = S_OK; | ||
55 | IBootstrapperEngine* pEngine = NULL; | ||
56 | |||
57 | hr = BalInitializeFromCreateArgs(pArgs, &pEngine); | ||
58 | ExitOnFailure(hr, "Failed to initialize Bal."); | ||
59 | |||
60 | if (!vstate.fInitialized) | ||
61 | { | ||
62 | hr = XmlInitialize(); | ||
63 | BalExitOnFailure(hr, "Failed to initialize XML."); | ||
64 | |||
65 | hr = LoadModulePaths(&vstate); | ||
66 | BalExitOnFailure(hr, "Failed to load the module paths."); | ||
67 | |||
68 | hr = LoadInternalUIBAConfiguration(&vstate, pArgs); | ||
69 | BalExitOnFailure(hr, "Failed to get the InternalUIBA configuration."); | ||
70 | |||
71 | vstate.fInitialized = TRUE; | ||
72 | } | ||
73 | |||
74 | if (vstate.prereqData.fAlwaysInstallPrereqs && !vstate.prereqData.fCompleted || | ||
75 | FAILED(vstate.prereqData.hrFatalError)) | ||
76 | { | ||
77 | BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Loading prerequisite bootstrapper application."); | ||
78 | |||
79 | hr = CreatePrerequisiteBA(&vstate, pEngine, pArgs, pResults); | ||
80 | BalExitOnFailure(hr, "Failed to create the pre-requisite bootstrapper application."); | ||
81 | } | ||
82 | else | ||
83 | { | ||
84 | hr = CreateBootstrapperApplication(vstate.hInstance, &vstate.prereqData, pEngine, pArgs, pResults, &vstate.pApplication); | ||
85 | BalExitOnFailure(hr, "Failed to create bootstrapper application interface."); | ||
86 | } | ||
87 | |||
88 | LExit: | ||
89 | ReleaseNullObject(pEngine); | ||
90 | |||
91 | return hr; | ||
92 | } | ||
93 | |||
94 | extern "C" void WINAPI BootstrapperApplicationDestroy( | ||
95 | __in const BOOTSTRAPPER_DESTROY_ARGS* pArgs, | ||
96 | __in BOOTSTRAPPER_DESTROY_RESULTS* pResults | ||
97 | ) | ||
98 | { | ||
99 | BOOTSTRAPPER_DESTROY_RESULTS childResults = { }; | ||
100 | |||
101 | if (vstate.hPrereqModule) | ||
102 | { | ||
103 | PFN_BOOTSTRAPPER_APPLICATION_DESTROY pfnDestroy = reinterpret_cast<PFN_BOOTSTRAPPER_APPLICATION_DESTROY>(::GetProcAddress(vstate.hPrereqModule, "PrereqBootstrapperApplicationDestroy")); | ||
104 | if (pfnDestroy) | ||
105 | { | ||
106 | (*pfnDestroy)(pArgs, &childResults); | ||
107 | } | ||
108 | |||
109 | ::FreeLibrary(vstate.hPrereqModule); | ||
110 | vstate.hPrereqModule = NULL; | ||
111 | } | ||
112 | |||
113 | if (vstate.pApplication) | ||
114 | { | ||
115 | DestroyBootstrapperApplication(vstate.pApplication, pArgs, pResults); | ||
116 | ReleaseNullObject(vstate.pApplication); | ||
117 | } | ||
118 | |||
119 | BalUninitialize(); | ||
120 | |||
121 | // Need to keep track of state between reloads. | ||
122 | pResults->fDisableUnloading = TRUE; | ||
123 | } | ||
124 | |||
125 | static HRESULT LoadModulePaths( | ||
126 | __in INTERNAL_UI_BA_STATE* pState | ||
127 | ) | ||
128 | { | ||
129 | HRESULT hr = S_OK; | ||
130 | LPWSTR sczFullPath = NULL; | ||
131 | |||
132 | hr = PathForCurrentProcess(&sczFullPath, pState->hInstance); | ||
133 | ExitOnFailure(hr, "Failed to get the full host path."); | ||
134 | |||
135 | hr = PathGetDirectory(sczFullPath, &pState->sczAppBase); | ||
136 | ExitOnFailure(hr, "Failed to get the directory of the full process path."); | ||
137 | |||
138 | LExit: | ||
139 | ReleaseStr(sczFullPath); | ||
140 | |||
141 | return hr; | ||
142 | } | ||
143 | |||
144 | static HRESULT LoadInternalUIBAConfiguration( | ||
145 | __in INTERNAL_UI_BA_STATE* pState, | ||
146 | __in const BOOTSTRAPPER_CREATE_ARGS* /*pArgs*/ | ||
147 | ) | 13 | ) |
148 | { | 14 | { |
149 | HRESULT hr = S_OK; | 15 | HRESULT hr = S_OK; |
16 | IBootstrapperApplication* pApplication = NULL; | ||
150 | 17 | ||
151 | pState->prereqData.fAlwaysInstallPrereqs = TRUE; | 18 | hr = CreateWixInternalUIBootstrapperApplication(hInstance, &pApplication); |
152 | pState->prereqData.fPerformHelp = TRUE; | 19 | ExitOnFailure(hr, "Failed to create WiX internal UI bootstrapper application."); |
153 | pState->prereqData.fPerformLayout = TRUE; | ||
154 | |||
155 | return hr; | ||
156 | } | ||
157 | |||
158 | static HRESULT CreatePrerequisiteBA( | ||
159 | __in INTERNAL_UI_BA_STATE* pState, | ||
160 | __in IBootstrapperEngine* pEngine, | ||
161 | __in const BOOTSTRAPPER_CREATE_ARGS* pArgs, | ||
162 | __inout BOOTSTRAPPER_CREATE_RESULTS* pResults | ||
163 | ) | ||
164 | { | ||
165 | HRESULT hr = S_OK; | ||
166 | LPWSTR sczPrereqPath = NULL; | ||
167 | HMODULE hModule = NULL; | ||
168 | |||
169 | hr = PathConcat(pState->sczAppBase, L"prereqba.dll", &sczPrereqPath); | ||
170 | BalExitOnFailure(hr, "Failed to get path to pre-requisite BA."); | ||
171 | |||
172 | hModule = ::LoadLibraryExW(sczPrereqPath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); | ||
173 | ExitOnNullWithLastError(hModule, hr, "Failed to load pre-requisite BA DLL."); | ||
174 | |||
175 | PFN_PREQ_BOOTSTRAPPER_APPLICATION_CREATE pfnCreate = reinterpret_cast<PFN_PREQ_BOOTSTRAPPER_APPLICATION_CREATE>(::GetProcAddress(hModule, "PrereqBootstrapperApplicationCreate")); | ||
176 | ExitOnNullWithLastError(pfnCreate, hr, "Failed to get PrereqBootstrapperApplicationCreate entry-point from: %ls", sczPrereqPath); | ||
177 | |||
178 | hr = pfnCreate(&pState->prereqData, pEngine, pArgs, pResults); | ||
179 | ExitOnFailure(hr, "Failed to create prequisite bootstrapper app."); | ||
180 | 20 | ||
181 | pState->hPrereqModule = hModule; | 21 | hr = BootstrapperApplicationRun(pApplication); |
182 | hModule = NULL; | 22 | ExitOnFailure(hr, "Failed to run WiX internal UI bootstrapper application."); |
183 | 23 | ||
184 | LExit: | 24 | LExit: |
185 | if (hModule) | 25 | ReleaseObject(pApplication); |
186 | { | ||
187 | ::FreeLibrary(hModule); | ||
188 | } | ||
189 | ReleaseStr(sczPrereqPath); | ||
190 | 26 | ||
191 | return hr; | 27 | return 0; |
192 | } | 28 | } |
diff --git a/src/ext/Bal/wixiuiba/wixiuiba.def b/src/ext/Bal/wixiuiba/wixiuiba.def deleted file mode 100644 index 4488df94..00000000 --- a/src/ext/Bal/wixiuiba/wixiuiba.def +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
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 | |||
4 | EXPORTS | ||
5 | BootstrapperApplicationCreate | ||
6 | BootstrapperApplicationDestroy | ||
diff --git a/src/ext/Bal/wixiuiba/wixiuiba.h b/src/ext/Bal/wixiuiba/wixiuiba.h deleted file mode 100644 index 76077f42..00000000 --- a/src/ext/Bal/wixiuiba/wixiuiba.h +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | #pragma once | ||
2 | // 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. | ||
3 | |||
4 | |||
5 | struct INTERNAL_UI_BA_STATE | ||
6 | { | ||
7 | BOOL fInitialized; | ||
8 | HINSTANCE hInstance; | ||
9 | LPWSTR sczAppBase; | ||
10 | HMODULE hPrereqModule; | ||
11 | PREQBA_DATA prereqData; | ||
12 | IBootstrapperApplication* pApplication; | ||
13 | }; | ||
diff --git a/src/ext/Bal/wixiuiba/wixiuiba.rc b/src/ext/Bal/wixiuiba/wixiuiba.rc new file mode 100644 index 00000000..a029458e --- /dev/null +++ b/src/ext/Bal/wixiuiba/wixiuiba.rc | |||
@@ -0,0 +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. | |||
diff --git a/src/ext/Bal/wixiuiba/wixiuiba.vcxproj b/src/ext/Bal/wixiuiba/wixiuiba.vcxproj index 29c7cb50..6b20db30 100644 --- a/src/ext/Bal/wixiuiba/wixiuiba.vcxproj +++ b/src/ext/Bal/wixiuiba/wixiuiba.vcxproj | |||
@@ -1,7 +1,7 @@ | |||
1 | <?xml version="1.0" encoding="utf-8"?> | 1 | <?xml version="1.0" encoding="utf-8"?> |
2 | <!-- 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 | <!-- 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. --> |
3 | 3 | ||
4 | <Project DefaultTargets="Build" Toolsxmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | 4 | <Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
5 | <ItemGroup Label="ProjectConfigurations"> | 5 | <ItemGroup Label="ProjectConfigurations"> |
6 | <ProjectConfiguration Include="Debug|ARM64"> | 6 | <ProjectConfiguration Include="Debug|ARM64"> |
7 | <Configuration>Debug</Configuration> | 7 | <Configuration>Debug</Configuration> |
@@ -31,39 +31,58 @@ | |||
31 | 31 | ||
32 | <PropertyGroup Label="Globals"> | 32 | <PropertyGroup Label="Globals"> |
33 | <ProjectGuid>{0F73E566-925C-448D-99CB-3A7F5DF399C8}</ProjectGuid> | 33 | <ProjectGuid>{0F73E566-925C-448D-99CB-3A7F5DF399C8}</ProjectGuid> |
34 | <ConfigurationType>DynamicLibrary</ConfigurationType> | 34 | <Keyword>Win32Proj</Keyword> |
35 | <ConfigurationType>Application</ConfigurationType> | ||
36 | <ProjectSubSystem>Windows</ProjectSubSystem> | ||
35 | <CharacterSet>Unicode</CharacterSet> | 37 | <CharacterSet>Unicode</CharacterSet> |
36 | <TargetName>wixiuiba</TargetName> | 38 | <Description>WiX Internal UI Bootstrapper Application</Description> |
37 | <ProjectModuleDefinitionFile>wixiuiba.def</ProjectModuleDefinitionFile> | ||
38 | </PropertyGroup> | 39 | </PropertyGroup> |
39 | 40 | ||
40 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | 41 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> |
41 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | 42 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> |
42 | 43 | ||
44 | <ImportGroup Label="ExtensionSettings"> | ||
45 | </ImportGroup> | ||
46 | |||
47 | <ImportGroup Label="Shared"> | ||
48 | </ImportGroup> | ||
49 | |||
43 | <PropertyGroup> | 50 | <PropertyGroup> |
44 | <ProjectAdditionalIncludeDirectories>..\wixstdba\inc</ProjectAdditionalIncludeDirectories> | 51 | <ProjectAdditionalIncludeDirectories>$(ProjectDir)..\stdbas\inc</ProjectAdditionalIncludeDirectories> |
45 | <ProjectAdditionalLinkLibraries>shlwapi.lib</ProjectAdditionalLinkLibraries> | 52 | <ProjectAdditionalLinkLibraries>stdbas.res</ProjectAdditionalLinkLibraries> |
46 | </PropertyGroup> | 53 | </PropertyGroup> |
47 | 54 | ||
55 | <ItemDefinitionGroup> | ||
56 | <Link> | ||
57 | <DelayLoadDLLs>version.dll</DelayLoadDLLs> | ||
58 | <AdditionalOptions>/DEPENDENTLOADFLAG:0x800 %(AdditionalOptions)</AdditionalOptions> | ||
59 | </Link> | ||
60 | </ItemDefinitionGroup> | ||
61 | |||
62 | <ItemGroup> | ||
63 | <ClInclude Include="precomp.h" /> | ||
64 | <ClInclude Include="wixiuiba.h" /> | ||
65 | </ItemGroup> | ||
48 | <ItemGroup> | 66 | <ItemGroup> |
49 | <ClCompile Include="precomp.cpp"> | 67 | <ClCompile Include="precomp.cpp"> |
50 | <PrecompiledHeader>Create</PrecompiledHeader> | 68 | <PrecompiledHeader>Create</PrecompiledHeader> |
51 | </ClCompile> | 69 | </ClCompile> |
52 | <ClCompile Include="WixInternalUIBootstrapperApplication.cpp" /> | ||
53 | <ClCompile Include="wixiuiba.cpp" /> | 70 | <ClCompile Include="wixiuiba.cpp" /> |
54 | </ItemGroup> | 71 | </ItemGroup> |
72 | |||
55 | <ItemGroup> | 73 | <ItemGroup> |
56 | <ClInclude Include="precomp.h" /> | 74 | <Manifest Include="..\stdbas\stdbas.manifest" /> |
57 | <ClInclude Include="WixInternalUIBootstrapperApplication.h" /> | 75 | <ResourceCompile Include="wixiuiba.rc" /> |
58 | <ClInclude Include="wixiuiba.h" /> | ||
59 | </ItemGroup> | 76 | </ItemGroup> |
77 | |||
60 | <ItemGroup> | 78 | <ItemGroup> |
61 | <None Include="wixiuiba.def" /> | 79 | <ProjectReference Include="..\stdbas\stdbas.vcxproj"> |
80 | <Project>{DBBF5F32-BAEA-46A8-99A0-17277A906456}</Project> | ||
81 | </ProjectReference> | ||
62 | </ItemGroup> | 82 | </ItemGroup> |
63 | 83 | ||
64 | <ItemGroup> | 84 | <ItemGroup> |
65 | <PackageReference Include="WixToolset.BalUtil" /> | 85 | <PackageReference Include="WixToolset.BalUtil" /> |
66 | |||
67 | <PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" /> | 86 | <PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" /> |
68 | </ItemGroup> | 87 | </ItemGroup> |
69 | 88 | ||