Files
shadowsocks-windows/shadowsocks-csharp/Controller/System/SystemProxy.cs
T
2016-10-06 16:12:35 +08:00

46 lines
1.3 KiB
C#

using System;
using Shadowsocks.Model;
using Shadowsocks.Util.SystemProxy;
namespace Shadowsocks.Controller
{
public static class SystemProxy
{
private static string GetTimestamp(DateTime value)
{
return value.ToString("yyyyMMddHHmmssfff");
}
public static void Update(Configuration config, bool forceDisable)
{
bool global = config.global;
bool enabled = config.enabled;
if (forceDisable)
{
enabled = false;
}
if (enabled)
{
if (global)
{
WinINet.SetIEProxy(true, true, "127.0.0.1:" + config.localPort.ToString(), "");
}
else
{
string pacUrl;
if (config.useOnlinePac && !config.pacUrl.IsNullOrEmpty())
pacUrl = config.pacUrl;
else
pacUrl = $"http://127.0.0.1:{config.localPort}/pac?t={GetTimestamp(DateTime.Now)}";
WinINet.SetIEProxy(true, false, "", pacUrl);
}
}
else
{
WinINet.SetIEProxy(false, false, "", "");
}
}
}
}