Get download counts method

This commit is contained in:
Jaex 2015-04-15 11:58:40 +03:00
parent a2ee2eb019
commit 152b23805a
3 changed files with 30 additions and 1 deletions

View file

@ -62,7 +62,7 @@ public void WriteElapsedSeconds(string text = null)
public void WriteElapsedMilliseconds(string text = null)
{
Write(text, timer.ElapsedMilliseconds + " millisecond.");
Write(text, timer.ElapsedMilliseconds + " milliseconds.");
}
public void Dispose()

View file

@ -29,6 +29,7 @@ You should have received a copy of the GNU General Public License
using System.Linq;
using System.Net;
using System.Net.Cache;
using System.Text;
namespace ShareX.HelpersLib
{
@ -113,6 +114,26 @@ public string GetLatestDownloadURL()
return null;
}
public string GetDownloadCounts()
{
StringBuilder sb = new StringBuilder();
List<GitHubRelease> releases = GetReleases();
if (releases != null)
{
foreach (GitHubRelease release in releases)
{
if (release.assets.Count > 0)
{
sb.AppendFormat("{0} ({1}): {2}\r\n", release.name, DateTime.Parse(release.published_at), release.assets.Sum(x => x.download_count));
}
}
}
return sb.ToString().Trim();
}
private string GetDownloadURL(GitHubRelease release)
{
if (release.assets != null && release.assets.Count > 0)

View file

@ -417,6 +417,14 @@ public static UpdateChecker CheckUpdate()
return updateChecker;
}
public static void CheckDownloadCounts()
{
GitHubUpdateChecker updateChecker = new GitHubUpdateChecker("ShareX", "ShareX");
updateChecker.Proxy = HelpersOptions.CurrentProxy.GetWebProxy();
string output = updateChecker.GetDownloadCounts();
Debug.WriteLine(output);
}
public static string CheckFilePath(string folder, string filename, TaskSettings taskSettings)
{
string filepath = Path.Combine(folder, filename);