/
AutomaticUpdater.cs
1535 lines (1225 loc) · 50.4 KB
/
AutomaticUpdater.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace wyDay.Controls
{
#if NET_2_0
/// <summary>
/// Represents the AutomaticUpdater control.
/// </summary>
[Designer(typeof(AutomaticUpdaterDesigner))]
#else
/// <summary>
/// Represents the AutomaticUpdater control.
/// </summary>
[Designer("wyDay.Controls.AutomaticUpdaterDesigner, AutomaticUpdater.Design")]
#endif
[ToolboxBitmapAttribute(typeof(AutomaticUpdater), "update-notify.png")]
public class AutomaticUpdater : ContainerControl, ISupportInitialize
{
AutomaticUpdaterBackend auBackend = new AutomaticUpdaterBackend(true);
Form ownerForm;
readonly AnimationControl ani = new AnimationControl();
Rectangle textRect;
readonly Timer tmrCollapse = new Timer { Interval = 3000 };
readonly Timer tmrAniExpandCollapse = new Timer { Interval = 30 };
int m_WaitBeforeCheckSecs = 10;
readonly Timer tmrWaitBeforeCheck = new Timer { Interval = 10000 };
int m_DaysBetweenChecks = 12;
FailArgs failArgs;
ContextMenu contextMenu;
MenuType CurrMenuType = MenuType.Nothing;
bool isMenuVisible;
// changes
bool ShowButtonUpdateNow;
string currentActionText;
// menu items
ToolStripItem toolStripItem;
MenuItem menuItem;
static readonly Bitmap BmpInfo = new Bitmap(typeof (AutomaticUpdater), "info.png");
static readonly Bitmap BmpWorking = new Bitmap(typeof (AutomaticUpdater), "update-working.png");
static readonly Bitmap BmpNotify = new Bitmap(typeof (AutomaticUpdater), "update-notify.png");
static readonly Bitmap BmpSuccess = new Bitmap(typeof (AutomaticUpdater), "tick.png");
static readonly Bitmap BmpFailed = new Bitmap(typeof (AutomaticUpdater), "cross.png");
SolidBrush backBrush;
#region Events
/// <summary>
/// Event is raised before the update checking begins.
/// </summary>
[Description("Event is raised before the update checking begins."),
Category("Updater")]
public event BeforeHandler BeforeChecking;
/// <summary>
/// Event is raised before the downloading of the update begins.
/// </summary>
[Description("Event is raised before the downloading of the update begins."),
Category("Updater")]
public event BeforeHandler BeforeDownloading;
/// <summary>
/// Event is raised when checking or updating is cancelled.
/// </summary>
[Description("Event is raised when checking or updating is cancelled."),
Category("Updater")]
public event EventHandler Cancelled;
/// <summary>
/// Event is raised when the checking for updates fails.
/// </summary>
[Description("Event is raised when the checking for updates fails."),
Category("Updater")]
public event FailHandler CheckingFailed;
/// <summary>
/// Event is raised after you or your user invoked InstallNow(). You should close your app as quickly as possible (because wyUpdate will be waiting).
/// </summary>
[Description("Event is raised after you or your user invoked InstallNow(). You should close your app as quickly as possible (because wyUpdate will be waiting)."),
Category("Updater")]
public event EventHandler CloseAppNow;
/// <summary>
/// Event is raised when an update can't be installed and the closing is aborted.
/// </summary>
[Description("Event is raised when an update can't be installed and the closing is aborted."),
Category("Updater")]
public event EventHandler ClosingAborted;
/// <summary>
/// Event is raised when the update fails to download or extract.
/// </summary>
[Description("Event is raised when the update fails to download or extract."),
Category("Updater")]
public event FailHandler DownloadingOrExtractingFailed;
/// <summary>
/// Event is raised when the current update step progress changes.
/// </summary>
[Description("Event is raised when the current update step progress changes."),
Category("Updater")]
public event UpdateProgressChanged ProgressChanged;
/// <summary>
/// Event is raised when the update is ready to be installed.
/// </summary>
[Description("Event is raised when the update is ready to be installed."),
Category("Updater")]
public event EventHandler ReadyToBeInstalled;
/// <summary>
/// Event is raised when a new update is found.
/// </summary>
[Description("Event is raised when a new update is found."),
Category("Updater")]
public event EventHandler UpdateAvailable;
/// <summary>
/// Event is raised when an update fails to install.
/// </summary>
[Description("Event is raised when an update fails to install."),
Category("Updater")]
public event FailHandler UpdateFailed;
/// <summary>
/// Event is raised when an update installs successfully.
/// </summary>
[Description("Event is raised when an update installs successfully."),
Category("Updater")]
public event SuccessHandler UpdateSuccessful;
/// <summary>
/// Event is raised when the latest version is already installed.
/// </summary>
[Description("Event is raised when the latest version is already installed."),
Category("Updater")]
public event SuccessHandler UpToDate;
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public event EventHandler TextChanged;
#endregion Events
#region Properties
/// <summary>
/// Gets or sets whether to slide the AutomaticUpdater out when you hover over it and in when you hover away.
/// </summary>
[Description("Whether to slide the AutomaticUpdater out when you hover over it and in when you hover away."),
DefaultValue(true),
Category("Updater")]
public bool Animate { get; set; }
/// <summary>
/// Gets or sets the arguments to pass to your app when it's being restarted after an update.
/// </summary>
[Description("The arguments to pass to your app when it's being restarted after an update."),
DefaultValue(null),
Category("Updater")]
public string Arguments
{
get { return auBackend.Arguments; }
set { auBackend.Arguments = value; }
}
/// <summary>
/// Gets the changes for the new update.
/// </summary>
[Browsable(false)]
public string Changes { get { return auBackend.Changes; } }
/// <summary>
/// Gets if this AutomaticUpdater has hidden this form and preparing to install an update.
/// </summary>
[Browsable(false)]
public bool ClosingForInstall { get { return auBackend.ClosingForInstall; } }
/// <summary>
/// Gets or sets the number of days to wait before automatically re-checking for updates.
/// </summary>
[Description("The number of days to wait before automatically re-checking for updates."),
DefaultValue(12),
Category("Updater")]
public int DaysBetweenChecks
{
get { return m_DaysBetweenChecks; }
set { m_DaysBetweenChecks = value; }
}
/// <summary>
/// Gets the GUID (Globally Unique ID) of the automatic updater. It is recommended you set this value (especially if there is more than one exe for your product).
/// </summary>
/// <exception cref="System.Exception">Thrown when trying to set the GUID at runtime.</exception>
[Description("The GUID (Globally Unique ID) of the automatic updater. It is recommended you set this value (especially if there is more than one exe for your product)."),
Category("Updater"),
DefaultValue(null),
EditorAttribute(typeof(GUIDEditor), typeof(UITypeEditor)),
EditorBrowsable(EditorBrowsableState.Never)]
public string GUID
{
get { return auBackend.GUID; }
set { auBackend.GUID = value; }
}
bool ShouldSerializeGUID()
{
return !string.IsNullOrEmpty(auBackend.GUID);
}
/// <summary>
/// Gets or sets whether the AutomaticUpdater control should stay hidden even when the user should be notified. (Not recommended).
/// </summary>
[Description("Keeps the AutomaticUpdater control hidden even when the user should be notified. (Not recommended)"),
DefaultValue(false),
Category("Updater")]
public bool KeepHidden { get; set; }
/// <summary>
/// Gets the date the updates were last checked for.
/// </summary>
[Browsable(false)]
public DateTime LastCheckDate
{
get { return auBackend.LastCheckDate; }
}
/// <summary>
/// Gets and sets the MenuItem that will be used to check for updates.
/// </summary>
[Description("The MenuItem that will be used to check for updates."),
Category("Updater"),
DefaultValue(null)]
public MenuItem MenuItem
{
get
{
return menuItem;
}
set
{
if (menuItem != null)
menuItem.Click -= menuItem_Click;
menuItem = value;
if (menuItem != null)
menuItem.Click += menuItem_Click;
}
}
/// <summary>
/// Gets and sets the ToolStripItem that will be used to check for updates.
/// </summary>
[Description("The ToolStripItem that will be used to check for updates."),
Category("Updater"),
DefaultValue(null)]
public ToolStripItem ToolStripItem
{
get
{
return toolStripItem;
}
set
{
if (toolStripItem != null)
toolStripItem.Click -= menuItem_Click;
toolStripItem = value;
if (toolStripItem != null)
toolStripItem.Click += menuItem_Click;
}
}
AUTranslation translation = new AUTranslation();
/// <summary>
/// The translation for the english strings in the AutomaticUpdater control.
/// </summary>
/// <exception cref="ArgumentNullException">The translation cannot be null.</exception>
[Browsable(false)]
public AUTranslation Translation
{
get { return translation; }
set
{
if (value == null)
throw new ArgumentNullException("value", "No translation present.");
translation = value;
}
}
bool ShouldSerializeTranslation() { return false; }
/// <summary>
/// Gets the update step the AutomaticUpdater is currently on.
/// </summary>
[Browsable(false)]
public UpdateStepOn UpdateStepOn { get { return auBackend.UpdateStepOn; } }
/// <summary>
/// Gets or sets how much this AutomaticUpdater control should do without user interaction.
/// </summary>
[Description("How much this AutomaticUpdater control should do without user interaction."),
DefaultValue(UpdateType.Automatic),
Category("Updater")]
public UpdateType UpdateType
{
get { return auBackend.UpdateType; }
set { auBackend.UpdateType = value; }
}
/// <summary>
/// Gets the version of the new update.
/// </summary>
[Browsable(false)]
public string Version { get { return auBackend.Version; } }
/// <summary>
/// Gets or sets the seconds to wait after the form is loaded before checking for updates.
/// </summary>
[Description("Seconds to wait after the form is loaded before checking for updates."),
DefaultValue(10),
Category("Updater")]
public int WaitBeforeCheckSecs
{
get { return m_WaitBeforeCheckSecs; }
set
{
m_WaitBeforeCheckSecs = value;
tmrWaitBeforeCheck.Interval = m_WaitBeforeCheckSecs * 1000;
}
}
/// <summary>
/// Gets or sets the arguments to pass to wyUpdate when it is started to check for updates.
/// </summary>
[Description("Arguments to pass to wyUpdate when it is started to check for updates."),
Category("Updater")]
public string wyUpdateCommandline
{
get { return auBackend.wyUpdateCommandline; }
set { auBackend.wyUpdateCommandline = value; }
}
/// <summary>
/// Gets or sets the relative path to the wyUpdate (e.g. wyUpdate.exe or SubDir\\wyUpdate.exe)
/// </summary>
[Description("The relative path to the wyUpdate (e.g. wyUpdate.exe or SubDir\\wyUpdate.exe)"),
DefaultValue("wyUpdate.exe"),
Category("Updater")]
public string wyUpdateLocation
{
get { return auBackend.wyUpdateLocation; }
set { auBackend.wyUpdateLocation = value; }
}
[Bindable(false), EditorBrowsable(EditorBrowsableState.Never), Browsable(false)]
public override string Text
{
get
{
return base.Text;
}
set
{
base.Text = value;
RefreshTextRect();
Invalidate();
}
}
[Browsable(false)]
public Size Size
{
get
{
return base.Size;
}
set
{
base.Size = value;
}
}
protected override void OnSizeChanged(EventArgs e)
{
if (DesignMode && Animate)
Size = new Size(16, 16);
else
Height = Math.Max(16, Font.Height);
base.OnSizeChanged(e);
}
#endregion
#region Dispose
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
// Not already disposed ?
if (disposing)
{
// Not already disposed ?
if (auBackend != null)
{
auBackend.Dispose(); // Dispose it
auBackend = null; // Its now inaccessible
}
if (backBrush != null)
{
backBrush.Dispose(); // Dispose it
backBrush = null; // Its now inaccessible
}
}
base.Dispose(disposing);
}
#endregion
//Methods and such
/// <summary>
/// Represents an AutomaticUpdater control.
/// </summary>
public AutomaticUpdater()
{
Animate = true;
// This turns on double buffering of all custom GDI+ drawing
SetStyle(ControlStyles.AllPaintingInWmPaint
| ControlStyles.SupportsTransparentBackColor
| ControlStyles.OptimizedDoubleBuffer
| ControlStyles.ResizeRedraw
| ControlStyles.UserPaint
| ControlStyles.FixedHeight
| ControlStyles.FixedWidth, true);
ani.Size = new Size(16, 16);
ani.Location = new Point(0, 0);
ani.Rows = 5;
ani.Columns = 10;
Controls.Add(ani);
ani.MouseEnter += ani_MouseEnter;
ani.MouseLeave += ani_MouseLeave;
ani.MouseDown += ani_MouseDown;
if (DesignMode)
ani.Visible = false;
// events for the timers
tmrCollapse.Tick += tmrCollapse_Tick;
tmrAniExpandCollapse.Tick += tmrAniExpandCollapse_Tick;
tmrWaitBeforeCheck.Tick += tmrWaitBeforeCheck_Tick;
Size = new Size(16, 16);
backBrush = new SolidBrush(BackColor);
// use all events from the AutomaticUpdater backend
auBackend.BeforeChecking += auBackend_BeforeChecking;
auBackend.BeforeDownloading += auBackend_BeforeDownloading;
auBackend.BeforeExtracting += auBackend_BeforeExtracting;
auBackend.Cancelled += auBackend_Cancelled;
auBackend.ReadyToBeInstalled += auBackend_ReadyToBeInstalled;
auBackend.UpdateAvailable += auBackend_UpdateAvailable;
auBackend.UpdateSuccessful += auBackend_UpdateSuccessful;
auBackend.UpToDate += auBackend_UpToDate;
auBackend.ProgressChanged += auBackend_ProgressChanged;
auBackend.CheckingFailed += auBackend_CheckingFailed;
auBackend.DownloadingFailed += auBackend_DownloadingFailed;
auBackend.ExtractingFailed += auBackend_ExtractingFailed;
auBackend.UpdateFailed += auBackend_UpdateFailed;
auBackend.ClosingAborted += auBackend_ClosingAborted;
auBackend.UpdateStepMismatch += auBackend_UpdateStepMismatch;
auBackend.CloseAppNow += auBackend_CloseAppNow;
}
/// <summary>
/// Represents an AutomaticUpdater control.
/// </summary>
/// <param name="parentControl">The owner form of the AutomaticUpdater.</param>
public AutomaticUpdater(Form parentControl)
: this()
{
ownerForm = parentControl;
ownerForm.Load += ownerForm_Load;
}
void auBackend_CloseAppNow(object sender, EventArgs e)
{
// call this function from ownerForm's thread context
if (sender != null)
{
ownerForm.Invoke(new EventHandler(auBackend_CloseAppNow), new object[] { null, e });
return;
}
// close this application so it can be updated
if (CloseAppNow != null)
CloseAppNow(this, EventArgs.Empty);
else
Application.Exit();
}
void auBackend_UpToDate(object sender, SuccessArgs e)
{
// call this function from ownerForm's thread context
if (sender != null)
{
ownerForm.Invoke(new SuccessHandler(auBackend_UpToDate), new object[] { null, e });
return;
}
Text = translation.AlreadyUpToDate;
if (Visible)
UpdateStepSuccessful(MenuType.AlreadyUpToDate);
SetMenuText(translation.CheckForUpdatesMenu);
if (UpToDate != null)
UpToDate(this, e);
}
void auBackend_UpdateSuccessful(object sender, SuccessArgs e)
{
// call this function from ownerForm's thread context
if (sender != null)
{
ownerForm.Invoke(new SuccessHandler(auBackend_UpdateSuccessful), new object[] { null, e });
return;
}
// show the control
Visible = !KeepHidden;
Text = translation.SuccessfullyUpdated.Replace("%version%", Version);
UpdateStepSuccessful(MenuType.UpdateSuccessful);
if (UpdateSuccessful != null)
UpdateSuccessful(this, e);
}
void auBackend_UpdateFailed(object sender, FailArgs e)
{
// call this function from ownerForm's thread context
if (sender != null)
{
ownerForm.Invoke(new FailHandler(auBackend_UpdateFailed), new object[] { null, e });
return;
}
// show the control
Visible = !KeepHidden;
failArgs = e;
// show failed Text & icon
Text = translation.UpdateFailed;
CreateMenu(MenuType.Error);
AnimateImage(BmpFailed, true);
if (UpdateFailed != null)
UpdateFailed(this, e);
}
void auBackend_UpdateAvailable(object sender, EventArgs e)
{
// call this function from ownerForm's thread context
if (sender != null)
{
ownerForm.Invoke(new EventHandler(auBackend_UpdateAvailable), new object[] { null, e });
return;
}
CreateMenu(MenuType.DownloadAndChanges);
SetUpdateStepOn(UpdateStepOn.UpdateAvailable);
if (!KeepHidden)
Show();
// temporarily disable the collapse timer
tmrCollapse.Enabled = false;
// animate this open
if (Animate)
BeginAniOpen();
AnimateImage(BmpNotify, true);
SetMenuText(translation.DownloadUpdateMenu);
if (UpdateAvailable != null)
UpdateAvailable(this, e);
}
void auBackend_ReadyToBeInstalled(object sender, EventArgs e)
{
// call this function from ownerForm's thread context
if (sender != null)
{
ownerForm.Invoke(new EventHandler(auBackend_ReadyToBeInstalled), new object[] { null, e });
return;
}
CreateMenu(MenuType.InstallAndChanges);
// UpdateDownloaded or UpdateReadyToInstall
SetUpdateStepOn(auBackend.UpdateStepOn);
if (!KeepHidden)
Show();
// temporarily disable the collapse timer
tmrCollapse.Enabled = false;
// animate this open
if (Animate)
BeginAniOpen();
AnimateImage(BmpInfo, true);
SetMenuText(translation.InstallUpdateMenu);
if (ReadyToBeInstalled != null)
ReadyToBeInstalled(this, e);
}
void auBackend_Cancelled(object sender, EventArgs e)
{
// call this function from ownerForm's thread context
if (sender != null)
{
ownerForm.Invoke(new EventHandler(auBackend_Cancelled), new object[] { null, e });
return;
}
// stop animation & hide
ani.StopAnimation();
Visible = false;
SetMenuText(translation.CheckForUpdatesMenu);
if (Cancelled != null)
Cancelled(this, e);
}
void auBackend_BeforeChecking(object sender, BeforeArgs e)
{
// disable any scheduled checking
tmrWaitBeforeCheck.Enabled = false;
SetMenuText(translation.CancelCheckingMenu);
if (BeforeChecking != null)
BeforeChecking(this, e);
if (e.Cancel)
{
// close wyUpdate
auBackend.Cancel();
return;
}
// show the working animation
SetUpdateStepOn(UpdateStepOn.Checking);
UpdateProcessing(false);
// setup the context menu
CreateMenu(MenuType.CheckingMenu);
}
void auBackend_BeforeDownloading(object sender, BeforeArgs e)
{
// call this function from ownerForm's thread context
if (sender != null)
{
ownerForm.Invoke(new BeforeHandler(auBackend_BeforeDownloading), new object[] { null, e });
return;
}
if (BeforeDownloading != null)
BeforeDownloading(this, e);
if (e.Cancel)
return;
SetMenuText(translation.CancelUpdatingMenu);
// if the control is hidden show it now (so the user can cancel the downloading if they want)
// show the 'working' animation
SetUpdateStepOn(UpdateStepOn.DownloadingUpdate);
UpdateProcessing(true);
CreateMenu(MenuType.CancelDownloading);
}
void auBackend_BeforeExtracting(object sender, BeforeArgs e)
{
// call this function from ownerForm's thread context
if (sender != null)
{
ownerForm.Invoke(new BeforeHandler(auBackend_BeforeExtracting), new object[] { null, e });
return;
}
SetUpdateStepOn(UpdateStepOn.ExtractingUpdate);
CreateMenu(MenuType.CancelExtracting);
}
void auBackend_CheckingFailed(object sender, FailArgs e)
{
// call this function from ownerForm's thread context
if (sender != null)
{
ownerForm.Invoke(new FailHandler(auBackend_CheckingFailed), new object[] { null, e });
return;
}
UpdateStepFailed(e);
Text = translation.FailedToCheck;
if (CheckingFailed != null)
CheckingFailed(this, e);
}
void auBackend_DownloadingFailed(object sender, FailArgs e)
{
// call this function from ownerForm's thread context
if (sender != null)
{
ownerForm.Invoke(new FailHandler(auBackend_DownloadingFailed), new object[] { null, e });
return;
}
UpdateStepFailed(e);
Text = translation.FailedToDownload;
if (DownloadingOrExtractingFailed != null)
DownloadingOrExtractingFailed(this, e);
}
void auBackend_ExtractingFailed(object sender, FailArgs e)
{
// call this function from ownerForm's thread context
if (sender != null)
{
ownerForm.Invoke(new FailHandler(auBackend_ExtractingFailed), new object[] { null, e });
return;
}
UpdateStepFailed(e);
Text = translation.FailedToExtract;
if (DownloadingOrExtractingFailed != null)
DownloadingOrExtractingFailed(this, e);
}
void UpdateStepFailed(FailArgs e)
{
if (e.wyUpdatePrematureExit)
{
e.ErrorTitle = translation.PrematureExitTitle;
// use the general "premature exit" message only when there's no other message present
if (e.ErrorMessage == null || e.ErrorMessage == AUTranslation.C_PrematureExitMessage)
e.ErrorMessage = translation.PrematureExitMessage;
}
failArgs = e;
//only show the error if this is visible
if (Visible)
{
CreateMenu(MenuType.Error);
AnimateImage(BmpFailed, true);
}
SetMenuText(translation.CheckForUpdatesMenu);
}
void auBackend_ProgressChanged(object sender, int progress)
{
// call this function from ownerForm's thread context
if (sender != null)
{
ownerForm.Invoke(new UpdateProgressChanged(auBackend_ProgressChanged), new object[] { null, progress });
return;
}
// update progress status (only for greater than 0%)
if (progress > 0)
Text = currentActionText + ", " + progress + "%";
// call the progress changed event
if (ProgressChanged != null)
ProgressChanged(this, progress);
}
void auBackend_ClosingAborted(object sender, EventArgs e)
{
// call this function from ownerForm's thread context
if (sender != null)
{
ownerForm.Invoke(new EventHandler(auBackend_ClosingAborted), new object[] { null, e });
return;
}
// we need to show the form (it was hidden in ISupport() )
if (auBackend.ClosingForInstall)
{
ownerForm.ShowInTaskbar = true;
ownerForm.WindowState = FormWindowState.Normal;
}
if (ClosingAborted != null)
ClosingAborted(this, EventArgs.Empty);
}
void auBackend_UpdateStepMismatch(object sender, EventArgs e)
{
// call this function from ownerForm's thread context
if (sender != null)
{
ownerForm.Invoke(new EventHandler(auBackend_UpdateStepMismatch), new object[] { null, e });
return;
}
SetUpdateStepOn(auBackend.UpdateStepOn);
// set the working progress animation
if (auBackend.UpdateStepOn == UpdateStepOn.Checking
|| auBackend.UpdateStepOn == UpdateStepOn.DownloadingUpdate
|| auBackend.UpdateStepOn == UpdateStepOn.ExtractingUpdate)
{
UpdateProcessing(false);
}
}
/// <summary>
/// The owner form of the AutomaticUpdater.
/// </summary>
[Browsable(false)]
public Form ContainerForm
{
get { return ownerForm; }
set
{
if (ownerForm != null)
ownerForm.Load -= ownerForm_Load;
ownerForm = value;
ownerForm.Load += ownerForm_Load;
}
}
public override ISite Site
{
set
{
// Runs at design time, ensures designer initializes ContainerControl
base.Site = value;
if (value == null) return;
IDesignerHost service = value.GetService(typeof(IDesignerHost)) as IDesignerHost;
if (service == null) return;
IComponent rootComponent = service.RootComponent;
ContainerForm = rootComponent as Form;
}
}
bool insideChildControl;
bool insideSelf;
void ani_MouseLeave(object sender, EventArgs e)
{
insideChildControl = false;
if (Animate && !insideSelf && isFullExpanded && !isMenuVisible)
tmrCollapse.Enabled = true;
}
void ani_MouseEnter(object sender, EventArgs e)
{
insideChildControl = true;
if (Animate)
{
tmrCollapse.Enabled = false;
if (!isFullExpanded)
BeginAniOpen();
}
}
protected override void OnMouseEnter(EventArgs e)
{
insideSelf = true;
if (Animate)
{
tmrCollapse.Enabled = false;
if (!isFullExpanded)
BeginAniOpen();
}
base.OnMouseEnter(e);
}
protected override void OnMouseLeave(EventArgs e)
{
insideSelf = false;
if (Animate && !insideChildControl && isFullExpanded && !isMenuVisible)
tmrCollapse.Enabled = true;
base.OnMouseLeave(e);
}
void tmrCollapse_Tick(object sender, EventArgs e)
{
// begin collapse animation
BeginAniClose();
// disable this timer
tmrCollapse.Stop();
}
bool skipNextMenuShow;
protected override void OnMouseDown(MouseEventArgs e)
{
ani_MouseDown(null, null);
base.OnMouseDown(e);
}
void ani_MouseDown(object sender, MouseEventArgs e)
{
if (!(insideChildControl || insideSelf))
//skip next menu show when "reclicking" while the menu is still visible
skipNextMenuShow = true;
if (skipNextMenuShow)
skipNextMenuShow = false;
else
ShowContextMenu();
}
void ShowContextMenu()
{
if (contextMenu != null)
{
isMenuVisible = true;