mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-04 12:14:45 +13:00
Beta support
This commit is contained in:
parent
dd171e810d
commit
b0453e4055
12 changed files with 75 additions and 124 deletions
|
@ -331,6 +331,16 @@ public static int CompareVersion(string version1, string version2)
|
||||||
return NormalizeVersion(version1).CompareTo(NormalizeVersion(version2));
|
return NormalizeVersion(version1).CompareTo(NormalizeVersion(version2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// If version1 newer than version2 = 1
|
||||||
|
/// If version1 equal to version2 = 0
|
||||||
|
/// If version1 older than version2 = -1
|
||||||
|
/// </summary>
|
||||||
|
public static int CompareVersion(Version version1, Version version2)
|
||||||
|
{
|
||||||
|
return version1.Normalize().CompareTo(version2.Normalize());
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// If version newer than ApplicationVersion = 1
|
/// If version newer than ApplicationVersion = 1
|
||||||
/// If version equal to ApplicationVersion = 0
|
/// If version equal to ApplicationVersion = 0
|
||||||
|
@ -346,14 +356,6 @@ private static Version NormalizeVersion(string version)
|
||||||
return Version.Parse(version).Normalize();
|
return Version.Parse(version).Normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// If latestVersion newer than currentVersion = true
|
|
||||||
/// </summary>
|
|
||||||
public static bool CheckVersion(Version currentVersion, Version latestVersion)
|
|
||||||
{
|
|
||||||
return currentVersion.Normalize() < latestVersion.Normalize();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool IsWindowsXP()
|
public static bool IsWindowsXP()
|
||||||
{
|
{
|
||||||
return OSVersion.Major == 5 && OSVersion.Minor == 1;
|
return OSVersion.Major == 5 && OSVersion.Minor == 1;
|
||||||
|
|
|
@ -331,7 +331,6 @@
|
||||||
<DependentUpon>MyPictureBox.cs</DependentUpon>
|
<DependentUpon>MyPictureBox.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="UpdateChecker\XMLUpdateChecker.cs" />
|
<Compile Include="UpdateChecker\XMLUpdateChecker.cs" />
|
||||||
<Compile Include="UpdateChecker\UpdateInfo.cs" />
|
|
||||||
<Compile Include="Links.cs" />
|
<Compile Include="Links.cs" />
|
||||||
<Compile Include="Vector2.cs" />
|
<Compile Include="Vector2.cs" />
|
||||||
<Compile Include="WindowState.cs" />
|
<Compile Include="WindowState.cs" />
|
||||||
|
|
|
@ -75,7 +75,7 @@ private DownloaderForm()
|
||||||
}
|
}
|
||||||
|
|
||||||
public DownloaderForm(UpdateChecker updateChecker)
|
public DownloaderForm(UpdateChecker updateChecker)
|
||||||
: this(updateChecker.UpdateInfo)
|
: this(updateChecker.DownloadURL, updateChecker.Filename)
|
||||||
{
|
{
|
||||||
Proxy = updateChecker.Proxy;
|
Proxy = updateChecker.Proxy;
|
||||||
|
|
||||||
|
@ -85,11 +85,6 @@ public DownloaderForm(UpdateChecker updateChecker)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public DownloaderForm(UpdateInfo updateInfo)
|
|
||||||
: this(updateInfo.DownloadURL, updateInfo.Filename)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public DownloaderForm(string url, string filename)
|
public DownloaderForm(string url, string filename)
|
||||||
: this()
|
: this()
|
||||||
{
|
{
|
||||||
|
|
|
@ -54,8 +54,6 @@ public GitHubUpdateChecker(string owner, string repo)
|
||||||
|
|
||||||
public override void CheckUpdate()
|
public override void CheckUpdate()
|
||||||
{
|
{
|
||||||
UpdateInfo = new UpdateInfo { CurrentVersion = this.CurrentVersion };
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
List<GitHubRelease> releases = GetReleases();
|
List<GitHubRelease> releases = GetReleases();
|
||||||
|
@ -67,7 +65,7 @@ public override void CheckUpdate()
|
||||||
if (latestRelease != null && !string.IsNullOrEmpty(latestRelease.tag_name) && latestRelease.tag_name.Length > 1 &&
|
if (latestRelease != null && !string.IsNullOrEmpty(latestRelease.tag_name) && latestRelease.tag_name.Length > 1 &&
|
||||||
latestRelease.tag_name[0] == 'v')
|
latestRelease.tag_name[0] == 'v')
|
||||||
{
|
{
|
||||||
UpdateInfo.LatestVersion = new Version(latestRelease.tag_name.Substring(1));
|
LatestVersion = new Version(latestRelease.tag_name.Substring(1));
|
||||||
|
|
||||||
if (latestRelease.assets != null && latestRelease.assets.Count > 0)
|
if (latestRelease.assets != null && latestRelease.assets.Count > 0)
|
||||||
{
|
{
|
||||||
|
@ -75,9 +73,9 @@ public override void CheckUpdate()
|
||||||
{
|
{
|
||||||
if (asset != null && !string.IsNullOrEmpty(asset.name) && asset.name.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase))
|
if (asset != null && !string.IsNullOrEmpty(asset.name) && asset.name.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase))
|
||||||
{
|
{
|
||||||
UpdateInfo.Filename = asset.name;
|
Filename = asset.name;
|
||||||
UpdateInfo.DownloadURL = asset.url;
|
DownloadURL = asset.url;
|
||||||
UpdateInfo.RefreshStatus();
|
RefreshStatus();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,7 +88,7 @@ public override void CheckUpdate()
|
||||||
DebugHelper.WriteException(e, "GitHub update check failed");
|
DebugHelper.WriteException(e, "GitHub update check failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateInfo.Status = UpdateStatus.UpdateCheckFailed;
|
Status = UpdateStatus.UpdateCheckFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetLatestDownloadURL()
|
public string GetLatestDownloadURL()
|
||||||
|
|
|
@ -25,21 +25,59 @@ You should have received a copy of the GNU General Public License
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Web;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace HelpersLib
|
namespace HelpersLib
|
||||||
{
|
{
|
||||||
public abstract class UpdateChecker
|
public abstract class UpdateChecker
|
||||||
{
|
{
|
||||||
|
public UpdateStatus Status { get; set; }
|
||||||
public Version CurrentVersion { get; set; }
|
public Version CurrentVersion { get; set; }
|
||||||
|
public Version LatestVersion { get; set; }
|
||||||
public ReleaseChannelType ReleaseType { get; set; }
|
public ReleaseChannelType ReleaseType { get; set; }
|
||||||
|
public bool IsBeta { get; set; }
|
||||||
public IWebProxy Proxy { get; set; }
|
public IWebProxy Proxy { get; set; }
|
||||||
public UpdateInfo UpdateInfo { get; protected set; }
|
|
||||||
|
|
||||||
public UpdateChecker()
|
private string filename;
|
||||||
|
|
||||||
|
public string Filename
|
||||||
{
|
{
|
||||||
CurrentVersion = Version.Parse(Application.ProductVersion);
|
get
|
||||||
ReleaseType = ReleaseChannelType.Stable;
|
{
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void CheckUpdate();
|
public abstract void CheckUpdate();
|
||||||
|
|
|
@ -70,7 +70,7 @@ private void UpdateControls()
|
||||||
pbLoading.Visible = false;
|
pbLoading.Visible = false;
|
||||||
lblCheckingUpdates.Visible = false;
|
lblCheckingUpdates.Visible = false;
|
||||||
|
|
||||||
switch (updateChecker.UpdateInfo.Status)
|
switch (updateChecker.Status)
|
||||||
{
|
{
|
||||||
case UpdateStatus.UpdateCheckFailed:
|
case UpdateStatus.UpdateCheckFailed:
|
||||||
lblStatus.Text = "Update check failed";
|
lblStatus.Text = "Update check failed";
|
||||||
|
@ -90,7 +90,7 @@ private void UpdateControls()
|
||||||
|
|
||||||
private void llblUpdateAvailable_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
private void llblUpdateAvailable_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
||||||
{
|
{
|
||||||
if (updateChecker != null && updateChecker.UpdateInfo != null && updateChecker.UpdateInfo.Status == UpdateStatus.UpdateAvailable)
|
if (updateChecker != null && updateChecker.Status == UpdateStatus.UpdateAvailable)
|
||||||
{
|
{
|
||||||
using (DownloaderForm updaterForm = new DownloaderForm(updateChecker))
|
using (DownloaderForm updaterForm = new DownloaderForm(updateChecker))
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,85 +0,0 @@
|
||||||
#region License Information (GPL v3)
|
|
||||||
|
|
||||||
/*
|
|
||||||
ShareX - A program that allows you to take screenshots and share any file type
|
|
||||||
Copyright (C) 2007-2014 ShareX Developers
|
|
||||||
|
|
||||||
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.Web;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace HelpersLib
|
|
||||||
{
|
|
||||||
public class UpdateInfo
|
|
||||||
{
|
|
||||||
public UpdateStatus Status { get; set; }
|
|
||||||
public Version CurrentVersion { get; set; }
|
|
||||||
public Version LatestVersion { get; set; }
|
|
||||||
|
|
||||||
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; }
|
|
||||||
public ReleaseChannelType ReleaseChannel { get; set; }
|
|
||||||
|
|
||||||
private bool forceUpdate = false; // For testing purposes
|
|
||||||
|
|
||||||
public UpdateInfo()
|
|
||||||
{
|
|
||||||
ReleaseChannel = ReleaseChannelType.Stable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RefreshStatus()
|
|
||||||
{
|
|
||||||
if (CurrentVersion == null)
|
|
||||||
{
|
|
||||||
CurrentVersion = Version.Parse(Application.ProductVersion);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Status != UpdateStatus.UpdateCheckFailed && CurrentVersion != null && LatestVersion != null && !string.IsNullOrEmpty(DownloadURL) &&
|
|
||||||
(forceUpdate || Helpers.CheckVersion(CurrentVersion, LatestVersion)))
|
|
||||||
{
|
|
||||||
Status = UpdateStatus.UpdateAvailable;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Status = UpdateStatus.UpToDate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -45,8 +45,6 @@ public XMLUpdateChecker(string url, string applicationName)
|
||||||
|
|
||||||
public override void CheckUpdate()
|
public override void CheckUpdate()
|
||||||
{
|
{
|
||||||
UpdateInfo = new UpdateInfo { CurrentVersion = this.CurrentVersion, ReleaseChannel = ReleaseType };
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (WebClient wc = new WebClient())
|
using (WebClient wc = new WebClient())
|
||||||
|
@ -83,9 +81,9 @@ public override void CheckUpdate()
|
||||||
|
|
||||||
if (xe != null)
|
if (xe != null)
|
||||||
{
|
{
|
||||||
UpdateInfo.LatestVersion = new Version(xe.Element("Version").Value);
|
LatestVersion = new Version(xe.Element("Version").Value);
|
||||||
UpdateInfo.DownloadURL = xe.Element("URL").Value;
|
DownloadURL = xe.Element("URL").Value;
|
||||||
UpdateInfo.RefreshStatus();
|
RefreshStatus();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,7 +95,7 @@ public override void CheckUpdate()
|
||||||
DebugHelper.WriteException(e, "XML update check failed");
|
DebugHelper.WriteException(e, "XML update check failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateInfo.Status = UpdateStatus.UpdateCheckFailed;
|
Status = UpdateStatus.UpdateCheckFailed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -533,8 +533,9 @@ private void CheckUpdate()
|
||||||
{
|
{
|
||||||
UpdateChecker updateChecker = TaskHelpers.CheckUpdate();
|
UpdateChecker updateChecker = TaskHelpers.CheckUpdate();
|
||||||
|
|
||||||
if (updateChecker.UpdateInfo != null && updateChecker.UpdateInfo.Status == UpdateStatus.UpdateAvailable &&
|
if (updateChecker != null && updateChecker.Status == UpdateStatus.UpdateAvailable &&
|
||||||
MessageBox.Show("A newer version of ShareX is available.\r\nWould you like to download and install it?", string.Format("{0} {1} is available", Application.ProductName, updateChecker.UpdateInfo.LatestVersion.ToString()),
|
MessageBox.Show("A newer version of ShareX is available.\r\nWould you like to download and install it?",
|
||||||
|
string.Format("ShareX {0} is available", updateChecker.LatestVersion.ToString()),
|
||||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
|
||||||
{
|
{
|
||||||
using (DownloaderForm updaterForm = new DownloaderForm(updateChecker))
|
using (DownloaderForm updaterForm = new DownloaderForm(updateChecker))
|
||||||
|
|
|
@ -213,6 +213,8 @@ public static string ToolsFolder
|
||||||
|
|
||||||
#endregion Paths
|
#endregion Paths
|
||||||
|
|
||||||
|
public const bool IsBeta = true;
|
||||||
|
|
||||||
public static string Title
|
public static string Title
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@ -221,6 +223,7 @@ public static string Title
|
||||||
string title = string.Format("ShareX {0}.{1}", version.Major, version.Minor);
|
string title = string.Format("ShareX {0}.{1}", version.Major, version.Minor);
|
||||||
if (version.Build > 0) title += "." + version.Build;
|
if (version.Build > 0) title += "." + version.Build;
|
||||||
if (IsPortable) title += " Portable";
|
if (IsPortable) title += " Portable";
|
||||||
|
if (IsBeta) title += " Beta";
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,5 +11,5 @@
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
[assembly: ComVisible(false)]
|
[assembly: ComVisible(false)]
|
||||||
[assembly: Guid("82E6AC09-0FEF-4390-AD9F-0DD3F5561EFC")]
|
[assembly: Guid("82E6AC09-0FEF-4390-AD9F-0DD3F5561EFC")]
|
||||||
[assembly: AssemblyVersion("9.2.1")]
|
[assembly: AssemblyVersion("9.3.0")]
|
||||||
[assembly: AssemblyFileVersion("9.2.1")]
|
[assembly: AssemblyFileVersion("9.3.0")]
|
|
@ -423,13 +423,15 @@ public static Icon GetProgressIcon(int percentage)
|
||||||
public static UpdateChecker CheckUpdate()
|
public static UpdateChecker CheckUpdate()
|
||||||
{
|
{
|
||||||
UpdateChecker updateChecker = new GitHubUpdateChecker("ShareX", "ShareX");
|
UpdateChecker updateChecker = new GitHubUpdateChecker("ShareX", "ShareX");
|
||||||
|
updateChecker.IsBeta = Program.IsBeta;
|
||||||
updateChecker.Proxy = ProxyInfo.Current.GetWebProxy();
|
updateChecker.Proxy = ProxyInfo.Current.GetWebProxy();
|
||||||
updateChecker.CheckUpdate();
|
updateChecker.CheckUpdate();
|
||||||
|
|
||||||
// Fallback if GitHub API fails
|
// Fallback if GitHub API fails
|
||||||
if (updateChecker.UpdateInfo == null || updateChecker.UpdateInfo.Status == UpdateStatus.UpdateCheckFailed)
|
if (updateChecker.Status == UpdateStatus.None || updateChecker.Status == UpdateStatus.UpdateCheckFailed)
|
||||||
{
|
{
|
||||||
updateChecker = new XMLUpdateChecker("http://getsharex.com/Update.xml", "ShareX");
|
updateChecker = new XMLUpdateChecker("http://getsharex.com/Update.xml", "ShareX");
|
||||||
|
updateChecker.IsBeta = Program.IsBeta;
|
||||||
updateChecker.Proxy = ProxyInfo.Current.GetWebProxy();
|
updateChecker.Proxy = ProxyInfo.Current.GetWebProxy();
|
||||||
updateChecker.CheckUpdate();
|
updateChecker.CheckUpdate();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue