Skip to content

Commit cb437b3

Browse files
committed
Add CancelWhenDeferred, like FailWhenDeferred.
Useful for integration testing packages.
1 parent ccfda4f commit cb437b3

8 files changed

Lines changed: 63 additions & 0 deletions

File tree

src/ext/Util/ca/test.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ static LRESULT CALLBACK WndProc(
3939
);
4040

4141

42+
/******************************************************************
43+
WixCancelWhenDeferred - entry point for WixCancelWhenDeferred
44+
custom action which always cancels when running as a deferred
45+
custom action (otherwise it blindly succeeds). It's useful when
46+
testing the rollback of deferred custom actions: Schedule it
47+
immediately after the rollback/deferred CA pair you're testing
48+
and it will fail, causing your rollback CA to get invoked.
49+
********************************************************************/
50+
extern "C" UINT __stdcall WixCancelWhenDeferred(
51+
__in MSIHANDLE hInstall
52+
)
53+
{
54+
return ::MsiGetMode(hInstall, MSIRUNMODE_SCHEDULED) ? ERROR_INSTALL_USEREXIT : ERROR_SUCCESS;
55+
}
56+
4257
/******************************************************************
4358
WixFailWhenDeferred - entry point for WixFailWhenDeferred
4459
custom action which always fails when running as a deferred

src/ext/Util/ca/utilca.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ EXPORTS
8282
WixShellExecBinary
8383
WixUnelevatedShellExec
8484
; test.cpp
85+
WixCancelWhenDeferred
8586
WixFailWhenDeferred
8687
WixWaitForEvent
8788
; TouchFile.cpp
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util">
2+
<Package Name="MsiPackage" Language="1033" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a">
3+
<File Source="$(sys.SOURCEFILEPATH)" />
4+
5+
<!-- Dead or alive, you're coming with me. -->
6+
<util:FailWhenDeferred />
7+
<util:CancelWhenDeferred />
8+
</Package>
9+
</Wix>

src/ext/Util/test/WixToolsetTest.Util/UtilExtensionFixture.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,21 @@ public void CanBuildCloseApplication()
100100
}, results.OrderBy(s => s).ToArray());
101101
}
102102

103+
[TestMethod]
104+
public void CanBuildWithFailures()
105+
{
106+
var folder = TestData.Get(@"TestData\Failures");
107+
var build = new Builder(folder, typeof(UtilExtensionFactory), new[] { folder });
108+
109+
var results = build.BuildAndQuery(BuildX64, "Binary", "CustomAction");
110+
WixAssert.CompareLineByLine(
111+
[
112+
"Binary:Wix4UtilCA_X64\t[Binary data]",
113+
"CustomAction:Wix4CancelWhenDeferred_X64\t1025\tWix4UtilCA_X64\tWixCancelWhenDeferred\t",
114+
"CustomAction:Wix4FailWhenDeferred_X64\t1025\tWix4UtilCA_X64\tWixFailWhenDeferred\t",
115+
], [.. results.OrderBy(s => s)]);
116+
}
117+
103118
[TestMethod]
104119
public void CanBuildInternetShortcutInProduct()
105120
{

src/ext/Util/wixext/UtilCompiler.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ public override IComponentKeyPath ParsePossibleKeyPathElement(Intermediate inter
210210
break;
211211
case "BroadcastEnvironmentChange":
212212
case "BroadcastSettingChange":
213+
case "CancelWhenDeferred":
213214
case "CheckRebootRequired":
214215
case "ExitEarlyWithSuccess":
215216
case "FailWhenDeferred":
@@ -328,6 +329,7 @@ public override IComponentKeyPath ParsePossibleKeyPathElement(Intermediate inter
328329
{
329330
case "BroadcastEnvironmentChange":
330331
case "BroadcastSettingChange":
332+
case "CancelWhenDeferred":
331333
case "CheckRebootRequired":
332334
case "ExitEarlyWithSuccess":
333335
case "FailWhenDeferred":
@@ -363,6 +365,7 @@ private void AddCustomActionReference(Intermediate intermediate, IntermediateSec
363365
{
364366
case "BroadcastEnvironmentChange":
365367
case "BroadcastSettingChange":
368+
case "CancelWhenDeferred":
366369
case "CheckRebootRequired":
367370
case "ExitEarlyWithSuccess":
368371
case "FailWhenDeferred":

src/ext/Util/wixlib/UtilExtension_Platform.wxi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
<Include xmlns="http://wixtoolset.org/schemas/v4/wxs">
55
<?include ..\..\caDecor.wxi ?>
66

7+
<Fragment>
8+
<CustomAction Id="$(Prefix)CancelWhenDeferred$(Suffix)" DllEntry="WixCancelWhenDeferred" Execute="deferred" Return="check" SuppressModularization="yes" BinaryRef="$(Prefix)UtilCA$(Suffix)" />
9+
10+
<InstallExecuteSequence>
11+
<Custom Action="virtual $(Prefix)CancelWhenDeferred$(Suffix)" Before="InstallFinalize" Condition="WIXCANCELWHENDEFERRED=1 AND VersionNT &gt; 400" />
12+
</InstallExecuteSequence>
13+
</Fragment>
14+
715
<Fragment>
816
<CustomAction Id="$(var.Prefix)FailWhenDeferred$(var.Suffix)" DllEntry="WixFailWhenDeferred" Execute="deferred" Return="check" SuppressModularization="yes" BinaryRef="$(var.Prefix)UtilCA$(var.Suffix)" />
917

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<element name="CancelWhenDeferred">
2+
<annotation>
3+
<documentation>Schedules the CancelWhenDeferred custom action for the current platform.</documentation>
4+
<appinfo>
5+
<parent namespace="http://wixtoolset.org/schemas/v4/wxs" ref="Package" />
6+
<parent namespace="http://wixtoolset.org/schemas/v4/wxs" ref="Module" />
7+
<parent namespace="http://wixtoolset.org/schemas/v4/wxs" ref="Fragment" />
8+
<parent namespace="http://wixtoolset.org/schemas/v4/wxs" ref="UI" />
9+
</appinfo>
10+
</annotation>
11+
</element>

src/xsd/util/order.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ element|XmlFile
3333
element|XmlConfig
3434
element|BroadcastEnvironmentChange
3535
element|BroadcastSettingChange
36+
element|CancelWhenDeferred
3637
element|CheckRebootRequired
3738
element|ExitEarlyWithSuccess
3839
element|FailWhenDeferred

0 commit comments

Comments
 (0)