BetterDiscordApp-v2/Installers/dotNet/BetterDiscordWI/Utils.cs

46 lines
1.5 KiB
C#
Raw Normal View History

2015-12-04 02:17:37 +01:00
using System;
using System.Diagnostics;
using System.Net;
using System.Threading;
using System.Windows.Forms;
namespace BetterDiscordWI
{
class Utils
{
2016-05-06 21:03:17 +02:00
public void StartDownload(ProgressBar pb, string url, string name)
2015-12-04 02:17:37 +01:00
{
Thread t = new Thread(() =>
{
2016-05-06 21:03:17 +02:00
WebClient webClient = new WebClient {Headers = {["User-Agent"] = "Mozilla/5.0"}};
2015-12-04 02:17:37 +01:00
webClient.DownloadProgressChanged += delegate(object sender, DownloadProgressChangedEventArgs args)
{
double percentage = (double.Parse(args.BytesReceived.ToString()) /double.Parse(args.TotalBytesToReceive.ToString())) * 100;
Debug.Print(percentage.ToString());
pb.Invoke((MethodInvoker) delegate
{
pb.Value = (int)Math.Truncate(percentage);
});
};
2015-12-05 02:15:00 +01:00
webClient.DownloadFile(new Uri(url), Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\BetterDiscord\\temp\\" + name);
2015-12-04 02:17:37 +01:00
});
t.Start();
}
2016-05-06 21:03:17 +02:00
public static string GetHash()
2015-12-04 02:17:37 +01:00
{
2016-05-06 21:03:17 +02:00
WebClient wc = new WebClient {Headers = {["User-Agent"] = "Mozilla/5.0"}};
string result = wc.DownloadString(@"https://api.github.com/repos/Jiiks/BetterDiscordApp/commits/master");
2015-12-04 02:17:37 +01:00
int start = result.IndexOf("{\"sha\":");
int end = result.IndexOf("\",\"");
return result.Substring(start + 8, end - 8);
}
}
2016-05-06 21:03:17 +02:00
}