From ca9f33a2cdc5f1494102417f776ca2f1aaff266f Mon Sep 17 00:00:00 2001 From: Jaex Date: Sat, 16 Jan 2016 17:41:04 +0200 Subject: [PATCH] In update message box if no button is clicked then don't check for updates next 24 hours --- .../UpdateChecker/UpdateMessageBox.Designer.cs | 1 + .../UpdateChecker/UpdateMessageBox.cs | 16 +++++++++++++--- .../UpdateChecker/UpdateMessageBox.resx | 5 +---- ShareX/Forms/MainForm.cs | 10 ++++++++-- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/ShareX.HelpersLib/UpdateChecker/UpdateMessageBox.Designer.cs b/ShareX.HelpersLib/UpdateChecker/UpdateMessageBox.Designer.cs index 8c6811c9d..495f29d5b 100644 --- a/ShareX.HelpersLib/UpdateChecker/UpdateMessageBox.Designer.cs +++ b/ShareX.HelpersLib/UpdateChecker/UpdateMessageBox.Designer.cs @@ -88,6 +88,7 @@ private void InitializeComponent() this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.MaximizeBox = false; this.Name = "UpdateMessageBox"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.UpdateMessageBox_FormClosing); this.Shown += new System.EventHandler(this.UpdateMessageBox_Shown); this.ResumeLayout(false); diff --git a/ShareX.HelpersLib/UpdateChecker/UpdateMessageBox.cs b/ShareX.HelpersLib/UpdateChecker/UpdateMessageBox.cs index 8fa5121d3..d57d52c0d 100644 --- a/ShareX.HelpersLib/UpdateChecker/UpdateMessageBox.cs +++ b/ShareX.HelpersLib/UpdateChecker/UpdateMessageBox.cs @@ -58,16 +58,16 @@ public UpdateMessageBox(bool activateWindow, bool isPortable = false) } } - public static void Start(UpdateChecker updateChecker, bool activateWindow = true) + public static DialogResult Start(UpdateChecker updateChecker, bool activateWindow = true) { + DialogResult result = DialogResult.None; + if (updateChecker != null && updateChecker.Status == UpdateStatus.UpdateAvailable) { IsOpen = true; try { - DialogResult result; - using (UpdateMessageBox messageBox = new UpdateMessageBox(activateWindow, updateChecker.IsPortable)) { result = messageBox.ShowDialog(); @@ -83,6 +83,8 @@ public static void Start(UpdateChecker updateChecker, bool activateWindow = true IsOpen = false; } } + + return result; } protected override bool ShowWithoutActivation => !ActivateWindow; @@ -95,6 +97,14 @@ private void UpdateMessageBox_Shown(object sender, System.EventArgs e) } } + private void UpdateMessageBox_FormClosing(object sender, FormClosingEventArgs e) + { + if (e.CloseReason == CloseReason.UserClosing) + { + DialogResult = DialogResult.No; + } + } + private void cbDontShow_CheckedChanged(object sender, System.EventArgs e) { DontShow = cbDontShow.Checked; diff --git a/ShareX.HelpersLib/UpdateChecker/UpdateMessageBox.resx b/ShareX.HelpersLib/UpdateChecker/UpdateMessageBox.resx index 0accb470d..66a3b515e 100644 --- a/ShareX.HelpersLib/UpdateChecker/UpdateMessageBox.resx +++ b/ShareX.HelpersLib/UpdateChecker/UpdateMessageBox.resx @@ -131,10 +131,6 @@ 2 - - - - lblText @@ -264,6 +260,7 @@ 400, 192 + CenterScreen diff --git a/ShareX/Forms/MainForm.cs b/ShareX/Forms/MainForm.cs index be76425b7..538412618 100644 --- a/ShareX/Forms/MainForm.cs +++ b/ShareX/Forms/MainForm.cs @@ -695,7 +695,7 @@ private void ConfigureAutoUpdate() { if (updateTimer == null) { - updateTimer = new System.Threading.Timer(state => CheckUpdate(), null, 0, 1000 * 60 * 60); + updateTimer = new System.Threading.Timer(state => CheckUpdate(), null, TimeSpan.Zero, TimeSpan.FromHours(1)); } } else if (updateTimer != null) @@ -712,7 +712,13 @@ private void CheckUpdate() if (!UpdateMessageBox.DontShow && !UpdateMessageBox.IsOpen) { UpdateChecker updateChecker = TaskHelpers.CheckUpdate(); - UpdateMessageBox.Start(updateChecker, firstUpdateCheck); + + if (UpdateMessageBox.Start(updateChecker, firstUpdateCheck) == DialogResult.No) + { + TimeSpan interval = TimeSpan.FromHours(24); + updateTimer.Change(interval, interval); + } + firstUpdateCheck = false; } }