summaryrefslogtreecommitdiff
path: root/src/test/dtf/EmbeddedUI/SampleEmbeddedUI.cs
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2022-03-31 11:56:14 -0700
committerRob Mensching <rob@firegiant.com>2022-03-31 18:01:06 -0700
commit47582b162368e8edf7a3b11c13b8e9dabc5f0a26 (patch)
tree2c4063eff325684bed39de0edacd7866a257ae02 /src/test/dtf/EmbeddedUI/SampleEmbeddedUI.cs
parent167296c42497c4e95f0d5d71168542d747655981 (diff)
downloadwix-47582b162368e8edf7a3b11c13b8e9dabc5f0a26.tar.gz
wix-47582b162368e8edf7a3b11c13b8e9dabc5f0a26.tar.bz2
wix-47582b162368e8edf7a3b11c13b8e9dabc5f0a26.zip
Provide managed CA and Embedded UI DTF libraries via NuGet
Lots of refactoring to bring the SFX tooling back into the 'dtf' layer since they are (in the end) tightly coupled to some DTF assemblies. Also refactored the DTF tests into their own folder and added a couple integration tests to build using the new CA/UI NuGet package. Closes wixtoolset/issues#6080
Diffstat (limited to 'src/test/dtf/EmbeddedUI/SampleEmbeddedUI.cs')
-rw-r--r--src/test/dtf/EmbeddedUI/SampleEmbeddedUI.cs130
1 files changed, 130 insertions, 0 deletions
diff --git a/src/test/dtf/EmbeddedUI/SampleEmbeddedUI.cs b/src/test/dtf/EmbeddedUI/SampleEmbeddedUI.cs
new file mode 100644
index 00000000..b9cd213a
--- /dev/null
+++ b/src/test/dtf/EmbeddedUI/SampleEmbeddedUI.cs
@@ -0,0 +1,130 @@
1namespace WixToolset.Samples.EmbeddedUI
2{
3 using System;
4 using System.Collections.Generic;
5 using System.Configuration;
6 using System.Threading;
7 using System.Windows;
8 using System.Windows.Threading;
9 using WixToolset.Dtf.WindowsInstaller;
10 using Application = System.Windows.Application;
11
12 public class SampleEmbeddedUI : IEmbeddedUI
13 {
14 private Thread appThread;
15 private Application app;
16 private SetupWizard setupWizard;
17 private ManualResetEvent installStartEvent;
18 private ManualResetEvent installExitEvent;
19
20 /// <summary>
21 /// Initializes the embedded UI.
22 /// </summary>
23 /// <param name="session">Handle to the installer which can be used to get and set properties.
24 /// The handle is only valid for the duration of this method call.</param>
25 /// <param name="resourcePath">Path to the directory that contains all the files from the MsiEmbeddedUI table.</param>
26 /// <param name="internalUILevel">On entry, contains the current UI level for the installation. After this
27 /// method returns, the installer resets the UI level to the returned value of this parameter.</param>
28 /// <returns>True if the embedded UI was successfully initialized; false if the installation
29 /// should continue without the embedded UI.</returns>
30 /// <exception cref="InstallCanceledException">The installation was canceled by the user.</exception>
31 /// <exception cref="InstallerException">The embedded UI failed to initialize and
32 /// causes the installation to fail.</exception>
33 public bool Initialize(Session session, string resourcePath, ref InstallUIOptions internalUILevel)
34 {
35 if (session != null)
36 {
37 if ((internalUILevel & InstallUIOptions.Full) != InstallUIOptions.Full)
38 {
39 // Don't show custom UI when the UI level is set to basic.
40 return false;
41
42 // An embedded UI could display an alternate dialog sequence for reduced or
43 // basic modes, but it's not implemented here. We'll just fall back to the
44 // built-in MSI basic UI.
45 }
46
47 if (String.Equals(session["REMOVE"], "All", StringComparison.OrdinalIgnoreCase))
48 {
49 // Don't show custom UI when uninstalling.
50 return false;
51
52 // An embedded UI could display an uninstall wizard, it's just not imlemented here.
53 }
54 }
55
56 // Start the setup wizard on a separate thread.
57 this.installStartEvent = new ManualResetEvent(false);
58 this.installExitEvent = new ManualResetEvent(false);
59 this.appThread = new Thread(this.Run);
60 this.appThread.SetApartmentState(ApartmentState.STA);
61 this.appThread.Start();
62
63 // Wait for the setup wizard to either kickoff the install or prematurely exit.
64 int waitResult = WaitHandle.WaitAny(new WaitHandle[] { this.installStartEvent, this.installExitEvent });
65 if (waitResult == 1)
66 {
67 // The setup wizard set the exit event instead of the start event. Cancel the installation.
68 throw new InstallCanceledException();
69 }
70 else
71 {
72 // Start the installation with a silenced internal UI.
73 // This "embedded external UI" will handle message types except for source resolution.
74 internalUILevel = InstallUIOptions.NoChange | InstallUIOptions.SourceResolutionOnly;
75 return true;
76 }
77 }
78
79 /// <summary>
80 /// Processes information and progress messages sent to the user interface.
81 /// </summary>
82 /// <param name="messageType">Message type.</param>
83 /// <param name="messageRecord">Record that contains message data.</param>
84 /// <param name="buttons">Message box buttons.</param>
85 /// <param name="icon">Message box icon.</param>
86 /// <param name="defaultButton">Message box default button.</param>
87 /// <returns>Result of processing the message.</returns>
88 public MessageResult ProcessMessage(InstallMessage messageType, Record messageRecord,
89 MessageButtons buttons, MessageIcon icon, MessageDefaultButton defaultButton)
90 {
91 // Synchronously send the message to the setup wizard window on its thread.
92 object result = this.setupWizard.Dispatcher.Invoke(DispatcherPriority.Send,
93 new Func<MessageResult>(delegate()
94 {
95 return this.setupWizard.ProcessMessage(messageType, messageRecord, buttons, icon, defaultButton);
96 }));
97 return (MessageResult) result;
98 }
99
100 /// <summary>
101 /// Shuts down the embedded UI at the end of the installation.
102 /// </summary>
103 /// <remarks>
104 /// If the installation was canceled during initialization, this method will not be called.
105 /// If the installation was canceled or failed at any later point, this method will be called at the end.
106 /// </remarks>
107 public void Shutdown()
108 {
109 // Wait for the user to exit the setup wizard.
110 this.setupWizard.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
111 new Action(delegate()
112 {
113 this.setupWizard.EnableExit();
114 }));
115 this.appThread.Join();
116 }
117
118 /// <summary>
119 /// Creates the setup wizard and runs the application thread.
120 /// </summary>
121 private void Run()
122 {
123 this.app = new Application();
124 this.setupWizard = new SetupWizard(this.installStartEvent);
125 this.setupWizard.InitializeComponent();
126 this.app.Run(this.setupWizard);
127 this.installExitEvent.Set();
128 }
129 }
130}