diff options
Diffstat (limited to 'src/samples/Dtf/EmbeddedUI/SetupWizard.xaml.cs')
-rw-r--r-- | src/samples/Dtf/EmbeddedUI/SetupWizard.xaml.cs | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/src/samples/Dtf/EmbeddedUI/SetupWizard.xaml.cs b/src/samples/Dtf/EmbeddedUI/SetupWizard.xaml.cs new file mode 100644 index 00000000..b25b8a9e --- /dev/null +++ b/src/samples/Dtf/EmbeddedUI/SetupWizard.xaml.cs | |||
@@ -0,0 +1,111 @@ | |||
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 | namespace WixToolset.Dtf.Samples.EmbeddedUI | ||
4 | { | ||
5 | using System; | ||
6 | using System.Collections.Generic; | ||
7 | using System.Linq; | ||
8 | using System.Text; | ||
9 | using System.Threading; | ||
10 | using System.Windows; | ||
11 | using System.Windows.Controls; | ||
12 | using System.Windows.Data; | ||
13 | using System.Windows.Documents; | ||
14 | using System.Windows.Input; | ||
15 | using System.Windows.Media; | ||
16 | using System.Windows.Media.Imaging; | ||
17 | using System.Windows.Navigation; | ||
18 | using System.Windows.Shapes; | ||
19 | using WixToolset.Dtf.WindowsInstaller; | ||
20 | |||
21 | /// <summary> | ||
22 | /// Interaction logic for SetupWizard.xaml | ||
23 | /// </summary> | ||
24 | public partial class SetupWizard : Window | ||
25 | { | ||
26 | private ManualResetEvent installStartEvent; | ||
27 | private InstallProgressCounter progressCounter; | ||
28 | private bool canceled; | ||
29 | |||
30 | public SetupWizard(ManualResetEvent installStartEvent) | ||
31 | { | ||
32 | this.installStartEvent = installStartEvent; | ||
33 | this.progressCounter = new InstallProgressCounter(0.5); | ||
34 | } | ||
35 | |||
36 | public MessageResult ProcessMessage(InstallMessage messageType, Record messageRecord, | ||
37 | MessageButtons buttons, MessageIcon icon, MessageDefaultButton defaultButton) | ||
38 | { | ||
39 | try | ||
40 | { | ||
41 | this.progressCounter.ProcessMessage(messageType, messageRecord); | ||
42 | this.progressBar.Value = this.progressBar.Minimum + | ||
43 | this.progressCounter.Progress * (this.progressBar.Maximum - this.progressBar.Minimum); | ||
44 | this.progressLabel.Content = "" + (int) Math.Round(100 * this.progressCounter.Progress) + "%"; | ||
45 | |||
46 | switch (messageType) | ||
47 | { | ||
48 | case InstallMessage.Error: | ||
49 | case InstallMessage.Warning: | ||
50 | case InstallMessage.Info: | ||
51 | string message = String.Format("{0}: {1}", messageType, messageRecord); | ||
52 | this.LogMessage(message); | ||
53 | break; | ||
54 | } | ||
55 | |||
56 | if (this.canceled) | ||
57 | { | ||
58 | this.canceled = false; | ||
59 | return MessageResult.Cancel; | ||
60 | } | ||
61 | } | ||
62 | catch (Exception ex) | ||
63 | { | ||
64 | this.LogMessage(ex.ToString()); | ||
65 | this.LogMessage(ex.StackTrace); | ||
66 | } | ||
67 | |||
68 | return MessageResult.OK; | ||
69 | } | ||
70 | |||
71 | private void LogMessage(string message) | ||
72 | { | ||
73 | this.messagesTextBox.Text += Environment.NewLine + message; | ||
74 | this.messagesTextBox.ScrollToEnd(); | ||
75 | } | ||
76 | |||
77 | internal void EnableExit() | ||
78 | { | ||
79 | this.progressBar.Visibility = Visibility.Hidden; | ||
80 | this.progressLabel.Visibility = Visibility.Hidden; | ||
81 | this.cancelButton.Visibility = Visibility.Hidden; | ||
82 | this.exitButton.Visibility = Visibility.Visible; | ||
83 | } | ||
84 | |||
85 | private void installButton_Click(object sender, RoutedEventArgs e) | ||
86 | { | ||
87 | this.installButton.Visibility = Visibility.Hidden; | ||
88 | this.progressBar.Visibility = Visibility.Visible; | ||
89 | this.progressLabel.Visibility = Visibility.Visible; | ||
90 | this.installStartEvent.Set(); | ||
91 | } | ||
92 | |||
93 | private void exitButton_Click(object sender, RoutedEventArgs e) | ||
94 | { | ||
95 | this.Close(); | ||
96 | } | ||
97 | |||
98 | private void cancelButton_Click(object sender, RoutedEventArgs e) | ||
99 | { | ||
100 | if (this.installButton.Visibility == Visibility.Visible) | ||
101 | { | ||
102 | this.Close(); | ||
103 | } | ||
104 | else | ||
105 | { | ||
106 | this.canceled = true; | ||
107 | this.cancelButton.IsEnabled = false; | ||
108 | } | ||
109 | } | ||
110 | } | ||
111 | } | ||