This commit is contained in:
sardelka9515
2022-10-23 19:02:39 +08:00
parent 6b34ab6e36
commit 2828b9b74f
114 changed files with 7374 additions and 7205 deletions

View File

@ -9,9 +9,9 @@ namespace RageCoop.Core
{
public static void DownloadFile(string url, string destination, Action<int> progressCallback = null)
{
if (File.Exists(destination)) { File.Delete(destination); }
AutoResetEvent ae = new AutoResetEvent(false);
WebClient client = new WebClient();
if (File.Exists(destination)) File.Delete(destination);
var ae = new AutoResetEvent(false);
var client = new WebClient();
// TLS only
ServicePointManager.Expect100Continue = true;
@ -19,13 +19,11 @@ namespace RageCoop.Core
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
client.DownloadProgressChanged += (s, e1) => progressCallback?.Invoke(e1.ProgressPercentage);
client.DownloadFileCompleted += (s, e2) =>
{
ae.Set();
};
client.DownloadFileCompleted += (s, e2) => { ae.Set(); };
client.DownloadFileAsync(new Uri(url), destination);
ae.WaitOne();
}
public static string DownloadString(string url)
{
// TLS only
@ -35,8 +33,8 @@ namespace RageCoop.Core
SecurityProtocolType.Tls;
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
WebClient client = new WebClient();
var client = new WebClient();
return client.DownloadString(url);
}
}
}
}