Only block shutdown during Apply.
Sean Hall committed
May 3, 2022 at 15:30 UTC
29f7e00586412163a20e298fbf84505f8a917425
25 files changed
+107
-231
src/api/burn/WixToolset.BootstrapperCore.Native/inc/BootstrapperApplication.h
-13
@@ -149,7 +149,6 @@ enum BOOTSTRAPPER_APPLICATION_MESSAGE
149
BOOTSTRAPPER_APPLICATION_MESSAGE_ONPLANCOMPLETE,
150
BOOTSTRAPPER_APPLICATION_MESSAGE_ONSTARTUP,
151
BOOTSTRAPPER_APPLICATION_MESSAGE_ONSHUTDOWN,
152
- BOOTSTRAPPER_APPLICATION_MESSAGE_ONSYSTEMSHUTDOWN,
152
BOOTSTRAPPER_APPLICATION_MESSAGE_ONDETECTFORWARDCOMPATIBLEBUNDLE,
153
BOOTSTRAPPER_APPLICATION_MESSAGE_ONDETECTUPDATEBEGIN,
154
BOOTSTRAPPER_APPLICATION_MESSAGE_ONDETECTUPDATE,
@@ -1463,18 +1462,6 @@ struct BA_ONSYSTEMRESTOREPOINTCOMPLETE_RESULTS
1462
DWORD cbSize;
1463
};
1464
1466
-struct BA_ONSYSTEMSHUTDOWN_ARGS
1467
-{
1468
- DWORD cbSize;
1469
- DWORD dwEndSession;
1470
-};
1471
-
1472
-struct BA_ONSYSTEMSHUTDOWN_RESULTS
1473
-{
1474
- DWORD cbSize;
1475
- BOOL fCancel;
1476
-};
1477
-
1465
struct BA_ONUNREGISTERBEGIN_ARGS
1466
{
1467
DWORD cbSize;
src/api/burn/WixToolset.Mba.Core/BootstrapperApplication.cs
-38
@@ -22,15 +22,12 @@ namespace WixToolset.Mba.Core
22
/// </summary>
23
protected readonly IEngine engine;
24
25
- private bool applying;
26
-
25
/// <summary>
26
/// Creates a new instance of the <see cref="BootstrapperApplication"/> class.
27
/// </summary>
28
protected BootstrapperApplication(IEngine engine)
29
{
30
this.engine = engine;
33
- this.applying = false;
31
this.asyncExecution = true;
32
}
33
@@ -40,9 +37,6 @@ namespace WixToolset.Mba.Core
37
/// <inheritdoc/>
38
public event EventHandler<ShutdownEventArgs> Shutdown;
39
43
- /// <inheritdoc/>
44
- public event EventHandler<SystemShutdownEventArgs> SystemShutdown;
45
-
40
/// <inheritdoc/>
41
public event EventHandler<DetectBeginEventArgs> DetectBegin;
42
@@ -331,25 +325,6 @@ namespace WixToolset.Mba.Core
325
}
326
}
327
334
- /// <summary>
335
- /// Called by the engine, raises the <see cref="SystemShutdown"/> event.
336
- /// </summary>
337
- /// <param name="args">Additional arguments for this event.</param>
338
- protected virtual void OnSystemShutdown(SystemShutdownEventArgs args)
339
- {
340
- EventHandler<SystemShutdownEventArgs> handler = this.SystemShutdown;
341
- if (null != handler)
342
- {
343
- handler(this, args);
344
- }
345
- else if (null != args)
346
- {
347
- // Allow requests to shut down when critical or not applying.
348
- bool critical = EndSessionReasons.Critical == (EndSessionReasons.Critical & args.Reasons);
349
- args.Cancel = !critical && this.applying;
350
- }
351
- }
352
-
328
/// <summary>
329
/// Called by the engine, raises the <see cref="DetectBegin"/> event.
330
/// </summary>
@@ -1433,15 +1408,6 @@ namespace WixToolset.Mba.Core
1408
return args.HResult;
1409
}
1410
1436
- int IBootstrapperApplication.OnSystemShutdown(EndSessionReasons dwEndSession, ref bool fCancel)
1437
- {
1438
- SystemShutdownEventArgs args = new SystemShutdownEventArgs(dwEndSession, fCancel);
1439
- this.OnSystemShutdown(args);
1440
-
1441
- fCancel = args.Cancel;
1442
- return args.HResult;
1443
- }
1444
-
1411
int IBootstrapperApplication.OnDetectBegin(bool fCached, RegistrationType registrationType, int cPackages, ref bool fCancel)
1412
{
1413
DetectBeginEventArgs args = new DetectBeginEventArgs(fCached, registrationType, cPackages, fCancel);
@@ -1693,8 +1659,6 @@ namespace WixToolset.Mba.Core
1659
1660
int IBootstrapperApplication.OnApplyBegin(int dwPhaseCount, ref bool fCancel)
1661
{
1696
- this.applying = true;
1697
-
1662
ApplyBeginEventArgs args = new ApplyBeginEventArgs(dwPhaseCount, fCancel);
1663
this.OnApplyBegin(args);
1664
@@ -1949,8 +1913,6 @@ namespace WixToolset.Mba.Core
1913
ApplyCompleteEventArgs args = new ApplyCompleteEventArgs(hrStatus, restart, recommendation, pAction);
1914
this.OnApplyComplete(args);
1915
1952
- this.applying = false;
1953
-
1916
pAction = args.Action;
1917
return args.HResult;
1918
}
src/api/burn/WixToolset.Mba.Core/EventArgs.cs
-26
@@ -216,32 +216,6 @@ namespace WixToolset.Mba.Core
216
public BOOTSTRAPPER_SHUTDOWN_ACTION Action { get; set; }
217
}
218
219
- /// <summary>
220
- /// Event arguments for <see cref="IDefaultBootstrapperApplication.SystemShutdown"/>
221
- /// </summary>
222
- [Serializable]
223
- public class SystemShutdownEventArgs : CancellableHResultEventArgs
224
- {
225
- /// <summary />
226
- public SystemShutdownEventArgs(EndSessionReasons reasons, bool cancelRecommendation)
227
- : base(cancelRecommendation)
228
- {
229
- this.Reasons = reasons;
230
- }
231
-
232
- /// <summary>
233
- /// Gets the reason the application is requested to close or being closed.
234
- /// </summary>
235
- /// <remarks>
236
- /// <para>To prevent shutting down or logging off, set <see cref="CancellableHResultEventArgs.Cancel"/> to
237
- /// true; otherwise, set it to false.</para>
238
- /// <para>If <see cref="SystemShutdownEventArgs.Reasons"/> contains <see cref="EndSessionReasons.Critical"/>
239
- /// the bootstrapper cannot prevent the shutdown and only has a few seconds to save state or perform any other
240
- /// critical operations before being closed by the operating system.</para>
241
- /// </remarks>
242
- public EndSessionReasons Reasons { get; private set; }
243
- }
244
-
219
/// <summary>
220
/// Event arguments for <see cref="IDefaultBootstrapperApplication.DetectBegin"/>
221
/// </summary>
src/api/burn/WixToolset.Mba.Core/IBootstrapperApplication.cs
-13
@@ -50,19 +50,6 @@ namespace WixToolset.Mba.Core
50
[return: MarshalAs(UnmanagedType.I4)]
51
int OnShutdown(ref BOOTSTRAPPER_SHUTDOWN_ACTION action);
52
53
- /// <summary>
54
- /// See <see cref="IDefaultBootstrapperApplication.SystemShutdown"/>.
55
- /// </summary>
56
- /// <param name="dwEndSession"></param>
57
- /// <param name="fCancel"></param>
58
- /// <returns></returns>
59
- [PreserveSig]
60
- [return: MarshalAs(UnmanagedType.I4)]
61
- int OnSystemShutdown(
62
- [MarshalAs(UnmanagedType.U4)] EndSessionReasons dwEndSession,
63
- [MarshalAs(UnmanagedType.Bool)] ref bool fCancel
64
- );
65
-
53
/// <summary>
54
/// See <see cref="IDefaultBootstrapperApplication.DetectBegin"/>.
55
/// </summary>
src/api/burn/WixToolset.Mba.Core/IDefaultBootstrapperApplication.cs
-16
@@ -418,22 +418,6 @@ namespace WixToolset.Mba.Core
418
/// </summary>
419
event EventHandler<SystemRestorePointCompleteEventArgs> SystemRestorePointComplete;
420
421
- /// <summary>
422
- /// Fired when the system is shutting down or user is logging off.
423
- /// </summary>
424
- /// <remarks>
425
- /// <para>To prevent shutting down or logging off, set <see cref="CancellableHResultEventArgs.Cancel"/> to
426
- /// true; otherwise, set it to false.</para>
427
- /// <para>By default setup will prevent shutting down or logging off between
428
- /// <see cref="IDefaultBootstrapperApplication.ApplyBegin"/> and <see cref="IDefaultBootstrapperApplication.ApplyComplete"/>.
429
- /// Derivatives can change this behavior by handling <see cref="IDefaultBootstrapperApplication.SystemShutdown"/>.</para>
430
- /// <para>If <see cref="SystemShutdownEventArgs.Reasons"/> contains <see cref="EndSessionReasons.Critical"/>
431
- /// the bootstrapper cannot prevent the shutdown and only has a few seconds to save state or perform any other
432
- /// critical operations before being closed by the operating system.</para>
433
- /// <para>This event may be fired on a different thread.</para>
434
- /// </remarks>
435
- event EventHandler<SystemShutdownEventArgs> SystemShutdown;
436
-
421
/// <summary>
422
/// Fired when the engine unregisters the bundle.
423
/// </summary>
src/api/burn/balutil/inc/BAFunctions.h
-1
@@ -15,7 +15,6 @@ enum BA_FUNCTIONS_MESSAGE
15
BA_FUNCTIONS_MESSAGE_ONPLANCOMPLETE = BOOTSTRAPPER_APPLICATION_MESSAGE_ONPLANCOMPLETE,
16
BA_FUNCTIONS_MESSAGE_ONSTARTUP = BOOTSTRAPPER_APPLICATION_MESSAGE_ONSTARTUP,
17
BA_FUNCTIONS_MESSAGE_ONSHUTDOWN = BOOTSTRAPPER_APPLICATION_MESSAGE_ONSHUTDOWN,
18
- BA_FUNCTIONS_MESSAGE_ONSYSTEMSHUTDOWN = BOOTSTRAPPER_APPLICATION_MESSAGE_ONSYSTEMSHUTDOWN,
18
BA_FUNCTIONS_MESSAGE_ONDETECTFORWARDCOMPATIBLEBUNDLE = BOOTSTRAPPER_APPLICATION_MESSAGE_ONDETECTFORWARDCOMPATIBLEBUNDLE,
19
BA_FUNCTIONS_MESSAGE_ONDETECTUPDATEBEGIN = BOOTSTRAPPER_APPLICATION_MESSAGE_ONDETECTUPDATEBEGIN,
20
BA_FUNCTIONS_MESSAGE_ONDETECTUPDATE = BOOTSTRAPPER_APPLICATION_MESSAGE_ONDETECTUPDATE,
src/api/burn/balutil/inc/BalBaseBAFunctions.h
-8
@@ -98,14 +98,6 @@ public: // IBootstrapperApplication
98
return S_OK;
99
}
100
101
- virtual STDMETHODIMP OnSystemShutdown(
102
- __in DWORD /*dwEndSession*/,
103
- __inout BOOL* /*pfCancel*/
104
- )
105
- {
106
- return S_OK;
107
- }
108
-
101
virtual STDMETHODIMP OnDetectBegin(
102
__in BOOL /*fCached*/,
103
__in BOOTSTRAPPER_REGISTRATION_TYPE /*registrationType*/,
src/api/burn/balutil/inc/BalBaseBAFunctionsProc.h
-1
@@ -86,7 +86,6 @@ static HRESULT WINAPI BalBaseBAFunctionsProc(
86
case BA_FUNCTIONS_MESSAGE_ONPLANCOMPLETE:
87
case BA_FUNCTIONS_MESSAGE_ONSTARTUP:
88
case BA_FUNCTIONS_MESSAGE_ONSHUTDOWN:
89
- case BA_FUNCTIONS_MESSAGE_ONSYSTEMSHUTDOWN:
89
case BA_FUNCTIONS_MESSAGE_ONDETECTFORWARDCOMPATIBLEBUNDLE:
90
case BA_FUNCTIONS_MESSAGE_ONDETECTUPDATEBEGIN:
91
case BA_FUNCTIONS_MESSAGE_ONDETECTUPDATE:
src/api/burn/balutil/inc/BalBaseBootstrapperApplication.h
-19
@@ -94,19 +94,6 @@ public: // IBootstrapperApplication
94
return S_OK;
95
}
96
97
- virtual STDMETHODIMP OnSystemShutdown(
98
- __in DWORD dwEndSession,
99
- __inout BOOL* pfCancel
100
- )
101
- {
102
- HRESULT hr = S_OK;
103
-
104
- // Allow requests to shut down when critical or not applying.
105
- *pfCancel = !(ENDSESSION_CRITICAL & dwEndSession || !m_fApplying);
106
-
107
- return hr;
108
- }
109
-
97
virtual STDMETHODIMP OnDetectBegin(
98
__in BOOL /*fCached*/,
99
__in BOOTSTRAPPER_REGISTRATION_TYPE /*registrationType*/,
@@ -406,8 +393,6 @@ public: // IBootstrapperApplication
393
__inout BOOL* pfCancel
394
)
395
{
409
- m_fApplying = TRUE;
410
-
396
m_dwProgressPercentage = 0;
397
m_dwOverallProgressPercentage = 0;
398
@@ -859,8 +844,6 @@ public: // IBootstrapperApplication
844
*pAction = BOOTSTRAPPER_APPLYCOMPLETE_ACTION_RESTART;
845
}
846
862
- m_fApplying = FALSE;
863
-
847
return hr;
848
}
849
@@ -1183,7 +1166,6 @@ protected:
1166
::InitializeCriticalSection(&m_csCanceled);
1167
m_fCanceled = FALSE;
1168
m_BalInfoCommand = { };
1186
- m_fApplying = FALSE;
1169
m_fRollingBack = FALSE;
1170
1171
m_dwProgressPercentage = 0;
@@ -1212,7 +1194,6 @@ private:
1194
BOOTSTRAPPER_DISPLAY m_display;
1195
IBootstrapperEngine* m_pEngine;
1196
1215
- BOOL m_fApplying;
1197
BOOL m_fRollingBack;
1198
1199
DWORD m_dwProgressPercentage;
src/api/burn/balutil/inc/BalBaseBootstrapperApplicationProc.h
-12
@@ -63,15 +63,6 @@ static HRESULT BalBaseBAProcOnShutdown(
63
return pBA->OnShutdown(&pResults->action);
64
}
65
66
-static HRESULT BalBaseBAProcOnSystemShutdown(
67
- __in IBootstrapperApplication* pBA,
68
- __in BA_ONSYSTEMSHUTDOWN_ARGS* pArgs,
69
- __inout BA_ONSYSTEMSHUTDOWN_RESULTS* pResults
70
- )
71
-{
72
- return pBA->OnSystemShutdown(pArgs->dwEndSession, &pResults->fCancel);
73
-}
74
-
66
static HRESULT BalBaseBAProcOnDetectForwardCompatibleBundle(
67
__in IBootstrapperApplication* pBA,
68
__in BA_ONDETECTFORWARDCOMPATIBLEBUNDLE_ARGS* pArgs,
@@ -803,9 +794,6 @@ static HRESULT WINAPI BalBaseBootstrapperApplicationProc(
794
case BOOTSTRAPPER_APPLICATION_MESSAGE_ONSHUTDOWN:
795
hr = BalBaseBAProcOnShutdown(pBA, reinterpret_cast<BA_ONSHUTDOWN_ARGS*>(pvArgs), reinterpret_cast<BA_ONSHUTDOWN_RESULTS*>(pvResults));
796
break;
806
- case BOOTSTRAPPER_APPLICATION_MESSAGE_ONSYSTEMSHUTDOWN:
807
- hr = BalBaseBAProcOnSystemShutdown(pBA, reinterpret_cast<BA_ONSYSTEMSHUTDOWN_ARGS*>(pvArgs), reinterpret_cast<BA_ONSYSTEMSHUTDOWN_RESULTS*>(pvResults));
808
- break;
797
case BOOTSTRAPPER_APPLICATION_MESSAGE_ONDETECTFORWARDCOMPATIBLEBUNDLE:
798
hr = BalBaseBAProcOnDetectForwardCompatibleBundle(pBA, reinterpret_cast<BA_ONDETECTFORWARDCOMPATIBLEBUNDLE_ARGS*>(pvArgs), reinterpret_cast<BA_ONDETECTFORWARDCOMPATIBLEBUNDLE_RESULTS*>(pvResults));
799
break;
src/api/burn/balutil/inc/IBootstrapperApplication.h
-6
@@ -33,12 +33,6 @@ DECLARE_INTERFACE_IID_(IBootstrapperApplication, IUnknown, "53C31D56-49C0-426B-A
33
__inout BOOTSTRAPPER_SHUTDOWN_ACTION* pAction
34
) = 0;
35
36
- // OnSystemShutdown - called when the operating system is instructed to shutdown the machine.
37
- STDMETHOD(OnSystemShutdown)(
38
- __in DWORD dwEndSession,
39
- __inout BOOL* pfCancel
40
- ) = 0;
41
-
36
// OnDetectBegin - called when the engine begins detection.
37
STDMETHOD(OnDetectBegin)(
38
__in BOOL fCached,
src/burn/engine/core.cpp
+4
@@ -681,6 +681,8 @@ extern "C" HRESULT CoreApply(
681
hr = ApplyLock(FALSE, &hLock);
682
ExitOnFailure(hr, "Another per-user setup is already executing.");
683
684
+ pEngineState->plan.fApplying = TRUE;
685
+
686
// Initialize only after getting a lock.
687
fApplyInitialize = TRUE;
688
ApplyInitialize();
@@ -814,6 +816,8 @@ LExit:
816
ApplyUninitialize();
817
}
818
819
+ pEngineState->plan.fApplying = FALSE;
820
+
821
if (hLock)
822
{
823
::ReleaseMutex(hLock);
src/burn/engine/elevation.cpp
+16
-5
@@ -94,6 +94,7 @@ typedef struct _BURN_ELEVATION_CHILD_MESSAGE_CONTEXT
94
HANDLE hPipe;
95
HANDLE* phLock;
96
BOOL* pfDisabledAutomaticUpdates;
97
+ BOOL* pfApplying;
98
BURN_APPROVED_EXES* pApprovedExes;
99
BURN_CACHE* pCache;
100
BURN_CONTAINERS* pContainers;
@@ -176,6 +177,7 @@ static HRESULT OnApplyInitialize(
177
__in BURN_PACKAGES* pPackages,
178
__in HANDLE* phLock,
179
__in BOOL* pfDisabledWindowsUpdate,
180
+ __in BOOL* pfApplying,
181
__in BYTE* pbData,
182
__in SIZE_T cbData
183
);
@@ -185,7 +187,8 @@ static HRESULT ElevatedProcessDetect(
187
__in BURN_PACKAGES* pPackages
188
);
189
static HRESULT OnApplyUninitialize(
188
- __in HANDLE* phLock
190
+ __in HANDLE* phLock,
191
+ __in BOOL* pfApplying
192
);
193
static HRESULT OnSessionBegin(
194
__in BURN_CACHE* pCache,
@@ -1538,7 +1541,8 @@ extern "C" HRESULT ElevationChildPumpMessages(
1541
__out HANDLE* phLock,
1542
__out BOOL* pfDisabledAutomaticUpdates,
1543
__out DWORD* pdwChildExitCode,
1541
- __out BOOL* pfRestart
1544
+ __out BOOL* pfRestart,
1545
+ __out BOOL* pfApplying
1546
)
1547
{
1548
HRESULT hr = S_OK;
@@ -1561,6 +1565,7 @@ extern "C" HRESULT ElevationChildPumpMessages(
1565
context.hPipe = hPipe;
1566
context.phLock = phLock;
1567
context.pfDisabledAutomaticUpdates = pfDisabledAutomaticUpdates;
1568
+ context.pfApplying = pfApplying;
1569
context.pApprovedExes = pApprovedExes;
1570
context.pCache = pCache;
1571
context.pContainers = pContainers;
@@ -2114,11 +2119,11 @@ static HRESULT ProcessElevatedChildMessage(
2119
break;
2120
2121
case BURN_ELEVATION_MESSAGE_TYPE_APPLY_INITIALIZE:
2117
- hrResult = OnApplyInitialize(pContext->hPipe, pContext->pVariables, pContext->pRegistration, pContext->pPackages, pContext->phLock, pContext->pfDisabledAutomaticUpdates, (BYTE*)pMsg->pvData, pMsg->cbData);
2122
+ hrResult = OnApplyInitialize(pContext->hPipe, pContext->pVariables, pContext->pRegistration, pContext->pPackages, pContext->phLock, pContext->pfDisabledAutomaticUpdates, pContext->pfApplying, (BYTE*)pMsg->pvData, pMsg->cbData);
2123
break;
2124
2125
case BURN_ELEVATION_MESSAGE_TYPE_APPLY_UNINITIALIZE:
2121
- hrResult = OnApplyUninitialize(pContext->phLock);
2126
+ hrResult = OnApplyUninitialize(pContext->phLock, pContext->pfApplying);
2127
break;
2128
2129
case BURN_ELEVATION_MESSAGE_TYPE_SESSION_BEGIN:
@@ -2267,6 +2272,7 @@ static HRESULT OnApplyInitialize(
2272
__in BURN_PACKAGES* pPackages,
2273
__in HANDLE* phLock,
2274
__in BOOL* pfDisabledWindowsUpdate,
2275
+ __in BOOL* pfApplying,
2276
__in BYTE* pbData,
2277
__in SIZE_T cbData
2278
)
@@ -2296,6 +2302,8 @@ static HRESULT OnApplyInitialize(
2302
hr = ApplyLock(TRUE, phLock);
2303
ExitOnFailure(hr, "Failed to acquire lock due to setup in other session.");
2304
2305
+ *pfApplying = TRUE;
2306
+
2307
// Detect.
2308
hr = ElevatedProcessDetect(pRegistration, pVariables, pPackages);
2309
ExitOnFailure(hr, "Failed to run detection in elevated process.");
@@ -2419,13 +2427,16 @@ LExit:
2427
}
2428
2429
static HRESULT OnApplyUninitialize(
2422
- __in HANDLE* phLock
2430
+ __in HANDLE* phLock,
2431
+ __in BOOL* pfApplying
2432
)
2433
{
2434
Assert(phLock);
2435
2436
// TODO: end system restore point.
2437
2438
+ *pfApplying = FALSE;
2439
+
2440
if (*phLock)
2441
{
2442
::ReleaseMutex(*phLock);
src/burn/engine/elevation.h
+2
-1
@@ -180,7 +180,8 @@ HRESULT ElevationChildPumpMessages(
180
__out HANDLE* phLock,
181
__out BOOL* pfDisabledAutomaticUpdates,
182
__out DWORD* pdwChildExitCode,
183
- __out BOOL* pfRestart
183
+ __out BOOL* pfRestart,
184
+ __out BOOL* pfApplying
185
);
186
HRESULT ElevationChildResumeAutomaticUpdates();
187
src/burn/engine/engine.cpp
+1
-1
@@ -653,7 +653,7 @@ static HRESULT RunElevated(
653
SrpInitialize(TRUE);
654
655
// Pump messages from parent process.
656
- hr = ElevationChildPumpMessages(pEngineState->dwElevatedLoggingTlsId, pEngineState->companionConnection.hPipe, pEngineState->companionConnection.hCachePipe, &pEngineState->approvedExes, &pEngineState->cache, &pEngineState->containers, &pEngineState->packages, &pEngineState->payloads, &pEngineState->variables, &pEngineState->registration, &pEngineState->userExperience, &hLock, &fDisabledAutomaticUpdates, &pEngineState->userExperience.dwExitCode, &pEngineState->fRestart);
656
+ hr = ElevationChildPumpMessages(pEngineState->dwElevatedLoggingTlsId, pEngineState->companionConnection.hPipe, pEngineState->companionConnection.hCachePipe, &pEngineState->approvedExes, &pEngineState->cache, &pEngineState->containers, &pEngineState->packages, &pEngineState->payloads, &pEngineState->variables, &pEngineState->registration, &pEngineState->userExperience, &hLock, &fDisabledAutomaticUpdates, &pEngineState->userExperience.dwExitCode, &pEngineState->fRestart, &pEngineState->plan.fApplying);
657
LogRedirect(NULL, NULL); // reset logging so the next failure gets written to "log buffer" for the failure log.
658
ExitOnFailure(hr, "Failed to pump messages from parent process.");
659
src/burn/engine/plan.h
+1
@@ -264,6 +264,7 @@ typedef struct _BURN_PLAN
264
LPWSTR sczLayoutDirectory;
265
BOOL fPlanPackageCacheRollback;
266
BOOL fDowngrade;
267
+ BOOL fApplying;
268
269
DWORD64 qwCacheSizeTotal;
270
src/burn/engine/uithread.cpp
+7
-13
@@ -17,8 +17,7 @@ struct UITHREAD_CONTEXT
17
struct UITHREAD_INFO
18
{
19
BOOL fElevatedEngine;
20
- BURN_USER_EXPERIENCE* pUserExperience;
21
- BOOL* pfCriticalShutdownInitiated;
20
+ BURN_ENGINE_STATE* pEngineState;
21
};
22
23
@@ -132,8 +131,7 @@ static DWORD WINAPI ThreadProc(
131
fRegistered = TRUE;
132
133
info.fElevatedEngine = fElevatedEngine;
135
- info.pUserExperience = &pEngineState->userExperience;
136
- info.pfCriticalShutdownInitiated = &pEngineState->fCriticalShutdownInitiated;
134
+ info.pEngineState = pEngineState;
135
136
// Create the window to handle reboots without activating it.
137
hWnd = ::CreateWindowExW(WS_EX_NOACTIVATE, wc.lpszClassName, NULL, WS_POPUP, 0, 0, 0, 0, HWND_DESKTOP, NULL, pContext->hInstance, &info);
@@ -196,21 +194,17 @@ static LRESULT CALLBACK WndProc(
194
{
195
DWORD dwEndSession = static_cast<DWORD>(lParam);
196
BOOL fCritical = ENDSESSION_CRITICAL & dwEndSession;
199
- BOOL fCancel = TRUE;
197
+ BOOL fCancel = FALSE;
198
BOOL fRet = FALSE;
199
202
- // Always block shutdown in the elevated process, but ask the BA in the non-elevated.
200
+ // Always block shutdown during apply.
201
UITHREAD_INFO* pInfo = reinterpret_cast<UITHREAD_INFO*>(::GetWindowLongPtrW(hWnd, GWLP_USERDATA));
204
- if (!pInfo->fElevatedEngine)
202
+ if (pInfo->pEngineState->plan.fApplying)
203
{
206
- // TODO: instead of recommending canceling all non-critical shutdowns, maybe we should only recommend cancel
207
- // when the engine is doing work?
208
- fCancel = !fCritical;
209
- // TODO: There's a race condition here where the BA may not have been loaded, or already was unloaded.
210
- UserExperienceOnSystemShutdown(pInfo->pUserExperience, dwEndSession, &fCancel);
204
+ fCancel = TRUE;
205
}
206
213
- *pInfo->pfCriticalShutdownInitiated |= fCritical;
207
+ pInfo->pEngineState->fCriticalShutdownInitiated |= fCritical;
208
209
fRet = !fCancel;
210
LogId(REPORT_STANDARD, MSG_SYSTEM_SHUTDOWN, LoggingBoolToString(fCritical), LoggingBoolToString(pInfo->fElevatedEngine), LoggingBoolToString(fRet));
src/burn/engine/userexperience.cpp
-25
@@ -2631,31 +2631,6 @@ LExit:
2631
return hr;
2632
}
2633
2634
-EXTERN_C BAAPI UserExperienceOnSystemShutdown(
2635
- __in BURN_USER_EXPERIENCE* pUserExperience,
2636
- __in DWORD dwEndSession,
2637
- __inout BOOL* pfCancel
2638
- )
2639
-{
2640
- HRESULT hr = S_OK;
2641
- BA_ONSYSTEMSHUTDOWN_ARGS args = { };
2642
- BA_ONSYSTEMSHUTDOWN_RESULTS results = { };
2643
-
2644
- args.cbSize = sizeof(args);
2645
- args.dwEndSession = dwEndSession;
2646
-
2647
- results.cbSize = sizeof(results);
2648
- results.fCancel = *pfCancel;
2649
-
2650
- hr = SendBAMessage(pUserExperience, BOOTSTRAPPER_APPLICATION_MESSAGE_ONSYSTEMSHUTDOWN, &args, &results);
2651
- ExitOnFailure(hr, "BA OnSystemShutdown failed.");
2652
-
2653
- *pfCancel = results.fCancel;
2654
-
2655
-LExit:
2656
- return hr;
2657
-}
2658
-
2634
EXTERN_C BAAPI UserExperienceOnUnregisterBegin(
2635
__in BURN_USER_EXPERIENCE* pUserExperience,
2636
__inout BOOTSTRAPPER_REGISTRATION_TYPE* pRegistrationType
src/burn/engine/userexperience.h
-5
@@ -583,11 +583,6 @@ BAAPI UserExperienceOnSystemRestorePointComplete(
583
__in BURN_USER_EXPERIENCE* pUserExperience,
584
__in HRESULT hrStatus
585
);
586
-BAAPI UserExperienceOnSystemShutdown(
587
- __in BURN_USER_EXPERIENCE* pUserExperience,
588
- __in DWORD dwEndSession,
589
- __inout BOOL* pfCancel
590
- );
586
BAAPI UserExperienceOnUnregisterBegin(
587
__in BURN_USER_EXPERIENCE* pUserExperience,
588
__inout BOOTSTRAPPER_REGISTRATION_TYPE* pRegistrationType
src/ext/Bal/wixstdba/WixStandardBootstrapperApplication.cpp
-17
@@ -1265,9 +1265,6 @@ public: // IBootstrapperApplication
1265
case BOOTSTRAPPER_APPLICATION_MESSAGE_ONSHUTDOWN:
1266
OnShutdownFallback(reinterpret_cast<BA_ONSHUTDOWN_ARGS*>(pvArgs), reinterpret_cast<BA_ONSHUTDOWN_RESULTS*>(pvResults));
1267
break;
1268
- case BOOTSTRAPPER_APPLICATION_MESSAGE_ONSYSTEMSHUTDOWN:
1269
- OnSystemShutdownFallback(reinterpret_cast<BA_ONSYSTEMSHUTDOWN_ARGS*>(pvArgs), reinterpret_cast<BA_ONSYSTEMSHUTDOWN_RESULTS*>(pvResults));
1270
- break;
1268
case BOOTSTRAPPER_APPLICATION_MESSAGE_ONDETECTFORWARDCOMPATIBLEBUNDLE:
1269
OnDetectForwardCompatibleBundleFallback(reinterpret_cast<BA_ONDETECTFORWARDCOMPATIBLEBUNDLE_ARGS*>(pvArgs), reinterpret_cast<BA_ONDETECTFORWARDCOMPATIBLEBUNDLE_RESULTS*>(pvResults));
1270
break;
@@ -1544,14 +1541,6 @@ private: // privates
1541
m_pfnBAFunctionsProc(BA_FUNCTIONS_MESSAGE_ONSHUTDOWN, pArgs, pResults, m_pvBAFunctionsProcContext);
1542
}
1543
1547
- void OnSystemShutdownFallback(
1548
- __in BA_ONSYSTEMSHUTDOWN_ARGS* pArgs,
1549
- __inout BA_ONSYSTEMSHUTDOWN_RESULTS* pResults
1550
- )
1551
- {
1552
- m_pfnBAFunctionsProc(BA_FUNCTIONS_MESSAGE_ONSYSTEMSHUTDOWN, pArgs, pResults, m_pvBAFunctionsProcContext);
1553
- }
1554
-
1544
void OnDetectForwardCompatibleBundleFallback(
1545
__in BA_ONDETECTFORWARDCOMPATIBLEBUNDLE_ARGS* pArgs,
1546
__inout BA_ONDETECTFORWARDCOMPATIBLEBUNDLE_RESULTS* pResults
@@ -2948,7 +2937,6 @@ private:
2937
{
2938
#pragma warning(suppress:4312)
2939
CWixStandardBootstrapperApplication* pBA = reinterpret_cast<CWixStandardBootstrapperApplication*>(::GetWindowLongPtrW(hWnd, GWLP_USERDATA));
2951
- BOOL fCancel = FALSE;
2940
2941
switch (uMsg)
2942
{
@@ -2975,11 +2963,6 @@ private:
2963
case WM_THMUTIL_LOADED_CONTROL:
2964
return pBA->OnThemeLoadedControl(reinterpret_cast<THEME_LOADEDCONTROL_ARGS*>(wParam), reinterpret_cast<THEME_LOADEDCONTROL_RESULTS*>(lParam));
2965
2978
- case WM_QUERYENDSESSION:
2979
- fCancel = true;
2980
- pBA->OnSystemShutdown(static_cast<DWORD>(lParam), &fCancel);
2981
- return !fCancel;
2982
-
2966
case WM_CLOSE:
2967
// If the user chose not to close, do *not* let the default window proc handle the message.
2968
if (!pBA->OnClose())
src/test/burn/TestBA/TestBA.cs
-9
@@ -531,15 +531,6 @@ namespace WixToolset.Test.BA
531
this.ShutdownUiThread();
532
}
533
534
- protected override void OnSystemShutdown(SystemShutdownEventArgs args)
535
- {
536
- // Always prevent shutdown.
537
- this.Log("Disallowed system request to shut down the bootstrapper application.");
538
- args.Cancel = true;
539
-
540
- this.ShutdownUiThread();
541
- }
542
-
534
protected override void OnUnregisterBegin(UnregisterBeginEventArgs args)
535
{
536
if (this.forceKeepRegistration && args.RegistrationType == RegistrationType.None)
src/test/burn/TestData/Manual/BafThmutilTesting/BafThmUtilTesting.cpp
+52
@@ -88,6 +88,56 @@ public: // IBAFunctions
88
return hr;
89
}
90
91
+ virtual STDMETHODIMP WndProc(
92
+ __in HWND hWnd,
93
+ __in UINT uMsg,
94
+ __in WPARAM /*wParam*/,
95
+ __in LPARAM lParam,
96
+ __inout BOOL* pfProcessed,
97
+ __inout LRESULT* plResult
98
+ )
99
+ {
100
+ switch (uMsg)
101
+ {
102
+ case WM_QUERYENDSESSION:
103
+ if (BOOTSTRAPPER_DISPLAY_FULL <= m_command.display)
104
+ {
105
+ DWORD dwEndSession = static_cast<DWORD>(lParam);
106
+ if (ENDSESSION_CRITICAL & dwEndSession)
107
+ {
108
+ // Return false to get the WM_ENDSESSION message so that critical shutdowns can be delayed.
109
+ *plResult = FALSE;
110
+ *pfProcessed = TRUE;
111
+ }
112
+ }
113
+ break;
114
+ case WM_ENDSESSION:
115
+ if (BOOTSTRAPPER_DISPLAY_FULL <= m_command.display)
116
+ {
117
+ ::MessageBoxW(hWnd, L"WM_ENDSESSION", L"BAFunctions WndProc", MB_OK);
118
+ }
119
+ break;
120
+ }
121
+ return S_OK;
122
+ }
123
+
124
+public: //IBootstrapperApplication
125
+ virtual STDMETHODIMP OnExecuteBegin(
126
+ __in DWORD /*cExecutingPackages*/,
127
+ __inout BOOL* pfCancel
128
+ )
129
+ {
130
+ if (BOOTSTRAPPER_DISPLAY_FULL <= m_command.display)
131
+ {
132
+ if (IDCANCEL == ::MessageBoxW(m_hwndParent, L"Shutdown requests should be denied right now.", L"OnExecuteBegin", MB_OKCANCEL))
133
+ {
134
+ *pfCancel = TRUE;
135
+ }
136
+ }
137
+
138
+ return S_OK;
139
+ }
140
+
141
private:
142
HRESULT OnShowTheme()
143
{
@@ -138,6 +188,8 @@ private:
188
189
ThemeInitializeWindowClass(m_pBafTheme, &wc, CBafThmUtilTesting::TestingWndProc, m_hModule, BAFTHMUTILTESTING_WINDOW_CLASS);
190
191
+ Assert(wc.lpszClassName);
192
+
193
// If the theme did not provide an icon, try using the icon from the bundle engine.
194
if (!wc.hIcon)
195
{
src/test/burn/TestData/Manual/BundleA/BundleA.wxs
+5
-2
@@ -1,4 +1,4 @@
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. -->
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
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:bal="http://wixtoolset.org/schemas/v4/wxs/bal">
@@ -8,7 +8,10 @@
8
<Payload SourceFile="$(var.BafThmUtilTesting.TargetPath)" bal:BAFunctions="yes" />
9
</BootstrapperApplication>
10
<PackageGroup Id="BundlePackages">
11
- <MsiPackage Id="PackageA" SourceFile="$(var.PackageA.TargetPath)" />
11
+ <MsiPackage Id="PackageA" SourceFile="$(var.PackageA.TargetPath)">
12
+ <MsiProperty Name="FORCERESTARTCA" Value="[FORCERESTARTCA]" />
13
+ </MsiPackage>
14
</PackageGroup>
15
+ <Variable Name="FORCERESTARTCA" bal:Overridable="yes" />
16
</Fragment>
17
</Wix>
src/test/burn/TestData/Manual/PackageA/PackageA.wixproj
+4
@@ -2,8 +2,12 @@
2
<Project Sdk="WixToolset.Sdk">
3
<PropertyGroup>
4
<UpgradeCode>{0D803A6E-8090-4174-8DAC-810ECC2B1BBF}</UpgradeCode>
5
+ <ProductComponentsRef>true</ProductComponentsRef>
6
</PropertyGroup>
7
<ItemGroup>
8
<Compile Include="..\..\Templates\Package.wxs" Link="Package.wxs" />
9
</ItemGroup>
10
+ <ItemGroup>
11
+ <PackageReference Include="WixToolset.Util.wixext" />
12
+ </ItemGroup>
13
</Project>
\ No newline at end of file
src/test/burn/TestData/Manual/PackageA/ProductA.wxs
new
+15
@@ -0,0 +1,15 @@
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
+<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util">
4
+ <Fragment>
5
+ <ComponentGroup Id="ProductComponents" />
6
+
7
+ <Property Id="FORCERESTARTCA" Secure="yes" />
8
+ <Property Id="ForceRestartCA" Value=""shutdown.exe" -r -f -t 0" />
9
+ <CustomAction Id="ForceRestartCA" DllEntry="WixQuietExec" BinaryRef="Wix4UtilCA_X86" Execute="deferred" Return="ignore" />
10
+
11
+ <InstallExecuteSequence>
12
+ <Custom Action="ForceRestartCA" After="InstallFiles" Condition="FORCERESTARTCA = 1" />
13
+ </InstallExecuteSequence>
14
+ </Fragment>
15
+</Wix>