root / trunk / NetSparkle / NetSparkle.cs @ 049333d2
History | View | Annotate | Download (26.1 kB)
1 | 46426dbd | Panagiotis Kanavos | using System; |
---|---|---|---|
2 | 46426dbd | Panagiotis Kanavos | using System.Collections.Generic; |
3 | 46426dbd | Panagiotis Kanavos | using System.Linq; |
4 | 46426dbd | Panagiotis Kanavos | using System.Text; |
5 | 46426dbd | Panagiotis Kanavos | using System.ComponentModel; |
6 | 46426dbd | Panagiotis Kanavos | using System.Threading; |
7 | 46426dbd | Panagiotis Kanavos | using System.Net; |
8 | 049333d2 | Panagiotis Kanavos | using System.Windows; |
9 | 46426dbd | Panagiotis Kanavos | using System.Windows.Forms; |
10 | 46426dbd | Panagiotis Kanavos | using System.Drawing; |
11 | 46426dbd | Panagiotis Kanavos | using System.Runtime.InteropServices; |
12 | 46426dbd | Panagiotis Kanavos | using System.Management; |
13 | 46426dbd | Panagiotis Kanavos | using System.Diagnostics; |
14 | 46426dbd | Panagiotis Kanavos | using System.Security.Cryptography.X509Certificates; |
15 | 46426dbd | Panagiotis Kanavos | using System.Net.Security; |
16 | 049333d2 | Panagiotis Kanavos | using Point = System.Drawing.Point; |
17 | 46426dbd | Panagiotis Kanavos | |
18 | 46426dbd | Panagiotis Kanavos | namespace AppLimit.NetSparkle |
19 | 46426dbd | Panagiotis Kanavos | { |
20 | 46426dbd | Panagiotis Kanavos | public delegate void LoopStartedOperation(Object sender); |
21 | 46426dbd | Panagiotis Kanavos | public delegate void LoopFinishedOperation(Object sender, Boolean UpdateRequired); |
22 | 46426dbd | Panagiotis Kanavos | |
23 | 46426dbd | Panagiotis Kanavos | /// <summary> |
24 | 46426dbd | Panagiotis Kanavos | /// Everytime when netsparkle detects an update the |
25 | 46426dbd | Panagiotis Kanavos | /// consumer can decide what should happen as next with the help |
26 | 46426dbd | Panagiotis Kanavos | /// of the UpdateDatected event |
27 | 46426dbd | Panagiotis Kanavos | /// </summary> |
28 | 46426dbd | Panagiotis Kanavos | public enum nNextUpdateAction |
29 | 46426dbd | Panagiotis Kanavos | { |
30 | 46426dbd | Panagiotis Kanavos | showStandardUserInterface = 1, |
31 | 46426dbd | Panagiotis Kanavos | performUpdateUnattended = 2, |
32 | 46426dbd | Panagiotis Kanavos | prohibitUpdate = 3 |
33 | 46426dbd | Panagiotis Kanavos | } |
34 | 46426dbd | Panagiotis Kanavos | |
35 | 46426dbd | Panagiotis Kanavos | /// <summary> |
36 | 46426dbd | Panagiotis Kanavos | /// Contains all information for the update detected event |
37 | 46426dbd | Panagiotis Kanavos | /// </summary> |
38 | 46426dbd | Panagiotis Kanavos | public class UpdateDetectedEventArgs : EventArgs |
39 | 46426dbd | Panagiotis Kanavos | { |
40 | 46426dbd | Panagiotis Kanavos | public nNextUpdateAction NextAction; |
41 | 46426dbd | Panagiotis Kanavos | public NetSparkleConfiguration ApplicationConfig; |
42 | 46426dbd | Panagiotis Kanavos | public NetSparkleAppCastItem LatestVersion; |
43 | 46426dbd | Panagiotis Kanavos | } |
44 | 46426dbd | Panagiotis Kanavos | |
45 | 46426dbd | Panagiotis Kanavos | /// <summary> |
46 | 46426dbd | Panagiotis Kanavos | /// This delegate will be used when an update was detected to allow library |
47 | 46426dbd | Panagiotis Kanavos | /// consumer to add own user interface capabilities. |
48 | 46426dbd | Panagiotis Kanavos | /// </summary> |
49 | 46426dbd | Panagiotis Kanavos | /// <param name="sender"></param> |
50 | 46426dbd | Panagiotis Kanavos | /// <param name="e"></param> |
51 | 46426dbd | Panagiotis Kanavos | public delegate void UpdateDetected(Object sender, UpdateDetectedEventArgs e); |
52 | 46426dbd | Panagiotis Kanavos | |
53 | 46426dbd | Panagiotis Kanavos | public class Sparkle : IDisposable |
54 | 46426dbd | Panagiotis Kanavos | { |
55 | 46426dbd | Panagiotis Kanavos | private BackgroundWorker _worker = new BackgroundWorker(); |
56 | 46426dbd | Panagiotis Kanavos | |
57 | 46426dbd | Panagiotis Kanavos | private String _AppCastUrl; |
58 | 46426dbd | Panagiotis Kanavos | private String _AppReferenceAssembly; |
59 | 46426dbd | Panagiotis Kanavos | |
60 | 46426dbd | Panagiotis Kanavos | private Boolean _DoInitialCheck; |
61 | 46426dbd | Panagiotis Kanavos | private Boolean _ForceInitialCheck; |
62 | 46426dbd | Panagiotis Kanavos | |
63 | 46426dbd | Panagiotis Kanavos | private EventWaitHandle _exitHandle; |
64 | 46426dbd | Panagiotis Kanavos | private EventWaitHandle _loopingHandle; |
65 | 46426dbd | Panagiotis Kanavos | |
66 | 46426dbd | Panagiotis Kanavos | private NetSparkleMainWindows _DiagnosticWindow; |
67 | 46426dbd | Panagiotis Kanavos | |
68 | 46426dbd | Panagiotis Kanavos | private TimeSpan _CheckFrequency; |
69 | 46426dbd | Panagiotis Kanavos | |
70 | 46426dbd | Panagiotis Kanavos | /// <summary> |
71 | 46426dbd | Panagiotis Kanavos | /// Enables system profiling against a profile server |
72 | 46426dbd | Panagiotis Kanavos | /// </summary> |
73 | 46426dbd | Panagiotis Kanavos | public Boolean EnableSystemProfiling = false; |
74 | 46426dbd | Panagiotis Kanavos | |
75 | 46426dbd | Panagiotis Kanavos | /// <summary> |
76 | 46426dbd | Panagiotis Kanavos | /// Hides the release notes view when an update was found. This |
77 | 46426dbd | Panagiotis Kanavos | /// mode is switched on automatically when no sparkle:releaseNotesLink |
78 | 46426dbd | Panagiotis Kanavos | /// tag was found in the app cast |
79 | 46426dbd | Panagiotis Kanavos | /// </summary> |
80 | 46426dbd | Panagiotis Kanavos | public Boolean HideReleaseNotes = false; |
81 | 46426dbd | Panagiotis Kanavos | |
82 | 46426dbd | Panagiotis Kanavos | /// <summary> |
83 | 46426dbd | Panagiotis Kanavos | /// Contains the profile url for System profiling |
84 | 46426dbd | Panagiotis Kanavos | /// </summary> |
85 | 46426dbd | Panagiotis Kanavos | public Uri SystemProfileUrl; |
86 | 46426dbd | Panagiotis Kanavos | |
87 | 46426dbd | Panagiotis Kanavos | /// <summary> |
88 | 46426dbd | Panagiotis Kanavos | /// This event will be raised when a check loop will be started |
89 | 46426dbd | Panagiotis Kanavos | /// </summary> |
90 | 46426dbd | Panagiotis Kanavos | public event LoopStartedOperation checkLoopStarted; |
91 | 46426dbd | Panagiotis Kanavos | |
92 | 46426dbd | Panagiotis Kanavos | /// <summary> |
93 | 46426dbd | Panagiotis Kanavos | /// This event will be raised when a check loop is finished |
94 | 46426dbd | Panagiotis Kanavos | /// </summary> |
95 | 46426dbd | Panagiotis Kanavos | public event LoopFinishedOperation checkLoopFinished; |
96 | 46426dbd | Panagiotis Kanavos | |
97 | 46426dbd | Panagiotis Kanavos | /// <summary> |
98 | 46426dbd | Panagiotis Kanavos | /// This event can be used to override the standard user interface |
99 | 46426dbd | Panagiotis Kanavos | /// process when an update is detected |
100 | 46426dbd | Panagiotis Kanavos | /// </summary> |
101 | 46426dbd | Panagiotis Kanavos | public event UpdateDetected updateDetected; |
102 | 46426dbd | Panagiotis Kanavos | |
103 | 46426dbd | Panagiotis Kanavos | /// <summary> |
104 | 46426dbd | Panagiotis Kanavos | /// This property holds an optional application icon |
105 | 46426dbd | Panagiotis Kanavos | /// which will be displayed in the software update dialog. The icon has |
106 | 46426dbd | Panagiotis Kanavos | /// to be 48x48 pixels. |
107 | 46426dbd | Panagiotis Kanavos | /// </summary> |
108 | 46426dbd | Panagiotis Kanavos | public Image ApplicationIcon { get; set; } |
109 | 46426dbd | Panagiotis Kanavos | |
110 | 46426dbd | Panagiotis Kanavos | /// <summary> |
111 | 46426dbd | Panagiotis Kanavos | /// This property returns an optional application icon |
112 | 46426dbd | Panagiotis Kanavos | /// which will displayed in the windows as self |
113 | 46426dbd | Panagiotis Kanavos | /// </summary> |
114 | 46426dbd | Panagiotis Kanavos | public Icon ApplicationWindowIcon { get; set; } |
115 | 46426dbd | Panagiotis Kanavos | |
116 | 46426dbd | Panagiotis Kanavos | /// <summary> |
117 | 46426dbd | Panagiotis Kanavos | /// This property enables a diagnostic window for debug reasons |
118 | 46426dbd | Panagiotis Kanavos | /// </summary> |
119 | 46426dbd | Panagiotis Kanavos | public Boolean ShowDiagnosticWindow { get; set; } |
120 | 46426dbd | Panagiotis Kanavos | |
121 | 46426dbd | Panagiotis Kanavos | /// <summary> |
122 | 46426dbd | Panagiotis Kanavos | /// This property enables the silent mode, this means |
123 | 46426dbd | Panagiotis Kanavos | /// the application will be updated without user interaction |
124 | 46426dbd | Panagiotis Kanavos | /// </summary> |
125 | 46426dbd | Panagiotis Kanavos | public Boolean EnableSilentMode { get; set; } |
126 | 46426dbd | Panagiotis Kanavos | |
127 | 46426dbd | Panagiotis Kanavos | /// <summary> |
128 | 46426dbd | Panagiotis Kanavos | /// This property returns true when the upadete loop is running |
129 | 46426dbd | Panagiotis Kanavos | /// and files when the loop is not running |
130 | 46426dbd | Panagiotis Kanavos | /// </summary> |
131 | 46426dbd | Panagiotis Kanavos | public Boolean IsUpdateLoopRunning |
132 | 46426dbd | Panagiotis Kanavos | { |
133 | 46426dbd | Panagiotis Kanavos | get |
134 | 46426dbd | Panagiotis Kanavos | { |
135 | 46426dbd | Panagiotis Kanavos | return _loopingHandle.WaitOne(0); |
136 | 46426dbd | Panagiotis Kanavos | } |
137 | 46426dbd | Panagiotis Kanavos | } |
138 | 46426dbd | Panagiotis Kanavos | |
139 | 46426dbd | Panagiotis Kanavos | /// <summary> |
140 | 46426dbd | Panagiotis Kanavos | /// This property defines if we trust every ssl connection also when |
141 | 46426dbd | Panagiotis Kanavos | /// this connection has not a valid cert |
142 | 46426dbd | Panagiotis Kanavos | /// </summary> |
143 | 46426dbd | Panagiotis Kanavos | public Boolean TrustEverySSLConnection { get; set; } |
144 | 46426dbd | Panagiotis Kanavos | |
145 | 46426dbd | Panagiotis Kanavos | /// <summary> |
146 | 46426dbd | Panagiotis Kanavos | /// ctor which needs the appcast url |
147 | 46426dbd | Panagiotis Kanavos | /// </summary> |
148 | 46426dbd | Panagiotis Kanavos | /// <param name="appcastUrl"></param> |
149 | 46426dbd | Panagiotis Kanavos | public Sparkle(String appcastUrl) |
150 | 46426dbd | Panagiotis Kanavos | : this(appcastUrl, null) |
151 | 46426dbd | Panagiotis Kanavos | { } |
152 | 46426dbd | Panagiotis Kanavos | |
153 | 46426dbd | Panagiotis Kanavos | /// <summary> |
154 | 46426dbd | Panagiotis Kanavos | /// ctor which needs the appcast url and a referenceassembly |
155 | 46426dbd | Panagiotis Kanavos | /// </summary> |
156 | 46426dbd | Panagiotis Kanavos | public Sparkle(String appcastUrl, String referenceAssembly) |
157 | 46426dbd | Panagiotis Kanavos | : this(appcastUrl, referenceAssembly, false) |
158 | 46426dbd | Panagiotis Kanavos | { } |
159 | 46426dbd | Panagiotis Kanavos | |
160 | 46426dbd | Panagiotis Kanavos | /// <summary> |
161 | 46426dbd | Panagiotis Kanavos | /// ctor which needs the appcast url and a referenceassembly |
162 | 46426dbd | Panagiotis Kanavos | /// </summary> |
163 | 46426dbd | Panagiotis Kanavos | public Sparkle(String appcastUrl, String referenceAssembly, Boolean ShowDiagnostic) |
164 | 46426dbd | Panagiotis Kanavos | { |
165 | 46426dbd | Panagiotis Kanavos | // preconfige ssl trust |
166 | 46426dbd | Panagiotis Kanavos | TrustEverySSLConnection = false; |
167 | 46426dbd | Panagiotis Kanavos | |
168 | 46426dbd | Panagiotis Kanavos | // configure ssl cert link |
169 | 46426dbd | Panagiotis Kanavos | ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidation; |
170 | 46426dbd | Panagiotis Kanavos | |
171 | 46426dbd | Panagiotis Kanavos | // enable visual style to ensure that we have XP style or higher |
172 | 46426dbd | Panagiotis Kanavos | // also in WPF applications |
173 | 46426dbd | Panagiotis Kanavos | System.Windows.Forms.Application.EnableVisualStyles(); |
174 | 46426dbd | Panagiotis Kanavos | |
175 | 46426dbd | Panagiotis Kanavos | // reset vars |
176 | 46426dbd | Panagiotis Kanavos | ApplicationIcon = null; |
177 | 46426dbd | Panagiotis Kanavos | _AppReferenceAssembly = null; |
178 | 46426dbd | Panagiotis Kanavos | |
179 | 46426dbd | Panagiotis Kanavos | // set var |
180 | 46426dbd | Panagiotis Kanavos | ShowDiagnosticWindow = ShowDiagnostic; |
181 | 46426dbd | Panagiotis Kanavos | |
182 | 46426dbd | Panagiotis Kanavos | // create the diagnotic window |
183 | 46426dbd | Panagiotis Kanavos | _DiagnosticWindow = new NetSparkleMainWindows(); |
184 | 46426dbd | Panagiotis Kanavos | |
185 | 46426dbd | Panagiotis Kanavos | // set the reference assembly |
186 | 46426dbd | Panagiotis Kanavos | if (referenceAssembly != null) |
187 | 46426dbd | Panagiotis Kanavos | { |
188 | 46426dbd | Panagiotis Kanavos | _AppReferenceAssembly = referenceAssembly; |
189 | 46426dbd | Panagiotis Kanavos | _DiagnosticWindow.Report("Checking the following file: " + _AppReferenceAssembly); |
190 | 46426dbd | Panagiotis Kanavos | } |
191 | 46426dbd | Panagiotis Kanavos | |
192 | 46426dbd | Panagiotis Kanavos | // show if needed |
193 | 46426dbd | Panagiotis Kanavos | ShowDiagnosticWindowIfNeeded(); |
194 | 46426dbd | Panagiotis Kanavos | |
195 | 46426dbd | Panagiotis Kanavos | // adjust the delegates |
196 | 46426dbd | Panagiotis Kanavos | _worker.WorkerReportsProgress = true; |
197 | 46426dbd | Panagiotis Kanavos | _worker.DoWork += new DoWorkEventHandler(_worker_DoWork); |
198 | 46426dbd | Panagiotis Kanavos | _worker.ProgressChanged += new ProgressChangedEventHandler(_worker_ProgressChanged); |
199 | 46426dbd | Panagiotis Kanavos | |
200 | 46426dbd | Panagiotis Kanavos | // build the wait handle |
201 | 46426dbd | Panagiotis Kanavos | _exitHandle = new EventWaitHandle(false, EventResetMode.AutoReset); |
202 | 46426dbd | Panagiotis Kanavos | _loopingHandle = new EventWaitHandle(false, EventResetMode.ManualReset); |
203 | 46426dbd | Panagiotis Kanavos | |
204 | 46426dbd | Panagiotis Kanavos | // set the url |
205 | 46426dbd | Panagiotis Kanavos | _AppCastUrl = appcastUrl; |
206 | 46426dbd | Panagiotis Kanavos | _DiagnosticWindow.Report("Using the following url: " + _AppCastUrl); |
207 | 46426dbd | Panagiotis Kanavos | } |
208 | 46426dbd | Panagiotis Kanavos | |
209 | 46426dbd | Panagiotis Kanavos | /// <summary> |
210 | 46426dbd | Panagiotis Kanavos | /// The method starts a NetSparkle background loop |
211 | 46426dbd | Panagiotis Kanavos | /// If NetSparkle is configured to check for updates on startup, proceeds to perform |
212 | 46426dbd | Panagiotis Kanavos | /// the check. You should only call this function when your app is initialized and |
213 | 46426dbd | Panagiotis Kanavos | /// shows its main window. |
214 | 46426dbd | Panagiotis Kanavos | /// </summary> |
215 | 46426dbd | Panagiotis Kanavos | /// <param name="doInitialCheck"></param> |
216 | 46426dbd | Panagiotis Kanavos | public void StartLoop(Boolean doInitialCheck) |
217 | 46426dbd | Panagiotis Kanavos | { |
218 | 46426dbd | Panagiotis Kanavos | StartLoop(doInitialCheck, false); |
219 | 46426dbd | Panagiotis Kanavos | } |
220 | 46426dbd | Panagiotis Kanavos | |
221 | 46426dbd | Panagiotis Kanavos | /// <summary> |
222 | 46426dbd | Panagiotis Kanavos | /// The method starts a NetSparkle background loop |
223 | 46426dbd | Panagiotis Kanavos | /// If NetSparkle is configured to check for updates on startup, proceeds to perform |
224 | 46426dbd | Panagiotis Kanavos | /// the check. You should only call this function when your app is initialized and |
225 | 46426dbd | Panagiotis Kanavos | /// shows its main window. |
226 | 46426dbd | Panagiotis Kanavos | /// </summary> |
227 | 46426dbd | Panagiotis Kanavos | /// <param name="doInitialCheck"></param> |
228 | 46426dbd | Panagiotis Kanavos | /// <param name="checkFrequency"></param> |
229 | 46426dbd | Panagiotis Kanavos | public void StartLoop(Boolean doInitialCheck, TimeSpan checkFrequency) |
230 | 46426dbd | Panagiotis Kanavos | { |
231 | 46426dbd | Panagiotis Kanavos | StartLoop(doInitialCheck, false, checkFrequency); |
232 | 46426dbd | Panagiotis Kanavos | } |
233 | 46426dbd | Panagiotis Kanavos | |
234 | 46426dbd | Panagiotis Kanavos | /// <summary> |
235 | 46426dbd | Panagiotis Kanavos | /// The method starts a NetSparkle background loop |
236 | 46426dbd | Panagiotis Kanavos | /// If NetSparkle is configured to check for updates on startup, proceeds to perform |
237 | 46426dbd | Panagiotis Kanavos | /// the check. You should only call this function when your app is initialized and |
238 | 46426dbd | Panagiotis Kanavos | /// shows its main window. |
239 | 46426dbd | Panagiotis Kanavos | /// </summary> |
240 | 46426dbd | Panagiotis Kanavos | /// <param name="doInitialCheck"></param> |
241 | 46426dbd | Panagiotis Kanavos | /// <param name="forceInitialCheck"></param> |
242 | 46426dbd | Panagiotis Kanavos | public void StartLoop(Boolean doInitialCheck, Boolean forceInitialCheck) |
243 | 46426dbd | Panagiotis Kanavos | { |
244 | 46426dbd | Panagiotis Kanavos | StartLoop(doInitialCheck, forceInitialCheck, TimeSpan.FromHours(24)); |
245 | 46426dbd | Panagiotis Kanavos | } |
246 | 46426dbd | Panagiotis Kanavos | |
247 | 46426dbd | Panagiotis Kanavos | /// <summary> |
248 | 46426dbd | Panagiotis Kanavos | /// The method starts a NetSparkle background loop |
249 | 46426dbd | Panagiotis Kanavos | /// If NetSparkle is configured to check for updates on startup, proceeds to perform |
250 | 46426dbd | Panagiotis Kanavos | /// the check. You should only call this function when your app is initialized and |
251 | 46426dbd | Panagiotis Kanavos | /// shows its main window. |
252 | 46426dbd | Panagiotis Kanavos | /// </summary> |
253 | 46426dbd | Panagiotis Kanavos | /// <param name="doInitialCheck"></param> |
254 | 46426dbd | Panagiotis Kanavos | /// <param name="forceInitialCheck"></param> |
255 | 46426dbd | Panagiotis Kanavos | /// <param name="checkFrequency"></param> |
256 | 46426dbd | Panagiotis Kanavos | public void StartLoop(Boolean doInitialCheck, Boolean forceInitialCheck, TimeSpan checkFrequency) |
257 | 46426dbd | Panagiotis Kanavos | { |
258 | 46426dbd | Panagiotis Kanavos | // first set the event handle |
259 | 46426dbd | Panagiotis Kanavos | _loopingHandle.Set(); |
260 | 46426dbd | Panagiotis Kanavos | |
261 | 46426dbd | Panagiotis Kanavos | // Start the helper thread as a background worker to |
262 | 46426dbd | Panagiotis Kanavos | // get well ui interaction |
263 | 46426dbd | Panagiotis Kanavos | |
264 | 46426dbd | Panagiotis Kanavos | // show if needed |
265 | 46426dbd | Panagiotis Kanavos | ShowDiagnosticWindowIfNeeded(); |
266 | 46426dbd | Panagiotis Kanavos | |
267 | 46426dbd | Panagiotis Kanavos | // store infos |
268 | 46426dbd | Panagiotis Kanavos | _DoInitialCheck = doInitialCheck; |
269 | 46426dbd | Panagiotis Kanavos | _ForceInitialCheck = forceInitialCheck; |
270 | 46426dbd | Panagiotis Kanavos | _CheckFrequency = checkFrequency; |
271 | 46426dbd | Panagiotis Kanavos | |
272 | 46426dbd | Panagiotis Kanavos | // create and configure the worker |
273 | 46426dbd | Panagiotis Kanavos | _DiagnosticWindow.Report("Starting background worker"); |
274 | 46426dbd | Panagiotis Kanavos | |
275 | 46426dbd | Panagiotis Kanavos | // start the work |
276 | 46426dbd | Panagiotis Kanavos | _worker.RunWorkerAsync(); |
277 | 46426dbd | Panagiotis Kanavos | } |
278 | 46426dbd | Panagiotis Kanavos | |
279 | 46426dbd | Panagiotis Kanavos | /// <summary> |
280 | 46426dbd | Panagiotis Kanavos | /// This method will stop the sparkle background loop and is called |
281 | 46426dbd | Panagiotis Kanavos | /// through the disposable interface automatically |
282 | 46426dbd | Panagiotis Kanavos | /// </summary> |
283 | 46426dbd | Panagiotis Kanavos | public void StopLoop() |
284 | 46426dbd | Panagiotis Kanavos | { |
285 | 46426dbd | Panagiotis Kanavos | // ensure the work will finished |
286 | 46426dbd | Panagiotis Kanavos | _exitHandle.Set(); |
287 | 46426dbd | Panagiotis Kanavos | } |
288 | 46426dbd | Panagiotis Kanavos | |
289 | 46426dbd | Panagiotis Kanavos | /// <summary> |
290 | 46426dbd | Panagiotis Kanavos | /// Is called in the using context and will stop all background activities |
291 | 46426dbd | Panagiotis Kanavos | /// </summary> |
292 | 46426dbd | Panagiotis Kanavos | public void Dispose() |
293 | 46426dbd | Panagiotis Kanavos | { |
294 | 46426dbd | Panagiotis Kanavos | StopLoop(); |
295 | 46426dbd | Panagiotis Kanavos | } |
296 | 46426dbd | Panagiotis Kanavos | |
297 | 46426dbd | Panagiotis Kanavos | /// <summary> |
298 | 46426dbd | Panagiotis Kanavos | /// This method updates the profile information which can be sended to the server if enabled |
299 | 46426dbd | Panagiotis Kanavos | /// </summary> |
300 | 46426dbd | Panagiotis Kanavos | /// <param name="config"></param> |
301 | 46426dbd | Panagiotis Kanavos | public void UpdateSystemProfileInformation(NetSparkleConfiguration config) |
302 | 46426dbd | Panagiotis Kanavos | { |
303 | 46426dbd | Panagiotis Kanavos | // check if profile data is enabled |
304 | 46426dbd | Panagiotis Kanavos | if (!EnableSystemProfiling) |
305 | 46426dbd | Panagiotis Kanavos | return; |
306 | 46426dbd | Panagiotis Kanavos | |
307 | 46426dbd | Panagiotis Kanavos | // check if we need an update |
308 | 46426dbd | Panagiotis Kanavos | if (DateTime.Now - config.LastProfileUpdate < new TimeSpan(7, 0, 0, 0)) |
309 | 46426dbd | Panagiotis Kanavos | return; |
310 | 46426dbd | Panagiotis Kanavos | |
311 | 46426dbd | Panagiotis Kanavos | // touch the profile update time |
312 | 46426dbd | Panagiotis Kanavos | config.TouchProfileTime(); |
313 | 46426dbd | Panagiotis Kanavos | |
314 | 46426dbd | Panagiotis Kanavos | // start the profile thread |
315 | 46426dbd | Panagiotis Kanavos | Thread t = new Thread(ProfileDataThreadStart); |
316 | 46426dbd | Panagiotis Kanavos | t.Start(config); |
317 | 46426dbd | Panagiotis Kanavos | } |
318 | 46426dbd | Panagiotis Kanavos | |
319 | 46426dbd | Panagiotis Kanavos | /// <summary> |
320 | 46426dbd | Panagiotis Kanavos | /// Profile data thread |
321 | 46426dbd | Panagiotis Kanavos | /// </summary> |
322 | 46426dbd | Panagiotis Kanavos | /// <param name="obj"></param> |
323 | 46426dbd | Panagiotis Kanavos | private void ProfileDataThreadStart(object obj) |
324 | 46426dbd | Panagiotis Kanavos | { |
325 | 46426dbd | Panagiotis Kanavos | try |
326 | 46426dbd | Panagiotis Kanavos | { |
327 | 46426dbd | Panagiotis Kanavos | if (SystemProfileUrl != null) |
328 | 46426dbd | Panagiotis Kanavos | { |
329 | 46426dbd | Panagiotis Kanavos | // get the config |
330 | 46426dbd | Panagiotis Kanavos | NetSparkleConfiguration config = obj as NetSparkleConfiguration; |
331 | 46426dbd | Panagiotis Kanavos | |
332 | 46426dbd | Panagiotis Kanavos | // collect data |
333 | 46426dbd | Panagiotis Kanavos | NetSparkleDeviceInventory inv = new NetSparkleDeviceInventory(config); |
334 | 46426dbd | Panagiotis Kanavos | inv.CollectInventory(); |
335 | 46426dbd | Panagiotis Kanavos | |
336 | 46426dbd | Panagiotis Kanavos | // build url |
337 | 46426dbd | Panagiotis Kanavos | String requestUrl = inv.BuildRequestUrl(SystemProfileUrl.ToString() + "?"); |
338 | 46426dbd | Panagiotis Kanavos | |
339 | 46426dbd | Panagiotis Kanavos | HttpWebRequest.DefaultWebProxy = HttpWebRequest.GetSystemWebProxy(); |
340 | 46426dbd | Panagiotis Kanavos | |
341 | 46426dbd | Panagiotis Kanavos | // perform the webrequest |
342 | 46426dbd | Panagiotis Kanavos | HttpWebRequest request = HttpWebRequest.Create(requestUrl) as HttpWebRequest; |
343 | 46426dbd | Panagiotis Kanavos | using (WebResponse response = request.GetResponse()) |
344 | 46426dbd | Panagiotis Kanavos | { |
345 | 46426dbd | Panagiotis Kanavos | // close the response |
346 | 46426dbd | Panagiotis Kanavos | response.Close(); |
347 | 46426dbd | Panagiotis Kanavos | } |
348 | 46426dbd | Panagiotis Kanavos | } |
349 | 46426dbd | Panagiotis Kanavos | } |
350 | 46426dbd | Panagiotis Kanavos | catch (Exception ex) |
351 | 46426dbd | Panagiotis Kanavos | { |
352 | 46426dbd | Panagiotis Kanavos | // No exception during data send |
353 | 46426dbd | Panagiotis Kanavos | ReportDiagnosticMessage(ex.Message); |
354 | 46426dbd | Panagiotis Kanavos | } |
355 | 46426dbd | Panagiotis Kanavos | } |
356 | 46426dbd | Panagiotis Kanavos | |
357 | 46426dbd | Panagiotis Kanavos | /// <summary> |
358 | 46426dbd | Panagiotis Kanavos | /// This method checks if an update is required. During this process the appcast |
359 | 46426dbd | Panagiotis Kanavos | /// will be downloaded and checked against the reference assembly. Ensure that |
360 | 46426dbd | Panagiotis Kanavos | /// the calling process has access to the internet and read access to the |
361 | 46426dbd | Panagiotis Kanavos | /// reference assembly. This method is also called from the background loops. |
362 | 46426dbd | Panagiotis Kanavos | /// </summary> |
363 | 46426dbd | Panagiotis Kanavos | /// <param name="config"></param> |
364 | 46426dbd | Panagiotis Kanavos | /// <returns></returns> |
365 | 46426dbd | Panagiotis Kanavos | public Boolean IsUpdateRequired(NetSparkleConfiguration config, out NetSparkleAppCastItem latestVersion) |
366 | 46426dbd | Panagiotis Kanavos | { |
367 | 46426dbd | Panagiotis Kanavos | // report |
368 | 46426dbd | Panagiotis Kanavos | ReportDiagnosticMessage("Downloading and checking appcast"); |
369 | 46426dbd | Panagiotis Kanavos | |
370 | 46426dbd | Panagiotis Kanavos | // init the appcast |
371 | 46426dbd | Panagiotis Kanavos | NetSparkleAppCast cast = new NetSparkleAppCast(_AppCastUrl, config); |
372 | 46426dbd | Panagiotis Kanavos | |
373 | 46426dbd | Panagiotis Kanavos | // check if any updates are available |
374 | 46426dbd | Panagiotis Kanavos | try |
375 | 46426dbd | Panagiotis Kanavos | { |
376 | 46426dbd | Panagiotis Kanavos | latestVersion = cast.GetLatestVersion(); |
377 | 46426dbd | Panagiotis Kanavos | } |
378 | 46426dbd | Panagiotis Kanavos | catch (Exception e) |
379 | 46426dbd | Panagiotis Kanavos | { |
380 | 46426dbd | Panagiotis Kanavos | // show the exeception message |
381 | 46426dbd | Panagiotis Kanavos | ReportDiagnosticMessage("Error during app cast download: " + e.Message); |
382 | 46426dbd | Panagiotis Kanavos | |
383 | 46426dbd | Panagiotis Kanavos | // just null the version info |
384 | 46426dbd | Panagiotis Kanavos | latestVersion = null; |
385 | 46426dbd | Panagiotis Kanavos | } |
386 | 46426dbd | Panagiotis Kanavos | |
387 | 46426dbd | Panagiotis Kanavos | if (latestVersion == null) |
388 | 46426dbd | Panagiotis Kanavos | { |
389 | 46426dbd | Panagiotis Kanavos | ReportDiagnosticMessage("No version information in app cast found"); |
390 | 46426dbd | Panagiotis Kanavos | return false; |
391 | 46426dbd | Panagiotis Kanavos | } |
392 | 46426dbd | Panagiotis Kanavos | else |
393 | 46426dbd | Panagiotis Kanavos | { |
394 | 46426dbd | Panagiotis Kanavos | ReportDiagnosticMessage("Lastest version on the server is " + latestVersion.Version); |
395 | 46426dbd | Panagiotis Kanavos | } |
396 | 46426dbd | Panagiotis Kanavos | |
397 | 46426dbd | Panagiotis Kanavos | // set the last check time |
398 | 46426dbd | Panagiotis Kanavos | ReportDiagnosticMessage("Touch the last check timestamp"); |
399 | 46426dbd | Panagiotis Kanavos | config.TouchCheckTime(); |
400 | 46426dbd | Panagiotis Kanavos | |
401 | 46426dbd | Panagiotis Kanavos | // check if the available update has to be skipped |
402 | 46426dbd | Panagiotis Kanavos | if (latestVersion.Version.Equals(config.SkipThisVersion)) |
403 | 46426dbd | Panagiotis Kanavos | { |
404 | 46426dbd | Panagiotis Kanavos | ReportDiagnosticMessage("Latest update has to be skipped (user decided to skip version " + config.SkipThisVersion + ")"); |
405 | 46426dbd | Panagiotis Kanavos | return false; |
406 | 46426dbd | Panagiotis Kanavos | } |
407 | 46426dbd | Panagiotis Kanavos | |
408 | 46426dbd | Panagiotis Kanavos | // check if the version will be the same then the installed version |
409 | 46426dbd | Panagiotis Kanavos | Version v1 = new Version(config.InstalledVersion); |
410 | 46426dbd | Panagiotis Kanavos | Version v2 = new Version(latestVersion.Version); |
411 | 46426dbd | Panagiotis Kanavos | |
412 | 46426dbd | Panagiotis Kanavos | if (v2 <= v1) |
413 | 46426dbd | Panagiotis Kanavos | { |
414 | 46426dbd | Panagiotis Kanavos | ReportDiagnosticMessage("Installed version is valid, no update needed (" + config.InstalledVersion + ")"); |
415 | 46426dbd | Panagiotis Kanavos | return false; |
416 | 46426dbd | Panagiotis Kanavos | } |
417 | 46426dbd | Panagiotis Kanavos | |
418 | 46426dbd | Panagiotis Kanavos | // ok we need an update |
419 | 46426dbd | Panagiotis Kanavos | return true; |
420 | 46426dbd | Panagiotis Kanavos | } |
421 | 46426dbd | Panagiotis Kanavos | |
422 | 46426dbd | Panagiotis Kanavos | /// <summary> |
423 | 46426dbd | Panagiotis Kanavos | /// This method reads the local sparkle configuration for the given |
424 | 46426dbd | Panagiotis Kanavos | /// reference assembly |
425 | 46426dbd | Panagiotis Kanavos | /// </summary> |
426 | 46426dbd | Panagiotis Kanavos | /// <param name="AppReferenceAssembly"></param> |
427 | 46426dbd | Panagiotis Kanavos | /// <returns></returns> |
428 | 46426dbd | Panagiotis Kanavos | public NetSparkleConfiguration GetApplicationConfig() |
429 | 46426dbd | Panagiotis Kanavos | { |
430 | 46426dbd | Panagiotis Kanavos | NetSparkleConfiguration config; |
431 | 46426dbd | Panagiotis Kanavos | config = new NetSparkleConfiguration(_AppReferenceAssembly); |
432 | 46426dbd | Panagiotis Kanavos | return config; |
433 | 46426dbd | Panagiotis Kanavos | } |
434 | 46426dbd | Panagiotis Kanavos | |
435 | 46426dbd | Panagiotis Kanavos | /// <summary> |
436 | 46426dbd | Panagiotis Kanavos | /// This method shows the update ui and allows to perform the |
437 | 46426dbd | Panagiotis Kanavos | /// update process |
438 | 46426dbd | Panagiotis Kanavos | /// </summary> |
439 | 46426dbd | Panagiotis Kanavos | /// <param name="currentItem"></param> |
440 | 46426dbd | Panagiotis Kanavos | public void ShowUpdateNeededUI(NetSparkleAppCastItem currentItem) |
441 | 46426dbd | Panagiotis Kanavos | { |
442 | 049333d2 | Panagiotis Kanavos | |
443 | 46426dbd | Panagiotis Kanavos | // create the form |
444 | 46426dbd | Panagiotis Kanavos | NetSparkleForm frm = new NetSparkleForm(currentItem, ApplicationIcon, ApplicationWindowIcon); |
445 | 46426dbd | Panagiotis Kanavos | |
446 | 46426dbd | Panagiotis Kanavos | // configure the form |
447 | 46426dbd | Panagiotis Kanavos | frm.TopMost = true; |
448 | 46426dbd | Panagiotis Kanavos | |
449 | 46426dbd | Panagiotis Kanavos | if (HideReleaseNotes) |
450 | 46426dbd | Panagiotis Kanavos | frm.RemoveReleaseNotesControls(); |
451 | 049333d2 | Panagiotis Kanavos | |
452 | 46426dbd | Panagiotis Kanavos | |
453 | 46426dbd | Panagiotis Kanavos | // show it |
454 | 46426dbd | Panagiotis Kanavos | DialogResult dlgResult = frm.ShowDialog(); |
455 | 46426dbd | Panagiotis Kanavos | |
456 | 46426dbd | Panagiotis Kanavos | |
457 | 46426dbd | Panagiotis Kanavos | if (dlgResult == DialogResult.No) |
458 | 46426dbd | Panagiotis Kanavos | { |
459 | 46426dbd | Panagiotis Kanavos | // skip this version |
460 | 46426dbd | Panagiotis Kanavos | NetSparkleConfiguration config = new NetSparkleConfiguration(_AppReferenceAssembly); |
461 | 46426dbd | Panagiotis Kanavos | config.SetVersionToSkip(currentItem.Version); |
462 | 46426dbd | Panagiotis Kanavos | } |
463 | 46426dbd | Panagiotis Kanavos | else if (dlgResult == DialogResult.Yes) |
464 | 46426dbd | Panagiotis Kanavos | { |
465 | 46426dbd | Panagiotis Kanavos | // download the binaries |
466 | 46426dbd | Panagiotis Kanavos | InitDownloadAndInstallProcess(currentItem); |
467 | 46426dbd | Panagiotis Kanavos | } |
468 | 46426dbd | Panagiotis Kanavos | |
469 | 46426dbd | Panagiotis Kanavos | } |
470 | 46426dbd | Panagiotis Kanavos | |
471 | 46426dbd | Panagiotis Kanavos | /// <summary> |
472 | 46426dbd | Panagiotis Kanavos | /// This method reports a message in the diagnostic window |
473 | 46426dbd | Panagiotis Kanavos | /// </summary> |
474 | 46426dbd | Panagiotis Kanavos | /// <param name="message"></param> |
475 | 46426dbd | Panagiotis Kanavos | public void ReportDiagnosticMessage(String message) |
476 | 46426dbd | Panagiotis Kanavos | { |
477 | 46426dbd | Panagiotis Kanavos | if (_DiagnosticWindow.InvokeRequired) |
478 | 46426dbd | Panagiotis Kanavos | { |
479 | 46426dbd | Panagiotis Kanavos | _DiagnosticWindow.Invoke(new Action<String>(ReportDiagnosticMessage), message); |
480 | 46426dbd | Panagiotis Kanavos | } |
481 | 46426dbd | Panagiotis Kanavos | else |
482 | 46426dbd | Panagiotis Kanavos | { |
483 | 46426dbd | Panagiotis Kanavos | _DiagnosticWindow.Report(message); |
484 | 46426dbd | Panagiotis Kanavos | } |
485 | 46426dbd | Panagiotis Kanavos | } |
486 | 46426dbd | Panagiotis Kanavos | |
487 | 46426dbd | Panagiotis Kanavos | /// <summary> |
488 | 46426dbd | Panagiotis Kanavos | /// This method will be executed as worker thread |
489 | 46426dbd | Panagiotis Kanavos | /// </summary> |
490 | 46426dbd | Panagiotis Kanavos | /// <param name="sender"></param> |
491 | 46426dbd | Panagiotis Kanavos | /// <param name="e"></param> |
492 | 46426dbd | Panagiotis Kanavos | void _worker_DoWork(object sender, DoWorkEventArgs e) |
493 | 46426dbd | Panagiotis Kanavos | { |
494 | 46426dbd | Panagiotis Kanavos | // store the did run once feature |
495 | 46426dbd | Panagiotis Kanavos | Boolean goIntoLoop = true; |
496 | 46426dbd | Panagiotis Kanavos | Boolean checkTSP = true; |
497 | 46426dbd | Panagiotis Kanavos | Boolean doInitialCheck = _DoInitialCheck; |
498 | 46426dbd | Panagiotis Kanavos | Boolean isInitialCheck = true; |
499 | 46426dbd | Panagiotis Kanavos | |
500 | 46426dbd | Panagiotis Kanavos | // start our lifecycles |
501 | 46426dbd | Panagiotis Kanavos | do |
502 | 46426dbd | Panagiotis Kanavos | { |
503 | 46426dbd | Panagiotis Kanavos | // set state |
504 | 46426dbd | Panagiotis Kanavos | Boolean bUpdateRequired = false; |
505 | 46426dbd | Panagiotis Kanavos | |
506 | 46426dbd | Panagiotis Kanavos | // notify |
507 | 46426dbd | Panagiotis Kanavos | if (checkLoopStarted != null) |
508 | 46426dbd | Panagiotis Kanavos | checkLoopStarted(this); |
509 | 46426dbd | Panagiotis Kanavos | |
510 | 46426dbd | Panagiotis Kanavos | // report status |
511 | 46426dbd | Panagiotis Kanavos | if (doInitialCheck == false) |
512 | 46426dbd | Panagiotis Kanavos | { |
513 | 46426dbd | Panagiotis Kanavos | ReportDiagnosticMessage("Initial check prohibited, going to wait"); |
514 | 46426dbd | Panagiotis Kanavos | doInitialCheck = true; |
515 | 46426dbd | Panagiotis Kanavos | goto WaitSection; |
516 | 46426dbd | Panagiotis Kanavos | } |
517 | 46426dbd | Panagiotis Kanavos | |
518 | 46426dbd | Panagiotis Kanavos | // report status |
519 | 46426dbd | Panagiotis Kanavos | ReportDiagnosticMessage("Starting update loop..."); |
520 | 46426dbd | Panagiotis Kanavos | |
521 | 46426dbd | Panagiotis Kanavos | // read the config |
522 | 46426dbd | Panagiotis Kanavos | ReportDiagnosticMessage("Reading config..."); |
523 | 46426dbd | Panagiotis Kanavos | NetSparkleConfiguration config = GetApplicationConfig(); |
524 | 46426dbd | Panagiotis Kanavos | |
525 | 46426dbd | Panagiotis Kanavos | // calc CheckTasp |
526 | 46426dbd | Panagiotis Kanavos | Boolean checkTSPInternal = checkTSP; |
527 | 46426dbd | Panagiotis Kanavos | |
528 | 46426dbd | Panagiotis Kanavos | if (isInitialCheck && checkTSPInternal) |
529 | 46426dbd | Panagiotis Kanavos | checkTSPInternal = !_ForceInitialCheck; |
530 | 46426dbd | Panagiotis Kanavos | |
531 | 46426dbd | Panagiotis Kanavos | // check if it's ok the recheck to software state |
532 | 46426dbd | Panagiotis Kanavos | if (checkTSPInternal) |
533 | 46426dbd | Panagiotis Kanavos | { |
534 | 46426dbd | Panagiotis Kanavos | TimeSpan csp = DateTime.Now - config.LastCheckTime; |
535 | 46426dbd | Panagiotis Kanavos | if (csp < _CheckFrequency) |
536 | 46426dbd | Panagiotis Kanavos | { |
537 | 46426dbd | Panagiotis Kanavos | ReportDiagnosticMessage(String.Format("Update check performed within the last {0} minutes!", _CheckFrequency.TotalMinutes)); |
538 | 46426dbd | Panagiotis Kanavos | goto WaitSection; |
539 | 46426dbd | Panagiotis Kanavos | } |
540 | 46426dbd | Panagiotis Kanavos | } |
541 | 46426dbd | Panagiotis Kanavos | else |
542 | 46426dbd | Panagiotis Kanavos | checkTSP = true; |
543 | 46426dbd | Panagiotis Kanavos | |
544 | 46426dbd | Panagiotis Kanavos | // when sparkle will be deactivated wait an other cycle |
545 | 46426dbd | Panagiotis Kanavos | if (config.CheckForUpdate == false) |
546 | 46426dbd | Panagiotis Kanavos | { |
547 | 46426dbd | Panagiotis Kanavos | ReportDiagnosticMessage("Check for updates disabled"); |
548 | 46426dbd | Panagiotis Kanavos | goto WaitSection; |
549 | 46426dbd | Panagiotis Kanavos | } |
550 | 46426dbd | Panagiotis Kanavos | |
551 | 46426dbd | Panagiotis Kanavos | // update the runonce feature |
552 | 46426dbd | Panagiotis Kanavos | goIntoLoop = !config.DidRunOnce; |
553 | 46426dbd | Panagiotis Kanavos | |
554 | 46426dbd | Panagiotis Kanavos | // update profile information is needed |
555 | 46426dbd | Panagiotis Kanavos | UpdateSystemProfileInformation(config); |
556 | 46426dbd | Panagiotis Kanavos | |
557 | 46426dbd | Panagiotis Kanavos | // check if update is required |
558 | 46426dbd | Panagiotis Kanavos | NetSparkleAppCastItem latestVersion = null; |
559 | 46426dbd | Panagiotis Kanavos | bUpdateRequired = IsUpdateRequired(config, out latestVersion); |
560 | 46426dbd | Panagiotis Kanavos | if (!bUpdateRequired) |
561 | 46426dbd | Panagiotis Kanavos | goto WaitSection; |
562 | 46426dbd | Panagiotis Kanavos | |
563 | 46426dbd | Panagiotis Kanavos | // show the update window |
564 | 46426dbd | Panagiotis Kanavos | ReportDiagnosticMessage("Update needed from version " + config.InstalledVersion + " to version " + latestVersion.Version); |
565 | 46426dbd | Panagiotis Kanavos | |
566 | 46426dbd | Panagiotis Kanavos | // send notification if needed |
567 | 46426dbd | Panagiotis Kanavos | UpdateDetectedEventArgs ev = new UpdateDetectedEventArgs() { NextAction = nNextUpdateAction.showStandardUserInterface, ApplicationConfig = config, LatestVersion = latestVersion }; |
568 | 46426dbd | Panagiotis Kanavos | if (updateDetected != null) |
569 | 46426dbd | Panagiotis Kanavos | updateDetected(this, ev); |
570 | 46426dbd | Panagiotis Kanavos | |
571 | 46426dbd | Panagiotis Kanavos | // check results |
572 | 46426dbd | Panagiotis Kanavos | switch(ev.NextAction) |
573 | 46426dbd | Panagiotis Kanavos | { |
574 | 46426dbd | Panagiotis Kanavos | case nNextUpdateAction.performUpdateUnattended: |
575 | 46426dbd | Panagiotis Kanavos | { |
576 | 46426dbd | Panagiotis Kanavos | ReportDiagnosticMessage("Unattended update whished from consumer"); |
577 | 46426dbd | Panagiotis Kanavos | EnableSilentMode = true; |
578 | 46426dbd | Panagiotis Kanavos | _worker.ReportProgress(1, latestVersion); |
579 | 46426dbd | Panagiotis Kanavos | break; |
580 | 46426dbd | Panagiotis Kanavos | } |
581 | 46426dbd | Panagiotis Kanavos | case nNextUpdateAction.prohibitUpdate: |
582 | 46426dbd | Panagiotis Kanavos | { |
583 | 46426dbd | Panagiotis Kanavos | ReportDiagnosticMessage("Update prohibited from consumer"); |
584 | 46426dbd | Panagiotis Kanavos | break; |
585 | 46426dbd | Panagiotis Kanavos | } |
586 | 46426dbd | Panagiotis Kanavos | case nNextUpdateAction.showStandardUserInterface: |
587 | 46426dbd | Panagiotis Kanavos | default: |
588 | 46426dbd | Panagiotis Kanavos | { |
589 | 46426dbd | Panagiotis Kanavos | ReportDiagnosticMessage("Standard UI update whished from consumer"); |
590 | 46426dbd | Panagiotis Kanavos | _worker.ReportProgress(1, latestVersion); |
591 | 46426dbd | Panagiotis Kanavos | break; |
592 | 46426dbd | Panagiotis Kanavos | } |
593 | 46426dbd | Panagiotis Kanavos | } |
594 | 46426dbd | Panagiotis Kanavos | |
595 | 46426dbd | Panagiotis Kanavos | WaitSection: |
596 | 46426dbd | Panagiotis Kanavos | // reset initialcheck |
597 | 46426dbd | Panagiotis Kanavos | isInitialCheck = false; |
598 | 46426dbd | Panagiotis Kanavos | |
599 | 46426dbd | Panagiotis Kanavos | // notify |
600 | 46426dbd | Panagiotis Kanavos | if (checkLoopFinished != null) |
601 | 46426dbd | Panagiotis Kanavos | checkLoopFinished(this, bUpdateRequired); |
602 | 46426dbd | Panagiotis Kanavos | |
603 | 46426dbd | Panagiotis Kanavos | // report wait statement |
604 | 46426dbd | Panagiotis Kanavos | ReportDiagnosticMessage(String.Format("Sleeping for an other {0} minutes, exit event or force update check event", _CheckFrequency.TotalMinutes)); |
605 | 46426dbd | Panagiotis Kanavos | |
606 | 46426dbd | Panagiotis Kanavos | // wait for |
607 | 46426dbd | Panagiotis Kanavos | if (!goIntoLoop) |
608 | 46426dbd | Panagiotis Kanavos | break; |
609 | 46426dbd | Panagiotis Kanavos | else |
610 | 46426dbd | Panagiotis Kanavos | { |
611 | 46426dbd | Panagiotis Kanavos | // build the event array |
612 | 46426dbd | Panagiotis Kanavos | WaitHandle[] handles = new WaitHandle[1]; |
613 | 46426dbd | Panagiotis Kanavos | handles[0] = _exitHandle; |
614 | 46426dbd | Panagiotis Kanavos | |
615 | 46426dbd | Panagiotis Kanavos | // wait for any |
616 | 46426dbd | Panagiotis Kanavos | int i = WaitHandle.WaitAny(handles, _CheckFrequency); |
617 | 46426dbd | Panagiotis Kanavos | if (WaitHandle.WaitTimeout == i) |
618 | 46426dbd | Panagiotis Kanavos | { |
619 | 46426dbd | Panagiotis Kanavos | ReportDiagnosticMessage(String.Format("{0} minutes are over", _CheckFrequency.TotalMinutes)); |
620 | 46426dbd | Panagiotis Kanavos | continue; |
621 | 46426dbd | Panagiotis Kanavos | } |
622 | 46426dbd | Panagiotis Kanavos | |
623 | 46426dbd | Panagiotis Kanavos | // check the exit hadnle |
624 | 46426dbd | Panagiotis Kanavos | if (i == 0) |
625 | 46426dbd | Panagiotis Kanavos | { |
626 | 46426dbd | Panagiotis Kanavos | ReportDiagnosticMessage("Got exit signal"); |
627 | 46426dbd | Panagiotis Kanavos | break; |
628 | 46426dbd | Panagiotis Kanavos | } |
629 | 46426dbd | Panagiotis Kanavos | |
630 | 46426dbd | Panagiotis Kanavos | // check an other check needed |
631 | 46426dbd | Panagiotis Kanavos | if (i == 1) |
632 | 46426dbd | Panagiotis Kanavos | { |
633 | 46426dbd | Panagiotis Kanavos | ReportDiagnosticMessage("Got force update check signal"); |
634 | 46426dbd | Panagiotis Kanavos | checkTSP = false; |
635 | 46426dbd | Panagiotis Kanavos | continue; |
636 | 46426dbd | Panagiotis Kanavos | } |
637 | 46426dbd | Panagiotis Kanavos | } |
638 | 46426dbd | Panagiotis Kanavos | } while (goIntoLoop); |
639 | 46426dbd | Panagiotis Kanavos | |
640 | 46426dbd | Panagiotis Kanavos | // reset the islooping handle |
641 | 46426dbd | Panagiotis Kanavos | _loopingHandle.Reset(); |
642 | 46426dbd | Panagiotis Kanavos | } |
643 | 46426dbd | Panagiotis Kanavos | |
644 | 46426dbd | Panagiotis Kanavos | /// <summary> |
645 | 46426dbd | Panagiotis Kanavos | /// This method will be notified |
646 | 46426dbd | Panagiotis Kanavos | /// </summary> |
647 | 46426dbd | Panagiotis Kanavos | /// <param name="sender"></param> |
648 | 46426dbd | Panagiotis Kanavos | /// <param name="e"></param> |
649 | 46426dbd | Panagiotis Kanavos | private void _worker_ProgressChanged(object sender, ProgressChangedEventArgs e) |
650 | 46426dbd | Panagiotis Kanavos | { |
651 | 46426dbd | Panagiotis Kanavos | switch (e.ProgressPercentage) |
652 | 46426dbd | Panagiotis Kanavos | { |
653 | 46426dbd | Panagiotis Kanavos | case 1: |
654 | 46426dbd | Panagiotis Kanavos | { |
655 | 46426dbd | Panagiotis Kanavos | // get the current item |
656 | 46426dbd | Panagiotis Kanavos | NetSparkleAppCastItem currentItem = e.UserState as NetSparkleAppCastItem; |
657 | 46426dbd | Panagiotis Kanavos | |
658 | 46426dbd | Panagiotis Kanavos | // show the update ui |
659 | 46426dbd | Panagiotis Kanavos | if (EnableSilentMode == true) |
660 | 46426dbd | Panagiotis Kanavos | InitDownloadAndInstallProcess(currentItem); |
661 | 46426dbd | Panagiotis Kanavos | else |
662 | 46426dbd | Panagiotis Kanavos | ShowUpdateNeededUI(currentItem); |
663 | 46426dbd | Panagiotis Kanavos | |
664 | 46426dbd | Panagiotis Kanavos | break; |
665 | 46426dbd | Panagiotis Kanavos | } |
666 | 46426dbd | Panagiotis Kanavos | case 0: |
667 | 46426dbd | Panagiotis Kanavos | { |
668 | 46426dbd | Panagiotis Kanavos | ReportDiagnosticMessage(e.UserState.ToString()); |
669 | 46426dbd | Panagiotis Kanavos | break; |
670 | 46426dbd | Panagiotis Kanavos | } |
671 | 46426dbd | Panagiotis Kanavos | } |
672 | 46426dbd | Panagiotis Kanavos | } |
673 | 46426dbd | Panagiotis Kanavos | |
674 | 46426dbd | Panagiotis Kanavos | private void InitDownloadAndInstallProcess(NetSparkleAppCastItem item) |
675 | 46426dbd | Panagiotis Kanavos | { |
676 | 46426dbd | Panagiotis Kanavos | NetSparkleDownloadProgress dlProgress = new NetSparkleDownloadProgress(this, item, _AppReferenceAssembly, ApplicationIcon, ApplicationWindowIcon, EnableSilentMode); |
677 | 46426dbd | Panagiotis Kanavos | dlProgress.ShowDialog(); |
678 | 46426dbd | Panagiotis Kanavos | } |
679 | 46426dbd | Panagiotis Kanavos | |
680 | 46426dbd | Panagiotis Kanavos | private void ShowDiagnosticWindowIfNeeded() |
681 | 46426dbd | Panagiotis Kanavos | { |
682 | 46426dbd | Panagiotis Kanavos | if (_DiagnosticWindow.InvokeRequired) |
683 | 46426dbd | Panagiotis Kanavos | { |
684 | 46426dbd | Panagiotis Kanavos | _DiagnosticWindow.Invoke(new Action(ShowDiagnosticWindowIfNeeded)); |
685 | 46426dbd | Panagiotis Kanavos | } |
686 | 46426dbd | Panagiotis Kanavos | else |
687 | 46426dbd | Panagiotis Kanavos | { |
688 | 46426dbd | Panagiotis Kanavos | // check the diagnotic value |
689 | 46426dbd | Panagiotis Kanavos | NetSparkleConfiguration config = new NetSparkleConfiguration(_AppReferenceAssembly); |
690 | 46426dbd | Panagiotis Kanavos | if (config.ShowDiagnosticWindow || ShowDiagnosticWindow) |
691 | 46426dbd | Panagiotis Kanavos | { |
692 | 46426dbd | Panagiotis Kanavos | Point newLocation = new Point(); |
693 | 46426dbd | Panagiotis Kanavos | |
694 | 46426dbd | Panagiotis Kanavos | newLocation.X = Screen.PrimaryScreen.Bounds.Width - _DiagnosticWindow.Width; |
695 | 46426dbd | Panagiotis Kanavos | newLocation.Y = 0; |
696 | 46426dbd | Panagiotis Kanavos | |
697 | 46426dbd | Panagiotis Kanavos | _DiagnosticWindow.Location = newLocation; |
698 | 46426dbd | Panagiotis Kanavos | _DiagnosticWindow.Show(); |
699 | 46426dbd | Panagiotis Kanavos | } |
700 | 46426dbd | Panagiotis Kanavos | } |
701 | 46426dbd | Panagiotis Kanavos | } |
702 | 46426dbd | Panagiotis Kanavos | |
703 | 46426dbd | Panagiotis Kanavos | private bool RemoteCertificateValidation(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) |
704 | 46426dbd | Panagiotis Kanavos | { |
705 | 46426dbd | Panagiotis Kanavos | if (TrustEverySSLConnection) |
706 | 46426dbd | Panagiotis Kanavos | { |
707 | 46426dbd | Panagiotis Kanavos | // verify if we talk about our app cast dll |
708 | 46426dbd | Panagiotis Kanavos | HttpWebRequest req = sender as HttpWebRequest; |
709 | 46426dbd | Panagiotis Kanavos | if (req == null) |
710 | 46426dbd | Panagiotis Kanavos | return (certificate is X509Certificate2) ? ((X509Certificate2)certificate).Verify() : false; |
711 | 46426dbd | Panagiotis Kanavos | |
712 | 46426dbd | Panagiotis Kanavos | // if so just return our trust |
713 | 46426dbd | Panagiotis Kanavos | if (req.RequestUri.Equals(new Uri(_AppCastUrl))) |
714 | 46426dbd | Panagiotis Kanavos | return true; |
715 | 46426dbd | Panagiotis Kanavos | else |
716 | 46426dbd | Panagiotis Kanavos | return (certificate is X509Certificate2) ? ((X509Certificate2)certificate).Verify() : false; |
717 | 46426dbd | Panagiotis Kanavos | } |
718 | 46426dbd | Panagiotis Kanavos | else |
719 | 46426dbd | Panagiotis Kanavos | { |
720 | 46426dbd | Panagiotis Kanavos | // check our cert |
721 | 46426dbd | Panagiotis Kanavos | return (certificate is X509Certificate2) ? ((X509Certificate2)certificate).Verify() : false; |
722 | 46426dbd | Panagiotis Kanavos | } |
723 | 46426dbd | Panagiotis Kanavos | } |
724 | 46426dbd | Panagiotis Kanavos | } |
725 | 46426dbd | Panagiotis Kanavos | } |