ShareX/ShareX.HelpersLib/UpdateChecker/UpdateCheckerLabel.cs

108 lines
3.6 KiB
C#
Raw Normal View History

2013-11-03 23:53:49 +13:00
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
2014-05-13 21:06:40 +12:00
Copyright (C) 2007-2014 ShareX Developers
2013-11-03 23:53:49 +13:00
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
*/
#endregion License Information (GPL v3)
2014-12-11 09:25:20 +13:00
using ShareX.HelpersLib.Properties;
2013-11-03 23:53:49 +13:00
using System.Threading;
using System.Windows.Forms;
2014-12-11 09:25:20 +13:00
namespace ShareX.HelpersLib
2013-11-03 23:53:49 +13:00
{
public delegate UpdateChecker CheckUpdate();
2013-11-03 23:53:49 +13:00
public partial class UpdateCheckerLabel : UserControl
{
private UpdateChecker updateChecker;
2013-11-03 23:53:49 +13:00
private bool isBusy;
public UpdateCheckerLabel()
{
InitializeComponent();
}
public void CheckUpdate(CheckUpdate checkUpdate)
2013-11-03 23:53:49 +13:00
{
if (!isBusy)
{
isBusy = true;
lblStatus.Visible = false;
llblUpdateAvailable.Visible = false;
pbLoading.Visible = true;
lblCheckingUpdates.Visible = true;
new Thread(() => CheckingUpdate(checkUpdate)).Start();
2013-11-03 23:53:49 +13:00
}
}
private void CheckingUpdate(CheckUpdate checkUpdate)
2013-11-03 23:53:49 +13:00
{
updateChecker = checkUpdate();
2013-11-03 23:53:49 +13:00
UpdateControls();
isBusy = false;
}
private void UpdateControls()
{
this.InvokeSafe(() =>
{
pbLoading.Visible = false;
lblCheckingUpdates.Visible = false;
2014-07-23 12:18:49 +12:00
switch (updateChecker.Status)
2013-11-03 23:53:49 +13:00
{
case UpdateStatus.UpdateCheckFailed:
lblStatus.Text = Resources.UpdateCheckerLabel_UpdateControls_Update_check_failed;
2013-11-03 23:53:49 +13:00
lblStatus.Visible = true;
break;
2013-11-15 18:30:54 +13:00
case UpdateStatus.UpdateAvailable:
llblUpdateAvailable.Text = Resources.UpdateCheckerLabel_UpdateControls_A_newer_version_of_ShareX_is_available;
2013-11-03 23:53:49 +13:00
llblUpdateAvailable.Visible = true;
break;
case UpdateStatus.UpToDate:
lblStatus.Text = Resources.UpdateCheckerLabel_UpdateControls_ShareX_is_up_to_date;
2013-11-03 23:53:49 +13:00
lblStatus.Visible = true;
break;
}
});
}
private void llblUpdateAvailable_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
2014-07-23 12:18:49 +12:00
if (updateChecker != null && updateChecker.Status == UpdateStatus.UpdateAvailable)
2013-11-03 23:53:49 +13:00
{
2014-05-10 12:23:47 +12:00
using (DownloaderForm updaterForm = new DownloaderForm(updateChecker))
2013-11-03 23:53:49 +13:00
{
2014-05-08 04:26:14 +12:00
updaterForm.ShowDialog();
if (updaterForm.Status == DownloaderFormStatus.InstallStarted)
{
Application.Exit();
}
2013-11-03 23:53:49 +13:00
}
}
}
}
}