Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f33da19f06 |
@@ -1,13 +1,3 @@
|
|||||||
2.3 2015-01-25
|
|
||||||
- Use the same port for every profile
|
|
||||||
- Use the same port for HTTP/Socks5/PAC
|
|
||||||
- Fix GFWList PAC compatibility issue with IE11
|
|
||||||
- Encourage users to report to GFWList when no update found
|
|
||||||
- Minor UI improvements
|
|
||||||
|
|
||||||
2.2.1 2015-01-18
|
|
||||||
- Fix QR Code compatibility
|
|
||||||
|
|
||||||
2.2 2015-01-14
|
2.2 2015-01-14
|
||||||
- Support updating PAC from GFWList
|
- Support updating PAC from GFWList
|
||||||
- Support adding server by scanning QR Code
|
- Support adding server by scanning QR Code
|
||||||
|
|||||||
@@ -20,8 +20,6 @@ a pull request, or ask some of your friends to do so.
|
|||||||
3. We don't answer questions of any other types here. Since very few people
|
3. We don't answer questions of any other types here. Since very few people
|
||||||
are watching the issue tracker here, you'll probably get no help from here.
|
are watching the issue tracker here, you'll probably get no help from here.
|
||||||
Read [Troubleshooting] and get help from forums or [mailing lists].
|
Read [Troubleshooting] and get help from forums or [mailing lists].
|
||||||
4. Issues in languages other than English will be Google translated into English
|
|
||||||
later.
|
|
||||||
|
|
||||||
|
|
||||||
[Troubleshooting]: https://github.com/clowwindy/shadowsocks/wiki/Troubleshooting
|
[Troubleshooting]: https://github.com/clowwindy/shadowsocks/wiki/Troubleshooting
|
||||||
|
|||||||
@@ -17,19 +17,18 @@ Download [latest release].
|
|||||||
|
|
||||||
For <= Windows 7, download Shadowsocks-win-x.x.x.zip.
|
For <= Windows 7, download Shadowsocks-win-x.x.x.zip.
|
||||||
|
|
||||||
For >= Windows 8, download Shadowsocks-win-dotnet4.0-x.x.x.zip, unless you have .Net 2.0 installed.
|
For >= Windows 8, download Shadowsocks-win-dotnet4.0-x.x.x.zip.
|
||||||
|
|
||||||
#### Usage
|
#### Usage
|
||||||
|
|
||||||
1. Find Shadowsocks icon in notification tray
|
1. Find Shadowsocks icon in notification tray
|
||||||
2. You can add multiple servers in servers menu
|
2. You can add multiple servers in servers menu
|
||||||
3. Select Enable System Proxy menu to enable system proxy. Please disable other
|
3. Select Enable menu to enable system proxy
|
||||||
proxy addons in your browser, or set them to use system proxy
|
4. Leave Enable menu unchecked, Shadowsocks will still provide an HTTP proxy at 127.0.0.1:8123
|
||||||
4. You can also configure your browser proxy manually if you don't want to enable
|
5. After you saved PAC file with any editor, Shadowsocks will notify browsers
|
||||||
system proxy. Set Socks5 or HTTP proxy to 127.0.0.1:1080. You can change this
|
about the change automatically
|
||||||
port in Server -> Edit Servers
|
6. Please disable other proxy addons in your browser, or set them to use
|
||||||
5. You can change PAC rules by editing the PAC file. When you save the PAC file
|
system proxy
|
||||||
with any editor, Shadowsocks will notify browsers about the change automatically
|
|
||||||
|
|
||||||
### Develop
|
### Develop
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ using System.IO;
|
|||||||
using Shadowsocks.Properties;
|
using Shadowsocks.Properties;
|
||||||
using SimpleJson;
|
using SimpleJson;
|
||||||
using Shadowsocks.Util;
|
using Shadowsocks.Util;
|
||||||
using Shadowsocks.Model;
|
|
||||||
|
|
||||||
namespace Shadowsocks.Controller
|
namespace Shadowsocks.Controller
|
||||||
{
|
{
|
||||||
@@ -16,53 +15,22 @@ namespace Shadowsocks.Controller
|
|||||||
|
|
||||||
private static string PAC_FILE = PACServer.PAC_FILE;
|
private static string PAC_FILE = PACServer.PAC_FILE;
|
||||||
|
|
||||||
private static string USER_RULE_FILE = PACServer.USER_RULE_FILE;
|
public event EventHandler UpdateCompleted;
|
||||||
|
|
||||||
public event EventHandler<ResultEventArgs> UpdateCompleted;
|
|
||||||
|
|
||||||
public event ErrorEventHandler Error;
|
public event ErrorEventHandler Error;
|
||||||
|
|
||||||
public class ResultEventArgs : EventArgs
|
|
||||||
{
|
|
||||||
public bool Success;
|
|
||||||
|
|
||||||
public ResultEventArgs(bool success)
|
|
||||||
{
|
|
||||||
this.Success = success;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void http_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
|
private void http_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
List<string> lines = ParseResult(e.Result);
|
List<string> lines = ParseResult(e.Result);
|
||||||
if (File.Exists(USER_RULE_FILE))
|
|
||||||
{
|
|
||||||
string local = File.ReadAllText(USER_RULE_FILE, Encoding.UTF8);
|
|
||||||
string[] rules = local.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
|
|
||||||
foreach(string rule in rules)
|
|
||||||
{
|
|
||||||
if (rule.StartsWith("!") || rule.StartsWith("["))
|
|
||||||
continue;
|
|
||||||
lines.Add(rule);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
string abpContent = Utils.UnGzip(Resources.abp_js);
|
string abpContent = Utils.UnGzip(Resources.abp_js);
|
||||||
abpContent = abpContent.Replace("__RULES__", SimpleJson.SimpleJson.SerializeObject(lines));
|
abpContent = abpContent.Replace("__RULES__", SimpleJson.SimpleJson.SerializeObject(lines));
|
||||||
if (File.Exists(PAC_FILE))
|
|
||||||
{
|
|
||||||
string original = File.ReadAllText(PAC_FILE, Encoding.UTF8);
|
|
||||||
if (original == abpContent)
|
|
||||||
{
|
|
||||||
UpdateCompleted(this, new ResultEventArgs(false));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File.WriteAllText(PAC_FILE, abpContent, Encoding.UTF8);
|
File.WriteAllText(PAC_FILE, abpContent, Encoding.UTF8);
|
||||||
if (UpdateCompleted != null)
|
if (UpdateCompleted != null)
|
||||||
{
|
{
|
||||||
UpdateCompleted(this, new ResultEventArgs(true));
|
UpdateCompleted(this, new EventArgs());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -74,10 +42,10 @@ namespace Shadowsocks.Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdatePACFromGFWList(Configuration config)
|
public void UpdatePACFromGFWList()
|
||||||
{
|
{
|
||||||
WebClient http = new WebClient();
|
WebClient http = new WebClient();
|
||||||
http.Proxy = new WebProxy(IPAddress.Loopback.ToString(), config.localPort);
|
http.Proxy = new WebProxy(IPAddress.Loopback.ToString(), 8123);
|
||||||
http.DownloadStringCompleted += http_DownloadStringCompleted;
|
http.DownloadStringCompleted += http_DownloadStringCompleted;
|
||||||
http.DownloadStringAsync(new Uri(GFWLIST_URL));
|
http.DownloadStringAsync(new Uri(GFWLIST_URL));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,10 +18,6 @@ namespace Shadowsocks.Controller
|
|||||||
string[] lines = Regex.Split(Resources.cn, "\r\n|\r|\n");
|
string[] lines = Regex.Split(Resources.cn, "\r\n|\r|\n");
|
||||||
foreach (string line in lines)
|
foreach (string line in lines)
|
||||||
{
|
{
|
||||||
if (line.StartsWith("#"))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
string[] kv = Regex.Split(line, "=");
|
string[] kv = Regex.Split(line, "=");
|
||||||
if (kv.Length == 2)
|
if (kv.Length == 2)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,163 +0,0 @@
|
|||||||
using Shadowsocks.Model;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Net;
|
|
||||||
using System.Net.NetworkInformation;
|
|
||||||
using System.Net.Sockets;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Shadowsocks.Controller
|
|
||||||
{
|
|
||||||
public class Listener
|
|
||||||
{
|
|
||||||
public interface Service
|
|
||||||
{
|
|
||||||
bool Handle(byte[] firstPacket, int length, Socket socket);
|
|
||||||
}
|
|
||||||
|
|
||||||
Configuration _config;
|
|
||||||
bool _shareOverLAN;
|
|
||||||
Socket _socket;
|
|
||||||
IList<Service> _services;
|
|
||||||
|
|
||||||
public Listener(IList<Service> services)
|
|
||||||
{
|
|
||||||
this._services = services;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool CheckIfPortInUse(int port)
|
|
||||||
{
|
|
||||||
IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();
|
|
||||||
IPEndPoint[] ipEndPoints = ipProperties.GetActiveTcpListeners();
|
|
||||||
|
|
||||||
foreach (IPEndPoint endPoint in ipEndPoints)
|
|
||||||
{
|
|
||||||
if (endPoint.Port == port)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Start(Configuration config)
|
|
||||||
{
|
|
||||||
this._config = config;
|
|
||||||
this._shareOverLAN = config.shareOverLan;
|
|
||||||
|
|
||||||
if (CheckIfPortInUse(_config.localPort))
|
|
||||||
throw new Exception(I18N.GetString("Port already in use"));
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Create a TCP/IP socket.
|
|
||||||
_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
|
||||||
_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
|
|
||||||
IPEndPoint localEndPoint = null;
|
|
||||||
if (_shareOverLAN)
|
|
||||||
{
|
|
||||||
localEndPoint = new IPEndPoint(IPAddress.Any, _config.localPort);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
localEndPoint = new IPEndPoint(IPAddress.Loopback, _config.localPort);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bind the socket to the local endpoint and listen for incoming connections.
|
|
||||||
_socket.Bind(localEndPoint);
|
|
||||||
_socket.Listen(1024);
|
|
||||||
|
|
||||||
|
|
||||||
// Start an asynchronous socket to listen for connections.
|
|
||||||
Console.WriteLine("Shadowsocks started");
|
|
||||||
_socket.BeginAccept(
|
|
||||||
new AsyncCallback(AcceptCallback),
|
|
||||||
_socket);
|
|
||||||
}
|
|
||||||
catch (SocketException)
|
|
||||||
{
|
|
||||||
_socket.Close();
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Stop()
|
|
||||||
{
|
|
||||||
if (_socket != null)
|
|
||||||
{
|
|
||||||
_socket.Close();
|
|
||||||
_socket = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AcceptCallback(IAsyncResult ar)
|
|
||||||
{
|
|
||||||
Socket listener = (Socket)ar.AsyncState;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Socket conn = listener.EndAccept(ar);
|
|
||||||
|
|
||||||
byte[] buf = new byte[4096];
|
|
||||||
object[] state = new object[] {
|
|
||||||
conn,
|
|
||||||
buf
|
|
||||||
};
|
|
||||||
|
|
||||||
conn.BeginReceive(buf, 0, buf.Length, 0,
|
|
||||||
new AsyncCallback(ReceiveCallback), state);
|
|
||||||
}
|
|
||||||
catch (ObjectDisposedException)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Console.WriteLine(e);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
listener.BeginAccept(
|
|
||||||
new AsyncCallback(AcceptCallback),
|
|
||||||
listener);
|
|
||||||
}
|
|
||||||
catch (ObjectDisposedException)
|
|
||||||
{
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Logging.LogUsefulException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void ReceiveCallback(IAsyncResult ar)
|
|
||||||
{
|
|
||||||
object[] state = (object[])ar.AsyncState;
|
|
||||||
|
|
||||||
Socket conn = (Socket)state[0];
|
|
||||||
byte[] buf = (byte[])state[1];
|
|
||||||
try
|
|
||||||
{
|
|
||||||
int bytesRead = conn.EndReceive(ar);
|
|
||||||
foreach (Service service in _services)
|
|
||||||
{
|
|
||||||
if (service.Handle(buf, bytesRead, conn))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// no service found for this
|
|
||||||
// shouldn't happen
|
|
||||||
conn.Close();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Console.WriteLine(e);
|
|
||||||
conn.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,43 +9,105 @@ using Shadowsocks.Model;
|
|||||||
namespace Shadowsocks.Controller
|
namespace Shadowsocks.Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
class Local : Listener.Service
|
class Local
|
||||||
{
|
{
|
||||||
private Configuration _config;
|
private Server _server;
|
||||||
|
private bool _shareOverLAN;
|
||||||
|
//private Encryptor encryptor;
|
||||||
|
Socket _listener;
|
||||||
public Local(Configuration config)
|
public Local(Configuration config)
|
||||||
{
|
{
|
||||||
this._config = config;
|
this._server = config.GetCurrentServer();
|
||||||
|
_shareOverLAN = config.shareOverLan;
|
||||||
|
//this.encryptor = new Encryptor(config.method, config.password);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Handle(byte[] firstPacket, int length, Socket socket)
|
public void Start()
|
||||||
{
|
{
|
||||||
if (length < 2 || firstPacket[0] != 5)
|
try
|
||||||
{
|
{
|
||||||
return false;
|
// Create a TCP/IP socket.
|
||||||
|
_listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||||
|
_listener.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
|
||||||
|
IPEndPoint localEndPoint = null;
|
||||||
|
if (_shareOverLAN)
|
||||||
|
{
|
||||||
|
localEndPoint = new IPEndPoint(IPAddress.Any, _server.local_port);
|
||||||
}
|
}
|
||||||
socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true);
|
else
|
||||||
|
{
|
||||||
|
localEndPoint = new IPEndPoint(IPAddress.Loopback, _server.local_port);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bind the socket to the local endpoint and listen for incoming connections.
|
||||||
|
_listener.Bind(localEndPoint);
|
||||||
|
_listener.Listen(100);
|
||||||
|
|
||||||
|
|
||||||
|
// Start an asynchronous socket to listen for connections.
|
||||||
|
Console.WriteLine("Shadowsocks started");
|
||||||
|
_listener.BeginAccept(
|
||||||
|
new AsyncCallback(AcceptCallback),
|
||||||
|
_listener);
|
||||||
|
}
|
||||||
|
catch(SocketException)
|
||||||
|
{
|
||||||
|
_listener.Close();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Stop()
|
||||||
|
{
|
||||||
|
_listener.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void AcceptCallback(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
Socket listener = (Socket)ar.AsyncState;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Socket conn = listener.EndAccept(ar);
|
||||||
|
conn.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true);
|
||||||
|
|
||||||
Handler handler = new Handler();
|
Handler handler = new Handler();
|
||||||
handler.connection = socket;
|
handler.connection = conn;
|
||||||
Server server = _config.GetCurrentServer();
|
handler.encryptor = EncryptorFactory.GetEncryptor(_server.method, _server.password);
|
||||||
handler.encryptor = EncryptorFactory.GetEncryptor(server.method, server.password);
|
handler.config = _server;
|
||||||
handler.server = server;
|
|
||||||
|
|
||||||
handler.Start(firstPacket, length);
|
handler.Start();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
//Console.WriteLine(e.Message);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
listener.BeginAccept(
|
||||||
|
new AsyncCallback(AcceptCallback),
|
||||||
|
listener);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
//Console.WriteLine(e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Handler
|
class Handler
|
||||||
{
|
{
|
||||||
//public Encryptor encryptor;
|
//public Encryptor encryptor;
|
||||||
public IEncryptor encryptor;
|
public IEncryptor encryptor;
|
||||||
public Server server;
|
public Server config;
|
||||||
// Client socket.
|
// Client socket.
|
||||||
public Socket remote;
|
public Socket remote;
|
||||||
public Socket connection;
|
public Socket connection;
|
||||||
|
|
||||||
private byte[] _firstPacket;
|
|
||||||
private int _firstPacketLength;
|
|
||||||
// Size of receive buffer.
|
// Size of receive buffer.
|
||||||
public const int RecvSize = 16384;
|
public const int RecvSize = 16384;
|
||||||
public const int BufferSize = RecvSize + 32;
|
public const int BufferSize = RecvSize + 32;
|
||||||
@@ -66,21 +128,19 @@ namespace Shadowsocks.Controller
|
|||||||
private object encryptionLock = new object();
|
private object encryptionLock = new object();
|
||||||
private object decryptionLock = new object();
|
private object decryptionLock = new object();
|
||||||
|
|
||||||
public void Start(byte[] firstPacket, int length)
|
public void Start()
|
||||||
{
|
{
|
||||||
this._firstPacket = firstPacket;
|
|
||||||
this._firstPacketLength = length;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// TODO async resolving
|
// TODO async resolving
|
||||||
IPAddress ipAddress;
|
IPAddress ipAddress;
|
||||||
bool parsed = IPAddress.TryParse(server.server, out ipAddress);
|
bool parsed = IPAddress.TryParse(config.server, out ipAddress);
|
||||||
if (!parsed)
|
if (!parsed)
|
||||||
{
|
{
|
||||||
IPHostEntry ipHostInfo = Dns.GetHostEntry(server.server);
|
IPHostEntry ipHostInfo = Dns.GetHostEntry(config.server);
|
||||||
ipAddress = ipHostInfo.AddressList[0];
|
ipAddress = ipHostInfo.AddressList[0];
|
||||||
}
|
}
|
||||||
IPEndPoint remoteEP = new IPEndPoint(ipAddress, server.server_port);
|
IPEndPoint remoteEP = new IPEndPoint(ipAddress, config.server_port);
|
||||||
|
|
||||||
|
|
||||||
remote = new Socket(ipAddress.AddressFamily,
|
remote = new Socket(ipAddress.AddressFamily,
|
||||||
@@ -180,15 +240,33 @@ namespace Shadowsocks.Controller
|
|||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int bytesRead = _firstPacketLength;
|
connection.BeginReceive(connetionRecvBuffer, 0, 256, 0,
|
||||||
|
new AsyncCallback(HandshakeReceiveCallback), null);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Logging.LogUsefulException(e);
|
||||||
|
this.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandshakeReceiveCallback(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
if (closed)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int bytesRead = connection.EndReceive(ar);
|
||||||
|
|
||||||
if (bytesRead > 1)
|
if (bytesRead > 1)
|
||||||
{
|
{
|
||||||
byte[] response = { 5, 0 };
|
byte[] response = { 5, 0 };
|
||||||
if (_firstPacket[0] != 5)
|
if (connetionRecvBuffer[0] != 5)
|
||||||
{
|
{
|
||||||
// reject socks 4
|
// reject socks 4
|
||||||
response = new byte[] { 0, 91 };
|
response = new byte[]{ 0, 91 };
|
||||||
Console.WriteLine("socks 5 protocol error");
|
Console.WriteLine("socks 5 protocol error");
|
||||||
}
|
}
|
||||||
connection.BeginSend(response, 0, response.Length, 0, new AsyncCallback(HandshakeSendCallback), null);
|
connection.BeginSend(response, 0, response.Length, 0, new AsyncCallback(HandshakeSendCallback), null);
|
||||||
|
|||||||
@@ -12,76 +12,59 @@ using System.Text;
|
|||||||
|
|
||||||
namespace Shadowsocks.Controller
|
namespace Shadowsocks.Controller
|
||||||
{
|
{
|
||||||
class PACServer : Listener.Service
|
class PACServer
|
||||||
{
|
{
|
||||||
|
private static int PORT = 8093;
|
||||||
public static string PAC_FILE = "pac.txt";
|
public static string PAC_FILE = "pac.txt";
|
||||||
|
private static Configuration config;
|
||||||
|
|
||||||
public static string USER_RULE_FILE = "user-rule.txt";
|
Socket _listener;
|
||||||
|
|
||||||
FileSystemWatcher watcher;
|
FileSystemWatcher watcher;
|
||||||
private Configuration _config;
|
|
||||||
|
|
||||||
public event EventHandler PACFileChanged;
|
public event EventHandler PACFileChanged;
|
||||||
|
|
||||||
public PACServer()
|
public void Start(Configuration configuration)
|
||||||
{
|
|
||||||
this.WatchPacFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UpdateConfiguration(Configuration config)
|
|
||||||
{
|
|
||||||
this._config = config;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Handle(byte[] firstPacket, int length, Socket socket)
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string request = Encoding.UTF8.GetString(firstPacket, 0, length);
|
config = configuration;
|
||||||
string[] lines = request.Split('\r', '\n');
|
// Create a TCP/IP socket.
|
||||||
bool hostMatch = false, pathMatch = false, useSocks = false;
|
_listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||||
foreach (string line in lines)
|
_listener.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
|
||||||
|
IPEndPoint localEndPoint = null;
|
||||||
|
if (configuration.shareOverLan)
|
||||||
{
|
{
|
||||||
string[] kv = line.Split(new char[]{':'}, 2);
|
localEndPoint = new IPEndPoint(IPAddress.Any, PORT);
|
||||||
if (kv.Length == 2)
|
|
||||||
{
|
|
||||||
if (kv[0] == "Host")
|
|
||||||
{
|
|
||||||
if (kv[1].Trim() == ((IPEndPoint)socket.LocalEndPoint).ToString())
|
|
||||||
{
|
|
||||||
hostMatch = true;
|
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else if (kv[0] == "User-Agent")
|
|
||||||
{
|
{
|
||||||
// we need to drop connections when changing servers
|
localEndPoint = new IPEndPoint(IPAddress.Loopback, PORT);
|
||||||
/* if (kv[1].IndexOf("Chrome") >= 0)
|
}
|
||||||
|
|
||||||
|
// Bind the socket to the local endpoint and listen for incoming connections.
|
||||||
|
_listener.Bind(localEndPoint);
|
||||||
|
_listener.Listen(100);
|
||||||
|
_listener.BeginAccept(
|
||||||
|
new AsyncCallback(AcceptCallback),
|
||||||
|
_listener);
|
||||||
|
|
||||||
|
WatchPacFile();
|
||||||
|
}
|
||||||
|
catch (SocketException)
|
||||||
{
|
{
|
||||||
useSocks = true;
|
_listener.Close();
|
||||||
} */
|
throw;
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (kv.Length == 1)
|
|
||||||
{
|
|
||||||
if (line.IndexOf("pac") >= 0)
|
|
||||||
{
|
|
||||||
pathMatch = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (hostMatch && pathMatch)
|
|
||||||
{
|
|
||||||
SendResponse(firstPacket, length, socket, useSocks);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
catch (ArgumentException)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Stop()
|
||||||
|
{
|
||||||
|
if (_listener != null)
|
||||||
|
{
|
||||||
|
_listener.Close();
|
||||||
|
_listener = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public string TouchPACFile()
|
public string TouchPACFile()
|
||||||
{
|
{
|
||||||
@@ -96,16 +79,47 @@ namespace Shadowsocks.Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal string TouchUserRuleFile()
|
// we don't even use it
|
||||||
|
static byte[] requestBuf = new byte[2048];
|
||||||
|
|
||||||
|
public void AcceptCallback(IAsyncResult ar)
|
||||||
{
|
{
|
||||||
if (File.Exists(USER_RULE_FILE))
|
Socket listener = (Socket)ar.AsyncState;
|
||||||
|
try
|
||||||
{
|
{
|
||||||
return USER_RULE_FILE;
|
Socket conn = listener.EndAccept(ar);
|
||||||
|
|
||||||
|
object[] state = new object[] {
|
||||||
|
conn,
|
||||||
|
requestBuf
|
||||||
|
};
|
||||||
|
|
||||||
|
conn.BeginReceive(requestBuf, 0, requestBuf.Length, 0,
|
||||||
|
new AsyncCallback(ReceiveCallback), state);
|
||||||
}
|
}
|
||||||
else
|
catch (ObjectDisposedException)
|
||||||
{
|
{
|
||||||
File.WriteAllText(USER_RULE_FILE, Resources.user_rule);
|
}
|
||||||
return USER_RULE_FILE;
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine(e);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
listener.BeginAccept(
|
||||||
|
new AsyncCallback(AcceptCallback),
|
||||||
|
listener);
|
||||||
|
}
|
||||||
|
catch (ObjectDisposedException)
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Logging.LogUsefulException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,18 +135,26 @@ namespace Shadowsocks.Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendResponse(byte[] firstPacket, int length, Socket socket, bool useSocks)
|
private void ReceiveCallback(IAsyncResult ar)
|
||||||
{
|
{
|
||||||
|
object[] state = (object[])ar.AsyncState;
|
||||||
|
|
||||||
|
Socket conn = (Socket)state[0];
|
||||||
|
byte[] requestBuf = (byte[])state[1];
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
int bytesRead = conn.EndReceive(ar);
|
||||||
|
|
||||||
string pac = GetPACContent();
|
string pac = GetPACContent();
|
||||||
|
|
||||||
IPEndPoint localEndPoint = (IPEndPoint)socket.LocalEndPoint;
|
IPEndPoint localEndPoint = (IPEndPoint)conn.LocalEndPoint;
|
||||||
|
|
||||||
string proxy = GetPACAddress(firstPacket, length, localEndPoint, useSocks);
|
string proxy = GetPACAddress(requestBuf, localEndPoint);
|
||||||
|
|
||||||
pac = pac.Replace("__PROXY__", proxy);
|
pac = pac.Replace("__PROXY__", proxy);
|
||||||
|
|
||||||
|
if (bytesRead > 0)
|
||||||
|
{
|
||||||
string text = String.Format(@"HTTP/1.1 200 OK
|
string text = String.Format(@"HTTP/1.1 200 OK
|
||||||
Server: Shadowsocks
|
Server: Shadowsocks
|
||||||
Content-Type: application/x-ns-proxy-autoconfig
|
Content-Type: application/x-ns-proxy-autoconfig
|
||||||
@@ -141,13 +163,18 @@ Connection: Close
|
|||||||
|
|
||||||
", System.Text.Encoding.UTF8.GetBytes(pac).Length) + pac;
|
", System.Text.Encoding.UTF8.GetBytes(pac).Length) + pac;
|
||||||
byte[] response = System.Text.Encoding.UTF8.GetBytes(text);
|
byte[] response = System.Text.Encoding.UTF8.GetBytes(text);
|
||||||
socket.BeginSend(response, 0, response.Length, 0, new AsyncCallback(SendCallback), socket);
|
conn.BeginSend(response, 0, response.Length, 0, new AsyncCallback(SendCallback), conn);
|
||||||
Util.Utils.ReleaseMemory();
|
Util.Utils.ReleaseMemory();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
conn.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Console.WriteLine(e);
|
Console.WriteLine(e);
|
||||||
socket.Close();
|
conn.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,8 +213,9 @@ Connection: Close
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetPACAddress(byte[] requestBuf, int length, IPEndPoint localEndPoint, bool useSocks)
|
private string GetPACAddress(byte[] requestBuf, IPEndPoint localEndPoint)
|
||||||
{
|
{
|
||||||
|
string proxy = "PROXY " + localEndPoint.Address + ":8123;";
|
||||||
//try
|
//try
|
||||||
//{
|
//{
|
||||||
// string requestString = Encoding.UTF8.GetString(requestBuf);
|
// string requestString = Encoding.UTF8.GetString(requestBuf);
|
||||||
@@ -201,7 +229,7 @@ Connection: Close
|
|||||||
//{
|
//{
|
||||||
// Console.WriteLine(e);
|
// Console.WriteLine(e);
|
||||||
//}
|
//}
|
||||||
return (useSocks ? "SOCKS5 " : "PROXY ") + localEndPoint.Address + ":" + this._config.localPort + ";";
|
return proxy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ using System.Diagnostics;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Net.NetworkInformation;
|
|
||||||
using System.Net;
|
|
||||||
|
|
||||||
namespace Shadowsocks.Controller
|
namespace Shadowsocks.Controller
|
||||||
{
|
{
|
||||||
@@ -15,7 +13,6 @@ namespace Shadowsocks.Controller
|
|||||||
{
|
{
|
||||||
private Process _process;
|
private Process _process;
|
||||||
private static string temppath;
|
private static string temppath;
|
||||||
private int _runningPort;
|
|
||||||
|
|
||||||
static PolipoRunner()
|
static PolipoRunner()
|
||||||
{
|
{
|
||||||
@@ -30,14 +27,6 @@ namespace Shadowsocks.Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int RunningPort
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return _runningPort;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Start(Configuration configuration)
|
public void Start(Configuration configuration)
|
||||||
{
|
{
|
||||||
Server server = configuration.GetCurrentServer();
|
Server server = configuration.GetCurrentServer();
|
||||||
@@ -57,9 +46,7 @@ namespace Shadowsocks.Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
string polipoConfig = Resources.polipo_config;
|
string polipoConfig = Resources.polipo_config;
|
||||||
_runningPort = this.GetFreePort();
|
polipoConfig = polipoConfig.Replace("__SOCKS_PORT__", server.local_port.ToString());
|
||||||
polipoConfig = polipoConfig.Replace("__SOCKS_PORT__", configuration.localPort.ToString());
|
|
||||||
polipoConfig = polipoConfig.Replace("__POLIPO_BIND_PORT__", _runningPort.ToString());
|
|
||||||
polipoConfig = polipoConfig.Replace("__POLIPO_BIND_IP__", configuration.shareOverLan ? "0.0.0.0" : "127.0.0.1");
|
polipoConfig = polipoConfig.Replace("__POLIPO_BIND_IP__", configuration.shareOverLan ? "0.0.0.0" : "127.0.0.1");
|
||||||
FileManager.ByteArrayToFile(temppath + "/polipo.conf", System.Text.Encoding.UTF8.GetBytes(polipoConfig));
|
FileManager.ByteArrayToFile(temppath + "/polipo.conf", System.Text.Encoding.UTF8.GetBytes(polipoConfig));
|
||||||
|
|
||||||
@@ -92,35 +79,5 @@ namespace Shadowsocks.Controller
|
|||||||
_process = null;
|
_process = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int GetFreePort()
|
|
||||||
{
|
|
||||||
int defaultPort = 8123;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
|
|
||||||
IPEndPoint[] tcpEndPoints = properties.GetActiveTcpListeners();
|
|
||||||
|
|
||||||
List<int> usedPorts = new List<int>();
|
|
||||||
foreach (IPEndPoint endPoint in IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners())
|
|
||||||
{
|
|
||||||
usedPorts.Add(endPoint.Port);
|
|
||||||
}
|
|
||||||
for (int port = defaultPort; port <= 65535; port++)
|
|
||||||
{
|
|
||||||
if (!usedPorts.Contains(port))
|
|
||||||
{
|
|
||||||
return port;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
// in case access denied
|
|
||||||
Logging.LogUsefulException(e);
|
|
||||||
return defaultPort;
|
|
||||||
}
|
|
||||||
throw new Exception("No free port found.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,264 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Net;
|
|
||||||
using System.Net.Sockets;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Shadowsocks.Controller
|
|
||||||
{
|
|
||||||
class PortForwarder : Listener.Service
|
|
||||||
{
|
|
||||||
int _targetPort;
|
|
||||||
|
|
||||||
public PortForwarder(int targetPort)
|
|
||||||
{
|
|
||||||
this._targetPort = targetPort;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Handle(byte[] firstPacket, int length, Socket socket)
|
|
||||||
{
|
|
||||||
new Handler().Start(firstPacket, length, socket, this._targetPort);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
class Handler
|
|
||||||
{
|
|
||||||
private byte[] _firstPacket;
|
|
||||||
private int _firstPacketLength;
|
|
||||||
private Socket _local;
|
|
||||||
private Socket _remote;
|
|
||||||
private bool _closed = false;
|
|
||||||
private bool _localShutdown = false;
|
|
||||||
private bool _remoteShutdown = false;
|
|
||||||
public const int RecvSize = 16384;
|
|
||||||
// remote receive buffer
|
|
||||||
private byte[] remoteRecvBuffer = new byte[RecvSize];
|
|
||||||
// connection receive buffer
|
|
||||||
private byte[] connetionRecvBuffer = new byte[RecvSize];
|
|
||||||
|
|
||||||
public void Start(byte[] firstPacket, int length, Socket socket, int targetPort)
|
|
||||||
{
|
|
||||||
this._firstPacket = firstPacket;
|
|
||||||
this._firstPacketLength = length;
|
|
||||||
this._local = socket;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// TODO async resolving
|
|
||||||
IPAddress ipAddress;
|
|
||||||
bool parsed = IPAddress.TryParse("127.0.0.1", out ipAddress);
|
|
||||||
IPEndPoint remoteEP = new IPEndPoint(ipAddress, targetPort);
|
|
||||||
|
|
||||||
|
|
||||||
_remote = new Socket(ipAddress.AddressFamily,
|
|
||||||
SocketType.Stream, ProtocolType.Tcp);
|
|
||||||
_remote.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true);
|
|
||||||
|
|
||||||
// Connect to the remote endpoint.
|
|
||||||
_remote.BeginConnect(remoteEP,
|
|
||||||
new AsyncCallback(ConnectCallback), null);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Logging.LogUsefulException(e);
|
|
||||||
this.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ConnectCallback(IAsyncResult ar)
|
|
||||||
{
|
|
||||||
if (_closed)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_remote.EndConnect(ar);
|
|
||||||
HandshakeReceive();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Logging.LogUsefulException(e);
|
|
||||||
this.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void HandshakeReceive()
|
|
||||||
{
|
|
||||||
if (_closed)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_remote.BeginSend(_firstPacket, 0, _firstPacketLength, 0, new AsyncCallback(StartPipe), null);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Logging.LogUsefulException(e);
|
|
||||||
this.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void StartPipe(IAsyncResult ar)
|
|
||||||
{
|
|
||||||
if (_closed)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_remote.EndSend(ar);
|
|
||||||
_remote.BeginReceive(remoteRecvBuffer, 0, RecvSize, 0,
|
|
||||||
new AsyncCallback(PipeRemoteReceiveCallback), null);
|
|
||||||
_local.BeginReceive(connetionRecvBuffer, 0, RecvSize, 0,
|
|
||||||
new AsyncCallback(PipeConnectionReceiveCallback), null);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Logging.LogUsefulException(e);
|
|
||||||
this.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void PipeRemoteReceiveCallback(IAsyncResult ar)
|
|
||||||
{
|
|
||||||
if (_closed)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
int bytesRead = _remote.EndReceive(ar);
|
|
||||||
|
|
||||||
if (bytesRead > 0)
|
|
||||||
{
|
|
||||||
_local.BeginSend(remoteRecvBuffer, 0, bytesRead, 0, new AsyncCallback(PipeConnectionSendCallback), null);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//Console.WriteLine("bytesRead: " + bytesRead.ToString());
|
|
||||||
_local.Shutdown(SocketShutdown.Send);
|
|
||||||
_localShutdown = true;
|
|
||||||
CheckClose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Logging.LogUsefulException(e);
|
|
||||||
this.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void PipeConnectionReceiveCallback(IAsyncResult ar)
|
|
||||||
{
|
|
||||||
if (_closed)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
int bytesRead = _local.EndReceive(ar);
|
|
||||||
|
|
||||||
if (bytesRead > 0)
|
|
||||||
{
|
|
||||||
_remote.BeginSend(connetionRecvBuffer, 0, bytesRead, 0, new AsyncCallback(PipeRemoteSendCallback), null);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_remote.Shutdown(SocketShutdown.Send);
|
|
||||||
_remoteShutdown = true;
|
|
||||||
CheckClose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Logging.LogUsefulException(e);
|
|
||||||
this.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void PipeRemoteSendCallback(IAsyncResult ar)
|
|
||||||
{
|
|
||||||
if (_closed)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_remote.EndSend(ar);
|
|
||||||
_local.BeginReceive(this.connetionRecvBuffer, 0, RecvSize, 0,
|
|
||||||
new AsyncCallback(PipeConnectionReceiveCallback), null);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Logging.LogUsefulException(e);
|
|
||||||
this.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void PipeConnectionSendCallback(IAsyncResult ar)
|
|
||||||
{
|
|
||||||
if (_closed)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_local.EndSend(ar);
|
|
||||||
_remote.BeginReceive(this.remoteRecvBuffer, 0, RecvSize, 0,
|
|
||||||
new AsyncCallback(PipeRemoteReceiveCallback), null);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Logging.LogUsefulException(e);
|
|
||||||
this.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CheckClose()
|
|
||||||
{
|
|
||||||
if (_localShutdown && _remoteShutdown)
|
|
||||||
{
|
|
||||||
this.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Close()
|
|
||||||
{
|
|
||||||
lock (this)
|
|
||||||
{
|
|
||||||
if (_closed)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_closed = true;
|
|
||||||
}
|
|
||||||
if (_local != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_local.Shutdown(SocketShutdown.Both);
|
|
||||||
_local.Close();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Logging.LogUsefulException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (_remote != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_remote.Shutdown(SocketShutdown.Both);
|
|
||||||
_remote.Close();
|
|
||||||
}
|
|
||||||
catch (SocketException e)
|
|
||||||
{
|
|
||||||
Logging.LogUsefulException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -17,8 +17,8 @@ namespace Shadowsocks.Controller
|
|||||||
|
|
||||||
private Thread _ramThread;
|
private Thread _ramThread;
|
||||||
|
|
||||||
private Listener _listener;
|
private Local local;
|
||||||
private PACServer _pacServer;
|
private PACServer pacServer;
|
||||||
private Configuration _config;
|
private Configuration _config;
|
||||||
private PolipoRunner polipoRunner;
|
private PolipoRunner polipoRunner;
|
||||||
private GFWListUpdater gfwListUpdater;
|
private GFWListUpdater gfwListUpdater;
|
||||||
@@ -38,9 +38,8 @@ namespace Shadowsocks.Controller
|
|||||||
|
|
||||||
// when user clicked Edit PAC, and PAC file has already created
|
// when user clicked Edit PAC, and PAC file has already created
|
||||||
public event EventHandler<PathEventArgs> PACFileReadyToOpen;
|
public event EventHandler<PathEventArgs> PACFileReadyToOpen;
|
||||||
public event EventHandler<PathEventArgs> UserRuleFileReadyToOpen;
|
|
||||||
|
|
||||||
public event EventHandler<GFWListUpdater.ResultEventArgs> UpdatePACFromGFWListCompleted;
|
public event EventHandler UpdatePACFromGFWListCompleted;
|
||||||
|
|
||||||
public event ErrorEventHandler UpdatePACFromGFWListError;
|
public event ErrorEventHandler UpdatePACFromGFWListError;
|
||||||
|
|
||||||
@@ -75,10 +74,9 @@ namespace Shadowsocks.Controller
|
|||||||
return Configuration.Load();
|
return Configuration.Load();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveServers(List<Server> servers, int localPort)
|
public void SaveServers(List<Server> servers)
|
||||||
{
|
{
|
||||||
_config.configs = servers;
|
_config.configs = servers;
|
||||||
_config.localPort = localPort;
|
|
||||||
SaveConfig(_config);
|
SaveConfig(_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,14 +137,15 @@ namespace Shadowsocks.Controller
|
|||||||
|
|
||||||
public void Stop()
|
public void Stop()
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("Stop");
|
||||||
if (stopped)
|
if (stopped)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
stopped = true;
|
stopped = true;
|
||||||
if (_listener != null)
|
if (local != null)
|
||||||
{
|
{
|
||||||
_listener.Stop();
|
local.Stop();
|
||||||
}
|
}
|
||||||
if (polipoRunner != null)
|
if (polipoRunner != null)
|
||||||
{
|
{
|
||||||
@@ -154,28 +153,19 @@ namespace Shadowsocks.Controller
|
|||||||
}
|
}
|
||||||
if (_config.enabled)
|
if (_config.enabled)
|
||||||
{
|
{
|
||||||
SystemProxy.Update(_config, true);
|
SystemProxy.Disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TouchPACFile()
|
public void TouchPACFile()
|
||||||
{
|
{
|
||||||
string pacFilename = _pacServer.TouchPACFile();
|
string pacFilename = pacServer.TouchPACFile();
|
||||||
if (PACFileReadyToOpen != null)
|
if (PACFileReadyToOpen != null)
|
||||||
{
|
{
|
||||||
PACFileReadyToOpen(this, new PathEventArgs() { Path = pacFilename });
|
PACFileReadyToOpen(this, new PathEventArgs() { Path = pacFilename });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TouchUserRuleFile()
|
|
||||||
{
|
|
||||||
string userRuleFilename = _pacServer.TouchUserRuleFile();
|
|
||||||
if (UserRuleFileReadyToOpen != null)
|
|
||||||
{
|
|
||||||
UserRuleFileReadyToOpen(this, new PathEventArgs() { Path = userRuleFilename });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string GetQRCodeForCurrentServer()
|
public string GetQRCodeForCurrentServer()
|
||||||
{
|
{
|
||||||
Server server = GetCurrentServer();
|
Server server = GetCurrentServer();
|
||||||
@@ -188,12 +178,13 @@ namespace Shadowsocks.Controller
|
|||||||
{
|
{
|
||||||
if (gfwListUpdater != null)
|
if (gfwListUpdater != null)
|
||||||
{
|
{
|
||||||
gfwListUpdater.UpdatePACFromGFWList(_config);
|
gfwListUpdater.UpdatePACFromGFWList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void Reload()
|
protected void Reload()
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("Reload");
|
||||||
// some logic in configuration updated the config when saving, we need to read it again
|
// some logic in configuration updated the config when saving, we need to read it again
|
||||||
_config = Configuration.Load();
|
_config = Configuration.Load();
|
||||||
|
|
||||||
@@ -201,12 +192,11 @@ namespace Shadowsocks.Controller
|
|||||||
{
|
{
|
||||||
polipoRunner = new PolipoRunner();
|
polipoRunner = new PolipoRunner();
|
||||||
}
|
}
|
||||||
if (_pacServer == null)
|
if (pacServer == null)
|
||||||
{
|
{
|
||||||
_pacServer = new PACServer();
|
pacServer = new PACServer();
|
||||||
_pacServer.PACFileChanged += pacServer_PACFileChanged;
|
pacServer.PACFileChanged += pacServer_PACFileChanged;
|
||||||
}
|
}
|
||||||
_pacServer.UpdateConfiguration(_config);
|
|
||||||
if (gfwListUpdater == null)
|
if (gfwListUpdater == null)
|
||||||
{
|
{
|
||||||
gfwListUpdater = new GFWListUpdater();
|
gfwListUpdater = new GFWListUpdater();
|
||||||
@@ -214,9 +204,11 @@ namespace Shadowsocks.Controller
|
|||||||
gfwListUpdater.Error += pacServer_PACUpdateError;
|
gfwListUpdater.Error += pacServer_PACUpdateError;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_listener != null)
|
pacServer.Stop();
|
||||||
|
|
||||||
|
if (local != null)
|
||||||
{
|
{
|
||||||
_listener.Stop();
|
local.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't put polipoRunner.Start() before pacServer.Stop()
|
// don't put polipoRunner.Start() before pacServer.Stop()
|
||||||
@@ -228,13 +220,9 @@ namespace Shadowsocks.Controller
|
|||||||
{
|
{
|
||||||
polipoRunner.Start(_config);
|
polipoRunner.Start(_config);
|
||||||
|
|
||||||
Local local = new Local(_config);
|
local = new Local(_config);
|
||||||
List<Listener.Service> services = new List<Listener.Service>();
|
local.Start();
|
||||||
services.Add(local);
|
pacServer.Start(_config);
|
||||||
services.Add(_pacServer);
|
|
||||||
services.Add(new PortForwarder(polipoRunner.RunningPort));
|
|
||||||
_listener = new Listener(services);
|
|
||||||
_listener.Start(_config);
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -271,9 +259,10 @@ namespace Shadowsocks.Controller
|
|||||||
|
|
||||||
private void UpdateSystemProxy()
|
private void UpdateSystemProxy()
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("UpdateSystemProxy");
|
||||||
if (_config.enabled)
|
if (_config.enabled)
|
||||||
{
|
{
|
||||||
SystemProxy.Update(_config, false);
|
SystemProxy.Enable(_config.global);
|
||||||
_systemProxyIsDirty = true;
|
_systemProxyIsDirty = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -281,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.Update(_config, false);
|
SystemProxy.Disable();
|
||||||
_systemProxyIsDirty = false;
|
_systemProxyIsDirty = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -292,7 +281,7 @@ namespace Shadowsocks.Controller
|
|||||||
UpdateSystemProxy();
|
UpdateSystemProxy();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pacServer_PACUpdateCompleted(object sender, GFWListUpdater.ResultEventArgs e)
|
private void pacServer_PACUpdateCompleted(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (UpdatePACFromGFWListCompleted != null)
|
if (UpdatePACFromGFWListCompleted != null)
|
||||||
UpdatePACFromGFWListCompleted(this, e);
|
UpdatePACFromGFWListCompleted(this, e);
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ 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
|
||||||
{
|
{
|
||||||
@@ -26,39 +25,24 @@ 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 Update(Configuration config, bool forceDisable)
|
public static void Enable(bool global)
|
||||||
{
|
{
|
||||||
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 (enabled)
|
|
||||||
{
|
|
||||||
if (global)
|
if (global)
|
||||||
{
|
{
|
||||||
registry.SetValue("ProxyEnable", 1);
|
registry.SetValue("ProxyEnable", 1);
|
||||||
registry.SetValue("ProxyServer", "127.0.0.1:" + config.localPort.ToString());
|
registry.SetValue("ProxyServer", "127.0.0.1:8123");
|
||||||
registry.SetValue("AutoConfigURL", "");
|
registry.SetValue("AutoConfigURL", "");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
registry.SetValue("ProxyEnable", 0);
|
registry.SetValue("ProxyEnable", 0);
|
||||||
registry.SetValue("ProxyServer", "");
|
registry.SetValue("ProxyServer", "");
|
||||||
registry.SetValue("AutoConfigURL", "http://127.0.0.1:" + config.localPort.ToString() + "/pac?t=" + GetTimestamp(DateTime.Now));
|
registry.SetValue("AutoConfigURL", "http://127.0.0.1:8093/pac?t=" + GetTimestamp(DateTime.Now));
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
registry.SetValue("ProxyEnable", 0);
|
|
||||||
registry.SetValue("ProxyServer", "");
|
|
||||||
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
|
||||||
@@ -72,6 +56,32 @@ namespace Shadowsocks.Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void Disable()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.WriteLine("Disable");
|
||||||
|
RegistryKey registry =
|
||||||
|
Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
|
||||||
|
true);
|
||||||
|
Console.WriteLine("Disable1");
|
||||||
|
registry.SetValue("ProxyEnable", 0);
|
||||||
|
registry.SetValue("ProxyServer", "");
|
||||||
|
registry.SetValue("AutoConfigURL", "");
|
||||||
|
Console.WriteLine("Disable2");
|
||||||
|
SystemProxy.NotifyIE();
|
||||||
|
Console.WriteLine("Disable3");
|
||||||
|
CopyProxySettingFromLan();
|
||||||
|
Console.WriteLine("Disable4");
|
||||||
|
}
|
||||||
|
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 =
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Shadowsocks.Model;
|
using System;
|
||||||
using System;
|
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
@@ -18,13 +17,13 @@ namespace Shadowsocks.Controller
|
|||||||
public string LatestVersionURL;
|
public string LatestVersionURL;
|
||||||
public event EventHandler NewVersionFound;
|
public event EventHandler NewVersionFound;
|
||||||
|
|
||||||
public const string Version = "2.3.1";
|
public const string Version = "2.2";
|
||||||
|
|
||||||
public void CheckUpdate(Configuration config)
|
public void CheckUpdate()
|
||||||
{
|
{
|
||||||
// TODO test failures
|
// TODO test failures
|
||||||
WebClient http = new WebClient();
|
WebClient http = new WebClient();
|
||||||
http.Proxy = new WebProxy(IPAddress.Loopback.ToString(), config.localPort);
|
http.Proxy = new WebProxy(IPAddress.Loopback.ToString(), 8123);
|
||||||
http.DownloadStringCompleted += http_DownloadStringCompleted;
|
http.DownloadStringCompleted += http_DownloadStringCompleted;
|
||||||
http.DownloadStringAsync(new Uri(UpdateURL));
|
http.DownloadStringAsync(new Uri(UpdateURL));
|
||||||
}
|
}
|
||||||
@@ -75,10 +74,6 @@ namespace Shadowsocks.Controller
|
|||||||
|
|
||||||
private bool IsNewVersion(string url)
|
private bool IsNewVersion(string url)
|
||||||
{
|
{
|
||||||
if (url.IndexOf("prerelease") >= 0)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// check dotnet 4.0
|
// check dotnet 4.0
|
||||||
AssemblyName[] references = Assembly.GetExecutingAssembly().GetReferencedAssemblies();
|
AssemblyName[] references = Assembly.GetExecutingAssembly().GetReferencedAssemblies();
|
||||||
Version dotNetVersion = Environment.Version;
|
Version dotNetVersion = Environment.Version;
|
||||||
|
|||||||
Binary file not shown.
@@ -1,28 +1,19 @@
|
|||||||
# translation for Simplified Chinese
|
|
||||||
|
|
||||||
Shadowsocks=Shadowsocks
|
Shadowsocks=Shadowsocks
|
||||||
|
Enable=启用代理
|
||||||
# Menu items
|
Mode=代理模式
|
||||||
|
|
||||||
Enable System Proxy=启用系统代理
|
|
||||||
Mode=系统代理模式
|
|
||||||
PAC=PAC 模式
|
PAC=PAC 模式
|
||||||
Global=全局模式
|
Global=全局模式
|
||||||
Servers=服务器
|
Servers=服务器
|
||||||
Edit Servers...=编辑服务器...
|
Edit Servers...=编辑服务器...
|
||||||
Start on Boot=开机启动
|
Start on Boot=开机启动
|
||||||
Allow Clients from LAN=允许来自局域网的连接
|
Share over LAN=在局域网共享代理
|
||||||
Edit PAC File...=编辑 PAC 文件...
|
Edit PAC File...=编辑 PAC 文件...
|
||||||
Edit User Rule for GFWList...=编辑 GFWList 的用户规则...
|
|
||||||
Show QRCode...=显示二维码...
|
Show QRCode...=显示二维码...
|
||||||
Scan QRCode from Screen...=扫描屏幕上的二维码...
|
Scan QRCode from Screen...=扫描屏幕上的二维码...
|
||||||
Show Logs...=显示日志...
|
Show Logs...=显示日志...
|
||||||
About...=关于...
|
About...=关于...
|
||||||
Quit=退出
|
Quit=退出
|
||||||
Edit Servers=编辑服务器
|
Edit Servers=编辑服务器
|
||||||
|
|
||||||
# Config Form
|
|
||||||
|
|
||||||
&Add=添加(&A)
|
&Add=添加(&A)
|
||||||
&Delete=删除(&D)
|
&Delete=删除(&D)
|
||||||
Server=服务器
|
Server=服务器
|
||||||
@@ -35,13 +26,7 @@ Remarks=备注
|
|||||||
OK=确定
|
OK=确定
|
||||||
Cancel=取消
|
Cancel=取消
|
||||||
New server=未配置的服务器
|
New server=未配置的服务器
|
||||||
|
|
||||||
# QRCode Form
|
|
||||||
|
|
||||||
QRCode=二维码
|
QRCode=二维码
|
||||||
|
|
||||||
# Messages
|
|
||||||
|
|
||||||
Shadowsocks Error: {0}=Shadowsocks 错误: {0}
|
Shadowsocks Error: {0}=Shadowsocks 错误: {0}
|
||||||
Port already in use=端口已被占用
|
Port already in use=端口已被占用
|
||||||
Illegal port number format=非法端口格式
|
Illegal port number format=非法端口格式
|
||||||
@@ -53,14 +38,11 @@ Shadowsocks {0} Update Found=Shadowsocks {0} 更新
|
|||||||
Click here to download=点击这里下载
|
Click here to download=点击这里下载
|
||||||
Shadowsocks is here=Shadowsocks 在这里
|
Shadowsocks is here=Shadowsocks 在这里
|
||||||
You can turn on/off Shadowsocks in the context menu=可以在右键菜单中开关 Shadowsocks
|
You can turn on/off Shadowsocks in the context menu=可以在右键菜单中开关 Shadowsocks
|
||||||
System Proxy Enabled=系统代理已启用
|
Enabled=已启用代理
|
||||||
System Proxy Disabled=系统代理未启用
|
Disabled=已禁用代理
|
||||||
Update PAC from GFWList=从 GFWList 更新 PAC
|
Update PAC from GFWList=从 GFWList 更新 PAC
|
||||||
Failed to update PAC file =更新 PAC 文件失败
|
Failed to update PAC file =更新 PAC 文件失败
|
||||||
PAC updated=更新 PAC 成功
|
PAC updated=更新 PAC 成功
|
||||||
No updates found. Please report to GFWList if you have problems with it.=未发现更新。如有问题请提交给 GFWList。
|
No QRCode found. Try to zoom in or move it to the center of the screen.=找不到二维码,尝试把它放大或者移动到靠近屏幕中间的位置
|
||||||
No QRCode found. Try to zoom in or move it to the center of the screen.=未发现二维码,尝试把它放大或移动到靠近屏幕中间的位置
|
|
||||||
Failed to decode QRCode=无法解析二维码
|
Failed to decode QRCode=无法解析二维码
|
||||||
Failed to update registry=无法修改注册表
|
Failed to update registry=无法修改注册表
|
||||||
System Proxy On: =系统代理已启用:
|
|
||||||
Running: Port {0}=正在运行:端口 {0}
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
proxyAddress = "__POLIPO_BIND_IP__"
|
proxyAddress = "__POLIPO_BIND_IP__"
|
||||||
proxyPort = 8123
|
|
||||||
|
|
||||||
socksParentProxy = "127.0.0.1:__SOCKS_PORT__"
|
socksParentProxy = "127.0.0.1:__SOCKS_PORT__"
|
||||||
socksProxyType = socks5
|
socksProxyType = socks5
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
! Put user rules line by line in this file.
|
|
||||||
! See https://adblockplus.org/en/filter-cheatsheet
|
|
||||||
@@ -16,7 +16,6 @@ namespace Shadowsocks.Model
|
|||||||
public bool enabled;
|
public bool enabled;
|
||||||
public bool shareOverLan;
|
public bool shareOverLan;
|
||||||
public bool isDefault;
|
public bool isDefault;
|
||||||
public int localPort;
|
|
||||||
|
|
||||||
private static string CONFIG_FILE = "gui-config.json";
|
private static string CONFIG_FILE = "gui-config.json";
|
||||||
|
|
||||||
@@ -34,6 +33,7 @@ namespace Shadowsocks.Model
|
|||||||
|
|
||||||
public static void CheckServer(Server server)
|
public static void CheckServer(Server server)
|
||||||
{
|
{
|
||||||
|
CheckPort(server.local_port);
|
||||||
CheckPort(server.server_port);
|
CheckPort(server.server_port);
|
||||||
CheckPassword(server.password);
|
CheckPassword(server.password);
|
||||||
CheckServer(server.server);
|
CheckServer(server.server);
|
||||||
@@ -46,10 +46,6 @@ namespace Shadowsocks.Model
|
|||||||
string configContent = File.ReadAllText(CONFIG_FILE);
|
string configContent = File.ReadAllText(CONFIG_FILE);
|
||||||
Configuration config = SimpleJson.SimpleJson.DeserializeObject<Configuration>(configContent, new JsonSerializerStrategy());
|
Configuration config = SimpleJson.SimpleJson.DeserializeObject<Configuration>(configContent, new JsonSerializerStrategy());
|
||||||
config.isDefault = false;
|
config.isDefault = false;
|
||||||
if (config.localPort == 0)
|
|
||||||
{
|
|
||||||
config.localPort = 1080;
|
|
||||||
}
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -62,7 +58,6 @@ namespace Shadowsocks.Model
|
|||||||
{
|
{
|
||||||
index = 0,
|
index = 0,
|
||||||
isDefault = true,
|
isDefault = true,
|
||||||
localPort = 1080,
|
|
||||||
configs = new List<Server>()
|
configs = new List<Server>()
|
||||||
{
|
{
|
||||||
GetDefaultServer()
|
GetDefaultServer()
|
||||||
@@ -110,7 +105,7 @@ namespace Shadowsocks.Model
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CheckPort(int port)
|
private static void CheckPort(int port)
|
||||||
{
|
{
|
||||||
if (port <= 0 || port > 65535)
|
if (port <= 0 || port > 65535)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@@ -14,6 +14,7 @@ namespace Shadowsocks.Model
|
|||||||
{
|
{
|
||||||
public string server;
|
public string server;
|
||||||
public int server_port;
|
public int server_port;
|
||||||
|
public int local_port;
|
||||||
public string password;
|
public string password;
|
||||||
public string method;
|
public string method;
|
||||||
public string remarks;
|
public string remarks;
|
||||||
@@ -38,6 +39,7 @@ namespace Shadowsocks.Model
|
|||||||
{
|
{
|
||||||
this.server = "";
|
this.server = "";
|
||||||
this.server_port = 8388;
|
this.server_port = 8388;
|
||||||
|
this.local_port = 1080;
|
||||||
this.method = "aes-256-cfb";
|
this.method = "aes-256-cfb";
|
||||||
this.password = "";
|
this.password = "";
|
||||||
this.remarks = "";
|
this.remarks = "";
|
||||||
@@ -48,8 +50,7 @@ namespace Shadowsocks.Model
|
|||||||
string[] r1 = Regex.Split(ssURL, "ss://", RegexOptions.IgnoreCase);
|
string[] r1 = Regex.Split(ssURL, "ss://", RegexOptions.IgnoreCase);
|
||||||
string base64 = r1[1].ToString();
|
string base64 = r1[1].ToString();
|
||||||
byte[] bytes = null;
|
byte[] bytes = null;
|
||||||
for (var i = 0; i < 3; i++)
|
for (var i = 0; i < 3; i++) {
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
bytes = System.Convert.FromBase64String(base64);
|
bytes = System.Convert.FromBase64String(base64);
|
||||||
@@ -63,25 +64,11 @@ namespace Shadowsocks.Model
|
|||||||
{
|
{
|
||||||
throw new FormatException();
|
throw new FormatException();
|
||||||
}
|
}
|
||||||
try
|
string[] parts = Encoding.UTF8.GetString(bytes).Split(new char[2] { ':', '@' });
|
||||||
{
|
this.method = parts[0].ToString();
|
||||||
string data = Encoding.UTF8.GetString(bytes);
|
this.password = parts[1].ToString();
|
||||||
int indexLastAt = data.LastIndexOf('@');
|
this.server = parts[2].ToString();
|
||||||
|
this.server_port = int.Parse(parts[3].ToString());
|
||||||
string afterAt = data.Substring(indexLastAt + 1);
|
|
||||||
int indexLastColon = afterAt.LastIndexOf(':');
|
|
||||||
this.server_port = int.Parse(afterAt.Substring(indexLastColon + 1));
|
|
||||||
this.server = afterAt.Substring(0, indexLastColon);
|
|
||||||
|
|
||||||
string beforeAt = data.Substring(0, indexLastAt);
|
|
||||||
string[] parts = beforeAt.Split(new[] { ':' });
|
|
||||||
this.method = parts[0];
|
|
||||||
this.password = parts[1];
|
|
||||||
}
|
|
||||||
catch (IndexOutOfRangeException)
|
|
||||||
{
|
|
||||||
throw new FormatException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-18
@@ -1,7 +1,7 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// <auto-generated>
|
// <auto-generated>
|
||||||
// This code was generated by a tool.
|
// This code was generated by a tool.
|
||||||
// Runtime Version:4.0.30319.34209
|
// Runtime Version:4.0.30319.18444
|
||||||
//
|
//
|
||||||
// Changes to this file may cause incorrect behavior and will be lost if
|
// Changes to this file may cause incorrect behavior and will be lost if
|
||||||
// the code is regenerated.
|
// the code is regenerated.
|
||||||
@@ -72,16 +72,15 @@ namespace Shadowsocks.Properties {
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Shadowsocks=Shadowsocks
|
/// Looks up a localized string similar to Shadowsocks=Shadowsocks
|
||||||
///Enable System Proxy=启用系统代理
|
///Enable=启用代理
|
||||||
///Mode=系统代理模式
|
///Mode=代理模式
|
||||||
///PAC=PAC 模式
|
///PAC=PAC 模式
|
||||||
///Global=全局模式
|
///Global=全局模式
|
||||||
///Servers=服务器
|
///Servers=服务器
|
||||||
///Edit Servers...=编辑服务器...
|
///Edit Servers...=编辑服务器...
|
||||||
///Start on Boot=开机启动
|
///Start on Boot=开机启动
|
||||||
///Allow Clients from LAN=允许来自局域网的连接
|
///Share over LAN=在局域网共享代理
|
||||||
///Edit PAC File...=编辑 PAC 文件...
|
///Edit PAC File...=编辑 PAC 文件...
|
||||||
///Edit User Rule for GFWList...=编辑 GFWList 的用户规则...
|
|
||||||
///Show QRCode...=显示二维码...
|
///Show QRCode...=显示二维码...
|
||||||
///Scan QRCode from Screen...=扫描屏幕上的二维码...
|
///Scan QRCode from Screen...=扫描屏幕上的二维码...
|
||||||
///Show Logs...=显示日志...
|
///Show Logs...=显示日志...
|
||||||
@@ -97,7 +96,11 @@ namespace Shadowsocks.Properties {
|
|||||||
///Encryption=加密
|
///Encryption=加密
|
||||||
///Proxy Port=代理端口
|
///Proxy Port=代理端口
|
||||||
///Remarks=备注
|
///Remarks=备注
|
||||||
///OK= [rest of string was truncated]";.
|
///OK=确定
|
||||||
|
///Cancel=取消
|
||||||
|
///New server=未配置的服务器
|
||||||
|
///QRCode=二维码
|
||||||
|
///Shadowsocks Error: {0}=Shadowsocks [rest of string was truncated]";.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static string cn {
|
internal static string cn {
|
||||||
get {
|
get {
|
||||||
@@ -117,7 +120,6 @@ namespace Shadowsocks.Properties {
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to proxyAddress = "__POLIPO_BIND_IP__"
|
/// Looks up a localized string similar to proxyAddress = "__POLIPO_BIND_IP__"
|
||||||
///proxyPort = 8123
|
|
||||||
///
|
///
|
||||||
///socksParentProxy = "127.0.0.1:__SOCKS_PORT__"
|
///socksParentProxy = "127.0.0.1:__SOCKS_PORT__"
|
||||||
///socksProxyType = socks5
|
///socksProxyType = socks5
|
||||||
@@ -192,16 +194,5 @@ namespace Shadowsocks.Properties {
|
|||||||
return ((System.Drawing.Bitmap)(obj));
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Looks up a localized string similar to ! Put user rules line by line in this file.
|
|
||||||
///! See https://adblockplus.org/en/filter-cheatsheet
|
|
||||||
///.
|
|
||||||
/// </summary>
|
|
||||||
internal static string user_rule {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("user_rule", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,7 +148,4 @@
|
|||||||
<data name="ssw128" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
<data name="ssw128" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
<value>..\Resources\ssw128.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
<value>..\Resources\ssw128.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="user_rule" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
|
||||||
<value>..\data\user-rule.txt;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
|
|
||||||
</data>
|
|
||||||
</root>
|
</root>
|
||||||
+33
-61
@@ -33,6 +33,8 @@
|
|||||||
this.RemarksLabel = new System.Windows.Forms.Label();
|
this.RemarksLabel = new System.Windows.Forms.Label();
|
||||||
this.IPLabel = new System.Windows.Forms.Label();
|
this.IPLabel = new System.Windows.Forms.Label();
|
||||||
this.ServerPortLabel = new System.Windows.Forms.Label();
|
this.ServerPortLabel = new System.Windows.Forms.Label();
|
||||||
|
this.ProxyPortTextBox = new System.Windows.Forms.TextBox();
|
||||||
|
this.ProxyPortLabel = new System.Windows.Forms.Label();
|
||||||
this.PasswordLabel = new System.Windows.Forms.Label();
|
this.PasswordLabel = new System.Windows.Forms.Label();
|
||||||
this.IPTextBox = new System.Windows.Forms.TextBox();
|
this.IPTextBox = new System.Windows.Forms.TextBox();
|
||||||
this.ServerPortTextBox = new System.Windows.Forms.TextBox();
|
this.ServerPortTextBox = new System.Windows.Forms.TextBox();
|
||||||
@@ -47,15 +49,11 @@
|
|||||||
this.ServerGroupBox = new System.Windows.Forms.GroupBox();
|
this.ServerGroupBox = new System.Windows.Forms.GroupBox();
|
||||||
this.ServersListBox = new System.Windows.Forms.ListBox();
|
this.ServersListBox = new System.Windows.Forms.ListBox();
|
||||||
this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel();
|
this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel();
|
||||||
this.tableLayoutPanel5 = new System.Windows.Forms.TableLayoutPanel();
|
|
||||||
this.ProxyPortTextBox = new System.Windows.Forms.TextBox();
|
|
||||||
this.ProxyPortLabel = new System.Windows.Forms.Label();
|
|
||||||
this.tableLayoutPanel3 = new System.Windows.Forms.TableLayoutPanel();
|
this.tableLayoutPanel3 = new System.Windows.Forms.TableLayoutPanel();
|
||||||
this.tableLayoutPanel4 = new System.Windows.Forms.TableLayoutPanel();
|
this.tableLayoutPanel4 = new System.Windows.Forms.TableLayoutPanel();
|
||||||
this.tableLayoutPanel1.SuspendLayout();
|
this.tableLayoutPanel1.SuspendLayout();
|
||||||
this.ServerGroupBox.SuspendLayout();
|
this.ServerGroupBox.SuspendLayout();
|
||||||
this.tableLayoutPanel2.SuspendLayout();
|
this.tableLayoutPanel2.SuspendLayout();
|
||||||
this.tableLayoutPanel5.SuspendLayout();
|
|
||||||
this.tableLayoutPanel3.SuspendLayout();
|
this.tableLayoutPanel3.SuspendLayout();
|
||||||
this.tableLayoutPanel4.SuspendLayout();
|
this.tableLayoutPanel4.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
@@ -71,6 +69,8 @@
|
|||||||
this.tableLayoutPanel1.Controls.Add(this.RemarksLabel, 0, 5);
|
this.tableLayoutPanel1.Controls.Add(this.RemarksLabel, 0, 5);
|
||||||
this.tableLayoutPanel1.Controls.Add(this.IPLabel, 0, 0);
|
this.tableLayoutPanel1.Controls.Add(this.IPLabel, 0, 0);
|
||||||
this.tableLayoutPanel1.Controls.Add(this.ServerPortLabel, 0, 1);
|
this.tableLayoutPanel1.Controls.Add(this.ServerPortLabel, 0, 1);
|
||||||
|
this.tableLayoutPanel1.Controls.Add(this.ProxyPortTextBox, 1, 4);
|
||||||
|
this.tableLayoutPanel1.Controls.Add(this.ProxyPortLabel, 0, 4);
|
||||||
this.tableLayoutPanel1.Controls.Add(this.PasswordLabel, 0, 2);
|
this.tableLayoutPanel1.Controls.Add(this.PasswordLabel, 0, 2);
|
||||||
this.tableLayoutPanel1.Controls.Add(this.IPTextBox, 1, 0);
|
this.tableLayoutPanel1.Controls.Add(this.IPTextBox, 1, 0);
|
||||||
this.tableLayoutPanel1.Controls.Add(this.ServerPortTextBox, 1, 1);
|
this.tableLayoutPanel1.Controls.Add(this.ServerPortTextBox, 1, 1);
|
||||||
@@ -88,13 +88,13 @@
|
|||||||
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
|
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
|
||||||
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
|
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
|
||||||
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
|
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
|
||||||
this.tableLayoutPanel1.Size = new System.Drawing.Size(238, 137);
|
this.tableLayoutPanel1.Size = new System.Drawing.Size(238, 163);
|
||||||
this.tableLayoutPanel1.TabIndex = 0;
|
this.tableLayoutPanel1.TabIndex = 0;
|
||||||
//
|
//
|
||||||
// RemarksTextBox
|
// RemarksTextBox
|
||||||
//
|
//
|
||||||
this.RemarksTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
|
this.RemarksTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
this.RemarksTextBox.Location = new System.Drawing.Point(72, 111);
|
this.RemarksTextBox.Location = new System.Drawing.Point(72, 137);
|
||||||
this.RemarksTextBox.MaxLength = 32;
|
this.RemarksTextBox.MaxLength = 32;
|
||||||
this.RemarksTextBox.Name = "RemarksTextBox";
|
this.RemarksTextBox.Name = "RemarksTextBox";
|
||||||
this.RemarksTextBox.Size = new System.Drawing.Size(160, 20);
|
this.RemarksTextBox.Size = new System.Drawing.Size(160, 20);
|
||||||
@@ -105,7 +105,7 @@
|
|||||||
//
|
//
|
||||||
this.RemarksLabel.Anchor = System.Windows.Forms.AnchorStyles.Right;
|
this.RemarksLabel.Anchor = System.Windows.Forms.AnchorStyles.Right;
|
||||||
this.RemarksLabel.AutoSize = true;
|
this.RemarksLabel.AutoSize = true;
|
||||||
this.RemarksLabel.Location = new System.Drawing.Point(17, 114);
|
this.RemarksLabel.Location = new System.Drawing.Point(17, 140);
|
||||||
this.RemarksLabel.Name = "RemarksLabel";
|
this.RemarksLabel.Name = "RemarksLabel";
|
||||||
this.RemarksLabel.Size = new System.Drawing.Size(49, 13);
|
this.RemarksLabel.Size = new System.Drawing.Size(49, 13);
|
||||||
this.RemarksLabel.TabIndex = 9;
|
this.RemarksLabel.TabIndex = 9;
|
||||||
@@ -131,6 +131,26 @@
|
|||||||
this.ServerPortLabel.TabIndex = 1;
|
this.ServerPortLabel.TabIndex = 1;
|
||||||
this.ServerPortLabel.Text = "Server Port";
|
this.ServerPortLabel.Text = "Server Port";
|
||||||
//
|
//
|
||||||
|
// ProxyPortTextBox
|
||||||
|
//
|
||||||
|
this.ProxyPortTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.ProxyPortTextBox.Location = new System.Drawing.Point(72, 111);
|
||||||
|
this.ProxyPortTextBox.MaxLength = 10;
|
||||||
|
this.ProxyPortTextBox.Name = "ProxyPortTextBox";
|
||||||
|
this.ProxyPortTextBox.Size = new System.Drawing.Size(160, 20);
|
||||||
|
this.ProxyPortTextBox.TabIndex = 4;
|
||||||
|
this.ProxyPortTextBox.WordWrap = false;
|
||||||
|
//
|
||||||
|
// ProxyPortLabel
|
||||||
|
//
|
||||||
|
this.ProxyPortLabel.Anchor = System.Windows.Forms.AnchorStyles.Right;
|
||||||
|
this.ProxyPortLabel.AutoSize = true;
|
||||||
|
this.ProxyPortLabel.Location = new System.Drawing.Point(11, 114);
|
||||||
|
this.ProxyPortLabel.Name = "ProxyPortLabel";
|
||||||
|
this.ProxyPortLabel.Size = new System.Drawing.Size(55, 13);
|
||||||
|
this.ProxyPortLabel.TabIndex = 3;
|
||||||
|
this.ProxyPortLabel.Text = "Proxy Port";
|
||||||
|
//
|
||||||
// PasswordLabel
|
// PasswordLabel
|
||||||
//
|
//
|
||||||
this.PasswordLabel.Anchor = System.Windows.Forms.AnchorStyles.Right;
|
this.PasswordLabel.Anchor = System.Windows.Forms.AnchorStyles.Right;
|
||||||
@@ -272,7 +292,7 @@
|
|||||||
this.ServerGroupBox.Location = new System.Drawing.Point(178, 0);
|
this.ServerGroupBox.Location = new System.Drawing.Point(178, 0);
|
||||||
this.ServerGroupBox.Margin = new System.Windows.Forms.Padding(12, 0, 0, 0);
|
this.ServerGroupBox.Margin = new System.Windows.Forms.Padding(12, 0, 0, 0);
|
||||||
this.ServerGroupBox.Name = "ServerGroupBox";
|
this.ServerGroupBox.Name = "ServerGroupBox";
|
||||||
this.ServerGroupBox.Size = new System.Drawing.Size(249, 174);
|
this.ServerGroupBox.Size = new System.Drawing.Size(249, 200);
|
||||||
this.ServerGroupBox.TabIndex = 6;
|
this.ServerGroupBox.TabIndex = 6;
|
||||||
this.ServerGroupBox.TabStop = false;
|
this.ServerGroupBox.TabStop = false;
|
||||||
this.ServerGroupBox.Text = "Server";
|
this.ServerGroupBox.Text = "Server";
|
||||||
@@ -295,7 +315,6 @@
|
|||||||
this.tableLayoutPanel2.ColumnCount = 2;
|
this.tableLayoutPanel2.ColumnCount = 2;
|
||||||
this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
|
this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
|
||||||
this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
|
this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
|
||||||
this.tableLayoutPanel2.Controls.Add(this.tableLayoutPanel5, 1, 1);
|
|
||||||
this.tableLayoutPanel2.Controls.Add(this.tableLayoutPanel3, 1, 2);
|
this.tableLayoutPanel2.Controls.Add(this.tableLayoutPanel3, 1, 2);
|
||||||
this.tableLayoutPanel2.Controls.Add(this.ServersListBox, 0, 0);
|
this.tableLayoutPanel2.Controls.Add(this.ServersListBox, 0, 0);
|
||||||
this.tableLayoutPanel2.Controls.Add(this.ServerGroupBox, 1, 0);
|
this.tableLayoutPanel2.Controls.Add(this.ServerGroupBox, 1, 0);
|
||||||
@@ -307,53 +326,9 @@
|
|||||||
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle());
|
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle());
|
||||||
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle());
|
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle());
|
||||||
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle());
|
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle());
|
||||||
this.tableLayoutPanel2.Size = new System.Drawing.Size(427, 238);
|
this.tableLayoutPanel2.Size = new System.Drawing.Size(427, 264);
|
||||||
this.tableLayoutPanel2.TabIndex = 7;
|
this.tableLayoutPanel2.TabIndex = 7;
|
||||||
//
|
//
|
||||||
// tableLayoutPanel5
|
|
||||||
//
|
|
||||||
this.tableLayoutPanel5.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
|
||||||
| System.Windows.Forms.AnchorStyles.Right)));
|
|
||||||
this.tableLayoutPanel5.AutoSize = true;
|
|
||||||
this.tableLayoutPanel5.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
|
|
||||||
this.tableLayoutPanel5.ColumnCount = 2;
|
|
||||||
this.tableLayoutPanel5.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
|
|
||||||
this.tableLayoutPanel5.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
|
|
||||||
this.tableLayoutPanel5.Controls.Add(this.ProxyPortTextBox, 1, 0);
|
|
||||||
this.tableLayoutPanel5.Controls.Add(this.ProxyPortLabel, 0, 0);
|
|
||||||
this.tableLayoutPanel5.Location = new System.Drawing.Point(241, 174);
|
|
||||||
this.tableLayoutPanel5.Margin = new System.Windows.Forms.Padding(0);
|
|
||||||
this.tableLayoutPanel5.Name = "tableLayoutPanel5";
|
|
||||||
this.tableLayoutPanel5.Padding = new System.Windows.Forms.Padding(3);
|
|
||||||
this.tableLayoutPanel5.RowCount = 1;
|
|
||||||
this.tableLayoutPanel5.RowStyles.Add(new System.Windows.Forms.RowStyle());
|
|
||||||
this.tableLayoutPanel5.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 26F));
|
|
||||||
this.tableLayoutPanel5.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 26F));
|
|
||||||
this.tableLayoutPanel5.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 26F));
|
|
||||||
this.tableLayoutPanel5.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 26F));
|
|
||||||
this.tableLayoutPanel5.Size = new System.Drawing.Size(186, 32);
|
|
||||||
this.tableLayoutPanel5.TabIndex = 9;
|
|
||||||
//
|
|
||||||
// ProxyPortTextBox
|
|
||||||
//
|
|
||||||
this.ProxyPortTextBox.Anchor = System.Windows.Forms.AnchorStyles.Left;
|
|
||||||
this.ProxyPortTextBox.Location = new System.Drawing.Point(67, 6);
|
|
||||||
this.ProxyPortTextBox.MaxLength = 10;
|
|
||||||
this.ProxyPortTextBox.Name = "ProxyPortTextBox";
|
|
||||||
this.ProxyPortTextBox.Size = new System.Drawing.Size(113, 20);
|
|
||||||
this.ProxyPortTextBox.TabIndex = 4;
|
|
||||||
this.ProxyPortTextBox.WordWrap = false;
|
|
||||||
//
|
|
||||||
// ProxyPortLabel
|
|
||||||
//
|
|
||||||
this.ProxyPortLabel.Anchor = System.Windows.Forms.AnchorStyles.Right;
|
|
||||||
this.ProxyPortLabel.AutoSize = true;
|
|
||||||
this.ProxyPortLabel.Location = new System.Drawing.Point(6, 9);
|
|
||||||
this.ProxyPortLabel.Name = "ProxyPortLabel";
|
|
||||||
this.ProxyPortLabel.Size = new System.Drawing.Size(55, 13);
|
|
||||||
this.ProxyPortLabel.TabIndex = 3;
|
|
||||||
this.ProxyPortLabel.Text = "Proxy Port";
|
|
||||||
//
|
|
||||||
// tableLayoutPanel3
|
// tableLayoutPanel3
|
||||||
//
|
//
|
||||||
this.tableLayoutPanel3.AutoSize = true;
|
this.tableLayoutPanel3.AutoSize = true;
|
||||||
@@ -365,7 +340,7 @@
|
|||||||
this.tableLayoutPanel3.Controls.Add(this.MyCancelButton, 1, 0);
|
this.tableLayoutPanel3.Controls.Add(this.MyCancelButton, 1, 0);
|
||||||
this.tableLayoutPanel3.Controls.Add(this.OKButton, 0, 0);
|
this.tableLayoutPanel3.Controls.Add(this.OKButton, 0, 0);
|
||||||
this.tableLayoutPanel3.Dock = System.Windows.Forms.DockStyle.Right;
|
this.tableLayoutPanel3.Dock = System.Windows.Forms.DockStyle.Right;
|
||||||
this.tableLayoutPanel3.Location = new System.Drawing.Point(268, 209);
|
this.tableLayoutPanel3.Location = new System.Drawing.Point(268, 235);
|
||||||
this.tableLayoutPanel3.Margin = new System.Windows.Forms.Padding(3, 3, 0, 3);
|
this.tableLayoutPanel3.Margin = new System.Windows.Forms.Padding(3, 3, 0, 3);
|
||||||
this.tableLayoutPanel3.Name = "tableLayoutPanel3";
|
this.tableLayoutPanel3.Name = "tableLayoutPanel3";
|
||||||
this.tableLayoutPanel3.RowCount = 1;
|
this.tableLayoutPanel3.RowCount = 1;
|
||||||
@@ -383,7 +358,7 @@
|
|||||||
this.tableLayoutPanel4.Controls.Add(this.DeleteButton, 1, 0);
|
this.tableLayoutPanel4.Controls.Add(this.DeleteButton, 1, 0);
|
||||||
this.tableLayoutPanel4.Controls.Add(this.AddButton, 0, 0);
|
this.tableLayoutPanel4.Controls.Add(this.AddButton, 0, 0);
|
||||||
this.tableLayoutPanel4.Dock = System.Windows.Forms.DockStyle.Top;
|
this.tableLayoutPanel4.Dock = System.Windows.Forms.DockStyle.Top;
|
||||||
this.tableLayoutPanel4.Location = new System.Drawing.Point(0, 174);
|
this.tableLayoutPanel4.Location = new System.Drawing.Point(0, 200);
|
||||||
this.tableLayoutPanel4.Margin = new System.Windows.Forms.Padding(0);
|
this.tableLayoutPanel4.Margin = new System.Windows.Forms.Padding(0);
|
||||||
this.tableLayoutPanel4.Name = "tableLayoutPanel4";
|
this.tableLayoutPanel4.Name = "tableLayoutPanel4";
|
||||||
this.tableLayoutPanel4.RowCount = 1;
|
this.tableLayoutPanel4.RowCount = 1;
|
||||||
@@ -418,8 +393,6 @@
|
|||||||
this.ServerGroupBox.PerformLayout();
|
this.ServerGroupBox.PerformLayout();
|
||||||
this.tableLayoutPanel2.ResumeLayout(false);
|
this.tableLayoutPanel2.ResumeLayout(false);
|
||||||
this.tableLayoutPanel2.PerformLayout();
|
this.tableLayoutPanel2.PerformLayout();
|
||||||
this.tableLayoutPanel5.ResumeLayout(false);
|
|
||||||
this.tableLayoutPanel5.PerformLayout();
|
|
||||||
this.tableLayoutPanel3.ResumeLayout(false);
|
this.tableLayoutPanel3.ResumeLayout(false);
|
||||||
this.tableLayoutPanel4.ResumeLayout(false);
|
this.tableLayoutPanel4.ResumeLayout(false);
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
@@ -433,9 +406,11 @@
|
|||||||
private System.Windows.Forms.Label IPLabel;
|
private System.Windows.Forms.Label IPLabel;
|
||||||
private System.Windows.Forms.Label ServerPortLabel;
|
private System.Windows.Forms.Label ServerPortLabel;
|
||||||
private System.Windows.Forms.Label PasswordLabel;
|
private System.Windows.Forms.Label PasswordLabel;
|
||||||
|
private System.Windows.Forms.Label ProxyPortLabel;
|
||||||
private System.Windows.Forms.TextBox IPTextBox;
|
private System.Windows.Forms.TextBox IPTextBox;
|
||||||
private System.Windows.Forms.TextBox ServerPortTextBox;
|
private System.Windows.Forms.TextBox ServerPortTextBox;
|
||||||
private System.Windows.Forms.TextBox PasswordTextBox;
|
private System.Windows.Forms.TextBox PasswordTextBox;
|
||||||
|
private System.Windows.Forms.TextBox ProxyPortTextBox;
|
||||||
private System.Windows.Forms.Label EncryptionLabel;
|
private System.Windows.Forms.Label EncryptionLabel;
|
||||||
private System.Windows.Forms.ComboBox EncryptionSelect;
|
private System.Windows.Forms.ComboBox EncryptionSelect;
|
||||||
private System.Windows.Forms.Panel panel2;
|
private System.Windows.Forms.Panel panel2;
|
||||||
@@ -450,9 +425,6 @@
|
|||||||
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2;
|
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2;
|
||||||
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel3;
|
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel3;
|
||||||
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel4;
|
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel4;
|
||||||
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel5;
|
|
||||||
private System.Windows.Forms.TextBox ProxyPortTextBox;
|
|
||||||
private System.Windows.Forms.Label ProxyPortLabel;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -79,14 +79,12 @@ namespace Shadowsocks.View
|
|||||||
server = IPTextBox.Text,
|
server = IPTextBox.Text,
|
||||||
server_port = int.Parse(ServerPortTextBox.Text),
|
server_port = int.Parse(ServerPortTextBox.Text),
|
||||||
password = PasswordTextBox.Text,
|
password = PasswordTextBox.Text,
|
||||||
|
local_port = int.Parse(ProxyPortTextBox.Text),
|
||||||
method = EncryptionSelect.Text,
|
method = EncryptionSelect.Text,
|
||||||
remarks = RemarksTextBox.Text
|
remarks = RemarksTextBox.Text
|
||||||
};
|
};
|
||||||
int localPort = int.Parse(ProxyPortTextBox.Text);
|
|
||||||
Configuration.CheckServer(server);
|
Configuration.CheckServer(server);
|
||||||
Configuration.CheckPort(localPort);
|
|
||||||
_modifiedConfiguration.configs[_oldSelectedIndex] = server;
|
_modifiedConfiguration.configs[_oldSelectedIndex] = server;
|
||||||
_modifiedConfiguration.localPort = localPort;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -110,7 +108,7 @@ namespace Shadowsocks.View
|
|||||||
IPTextBox.Text = server.server;
|
IPTextBox.Text = server.server;
|
||||||
ServerPortTextBox.Text = server.server_port.ToString();
|
ServerPortTextBox.Text = server.server_port.ToString();
|
||||||
PasswordTextBox.Text = server.password;
|
PasswordTextBox.Text = server.password;
|
||||||
ProxyPortTextBox.Text = _modifiedConfiguration.localPort.ToString();
|
ProxyPortTextBox.Text = server.local_port.ToString();
|
||||||
EncryptionSelect.Text = server.method ?? "aes-256-cfb";
|
EncryptionSelect.Text = server.method ?? "aes-256-cfb";
|
||||||
RemarksTextBox.Text = server.remarks;
|
RemarksTextBox.Text = server.remarks;
|
||||||
ServerGroupBox.Visible = true;
|
ServerGroupBox.Visible = true;
|
||||||
@@ -204,7 +202,7 @@ namespace Shadowsocks.View
|
|||||||
MessageBox.Show(I18N.GetString("Please add at least one server"));
|
MessageBox.Show(I18N.GetString("Please add at least one server"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
controller.SaveServers(_modifiedConfiguration.configs, _modifiedConfiguration.localPort);
|
controller.SaveServers(_modifiedConfiguration.configs);
|
||||||
this.Close();
|
this.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ namespace Shadowsocks.View
|
|||||||
|
|
||||||
private bool _isFirstRun;
|
private bool _isFirstRun;
|
||||||
private MenuItem enableItem;
|
private MenuItem enableItem;
|
||||||
private MenuItem modeItem;
|
|
||||||
private MenuItem AutoStartupItem;
|
private MenuItem AutoStartupItem;
|
||||||
private MenuItem ShareOverLANItem;
|
private MenuItem ShareOverLANItem;
|
||||||
private MenuItem SeperatorItem;
|
private MenuItem SeperatorItem;
|
||||||
@@ -46,8 +45,7 @@ namespace Shadowsocks.View
|
|||||||
|
|
||||||
controller.EnableStatusChanged += controller_EnableStatusChanged;
|
controller.EnableStatusChanged += controller_EnableStatusChanged;
|
||||||
controller.ConfigChanged += controller_ConfigChanged;
|
controller.ConfigChanged += controller_ConfigChanged;
|
||||||
controller.PACFileReadyToOpen += controller_FileReadyToOpen;
|
controller.PACFileReadyToOpen += controller_PACFileReadyToOpen;
|
||||||
controller.UserRuleFileReadyToOpen += controller_FileReadyToOpen;
|
|
||||||
controller.ShareOverLANStatusChanged += controller_ShareOverLANStatusChanged;
|
controller.ShareOverLANStatusChanged += controller_ShareOverLANStatusChanged;
|
||||||
controller.EnableGlobalChanged += controller_EnableGlobalChanged;
|
controller.EnableGlobalChanged += controller_EnableGlobalChanged;
|
||||||
controller.Errored += controller_Errored;
|
controller.Errored += controller_Errored;
|
||||||
@@ -65,7 +63,7 @@ namespace Shadowsocks.View
|
|||||||
|
|
||||||
LoadCurrentConfiguration();
|
LoadCurrentConfiguration();
|
||||||
|
|
||||||
updateChecker.CheckUpdate(controller.GetConfiguration());
|
updateChecker.CheckUpdate();
|
||||||
|
|
||||||
if (controller.GetConfiguration().isDefault)
|
if (controller.GetConfiguration().isDefault)
|
||||||
{
|
{
|
||||||
@@ -100,9 +98,7 @@ namespace Shadowsocks.View
|
|||||||
{
|
{
|
||||||
icon = Resources.ss24;
|
icon = Resources.ss24;
|
||||||
}
|
}
|
||||||
Configuration config = controller.GetConfiguration();
|
bool enabled = controller.GetConfiguration().enabled;
|
||||||
bool enabled = config.enabled;
|
|
||||||
bool global = config.global;
|
|
||||||
if (!enabled)
|
if (!enabled)
|
||||||
{
|
{
|
||||||
Bitmap iconCopy = new Bitmap(icon);
|
Bitmap iconCopy = new Bitmap(icon);
|
||||||
@@ -111,19 +107,14 @@ namespace Shadowsocks.View
|
|||||||
for (int y = 0; y < iconCopy.Height; y++)
|
for (int y = 0; y < iconCopy.Height; y++)
|
||||||
{
|
{
|
||||||
Color color = icon.GetPixel(x, y);
|
Color color = icon.GetPixel(x, y);
|
||||||
iconCopy.SetPixel(x, y, Color.FromArgb((byte)(color.A / 1.25), color.R, color.G, color.B));
|
iconCopy.SetPixel(x, y , Color.FromArgb((byte)(color.A / 1.25), color.R, color.G, color.B));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
icon = iconCopy;
|
icon = iconCopy;
|
||||||
}
|
}
|
||||||
_notifyIcon.Icon = Icon.FromHandle(icon.GetHicon());
|
_notifyIcon.Icon = Icon.FromHandle(icon.GetHicon());
|
||||||
|
|
||||||
// we want to show more details but notify icon title is limited to 63 characters
|
string text = I18N.GetString("Shadowsocks") + " " + UpdateChecker.Version + "\n" + (enabled ? I18N.GetString("Enabled") : I18N.GetString("Disabled")) + "\n" + controller.GetCurrentServer().FriendlyName();
|
||||||
string text = I18N.GetString("Shadowsocks") + " " + UpdateChecker.Version + "\n" +
|
|
||||||
(enabled ?
|
|
||||||
I18N.GetString("System Proxy On: ") + (global ? I18N.GetString("Global") : I18N.GetString("PAC")) :
|
|
||||||
String.Format(I18N.GetString("Running: Port {0}"), config.localPort)) // this feedback is very important because they need to know Shadowsocks is running
|
|
||||||
+ "\n" + config.GetCurrentServer().FriendlyName();
|
|
||||||
_notifyIcon.Text = text.Substring(0, Math.Min(63, text.Length));
|
_notifyIcon.Text = text.Substring(0, Math.Min(63, text.Length));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,8 +131,8 @@ namespace Shadowsocks.View
|
|||||||
private void LoadMenu()
|
private void LoadMenu()
|
||||||
{
|
{
|
||||||
this.contextMenu1 = new ContextMenu(new MenuItem[] {
|
this.contextMenu1 = new ContextMenu(new MenuItem[] {
|
||||||
this.enableItem = CreateMenuItem("Enable System Proxy", new EventHandler(this.EnableItem_Click)),
|
this.enableItem = CreateMenuItem("Enable", new EventHandler(this.EnableItem_Click)),
|
||||||
this.modeItem = CreateMenuGroup("Mode", new MenuItem[] {
|
CreateMenuGroup("Mode", new MenuItem[] {
|
||||||
this.PACModeItem = CreateMenuItem("PAC", new EventHandler(this.PACModeItem_Click)),
|
this.PACModeItem = CreateMenuItem("PAC", new EventHandler(this.PACModeItem_Click)),
|
||||||
this.globalModeItem = CreateMenuItem("Global", new EventHandler(this.GlobalModeItem_Click))
|
this.globalModeItem = CreateMenuItem("Global", new EventHandler(this.GlobalModeItem_Click))
|
||||||
}),
|
}),
|
||||||
@@ -152,12 +143,10 @@ namespace Shadowsocks.View
|
|||||||
CreateMenuItem("Scan QRCode from Screen...", new EventHandler(this.ScanQRCodeItem_Click))
|
CreateMenuItem("Scan QRCode from Screen...", new EventHandler(this.ScanQRCodeItem_Click))
|
||||||
}),
|
}),
|
||||||
new MenuItem("-"),
|
new MenuItem("-"),
|
||||||
|
this.AutoStartupItem = CreateMenuItem("Start on Boot", new EventHandler(this.AutoStartupItem_Click)),
|
||||||
|
this.ShareOverLANItem = CreateMenuItem("Share over LAN", new EventHandler(this.ShareOverLANItem_Click)),
|
||||||
CreateMenuItem("Edit PAC File...", new EventHandler(this.EditPACFileItem_Click)),
|
CreateMenuItem("Edit PAC File...", new EventHandler(this.EditPACFileItem_Click)),
|
||||||
CreateMenuItem("Update PAC from GFWList", new EventHandler(this.UpdatePACFromGFWListItem_Click)),
|
CreateMenuItem("Update PAC from GFWList", new EventHandler(this.UpdatePACFromGFWListItem_Click)),
|
||||||
CreateMenuItem("Edit User Rule for GFWList...", new EventHandler(this.EditUserRuleFileForGFWListItem_Click)),
|
|
||||||
new MenuItem("-"),
|
|
||||||
this.AutoStartupItem = CreateMenuItem("Start on Boot", new EventHandler(this.AutoStartupItem_Click)),
|
|
||||||
this.ShareOverLANItem = CreateMenuItem("Allow Clients from LAN", new EventHandler(this.ShareOverLANItem_Click)),
|
|
||||||
new MenuItem("-"),
|
new MenuItem("-"),
|
||||||
CreateMenuItem("Show Logs...", new EventHandler(this.ShowLogItem_Click)),
|
CreateMenuItem("Show Logs...", new EventHandler(this.ShowLogItem_Click)),
|
||||||
CreateMenuItem("About...", new EventHandler(this.AboutItem_Click)),
|
CreateMenuItem("About...", new EventHandler(this.AboutItem_Click)),
|
||||||
@@ -175,7 +164,6 @@ namespace Shadowsocks.View
|
|||||||
private void controller_EnableStatusChanged(object sender, EventArgs e)
|
private void controller_EnableStatusChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
enableItem.Checked = controller.GetConfiguration().enabled;
|
enableItem.Checked = controller.GetConfiguration().enabled;
|
||||||
modeItem.Enabled = enableItem.Checked;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void controller_ShareOverLANStatusChanged(object sender, EventArgs e)
|
void controller_ShareOverLANStatusChanged(object sender, EventArgs e)
|
||||||
@@ -189,7 +177,7 @@ namespace Shadowsocks.View
|
|||||||
PACModeItem.Checked = !globalModeItem.Checked;
|
PACModeItem.Checked = !globalModeItem.Checked;
|
||||||
}
|
}
|
||||||
|
|
||||||
void controller_FileReadyToOpen(object sender, ShadowsocksController.PathEventArgs e)
|
void controller_PACFileReadyToOpen(object sender, ShadowsocksController.PathEventArgs e)
|
||||||
{
|
{
|
||||||
string argument = @"/select, " + e.Path;
|
string argument = @"/select, " + e.Path;
|
||||||
|
|
||||||
@@ -210,10 +198,9 @@ namespace Shadowsocks.View
|
|||||||
Logging.LogUsefulException(e.GetException());
|
Logging.LogUsefulException(e.GetException());
|
||||||
}
|
}
|
||||||
|
|
||||||
void controller_UpdatePACFromGFWListCompleted(object sender, GFWListUpdater.ResultEventArgs e)
|
void controller_UpdatePACFromGFWListCompleted(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
string result = e.Success ? I18N.GetString("PAC updated") : I18N.GetString("No updates found. Please report to GFWList if you have problems with it.");
|
ShowBalloonTip(I18N.GetString("Shadowsocks"), I18N.GetString("PAC updated"), ToolTipIcon.Info, 1000);
|
||||||
ShowBalloonTip(I18N.GetString("Shadowsocks"), result, ToolTipIcon.Info, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateChecker_NewVersionFound(object sender, EventArgs e)
|
void updateChecker_NewVersionFound(object sender, EventArgs e)
|
||||||
@@ -235,7 +222,6 @@ namespace Shadowsocks.View
|
|||||||
Configuration config = controller.GetConfiguration();
|
Configuration config = controller.GetConfiguration();
|
||||||
UpdateServersMenu();
|
UpdateServersMenu();
|
||||||
enableItem.Checked = config.enabled;
|
enableItem.Checked = config.enabled;
|
||||||
modeItem.Enabled = config.enabled;
|
|
||||||
globalModeItem.Checked = config.global;
|
globalModeItem.Checked = config.global;
|
||||||
PACModeItem.Checked = !config.global;
|
PACModeItem.Checked = !config.global;
|
||||||
ShareOverLANItem.Checked = config.shareOverLan;
|
ShareOverLANItem.Checked = config.shareOverLan;
|
||||||
@@ -355,11 +341,6 @@ namespace Shadowsocks.View
|
|||||||
controller.UpdatePACFromGFWList();
|
controller.UpdatePACFromGFWList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void EditUserRuleFileForGFWListItem_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
controller.TouchUserRuleFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void AServerItem_Click(object sender, EventArgs e)
|
private void AServerItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
MenuItem item = (MenuItem)sender;
|
MenuItem item = (MenuItem)sender;
|
||||||
@@ -383,28 +364,25 @@ namespace Shadowsocks.View
|
|||||||
|
|
||||||
private void ScanQRCodeItem_Click(object sender, EventArgs e)
|
private void ScanQRCodeItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
foreach (Screen screen in Screen.AllScreens)
|
|
||||||
{
|
using (Bitmap fullImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
|
||||||
using (Bitmap fullImage = new Bitmap(screen.Bounds.Width,
|
Screen.PrimaryScreen.Bounds.Height))
|
||||||
screen.Bounds.Height))
|
|
||||||
{
|
{
|
||||||
using (Graphics g = Graphics.FromImage(fullImage))
|
using (Graphics g = Graphics.FromImage(fullImage))
|
||||||
{
|
{
|
||||||
g.CopyFromScreen(screen.Bounds.X,
|
g.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
|
||||||
screen.Bounds.Y,
|
Screen.PrimaryScreen.Bounds.Y,
|
||||||
0, 0,
|
0, 0,
|
||||||
fullImage.Size,
|
fullImage.Size,
|
||||||
CopyPixelOperation.SourceCopy);
|
CopyPixelOperation.SourceCopy);
|
||||||
}
|
}
|
||||||
int maxTry = 10;
|
for (int i = 0; i < 5; i++)
|
||||||
for (int i = 0; i < maxTry; i++)
|
|
||||||
{
|
{
|
||||||
int marginLeft = (int)((double)fullImage.Width * i / 2.5 / maxTry);
|
int marginLeft = fullImage.Width * i / 3 / 5;
|
||||||
int marginTop = (int)((double)fullImage.Height * i / 2.5 / maxTry);
|
int marginTop = fullImage.Height * i / 3 / 5;
|
||||||
Rectangle cropRect = new Rectangle(marginLeft, marginTop, fullImage.Width - marginLeft * 2, fullImage.Height - marginTop * 2);
|
Rectangle cropRect = new Rectangle(marginLeft, marginTop, fullImage.Width - marginLeft * 2, fullImage.Height - marginTop * 2);
|
||||||
Bitmap target = new Bitmap(screen.Bounds.Width, screen.Bounds.Height);
|
Bitmap target = new Bitmap(cropRect.Width, cropRect.Height);
|
||||||
|
|
||||||
double imageScale = (double)screen.Bounds.Width / (double)cropRect.Width;
|
|
||||||
using (Graphics g = Graphics.FromImage(target))
|
using (Graphics g = Graphics.FromImage(target))
|
||||||
{
|
{
|
||||||
g.DrawImage(fullImage, new Rectangle(0, 0, target.Width, target.Height),
|
g.DrawImage(fullImage, new Rectangle(0, 0, target.Width, target.Height),
|
||||||
@@ -433,7 +411,7 @@ namespace Shadowsocks.View
|
|||||||
MessageBox.Show(I18N.GetString("Failed to decode QRCode"));
|
MessageBox.Show(I18N.GetString("Failed to decode QRCode"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
double minX = Int32.MaxValue, minY = Int32.MaxValue, maxX = 0, maxY = 0;
|
float minX = Int32.MaxValue, minY = Int32.MaxValue, maxX = 0, maxY = 0;
|
||||||
foreach (ResultPoint point in result.ResultPoints)
|
foreach (ResultPoint point in result.ResultPoints)
|
||||||
{
|
{
|
||||||
minX = Math.Min(minX, point.X);
|
minX = Math.Min(minX, point.X);
|
||||||
@@ -441,27 +419,22 @@ namespace Shadowsocks.View
|
|||||||
maxX = Math.Max(maxX, point.X);
|
maxX = Math.Max(maxX, point.X);
|
||||||
maxY = Math.Max(maxY, point.Y);
|
maxY = Math.Max(maxY, point.Y);
|
||||||
}
|
}
|
||||||
minX /= imageScale;
|
|
||||||
minY /= imageScale;
|
|
||||||
maxX /= imageScale;
|
|
||||||
maxY /= imageScale;
|
|
||||||
// make it 20% larger
|
// make it 20% larger
|
||||||
double margin = (maxX - minX) * 0.20f;
|
float margin = (maxX - minX) * 0.20f;
|
||||||
minX += -margin + marginLeft;
|
minX += -margin + marginLeft;
|
||||||
maxX += margin + marginLeft;
|
maxX += margin + marginLeft;
|
||||||
minY += -margin + marginTop;
|
minY += -margin + marginTop;
|
||||||
maxY += margin + marginTop;
|
maxY += margin + marginTop;
|
||||||
splash.Location = new Point(screen.Bounds.X, screen.Bounds.Y);
|
splash.Location = new Point(0, 0);
|
||||||
// we need a panel because a window has a minimal size
|
// we need a panel because a window has a minimal size
|
||||||
// TODO: test on high DPI
|
// TODO: test on high DPI
|
||||||
splash.TargetRect = new Rectangle((int)minX + screen.Bounds.X, (int)minY + screen.Bounds.Y, (int)maxX - (int)minX, (int)maxY - (int)minY);
|
splash.TargetRect = new Rectangle((int)minX, (int)minY, (int)maxX - (int)minX, (int)maxY - (int)minY);
|
||||||
splash.Size = new Size(fullImage.Width, fullImage.Height);
|
splash.Size = new Size(fullImage.Width, fullImage.Height);
|
||||||
splash.Show();
|
splash.Show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
MessageBox.Show(I18N.GetString("No QRCode found. Try to zoom in or move it to the center of the screen."));
|
MessageBox.Show(I18N.GetString("No QRCode found. Try to zoom in or move it to the center of the screen."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -127,9 +127,7 @@
|
|||||||
<Compile Include="Controller\FileManager.cs" />
|
<Compile Include="Controller\FileManager.cs" />
|
||||||
<Compile Include="Controller\GFWListUpdater.cs" />
|
<Compile Include="Controller\GFWListUpdater.cs" />
|
||||||
<Compile Include="Controller\I18N.cs" />
|
<Compile Include="Controller\I18N.cs" />
|
||||||
<Compile Include="Controller\Listener.cs" />
|
|
||||||
<Compile Include="Controller\Logging.cs" />
|
<Compile Include="Controller\Logging.cs" />
|
||||||
<Compile Include="Controller\PortForwarder.cs" />
|
|
||||||
<Compile Include="Controller\UpdateChecker.cs" />
|
<Compile Include="Controller\UpdateChecker.cs" />
|
||||||
<Compile Include="Encryption\EncryptorBase.cs" />
|
<Compile Include="Encryption\EncryptorBase.cs" />
|
||||||
<Compile Include="Encryption\EncryptorFactory.cs" />
|
<Compile Include="Encryption\EncryptorFactory.cs" />
|
||||||
@@ -198,7 +196,6 @@
|
|||||||
<None Include="Resources\ss24.png" />
|
<None Include="Resources\ss24.png" />
|
||||||
<None Include="Resources\ssw128.png" />
|
<None Include="Resources\ssw128.png" />
|
||||||
<Content Include="Data\cn.txt" />
|
<Content Include="Data\cn.txt" />
|
||||||
<Content Include="Data\user-rule.txt" />
|
|
||||||
<Content Include="shadowsocks.ico" />
|
<Content Include="shadowsocks.ico" />
|
||||||
<None Include="Data\polipo_config.txt" />
|
<None Include="Data\polipo_config.txt" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user