@@ -47,7 +47,6 @@ public void FreeMutex()
47
47
48
48
private void Application_Startup ( object sender , StartupEventArgs e )
49
49
{
50
-
51
50
InitLanguage ( ) ;
52
51
if ( e . Args . Length > 0 )
53
52
{
@@ -170,6 +169,34 @@ private void InitViewAndNeedCloseResourcees()
170
169
SystemParameters . StaticPropertyChanged += SystemParameters_StaticPropertyChanged ;
171
170
timer . Elapsed += Timer_Elapsed ;
172
171
timer . Enabled = true ;
172
+ if ( Settings . Default . AutoUpdate )
173
+ {
174
+ System . Timers . Timer myTimer = new System . Timers . Timer
175
+ {
176
+ AutoReset = false ,
177
+ Interval = 2000
178
+ } ;
179
+ myTimer . Elapsed += MyTimer_Elapsed_AutoCheckUpdate ;
180
+ myTimer . Enabled = true ;
181
+ }
182
+ }
183
+
184
+ private void MyTimer_Elapsed_AutoCheckUpdate ( object sender , ElapsedEventArgs e )
185
+ {
186
+ try
187
+ {
188
+ System . Net . NetworkInformation . Ping ping = new System . Net . NetworkInformation . Ping ( ) ;
189
+ System . Net . NetworkInformation . PingReply pr = ping . Send ( "www.baidu.com" , 12000 ) ;
190
+ if ( pr . Status == System . Net . NetworkInformation . IPStatus . Success )
191
+ {
192
+ checkUpdateManager . CheckForUpdates ( false ) ;
193
+ }
194
+ }
195
+ catch ( Exception e2 )
196
+ {
197
+ Console . WriteLine ( e2 . ToString ( ) ) ;
198
+ }
199
+
173
200
}
174
201
175
202
private void SystemParameters_StaticPropertyChanged ( object sender , System . ComponentModel . PropertyChangedEventArgs e )
@@ -256,8 +283,15 @@ private void InitializeTray()
256
283
{
257
284
menuDefault . Checked = true ;
258
285
}
259
-
260
- System . Windows . Forms . ContextMenu menu = new System . Windows . Forms . ContextMenu ( new System . Windows . Forms . MenuItem [ ] { menuStartOnBoot , menuEdgeHide , menuLanguage , menuExit } ) ;
286
+ menuAutoUpdate = new System . Windows . Forms . MenuItem ( FindResource ( "CheckForUpdatesAutomatically" ) . ToString ( ) , TrayMenu_Click )
287
+ {
288
+ Checked = Settings . Default . AutoUpdate
289
+ } ;
290
+ menuCheckUpdate = new System . Windows . Forms . MenuItem ( FindResource ( "CheckForUpdates" ) . ToString ( ) , TrayMenu_Click ) ;
291
+ System . Windows . Forms . MenuItem menuUpdate = new System . Windows . Forms . MenuItem ( FindResource ( "Update" ) . ToString ( ) ) ;
292
+ menuUpdate . MenuItems . Add ( menuAutoUpdate ) ;
293
+ menuUpdate . MenuItems . Add ( menuCheckUpdate ) ;
294
+ System . Windows . Forms . ContextMenu menu = new System . Windows . Forms . ContextMenu ( new System . Windows . Forms . MenuItem [ ] { menuStartOnBoot , menuEdgeHide , menuLanguage , menuUpdate , menuExit } ) ;
261
295
262
296
notifyIcon = new System . Windows . Forms . NotifyIcon
263
297
{
@@ -298,6 +332,17 @@ public void TryToSetLanguage(String path)
298
332
}
299
333
}
300
334
335
+ public void TryToSetAutoUpdate ( bool autoUpdate )
336
+ {
337
+ Settings . Default . AutoUpdate = autoUpdate ;
338
+ Settings . Default . Save ( ) ;
339
+ }
340
+
341
+ public void TryToCheckUpdate ( )
342
+ {
343
+ checkUpdateManager . CheckForUpdates ( true ) ;
344
+ }
345
+
301
346
public void TryToSetStartOnBoot ( bool startOnBoot )
302
347
{
303
348
Settings . Default . startOnBoot = startOnBoot ;
@@ -350,6 +395,16 @@ private void TrayMenu_Click(object sender, EventArgs e)
350
395
mainWindow . WindowMenuEdgeHide . IsChecked = menuEdgeHide . Checked ;
351
396
TryToSetEdgeHide ( menuEdgeHide . Checked ) ;
352
397
}
398
+ else if ( sender == menuAutoUpdate )
399
+ {
400
+ menuAutoUpdate . Checked = ! menuAutoUpdate . Checked ;
401
+ mainWindow . WindowMenuAutoUpdate . IsChecked = menuAutoUpdate . Checked ;
402
+ TryToSetAutoUpdate ( menuAutoUpdate . Checked ) ;
403
+ }
404
+ else if ( sender == menuCheckUpdate )
405
+ {
406
+ TryToCheckUpdate ( ) ;
407
+ }
353
408
}
354
409
355
410
private void Timer_Elapsed ( object sender , ElapsedEventArgs e )
@@ -366,7 +421,7 @@ private void Timer_Elapsed(object sender, ElapsedEventArgs e)
366
421
} ) ) ;
367
422
}
368
423
369
- public System . Windows . Forms . MenuItem menuExit , menuEdgeHide , menuStartOnBoot ;
424
+ public System . Windows . Forms . MenuItem menuExit , menuEdgeHide , menuStartOnBoot , menuAutoUpdate , menuCheckUpdate ;
370
425
371
426
private System . Windows . Forms . NotifyIcon notifyIcon ;
372
427
private MainWindow mainWindow ;
@@ -375,6 +430,7 @@ private void Timer_Elapsed(object sender, ElapsedEventArgs e)
375
430
private CaptureManager captureManager ;
376
431
private UDMap udMap = new UDMap ( ) ;
377
432
private PortProcessMap portProcessMap = PortProcessMap . GetInstance ( ) ;
433
+ private CheckUpdateManager checkUpdateManager = new CheckUpdateManager ( ) ;
378
434
379
435
private System . Timers . Timer timer = new System . Timers . Timer
380
436
{
0 commit comments