PAC edit
This commit is contained in:
@@ -22,22 +22,29 @@ namespace shadowsocks_csharp.Controller
|
||||
|
||||
public void Start()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Create a TCP/IP socket.
|
||||
listener = new Socket(AddressFamily.InterNetwork,
|
||||
SocketType.Stream, ProtocolType.Tcp);
|
||||
IPEndPoint localEndPoint = new IPEndPoint(0, config.local_port);
|
||||
|
||||
// Create a TCP/IP socket.
|
||||
listener = new Socket(AddressFamily.InterNetwork,
|
||||
SocketType.Stream, ProtocolType.Tcp);
|
||||
IPEndPoint localEndPoint = new IPEndPoint(0, config.local_port);
|
||||
|
||||
// Bind the socket to the local endpoint and listen for incoming connections.
|
||||
listener.Bind(localEndPoint);
|
||||
listener.Listen(100);
|
||||
// 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);
|
||||
// Start an asynchronous socket to listen for connections.
|
||||
Console.WriteLine("Shadowsocks started");
|
||||
listener.BeginAccept(
|
||||
new AsyncCallback(AcceptCallback),
|
||||
listener);
|
||||
}
|
||||
catch(SocketException)
|
||||
{
|
||||
listener.Close();
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ namespace shadowsocks_csharp.Controller
|
||||
{
|
||||
class PACServer
|
||||
{
|
||||
private static string PAC_FILE = "pac.txt";
|
||||
|
||||
Socket listener;
|
||||
public void Start()
|
||||
{
|
||||
@@ -28,6 +30,19 @@ namespace shadowsocks_csharp.Controller
|
||||
listener);
|
||||
}
|
||||
|
||||
public string TouchPACFile()
|
||||
{
|
||||
if (File.Exists(PAC_FILE))
|
||||
{
|
||||
return PAC_FILE;
|
||||
}
|
||||
else
|
||||
{
|
||||
FileManager.UncompressFile(PAC_FILE, Resources.proxy_pac_txt);
|
||||
return PAC_FILE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void AcceptCallback(IAsyncResult ar)
|
||||
{
|
||||
@@ -51,21 +66,29 @@ namespace shadowsocks_csharp.Controller
|
||||
private string getPACContent()
|
||||
{
|
||||
// TODO try pac.txt in current directory
|
||||
byte[] pacGZ = Resources.proxy_pac_txt;
|
||||
|
||||
byte[] buffer = new byte[1024 * 1024]; // builtin pac gzip size: maximum 1M
|
||||
int n;
|
||||
|
||||
using (GZipStream input = new GZipStream(new MemoryStream(pacGZ),
|
||||
CompressionMode.Decompress, false))
|
||||
|
||||
if (File.Exists(PAC_FILE))
|
||||
{
|
||||
n = input.Read(buffer, 0, buffer.Length);
|
||||
if (n == 0)
|
||||
{
|
||||
throw new IOException("can not decompress pac");
|
||||
}
|
||||
return System.Text.Encoding.UTF8.GetString(buffer, 0, n);
|
||||
return File.ReadAllText(PAC_FILE, Encoding.UTF8);
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] pacGZ = Resources.proxy_pac_txt;
|
||||
byte[] buffer = new byte[1024 * 1024]; // builtin pac gzip size: maximum 1M
|
||||
int n;
|
||||
|
||||
using (GZipStream input = new GZipStream(new MemoryStream(pacGZ),
|
||||
CompressionMode.Decompress, false))
|
||||
{
|
||||
n = input.Read(buffer, 0, buffer.Length);
|
||||
if (n == 0)
|
||||
{
|
||||
throw new IOException("can not decompress pac");
|
||||
}
|
||||
return System.Text.Encoding.UTF8.GetString(buffer, 0, n);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void receiveCallback(IAsyncResult ar)
|
||||
|
||||
@@ -23,8 +23,15 @@ namespace shadowsocks_csharp.Controller
|
||||
public string Path;
|
||||
}
|
||||
|
||||
public class ErrorEventArgs : EventArgs
|
||||
{
|
||||
public string Error;
|
||||
}
|
||||
|
||||
public event EventHandler ConfigChanged;
|
||||
public event EventHandler EnableStatusChanged;
|
||||
|
||||
public event EventHandler<ErrorEventArgs> LocalFailToStart;
|
||||
|
||||
// when user clicked Edit PAC, and PAC file has already created
|
||||
public event EventHandler<PathEventArgs> PACFileReadyToOpen;
|
||||
@@ -35,9 +42,16 @@ namespace shadowsocks_csharp.Controller
|
||||
polipoRunner = new PolipoRunner();
|
||||
polipoRunner.Start(config);
|
||||
local = new Local(config);
|
||||
local.Start();
|
||||
pacServer = new PACServer();
|
||||
pacServer.Start();
|
||||
try
|
||||
{
|
||||
local.Start();
|
||||
pacServer = new PACServer();
|
||||
pacServer.Start();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
|
||||
updateSystemProxy();
|
||||
}
|
||||
@@ -93,6 +107,11 @@ namespace shadowsocks_csharp.Controller
|
||||
|
||||
public void TouchPACFile()
|
||||
{
|
||||
string pacFilename = pacServer.TouchPACFile();
|
||||
if (PACFileReadyToOpen != null)
|
||||
{
|
||||
PACFileReadyToOpen(this, new PathEventArgs() { Path = pacFilename });
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSystemProxy()
|
||||
|
||||
Binary file not shown.
@@ -271,7 +271,7 @@ namespace shadowsocks_csharp.Encrypt
|
||||
PolarSSL.blowfish_free(_encryptCtx);
|
||||
break;
|
||||
case CIPHER_RC4:
|
||||
PolarSSL.arc4_free(_encryptCtx);
|
||||
//PolarSSL.arc4_free(_encryptCtx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -286,7 +286,7 @@ namespace shadowsocks_csharp.Encrypt
|
||||
PolarSSL.blowfish_free(_decryptCtx);
|
||||
break;
|
||||
case CIPHER_RC4:
|
||||
PolarSSL.arc4_free(_decryptCtx);
|
||||
//PolarSSL.arc4_free(_decryptCtx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,10 @@ namespace shadowsocks_csharp.Model
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
if (!(e is FileNotFoundException))
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
return new Config
|
||||
{
|
||||
server = "127.0.0.1",
|
||||
|
||||
@@ -20,13 +20,20 @@ namespace shadowsocks_csharp
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
string tempPath = Path.GetTempPath();
|
||||
string dllPath = tempPath + "/polarssl.dll";
|
||||
try
|
||||
{
|
||||
string tempPath = Path.GetTempPath();
|
||||
string dllPath = tempPath + "/polarssl.dll";
|
||||
FileManager.UncompressFile(dllPath, Resources.polarssl_dll);
|
||||
LoadLibrary(dllPath);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
LoadLibrary(dllPath);
|
||||
|
||||
try
|
||||
{
|
||||
FileStream fs = new FileStream("shadowsocks.log", FileMode.Append);
|
||||
TextWriter tmp = Console.Out;
|
||||
StreamWriter sw = new StreamWriter(fs);
|
||||
|
||||
+12
-3
@@ -52,6 +52,7 @@
|
||||
this.aboutItem = new System.Windows.Forms.MenuItem();
|
||||
this.menuItem3 = new System.Windows.Forms.MenuItem();
|
||||
this.quitItem = new System.Windows.Forms.MenuItem();
|
||||
this.editPACFileItem = new System.Windows.Forms.MenuItem();
|
||||
this.tableLayoutPanel1.SuspendLayout();
|
||||
this.panel1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
@@ -249,6 +250,7 @@
|
||||
this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
|
||||
this.enableItem,
|
||||
this.configItem,
|
||||
this.editPACFileItem,
|
||||
this.aboutItem,
|
||||
this.menuItem3,
|
||||
this.quitItem});
|
||||
@@ -267,21 +269,27 @@
|
||||
//
|
||||
// aboutItem
|
||||
//
|
||||
this.aboutItem.Index = 2;
|
||||
this.aboutItem.Index = 3;
|
||||
this.aboutItem.Text = "About";
|
||||
this.aboutItem.Click += new System.EventHandler(this.aboutToolStripMenuItem_Click);
|
||||
//
|
||||
// menuItem3
|
||||
//
|
||||
this.menuItem3.Index = 3;
|
||||
this.menuItem3.Index = 4;
|
||||
this.menuItem3.Text = "-";
|
||||
//
|
||||
// quitItem
|
||||
//
|
||||
this.quitItem.Index = 4;
|
||||
this.quitItem.Index = 5;
|
||||
this.quitItem.Text = "Quit";
|
||||
this.quitItem.Click += new System.EventHandler(this.Quit_Click);
|
||||
//
|
||||
// editPACFileItem
|
||||
//
|
||||
this.editPACFileItem.Index = 2;
|
||||
this.editPACFileItem.Text = "Edit PAC File...";
|
||||
this.editPACFileItem.Click += new System.EventHandler(this.editPACFileItem_Click);
|
||||
//
|
||||
// ConfigForm
|
||||
//
|
||||
this.AcceptButton = this.button1;
|
||||
@@ -332,6 +340,7 @@
|
||||
private System.Windows.Forms.MenuItem menuItem3;
|
||||
private System.Windows.Forms.MenuItem quitItem;
|
||||
private System.Windows.Forms.MenuItem configItem;
|
||||
private System.Windows.Forms.MenuItem editPACFileItem;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace shadowsocks_csharp.View
|
||||
this.controller = controller;
|
||||
controller.EnableStatusChanged += controller_EnableStatusChanged;
|
||||
controller.ConfigChanged += controller_ConfigChanged;
|
||||
controller.PACFileReadyToOpen += controller_PACFileReadyToOpen;
|
||||
|
||||
updateUI();
|
||||
}
|
||||
@@ -35,6 +36,14 @@ namespace shadowsocks_csharp.View
|
||||
{
|
||||
updateUI();
|
||||
}
|
||||
|
||||
void controller_PACFileReadyToOpen(object sender, ShadowsocksController.PathEventArgs e)
|
||||
{
|
||||
string argument = @"/select, " + e.Path;
|
||||
|
||||
System.Diagnostics.Process.Start("explorer.exe", argument);
|
||||
}
|
||||
|
||||
|
||||
private void showWindow()
|
||||
{
|
||||
@@ -131,5 +140,10 @@ namespace shadowsocks_csharp.View
|
||||
controller.ToggleEnable(enableItem.Checked);
|
||||
}
|
||||
|
||||
private void editPACFileItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
controller.TouchPACFile();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user