mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-28 09:15:46 +02:00
* Switch to .NET Framework 4.7.2 & C# 8.0, update libraries * Add TweetLib.Core project targeting .NET Standard 2.0 * Enable reference nullability checks for TweetLib.Core * Move a bunch of utility classes into TweetLib.Core & refactor * Partially move TweetDuck plugin & update system to TweetLib.Core * Move some constants and CultureInfo setup to TweetLib.Core * Move some configuration classes to TweetLib.Core * Minor refactoring and warning suppression * Add App to TweetLib.Core * Add IAppErrorHandler w/ implementation * Continue moving config, plugin, and update classes to TweetLib.Core * Fix a few nullability checks * Update installers to check for .NET Framework 4.7.2
45 lines
1.5 KiB
C#
45 lines
1.5 KiB
C#
using System;
|
|
using System.ComponentModel;
|
|
using System.IO;
|
|
using System.Net;
|
|
|
|
namespace TweetLib.Core.Utils{
|
|
public static class WebUtils{
|
|
private static bool HasMicrosoftBeenBroughtTo2008Yet;
|
|
|
|
private static void EnsureTLS12(){
|
|
if (!HasMicrosoftBeenBroughtTo2008Yet){
|
|
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
|
|
ServicePointManager.SecurityProtocol &= ~(SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11);
|
|
HasMicrosoftBeenBroughtTo2008Yet = true;
|
|
}
|
|
}
|
|
|
|
public static WebClient NewClient(string userAgent){
|
|
EnsureTLS12();
|
|
|
|
WebClient client = new WebClient{ Proxy = null };
|
|
client.Headers[HttpRequestHeader.UserAgent] = userAgent;
|
|
return client;
|
|
}
|
|
|
|
public static AsyncCompletedEventHandler FileDownloadCallback(string file, Action? onSuccess, Action<Exception>? onFailure){
|
|
return (sender, args) => {
|
|
if (args.Cancelled){
|
|
try{
|
|
File.Delete(file);
|
|
}catch{
|
|
// didn't want it deleted anyways
|
|
}
|
|
}
|
|
else if (args.Error != null){
|
|
onFailure?.Invoke(args.Error);
|
|
}
|
|
else{
|
|
onSuccess?.Invoke();
|
|
}
|
|
};
|
|
}
|
|
}
|
|
}
|