main
cs 225 lines 6.39 KB
Raw
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.WixBA
4 {
5 using System;
6 using System.Windows;
7 using System.Windows.Input;
8 using System.Windows.Threading;
9 using WixToolset.BootstrapperApplicationApi;
10
11 /// <summary>
12 /// The errors returned from the engine
13 /// </summary>
14 public enum Error
15 {
16 UserCancelled = 1223,
17 }
18
19 /// <summary>
20 /// The model of the root view in WixBA.
21 /// </summary>
22 public class RootViewModel : PropertyNotifyBase
23 {
24 private ICommand cancelCommand;
25 private ICommand closeCommand;
26
27 private bool canceled;
28 private InstallationState installState;
29 private DetectionState detectState;
30 private UpgradeDetectionState upgradeDetectState;
31
32 /// <summary>
33 /// Creates a new model of the root view.
34 /// </summary>
35 public RootViewModel()
36 {
37 this.InstallationViewModel = new InstallationViewModel(this);
38 this.ProgressViewModel = new ProgressViewModel(this);
39 this.UpdateViewModel = new UpdateViewModel(this);
40 }
41
42 public InstallationViewModel InstallationViewModel { get; private set; }
43 public ProgressViewModel ProgressViewModel { get; private set; }
44 public UpdateViewModel UpdateViewModel { get; private set; }
45 public Dispatcher Dispatcher { get; set; }
46 public IntPtr ViewWindowHandle { get; set; }
47 public bool AutoClose { get; set; }
48
49 public ICommand CloseCommand
50 {
51 get
52 {
53 if (this.closeCommand == null)
54 {
55 this.closeCommand = new RelayCommand(param => WixBA.View.Close());
56 }
57
58 return this.closeCommand;
59 }
60 }
61
62 public ICommand CancelCommand
63 {
64 get
65 {
66 if (this.cancelCommand == null)
67 {
68 this.cancelCommand = new RelayCommand(param =>
69 {
70 this.CancelButton_Click();
71 },
72 param => !this.Canceled);
73 }
74
75 return this.cancelCommand;
76 }
77 }
78
79 public bool CancelAvailable
80 {
81 get { return InstallationState.Applying == this.InstallState; }
82 }
83
84 public bool Canceled
85 {
86 get
87 {
88 return this.canceled;
89 }
90
91 set
92 {
93 if (this.canceled != value)
94 {
95 this.canceled = value;
96 base.OnPropertyChanged("Canceled");
97 }
98 }
99 }
100
101 /// <summary>
102 /// Gets and sets the detect state of the view's model.
103 /// </summary>
104 public DetectionState DetectState
105 {
106 get
107 {
108 return this.detectState;
109 }
110
111 set
112 {
113 if (this.detectState != value)
114 {
115 this.detectState = value;
116
117 // Notify all the properties derived from the state that the state changed.
118 base.OnPropertyChanged("DetectState");
119 }
120 }
121 }
122
123 /// <summary>
124 /// Gets and sets the upgrade detect state of the view's model.
125 /// </summary>
126 public UpgradeDetectionState UpgradeDetectState
127 {
128 get
129 {
130 return this.upgradeDetectState;
131 }
132
133 set
134 {
135 if (this.upgradeDetectState != value)
136 {
137 this.upgradeDetectState = value;
138
139 // Notify all the properties derived from the state that the state changed.
140 base.OnPropertyChanged("UpgradeDetectState");
141 }
142 }
143 }
144
145 /// <summary>
146 /// Gets and sets the installation state of the view's model.
147 /// </summary>
148 public InstallationState InstallState
149 {
150 get
151 {
152 return this.installState;
153 }
154
155 set
156 {
157 if (this.installState != value)
158 {
159 this.installState = value;
160
161 // Notify all the properties derived from the state that the state changed.
162 base.OnPropertyChanged("InstallState");
163 base.OnPropertyChanged("CancelAvailable");
164 }
165 }
166 }
167
168 /// <summary>
169 /// Gets and sets the state of the view's model before apply begins in order to return to that state if cancel or rollback occurs.
170 /// </summary>
171 public InstallationState PreApplyState { get; set; }
172
173 /// <summary>
174 /// Gets and sets the path where the bundle is currently installed or will be installed.
175 /// </summary>
176 public string InstallDirectory
177 {
178 get
179 {
180 return WixBA.Model.InstallDirectory;
181 }
182
183 set
184 {
185 if (WixBA.Model.InstallDirectory != value)
186 {
187 WixBA.Model.InstallDirectory = value;
188 base.OnPropertyChanged("InstallDirectory");
189 }
190 }
191 }
192
193 /// <summary>
194 /// The Title of this bundle.
195 /// </summary>
196 public string Title
197 {
198 get
199 {
200 return WixDistribution.ShortProduct;
201 }
202 }
203
204 /// <summary>
205 /// Prompts the user to make sure they want to cancel.
206 /// This needs to run on the UI thread, use Dispatcher.Invoke to call this from a background thread.
207 /// </summary>
208 public void CancelButton_Click()
209 {
210 if (this.Canceled)
211 {
212 return;
213 }
214
215 if (Display.Full == WixBA.Model.Command.Display)
216 {
217 this.Canceled = (MessageBoxResult.Yes == MessageBox.Show(WixBA.View, "Are you sure you want to cancel?", "WiX Toolset", MessageBoxButton.YesNo, MessageBoxImage.Error));
218 }
219 else
220 {
221 this.Canceled = true;
222 }
223 }
224 }
225 }