ShareX/ShareX.HelpersLib/UpdateChecker/UpdateCheckerLabel.cs

118 lines
3.7 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
2024-01-03 12:57:14 +13:00
Copyright (c) 2007-2024 ShareX Team
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;
2022-01-13 12:59:56 +13:00
using System.Threading.Tasks;
2013-11-03 23:53:49 +13:00
using System.Windows.Forms;
2014-12-11 09:25:20 +13:00
namespace ShareX.HelpersLib
2013-11-03 23:53:49 +13:00
{
public partial class UpdateCheckerLabel : UserControl
{
2016-09-29 13:33:12 +13:00
public bool IsBusy { get; private set; }
private UpdateChecker updateChecker;
2013-11-03 23:53:49 +13:00
public UpdateCheckerLabel()
{
InitializeComponent();
}
2022-01-13 12:59:56 +13:00
public async Task CheckUpdate(UpdateChecker updateChecker)
2013-11-03 23:53:49 +13:00
{
2016-09-29 13:33:12 +13:00
if (!IsBusy)
2013-11-03 23:53:49 +13:00
{
2016-09-29 13:33:12 +13:00
IsBusy = true;
this.updateChecker = updateChecker;
2013-11-03 23:53:49 +13:00
lblStatus.Visible = false;
llblUpdateAvailable.Visible = false;
pbLoading.Visible = true;
lblCheckingUpdates.Visible = true;
2022-01-13 12:59:56 +13:00
await CheckingUpdate();
2013-11-03 23:53:49 +13:00
}
}
public void UpdateLoadingImage()
{
if (ShareXResources.IsDarkTheme)
{
pbLoading.Image = Resources.LoadingSmallWhite;
}
else
{
pbLoading.Image = Resources.LoadingSmallBlack;
}
}
2022-01-13 12:59:56 +13:00
private async Task CheckingUpdate()
2013-11-03 23:53:49 +13:00
{
2022-01-13 12:59:56 +13:00
await updateChecker.CheckUpdateAsync();
2015-05-19 03:35:04 +12:00
try
{
UpdateControls();
}
catch
{
}
2016-09-29 13:33:12 +13:00
IsBusy = false;
2013-11-03 23:53:49 +13:00
}
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 = string.Format(Resources.UpdateCheckerLabel_UpdateControls_A_newer_version_of_ShareX_is_available, Application.ProductName);
2013-11-03 23:53:49 +13:00
llblUpdateAvailable.Visible = true;
break;
case UpdateStatus.UpToDate:
lblStatus.Text = string.Format(Resources.UpdateCheckerLabel_UpdateControls_ShareX_is_up_to_date, Application.ProductName);
2013-11-03 23:53:49 +13:00
lblStatus.Visible = true;
break;
}
});
}
private void llblUpdateAvailable_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
2022-09-22 09:57:04 +12:00
UpdateMessageBox.Start(updateChecker);
2013-11-03 23:53:49 +13:00
}
}
}