Browse Source

link config to window

tags/2.3
clowwindy 12 years ago
parent
commit
01d2a904ed
5 changed files with 79 additions and 38 deletions
  1. +4
    -4
      shadowsocks-csharp/Config.cs
  2. +19
    -16
      shadowsocks-csharp/Form1.Designer.cs
  3. +36
    -0
      shadowsocks-csharp/Form1.cs
  4. +20
    -15
      shadowsocks-csharp/Local.cs
  5. +0
    -3
      shadowsocks-csharp/Program.cs

+ 4
- 4
shadowsocks-csharp/Config.cs View File

@@ -25,14 +25,14 @@ namespace shadowsocks_csharp
return config; return config;
} }
} }
catch (IOException e)
catch (IOException)
{ {
return new Config return new Config
{ {
server = "127.0.0.1", server = "127.0.0.1",
server_port = 8388, server_port = 8388,
local_port = 1080,
password = "foobar!"
local_port = 1081,
password = "barfoo!"
}; };
} }
} }
@@ -42,7 +42,7 @@ namespace shadowsocks_csharp
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Config)); DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Config));
try try
{ {
using (FileStream fs = File.Open(@"config.json",FileMode.Create))
using (FileStream fs = File.Open(@"config.json", FileMode.Create))
{ {
ser.WriteObject(fs, config); ser.WriteObject(fs, config);
} }


+ 19
- 16
shadowsocks-csharp/Form1.Designer.cs View File

@@ -45,8 +45,8 @@
this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel();
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components); this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.Config = new System.Windows.Forms.ToolStripMenuItem();
this.Quit = new System.Windows.Forms.ToolStripMenuItem();
this.ConfigItem = new System.Windows.Forms.ToolStripMenuItem();
this.QuitItem = new System.Windows.Forms.ToolStripMenuItem();
this.tableLayoutPanel1.SuspendLayout(); this.tableLayoutPanel1.SuspendLayout();
this.panel1.SuspendLayout(); this.panel1.SuspendLayout();
this.tableLayoutPanel2.SuspendLayout(); this.tableLayoutPanel2.SuspendLayout();
@@ -178,6 +178,7 @@
this.button2.TabIndex = 1; this.button2.TabIndex = 1;
this.button2.Text = "Cancel"; this.button2.Text = "Cancel";
this.button2.UseVisualStyleBackColor = true; this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
// //
// button1 // button1
// //
@@ -188,6 +189,7 @@
this.button1.TabIndex = 0; this.button1.TabIndex = 0;
this.button1.Text = "OK"; this.button1.Text = "OK";
this.button1.UseVisualStyleBackColor = true; this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
// //
// tableLayoutPanel2 // tableLayoutPanel2
// //
@@ -217,26 +219,26 @@
// contextMenuStrip1 // contextMenuStrip1
// //
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.Config,
this.Quit});
this.ConfigItem,
this.QuitItem});
this.contextMenuStrip1.Name = "contextMenuStrip1"; this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.System; this.contextMenuStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.System;
this.contextMenuStrip1.ShowImageMargin = false; this.contextMenuStrip1.ShowImageMargin = false;
this.contextMenuStrip1.Size = new System.Drawing.Size(86, 48); this.contextMenuStrip1.Size = new System.Drawing.Size(86, 48);
// //
// Config
// ConfigItem
// //
this.Config.Name = "Config";
this.Config.Size = new System.Drawing.Size(127, 22);
this.Config.Text = "Config";
this.Config.Click += new System.EventHandler(this.Config_Click);
this.ConfigItem.Name = "ConfigItem";
this.ConfigItem.Size = new System.Drawing.Size(127, 22);
this.ConfigItem.Text = "Config";
this.ConfigItem.Click += new System.EventHandler(this.Config_Click);
// //
// Quit
// QuitItem
// //
this.Quit.Name = "Quit";
this.Quit.Size = new System.Drawing.Size(127, 22);
this.Quit.Text = "Quit";
this.Quit.Click += new System.EventHandler(this.Quit_Click);
this.QuitItem.Name = "QuitItem";
this.QuitItem.Size = new System.Drawing.Size(127, 22);
this.QuitItem.Text = "Quit";
this.QuitItem.Click += new System.EventHandler(this.Quit_Click);
// //
// Form1 // Form1
// //
@@ -251,6 +253,7 @@
this.Controls.Add(this.tableLayoutPanel1); this.Controls.Add(this.tableLayoutPanel1);
this.Name = "Form1"; this.Name = "Form1";
this.Text = "Shadowsocks"; this.Text = "Shadowsocks";
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Form1_FormClosed);
this.tableLayoutPanel1.ResumeLayout(false); this.tableLayoutPanel1.ResumeLayout(false);
this.tableLayoutPanel1.PerformLayout(); this.tableLayoutPanel1.PerformLayout();
this.panel1.ResumeLayout(false); this.panel1.ResumeLayout(false);
@@ -279,8 +282,8 @@
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2;
private System.Windows.Forms.NotifyIcon notifyIcon1; private System.Windows.Forms.NotifyIcon notifyIcon1;
private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
private System.Windows.Forms.ToolStripMenuItem Config;
private System.Windows.Forms.ToolStripMenuItem Quit;
private System.Windows.Forms.ToolStripMenuItem ConfigItem;
private System.Windows.Forms.ToolStripMenuItem QuitItem;
} }
} }

+ 36
- 0
shadowsocks-csharp/Form1.cs View File

@@ -10,9 +10,29 @@ namespace shadowsocks_csharp
{ {
public partial class Form1 : Form public partial class Form1 : Form
{ {
Local local;
Config config;
public Form1() public Form1()
{ {
config = Config.Load();
reload(config);
InitializeComponent(); InitializeComponent();
textBox1.Text = config.server;
textBox2.Text = config.server_port.ToString();
textBox3.Text = config.password;
textBox4.Text = config.local_port.ToString();
}
private void reload(Config config)
{
if (local != null)
{
local.Stop();
}
local = new Local(config.local_port);
local.Start();
} }
private void Config_Click(object sender, EventArgs e) private void Config_Click(object sender, EventArgs e)
@@ -24,5 +44,21 @@ namespace shadowsocks_csharp
{ {
} }
private void button1_Click(object sender, EventArgs e)
{
reload(Config.Load());
}
private void button2_Click(object sender, EventArgs e)
{
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
local.Stop();
}
} }
} }

+ 20
- 15
shadowsocks-csharp/Local.cs View File

@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Text; using System.Text;
using System.Net.Sockets; using System.Net.Sockets;
using System.Net; using System.Net;
using System.Threading;
namespace shadowsocks_csharp namespace shadowsocks_csharp
{ {
@@ -49,23 +48,30 @@ namespace shadowsocks_csharp
public void AcceptCallback(IAsyncResult ar) public void AcceptCallback(IAsyncResult ar)
{ {
try
{
// Get the socket that handles the client request.
Socket listener = (Socket)ar.AsyncState;
listener.BeginAccept(
new AsyncCallback(AcceptCallback),
listener);
// Get the socket that handles the client request.
Socket listener = (Socket)ar.AsyncState;
listener.BeginAccept(
new AsyncCallback(AcceptCallback),
listener);
Socket conn = listener.EndAccept(ar);
Socket conn = listener.EndAccept(ar);
// Create the state object.
Handler handler = new Handler();
handler.connection = conn;
handler.encryptor = encryptor;
// Create the state object.
Handler handler = new Handler();
handler.connection = conn;
handler.encryptor = encryptor;
handler.Start();
//handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
// new AsyncCallback(ReadCallback), state);
handler.Start();
//handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
// new AsyncCallback(ReadCallback), state);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
} }
} }
@@ -110,7 +116,6 @@ namespace shadowsocks_csharp
Console.WriteLine("Socket connected to {0}", Console.WriteLine("Socket connected to {0}",
remote.RemoteEndPoint.ToString()); remote.RemoteEndPoint.ToString());
Console.WriteLine(Thread.CurrentThread.ManagedThreadId);
handshakeReceive(); handshakeReceive();
} }


+ 0
- 3
shadowsocks-csharp/Program.cs View File

@@ -12,12 +12,9 @@ namespace shadowsocks_csharp
[STAThread] [STAThread]
static void Main() static void Main()
{ {
Local local = new Local(1081);
local.Start();
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1()); Application.Run(new Form1());
local.Stop();
} }
} }
} }

Loading…
Cancel
Save