Added AppVeyor dev build downloader, middle clicking on application settings pre release check box will start it

This commit is contained in:
Jaex 2017-11-03 15:27:26 +03:00
parent 2a82d3fa1d
commit ed547cb2aa
6 changed files with 238 additions and 0 deletions

View file

@ -350,6 +350,8 @@
<Compile Include="UITypeEditors\StringCollectionToStringTypeConverter.cs" />
<Compile Include="UITypeEditors\WavFileNameEditor.cs" />
<Compile Include="UnsafeBitmap.cs" />
<Compile Include="UpdateChecker\AppVeyor.cs" />
<Compile Include="UpdateChecker\AppVeyorUpdateChecker.cs" />
<Compile Include="UpdateChecker\GitHubUpdateChecker.cs" />
<Compile Include="UpdateChecker\UpdateChecker.cs" />
<Compile Include="UpdateChecker\DownloaderForm.cs">

View file

@ -0,0 +1,124 @@
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
Copyright (c) 2007-2017 ShareX Team
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 Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Cache;
using System.Text;
namespace ShareX.HelpersLib
{
public class AppVeyor
{
public string AccountName { get; set; }
public string ProjectSlug { get; set; }
public IWebProxy Proxy { get; set; }
private const string APIURL = "https://ci.appveyor.com/api";
public AppVeyorProject GetProjectByBranch(string branch = "master")
{
string url = $"{APIURL}/projects/{AccountName}/{ProjectSlug}/branch/{branch}";
using (WebClient wc = new WebClient())
{
wc.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
wc.Headers.Add(HttpRequestHeader.UserAgent, ShareXResources.UserAgent);
wc.Proxy = Proxy;
string response = wc.DownloadString(url);
if (!string.IsNullOrEmpty(response))
{
return JsonConvert.DeserializeObject<AppVeyorProject>(response);
}
}
return null;
}
public AppVeyorProjectArtifact[] GetArtifacts(string jobId)
{
string url = $"{APIURL}/buildjobs/{jobId}/artifacts";
using (WebClient wc = new WebClient())
{
wc.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
wc.Headers.Add(HttpRequestHeader.UserAgent, ShareXResources.UserAgent);
wc.Proxy = Proxy;
string response = wc.DownloadString(url);
if (!string.IsNullOrEmpty(response))
{
return JsonConvert.DeserializeObject<AppVeyorProjectArtifact[]>(response);
}
}
return null;
}
public string GetArtifactDownloadURL(string jobId, string fileName)
{
return $"{APIURL}/buildjobs/{jobId}/artifacts/{fileName}";
}
}
public class AppVeyorProject
{
public AppVeyorProjectInfo project { get; set; }
public AppVeyorProjectBuild build { get; set; }
}
public class AppVeyorProjectInfo
{
}
public class AppVeyorProjectBuild
{
public AppVeyorProjectJob[] jobs { get; set; }
public string version { get; set; }
public string status { get; set; }
}
public class AppVeyorProjectJob
{
public string jobId { get; set; }
public string name { get; set; }
public string osType { get; set; }
public string status { get; set; }
}
public class AppVeyorProjectArtifact
{
public string fileName { get; set; }
public string name { get; set; }
public string type { get; set; }
public long size { get; set; }
}
}

View file

@ -0,0 +1,90 @@
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
Copyright (c) 2007-2017 ShareX Team
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.Collections.Generic;
using System.Linq;
using System.Text;
namespace ShareX.HelpersLib
{
public class AppVeyorUpdateChecker : UpdateChecker
{
public override void CheckUpdate()
{
try
{
AppVeyor appveyor = new AppVeyor()
{
AccountName = "ShareX",
ProjectSlug = "sharex",
Proxy = Proxy
};
AppVeyorProject project = appveyor.GetProjectByBranch("master");
if (!project.build.status.Equals("success", StringComparison.InvariantCultureIgnoreCase))
{
throw new Exception("Latest project build is not successful.");
}
AppVeyorProjectJob job = project.build.jobs.FirstOrDefault(x =>
x.name.Equals("Configuration: Release", StringComparison.InvariantCultureIgnoreCase) &&
x.osType.Equals("Windows", StringComparison.InvariantCultureIgnoreCase) &&
x.status.Equals("success", StringComparison.InvariantCultureIgnoreCase));
if (job == null)
{
throw new Exception("Unable to find successful release build.");
}
AppVeyorProjectArtifact[] artifacts = appveyor.GetArtifacts(job.jobId);
AppVeyorProjectArtifact artifact = artifacts.FirstOrDefault(x => x.name.Equals("Setup", StringComparison.InvariantCultureIgnoreCase));
if (artifact == null)
{
throw new Exception("Unable to find setup file.");
}
Filename = artifact.fileName;
DownloadURL = appveyor.GetArtifactDownloadURL(job.jobId, artifact.fileName);
if (Version.TryParse(project.build.version, out Version version))
{
LatestVersion = version;
}
RefreshStatus();
Status = UpdateStatus.UpdateAvailable;
return;
}
catch (Exception e)
{
e.ShowError();
}
Status = UpdateStatus.UpdateCheckFailed;
}
}
}

View file

@ -218,6 +218,7 @@ private void InitializeComponent()
this.cbCheckPreReleaseUpdates.Name = "cbCheckPreReleaseUpdates";
this.cbCheckPreReleaseUpdates.UseVisualStyleBackColor = true;
this.cbCheckPreReleaseUpdates.CheckedChanged += new System.EventHandler(this.cbCheckPreReleaseUpdates_CheckedChanged);
this.cbCheckPreReleaseUpdates.MouseUp += new System.Windows.Forms.MouseEventHandler(this.cbCheckPreReleaseUpdates_MouseUp);
//
// cbTrayMiddleClickAction
//
@ -1031,6 +1032,7 @@ private void InitializeComponent()
//
this.pgSettings.CategoryForeColor = System.Drawing.SystemColors.InactiveCaptionText;
resources.ApplyResources(this.pgSettings, "pgSettings");
this.pgSettings.LineColor = System.Drawing.SystemColors.ControlDark;
this.pgSettings.Name = "pgSettings";
this.pgSettings.PropertySort = System.Windows.Forms.PropertySort.Categorized;
this.pgSettings.ToolbarVisible = false;

View file

@ -397,6 +397,14 @@ private void cbCheckPreReleaseUpdates_CheckedChanged(object sender, EventArgs e)
Program.Settings.CheckPreReleaseUpdates = cbCheckPreReleaseUpdates.Checked;
}
private void cbCheckPreReleaseUpdates_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Middle)
{
TaskHelpers.DownloadAppVeyorBuild();
}
}
#endregion General
#region Integration

View file

@ -1596,5 +1596,17 @@ public static void ToggleActionsToolbar()
ActionsToolbarForm.Instance.ForceActivate();
}
}
public static void DownloadAppVeyorBuild()
{
AppVeyorUpdateChecker updateChecker = new AppVeyorUpdateChecker()
{
IsBeta = Program.Beta,
IsPortable = Program.Portable,
Proxy = HelpersOptions.CurrentProxy.GetWebProxy()
};
updateChecker.CheckUpdate();
UpdateMessageBox.Start(updateChecker);
}
}
}