ShareX/ShareX.HelpersLib/UpdateChecker/UpdateChecker.cs

85 lines
2.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
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)
using System;
using System.Net;
2014-07-23 12:18:49 +12:00
using System.Web;
using System.Windows.Forms;
2013-11-03 23:53:49 +13:00
2013-11-14 23:50:25 +13:00
namespace HelpersLib
2013-11-03 23:53:49 +13:00
{
public abstract class UpdateChecker
2013-11-03 23:53:49 +13:00
{
2014-07-23 12:18:49 +12:00
public UpdateStatus Status { get; set; }
public Version CurrentVersion { get; set; }
2014-07-23 12:18:49 +12:00
public Version LatestVersion { get; set; }
public ReleaseChannelType ReleaseType { get; set; }
2014-07-23 12:18:49 +12:00
public bool IsBeta { get; set; }
public IWebProxy Proxy { get; set; }
2013-11-03 23:53:49 +13:00
2014-07-23 12:18:49 +12:00
private string filename;
public string Filename
{
get
{
if (string.IsNullOrEmpty(filename))
{
return HttpUtility.UrlDecode(DownloadURL.Substring(DownloadURL.LastIndexOf('/') + 1));
}
return filename;
}
set
{
filename = value;
}
}
public string DownloadURL { get; set; }
private const bool forceUpdate = false; // For testing purposes
public void RefreshStatus()
2013-11-03 23:53:49 +13:00
{
2014-07-23 12:18:49 +12:00
if (CurrentVersion == null)
{
CurrentVersion = Version.Parse(Application.ProductVersion);
}
if (Status != UpdateStatus.UpdateCheckFailed && CurrentVersion != null && LatestVersion != null && !string.IsNullOrEmpty(DownloadURL) &&
(forceUpdate || Helpers.CompareVersion(CurrentVersion, LatestVersion) < 0 || (IsBeta && Helpers.CompareVersion(CurrentVersion, LatestVersion) == 0)))
{
Status = UpdateStatus.UpdateAvailable;
}
else
{
Status = UpdateStatus.UpToDate;
}
2013-11-03 23:53:49 +13:00
}
public abstract void CheckUpdate();
2013-11-03 23:53:49 +13:00
}
}