Interim update checker commit

This commit is contained in:
Jaex 2013-11-14 12:50:25 +02:00
parent 192305d57c
commit 7189210661
8 changed files with 24 additions and 22 deletions

View file

@ -38,9 +38,11 @@ public class GitHubUpdateChecker
{ {
private const string APIURL = "https://api.github.com"; private const string APIURL = "https://api.github.com";
public IWebProxy Proxy { get; set; }
public string Owner { get; set; } public string Owner { get; set; }
public string Repo { get; set; } public string Repo { get; set; }
public Version CurrentVersion { get; set; }
public IWebProxy Proxy { get; set; }
public UpdateInfo UpdateInfo { get; private set; }
public string ReleasesURL public string ReleasesURL
{ {
@ -50,13 +52,14 @@ public string ReleasesURL
} }
} }
public GitHubUpdateChecker(string owner, string repo) public GitHubUpdateChecker(string owner, string repo, Version currentVersion)
{ {
Owner = owner; Owner = owner;
Repo = repo; Repo = repo;
CurrentVersion = currentVersion;
} }
public string CheckUpdate(Version currentVersion) public string CheckUpdate()
{ {
try try
{ {
@ -69,7 +72,7 @@ public string CheckUpdate(Version currentVersion)
if (latestRelease != null && !string.IsNullOrEmpty(latestRelease.tag_name) && latestRelease.tag_name[0] == 'v') if (latestRelease != null && !string.IsNullOrEmpty(latestRelease.tag_name) && latestRelease.tag_name[0] == 'v')
{ {
Version latestVersion = new Version(latestRelease.tag_name.Substring(1)); Version latestVersion = new Version(latestRelease.tag_name.Substring(1));
bool isUpdateExist = Helpers.CheckVersion(latestVersion, currentVersion); bool isUpdateExist = Helpers.CheckVersion(latestVersion, CurrentVersion);
if (isUpdateExist) if (isUpdateExist)
{ {
@ -150,6 +153,6 @@ public class GitHubAsset
public int size { get; set; } public int size { get; set; }
public int download_count { get; set; } public int download_count { get; set; }
public string created_at { get; set; } public string created_at { get; set; }
public string published_at { get; set; } public string updated_at { get; set; }
} }
} }

View file

@ -33,7 +33,7 @@ You should have received a copy of the GNU General Public License
using System.Xml; using System.Xml;
using System.Xml.Linq; using System.Xml.Linq;
namespace UpdateCheckerLib namespace HelpersLib
{ {
public class UpdateChecker public class UpdateChecker
{ {

View file

@ -1,4 +1,4 @@
namespace UpdateCheckerLib namespace HelpersLib
{ {
partial class UpdateCheckerLabel partial class UpdateCheckerLabel
{ {

View file

@ -27,11 +27,11 @@ You should have received a copy of the GNU General Public License
using System.Threading; using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
namespace UpdateCheckerLib namespace HelpersLib
{ {
public partial class UpdateCheckerLabel : UserControl public partial class UpdateCheckerLabel : UserControl
{ {
private UpdateChecker updateChecker; private GitHubUpdateChecker updateChecker;
private bool isBusy; private bool isBusy;
public UpdateCheckerLabel() public UpdateCheckerLabel()
@ -39,7 +39,7 @@ public UpdateCheckerLabel()
InitializeComponent(); InitializeComponent();
} }
public void CheckUpdate(UpdateChecker updateChecker) public void CheckUpdate(GitHubUpdateChecker updateChecker)
{ {
this.updateChecker = updateChecker; this.updateChecker = updateChecker;
@ -78,11 +78,11 @@ private void UpdateControls()
lblStatus.Visible = true; lblStatus.Visible = true;
break; break;
case UpdateStatus.UpdateRequired: case UpdateStatus.UpdateRequired:
llblUpdateAvailable.Text = "A newer version of " + updateChecker.ApplicationName + " is available"; llblUpdateAvailable.Text = "A newer version of ShareX is available";
llblUpdateAvailable.Visible = true; llblUpdateAvailable.Visible = true;
break; break;
case UpdateStatus.UpToDate: case UpdateStatus.UpToDate:
lblStatus.Text = updateChecker.ApplicationName + " is up to date"; lblStatus.Text = "ShareX is up to date";
lblStatus.Visible = true; lblStatus.Visible = true;
break; break;
} }

View file

@ -27,7 +27,7 @@ You should have received a copy of the GNU General Public License
using System; using System;
using System.Text; using System.Text;
namespace UpdateCheckerLib namespace HelpersLib
{ {
public class UpdateInfo public class UpdateInfo
{ {

View file

@ -49,7 +49,7 @@ private void InitializeComponent()
this.pbDanaSteamURL = new System.Windows.Forms.PictureBox(); this.pbDanaSteamURL = new System.Windows.Forms.PictureBox();
this.rtbShareXInfo = new System.Windows.Forms.RichTextBox(); this.rtbShareXInfo = new System.Windows.Forms.RichTextBox();
this.cLogo = new HelpersLib.Canvas(); this.cLogo = new HelpersLib.Canvas();
this.uclUpdate = new UpdateCheckerLib.UpdateCheckerLabel(); this.uclUpdate = new HelpersLib.UpdateCheckerLabel();
this.lblOwners = new System.Windows.Forms.Label(); this.lblOwners = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.pbTR)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pbTR)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pbBerkURL)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pbBerkURL)).BeginInit();
@ -363,7 +363,6 @@ private void InitializeComponent()
private System.Windows.Forms.PictureBox pbMikeURL; private System.Windows.Forms.PictureBox pbMikeURL;
private System.Windows.Forms.PictureBox pbAU; private System.Windows.Forms.PictureBox pbAU;
private System.Windows.Forms.Label lblMike; private System.Windows.Forms.Label lblMike;
private UpdateCheckerLib.UpdateCheckerLabel uclUpdate;
private HelpersLib.Canvas cLogo; private HelpersLib.Canvas cLogo;
private System.Windows.Forms.PictureBox pbBerkSteamURL; private System.Windows.Forms.PictureBox pbBerkSteamURL;
private System.Windows.Forms.RichTextBox rtbCredits; private System.Windows.Forms.RichTextBox rtbCredits;
@ -378,5 +377,6 @@ private void InitializeComponent()
private System.Windows.Forms.PictureBox pbDanaSteamURL; private System.Windows.Forms.PictureBox pbDanaSteamURL;
private System.Windows.Forms.RichTextBox rtbShareXInfo; private System.Windows.Forms.RichTextBox rtbShareXInfo;
private System.Windows.Forms.Label lblOwners; private System.Windows.Forms.Label lblOwners;
private HelpersLib.UpdateCheckerLabel uclUpdate;
} }
} }

View file

@ -30,7 +30,6 @@ You should have received a copy of the GNU General Public License
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Windows.Forms; using System.Windows.Forms;
using UpdateCheckerLib;
using UploadersLib; using UploadersLib;
namespace ShareX namespace ShareX
@ -44,9 +43,10 @@ public AboutForm()
Text = Program.FullTitle; Text = Program.FullTitle;
lblProductName.Text = Program.FullTitle; lblProductName.Text = Program.FullTitle;
UpdateChecker updateChecker = new UpdateChecker("", Application.ProductName, Program.AssemblyVersion, GitHubUpdateChecker updateChecker = new GitHubUpdateChecker("ShareX", "ShareX", Program.AssemblyVersion);
ReleaseChannelType.Stable, Uploader.ProxyInfo.GetWebProxy()); updateChecker.Proxy = Uploader.ProxyInfo.GetWebProxy();
uclUpdate.CheckUpdate(updateChecker);
//uclUpdate.CheckUpdate(updateChecker);
} }
private void AboutForm_Shown(object sender, EventArgs e) private void AboutForm_Shown(object sender, EventArgs e)

View file

@ -32,7 +32,6 @@ You should have received a copy of the GNU General Public License
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
using UpdateCheckerLib;
using UploadersLib; using UploadersLib;
namespace ShareX namespace ShareX
@ -404,9 +403,9 @@ private void UpdateUploaderMenuNames()
private void CheckUpdate() private void CheckUpdate()
{ {
GitHubUpdateChecker updateChecker = new GitHubUpdateChecker("ShareX", "ShareX"); GitHubUpdateChecker updateChecker = new GitHubUpdateChecker("ShareX", "ShareX", Program.AssemblyVersion);
updateChecker.Proxy = Uploader.ProxyInfo.GetWebProxy(); updateChecker.Proxy = Uploader.ProxyInfo.GetWebProxy();
string downloadURL = updateChecker.CheckUpdate(Program.AssemblyVersion); string downloadURL = updateChecker.CheckUpdate();
if (!string.IsNullOrEmpty(downloadURL) && MessageBox.Show("An update is available for ShareX.\r\nWould you like to download it?", if (!string.IsNullOrEmpty(downloadURL) && MessageBox.Show("An update is available for ShareX.\r\nWould you like to download it?",
"ShareX", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes) "ShareX", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)