add global mode

This commit is contained in:
clowwindy
2014-12-14 17:43:04 +08:00
parent c65efc17fc
commit 5ed49ac6b6
4 changed files with 101 additions and 35 deletions
@@ -31,6 +31,7 @@ namespace Shadowsocks.Controller
public event EventHandler ConfigChanged;
public event EventHandler EnableStatusChanged;
public event EventHandler EnableGlobalChanged;
public event EventHandler ShareOverLANStatusChanged;
// when user clicked Edit PAC, and PAC file has already created
@@ -93,6 +94,17 @@ namespace Shadowsocks.Controller
}
}
public void ToggleGlobal(bool global)
{
_config.global = global;
UpdateSystemProxy();
SaveConfig(_config);
if (EnableGlobalChanged != null)
{
EnableGlobalChanged(this, new EventArgs());
}
}
public void ToggleShareOverLAN(bool enabled)
{
_config.shareOverLan = enabled;
@@ -175,7 +187,7 @@ namespace Shadowsocks.Controller
{
if (_config.enabled)
{
SystemProxy.Enable();
SystemProxy.Enable(_config.global);
_systemProxyIsDirty = true;
}
else
+13 -4
View File
@@ -24,16 +24,25 @@ namespace Shadowsocks.Controller
_refreshReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_REFRESH, IntPtr.Zero, 0);
}
public static void Enable()
public static void Enable(bool global)
{
try
{
RegistryKey registry =
Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
true);
registry.SetValue("ProxyEnable", 0);
registry.SetValue("ProxyServer", "");
registry.SetValue("AutoConfigURL", "http://127.0.0.1:8093/pac?t=" + GetTimestamp(DateTime.Now));
if (global)
{
registry.SetValue("ProxyEnable", 1);
registry.SetValue("ProxyServer", "127.0.0.1:8123");
registry.SetValue("AutoConfigURL", "");
}
else
{
registry.SetValue("ProxyEnable", 0);
registry.SetValue("ProxyServer", "");
registry.SetValue("AutoConfigURL", "http://127.0.0.1:8093/pac?t=" + GetTimestamp(DateTime.Now));
}
SystemProxy.NotifyIE();
//Must Notify IE first, or the connections do not chanage
CopyProxySettingFromLan();