public static void SetDefaultProxy(Config.ProxySettings settings, bool throwExceptions = false)
{
try
{
IWebProxy proxy = null;
switch(settings.Selection) {
case Config.ProxySelection.SYSTEM:
proxy = WebRequest.GetSystemWebProxy();
break;
case Config.ProxySelection.CUSTOM:
proxy = new WebProxy(settings.Server);
break;
}
if (settings.LoginRequired && proxy != null) {
proxy.Credentials = new NetworkCredential(settings.Username, Crypto.Deobfuscate(settings.ObfuscatedPassword));
}
WebRequest.DefaultWebProxy = proxy;
}
catch (Exception e)
{
if (throwExceptions) {
throw;
}
Logger.Warn("Failed to set the default proxy, please check your proxy config: ", e);
}
}
}