Browse Source

update system proxy

tags/2.3
clowwindy 9 years ago
parent
commit
18e6daf47d
3 changed files with 25 additions and 31 deletions
  1. +0
    -1
      shadowsocks-csharp/Controller/PortForwarder.cs
  2. +3
    -3
      shadowsocks-csharp/Controller/ShadowsocksController.cs
  3. +22
    -27
      shadowsocks-csharp/Controller/SystemProxy.cs

+ 0
- 1
shadowsocks-csharp/Controller/PortForwarder.cs View File

@@ -133,7 +133,6 @@ namespace Shadowsocks.Controller
if (bytesRead > 0) if (bytesRead > 0)
{ {
int bytesToSend;
_local.BeginSend(remoteRecvBuffer, 0, bytesRead, 0, new AsyncCallback(PipeConnectionSendCallback), null); _local.BeginSend(remoteRecvBuffer, 0, bytesRead, 0, new AsyncCallback(PipeConnectionSendCallback), null);
} }
else else


+ 3
- 3
shadowsocks-csharp/Controller/ShadowsocksController.cs View File

@@ -153,7 +153,7 @@ namespace Shadowsocks.Controller
} }
if (_config.enabled) if (_config.enabled)
{ {
SystemProxy.Disable();
SystemProxy.Update(_config, true);
} }
} }
@@ -262,7 +262,7 @@ namespace Shadowsocks.Controller
{ {
if (_config.enabled) if (_config.enabled)
{ {
SystemProxy.Enable(_config.global);
SystemProxy.Update(_config, false);
_systemProxyIsDirty = true; _systemProxyIsDirty = true;
} }
else else
@@ -270,7 +270,7 @@ namespace Shadowsocks.Controller
// only switch it off if we have switched it on // only switch it off if we have switched it on
if (_systemProxyIsDirty) if (_systemProxyIsDirty)
{ {
SystemProxy.Disable();
SystemProxy.Update(_config, false);
_systemProxyIsDirty = false; _systemProxyIsDirty = false;
} }
} }


+ 22
- 27
shadowsocks-csharp/Controller/SystemProxy.cs View File

@@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.IO; using System.IO;
using Shadowsocks.Model;
namespace Shadowsocks.Controller namespace Shadowsocks.Controller
{ {
@@ -25,24 +26,39 @@ namespace Shadowsocks.Controller
_refreshReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_REFRESH, IntPtr.Zero, 0); _refreshReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_REFRESH, IntPtr.Zero, 0);
} }
public static void Enable(bool global)
public static void Update(Configuration config, bool forceDisable)
{ {
bool global = config.global;
bool enabled = config.enabled;
if (forceDisable)
{
enabled = false;
}
try try
{ {
RegistryKey registry = RegistryKey registry =
Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
true); true);
if (global)
if (enabled)
{ {
registry.SetValue("ProxyEnable", 1);
registry.SetValue("ProxyServer", "127.0.0.1:8123");
registry.SetValue("AutoConfigURL", "");
if (global)
{
registry.SetValue("ProxyEnable", 1);
registry.SetValue("ProxyServer", "127.0.0.1:" + config.localPort.ToString());
registry.SetValue("AutoConfigURL", "");
}
else
{
registry.SetValue("ProxyEnable", 0);
registry.SetValue("ProxyServer", "");
registry.SetValue("AutoConfigURL", "http://127.0.0.1:" + config.localPort.ToString() + "/pac?t=" + GetTimestamp(DateTime.Now));
}
} }
else else
{ {
registry.SetValue("ProxyEnable", 0); registry.SetValue("ProxyEnable", 0);
registry.SetValue("ProxyServer", ""); registry.SetValue("ProxyServer", "");
registry.SetValue("AutoConfigURL", "http://127.0.0.1:8093/pac?t=" + GetTimestamp(DateTime.Now));
registry.SetValue("AutoConfigURL", "");
} }
SystemProxy.NotifyIE(); SystemProxy.NotifyIE();
//Must Notify IE first, or the connections do not chanage //Must Notify IE first, or the connections do not chanage
@@ -56,27 +72,6 @@ namespace Shadowsocks.Controller
} }
} }
public static void Disable()
{
try
{
RegistryKey registry =
Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
true);
registry.SetValue("ProxyEnable", 0);
registry.SetValue("ProxyServer", "");
registry.SetValue("AutoConfigURL", "");
SystemProxy.NotifyIE();
CopyProxySettingFromLan();
}
catch (Exception e)
{
Logging.LogUsefulException(e);
// TODO this should be moved into views
MessageBox.Show(I18N.GetString("Failed to update registry"));
}
}
private static void CopyProxySettingFromLan() private static void CopyProxySettingFromLan()
{ {
RegistryKey registry = RegistryKey registry =


Loading…
Cancel
Save