diff --git a/shadowsocks-csharp/Controller/Service/TCPRelay.cs b/shadowsocks-csharp/Controller/Service/TCPRelay.cs
index d266e0ee..8f382c78 100644
--- a/shadowsocks-csharp/Controller/Service/TCPRelay.cs
+++ b/shadowsocks-csharp/Controller/Service/TCPRelay.cs
@@ -412,10 +412,10 @@ namespace Shadowsocks.Controller
// Setting up proxy
IProxy remote;
EndPoint proxyEP;
- if (_config.useProxy)
+ if (_config.proxy.useProxy)
{
remote = new Socks5Proxy();
- proxyEP = SocketUtil.GetEndPoint(_config.proxyServer, _config.proxyPort);
+ proxyEP = SocketUtil.GetEndPoint(_config.proxy.proxyServer, _config.proxy.proxyPort);
}
else
{
diff --git a/shadowsocks-csharp/Controller/ShadowsocksController.cs b/shadowsocks-csharp/Controller/ShadowsocksController.cs
index 983130a5..d5a9a751 100644
--- a/shadowsocks-csharp/Controller/ShadowsocksController.cs
+++ b/shadowsocks-csharp/Controller/ShadowsocksController.cs
@@ -217,15 +217,15 @@ namespace Shadowsocks.Controller
public void DisableProxy()
{
- _config.useProxy = false;
+ _config.proxy.useProxy = false;
SaveConfig(_config);
}
public void EnableProxy(string proxy, int port)
{
- _config.useProxy = true;
- _config.proxyServer = proxy;
- _config.proxyPort = port;
+ _config.proxy.useProxy = true;
+ _config.proxy.proxyServer = proxy;
+ _config.proxy.proxyPort = port;
SaveConfig(_config);
}
@@ -356,6 +356,12 @@ namespace Shadowsocks.Controller
Configuration.Save(_config);
}
+ public void SaveProxyConfig(ProxyConfig newConfig)
+ {
+ _config.proxy = newConfig;
+ Configuration.Save(_config);
+ }
+
public void UpdateLatency(Server server, TimeSpan latency)
{
if (_config.availabilityStatistics)
diff --git a/shadowsocks-csharp/Model/Configuration.cs b/shadowsocks-csharp/Model/Configuration.cs
index 010189ed..12d8ec3f 100755
--- a/shadowsocks-csharp/Model/Configuration.cs
+++ b/shadowsocks-csharp/Model/Configuration.cs
@@ -26,9 +26,7 @@ namespace Shadowsocks.Model
public bool autoCheckUpdate;
public bool isVerboseLogging;
public LogViewerConfig logViewer;
- public bool useProxy;
- public string proxyServer;
- public int proxyPort;
+ public ProxyConfig proxy;
private static string CONFIG_FILE = "gui-config.json";
diff --git a/shadowsocks-csharp/Model/ProxyConfig.cs b/shadowsocks-csharp/Model/ProxyConfig.cs
new file mode 100644
index 00000000..0af17edb
--- /dev/null
+++ b/shadowsocks-csharp/Model/ProxyConfig.cs
@@ -0,0 +1,22 @@
+using Shadowsocks.View;
+using System;
+using System.Drawing;
+using System.Windows.Forms;
+
+namespace Shadowsocks.Model
+{
+ [Serializable]
+ public class ProxyConfig
+ {
+ public bool useProxy;
+ public string proxyServer;
+ public int proxyPort;
+
+ public ProxyConfig()
+ {
+ useProxy = false;
+ proxyServer = "";
+ proxyPort = 0;
+ }
+ }
+}
diff --git a/shadowsocks-csharp/View/ProxyForm.cs b/shadowsocks-csharp/View/ProxyForm.cs
index 4f2a900d..e482dfa8 100644
--- a/shadowsocks-csharp/View/ProxyForm.cs
+++ b/shadowsocks-csharp/View/ProxyForm.cs
@@ -1,116 +1,129 @@
-using System;
-using System.Drawing;
-using System.Windows.Forms;
-using Shadowsocks.Controller;
-using Shadowsocks.Model;
-using Shadowsocks.Properties;
-
-namespace Shadowsocks.View
-{
- public partial class ProxyForm : Form
- {
- private ShadowsocksController controller;
-
- // this is a copy of configuration that we are working on
- private Configuration _modifiedConfiguration;
-
- public ProxyForm(ShadowsocksController controller)
- {
- this.Font = System.Drawing.SystemFonts.MessageBoxFont;
- InitializeComponent();
-
- UpdateTexts();
- this.Icon = Icon.FromHandle(Resources.ssw128.GetHicon());
-
- this.controller = controller;
- controller.ConfigChanged += controller_ConfigChanged;
-
- UpdateEnabled();
- LoadCurrentConfiguration();
- }
-
- private void UpdateTexts()
- {
- UseProxyCheckBox.Text = I18N.GetString("Use Proxy");
- ProxyAddrLabel.Text = I18N.GetString("Proxy Addr");
- ProxyPortLable.Text = I18N.GetString("Proxy Port");
- OKButton.Text = I18N.GetString("OK");
- MyCancelButton.Text = I18N.GetString("Cancel");
- this.Text = I18N.GetString("Edit Proxy");
- }
-
- private void controller_ConfigChanged(object sender, EventArgs e)
- {
- LoadCurrentConfiguration();
- }
-
- private void LoadCurrentConfiguration()
- {
- _modifiedConfiguration = controller.GetConfigurationCopy();
-
- UseProxyCheckBox.Checked = _modifiedConfiguration.useProxy;
- ProxyServerTextBox.Text = _modifiedConfiguration.proxyServer;
- ProxyPortTextBox.Text = _modifiedConfiguration.proxyPort.ToString();
- }
-
- private void OKButton_Click(object sender, EventArgs e)
- {
- if (UseProxyCheckBox.Checked)
- {
- try
- {
- var proxy = ProxyServerTextBox.Text;
- var port = int.Parse(ProxyPortTextBox.Text);
- Configuration.CheckServer(proxy);
- Configuration.CheckPort(port);
-
- controller.EnableProxy(proxy, port);
- }
- catch (FormatException)
- {
- MessageBox.Show(I18N.GetString("Illegal port number format"));
- return;
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- return;
- }
- }
- else
- {
- controller.DisableProxy();
- }
- this.Close();
- }
-
- private void CancelButton_Click(object sender, EventArgs e)
- {
- this.Close();
- }
-
- private void ProxyForm_FormClosed(object sender, FormClosedEventArgs e)
- {
- controller.ConfigChanged -= controller_ConfigChanged;
- }
-
- private void UseProxyCheckBox_CheckedChanged(object sender, EventArgs e)
- {
- UpdateEnabled();
- }
-
- private void UpdateEnabled()
- {
- if (UseProxyCheckBox.Checked)
- {
- ProxyServerTextBox.Enabled = true;
- ProxyPortTextBox.Enabled = true;
- }
- else
- {
- ProxyServerTextBox.Enabled = false;
- ProxyPortTextBox.Enabled = false;
- }
- }
- }
-}
+using System;
+using System.Drawing;
+using System.Windows.Forms;
+using Shadowsocks.Controller;
+using Shadowsocks.Model;
+using Shadowsocks.Properties;
+
+namespace Shadowsocks.View
+{
+ public partial class ProxyForm : Form
+ {
+ private ShadowsocksController controller;
+
+ // this is a copy of configuration that we are working on
+ private ProxyConfig _modifiedConfiguration;
+
+ public ProxyForm(ShadowsocksController controller)
+ {
+ this.Font = System.Drawing.SystemFonts.MessageBoxFont;
+ InitializeComponent();
+
+ UpdateTexts();
+ this.Icon = Icon.FromHandle(Resources.ssw128.GetHicon());
+
+ this.controller = controller;
+ controller.ConfigChanged += controller_ConfigChanged;
+
+ UpdateEnabled();
+ LoadCurrentConfiguration();
+ }
+
+ private void UpdateTexts()
+ {
+ UseProxyCheckBox.Text = I18N.GetString("Use Proxy");
+ ProxyAddrLabel.Text = I18N.GetString("Proxy Addr");
+ ProxyPortLable.Text = I18N.GetString("Proxy Port");
+ OKButton.Text = I18N.GetString("OK");
+ MyCancelButton.Text = I18N.GetString("Cancel");
+ this.Text = I18N.GetString("Edit Proxy");
+ }
+
+ private void controller_ConfigChanged(object sender, EventArgs e)
+ {
+ LoadCurrentConfiguration();
+ }
+
+ private void LoadCurrentConfiguration()
+ {
+ _modifiedConfiguration = controller.GetConfigurationCopy().proxy;
+ if(_modifiedConfiguration == null)
+ _modifiedConfiguration = new ProxyConfig();
+ UseProxyCheckBox.Checked = _modifiedConfiguration.useProxy;
+ ProxyServerTextBox.Text = _modifiedConfiguration.proxyServer;
+ ProxyPortTextBox.Text = _modifiedConfiguration.proxyPort.ToString();
+ }
+
+ private void OKButton_Click(object sender, EventArgs e)
+ {
+ if (UseProxyCheckBox.Checked)
+ {
+ try
+ {
+ var proxy = ProxyServerTextBox.Text;
+ var port = int.Parse(ProxyPortTextBox.Text);
+ Configuration.CheckServer(proxy);
+ Configuration.CheckPort(port);
+
+ controller.EnableProxy(proxy, port);
+ }
+ catch (FormatException)
+ {
+ MessageBox.Show(I18N.GetString("Illegal port number format"));
+ return;
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message);
+ return;
+ }
+ }
+ else
+ {
+ controller.DisableProxy();
+ }
+ this.Close();
+ }
+
+ private void CancelButton_Click(object sender, EventArgs e)
+ {
+ this.Close();
+ }
+
+ private void ProxyForm_FormClosed(object sender, FormClosedEventArgs e)
+ {
+ controller.ConfigChanged -= controller_ConfigChanged;
+ var conf = controller.GetConfigurationCopy().proxy;
+ if (conf == null)
+ conf = new ProxyConfig();
+ conf.useProxy = UseProxyCheckBox.Checked;
+ conf.proxyServer = ProxyServerTextBox.Text;
+ int tmpProxyPort;
+ int.TryParse(ProxyPortTextBox.Text, out tmpProxyPort);
+ conf.proxyPort = tmpProxyPort;
+ controller.SaveProxyConfig(conf);
+
+ }
+
+ private void UseProxyCheckBox_CheckedChanged(object sender, EventArgs e)
+ {
+ UpdateEnabled();
+ }
+
+ private void UpdateEnabled()
+ {
+ if (UseProxyCheckBox.Checked)
+ {
+ ProxyServerTextBox.Enabled = true;
+ ProxyPortTextBox.Enabled = true;
+ }
+ else
+ {
+ ProxyServerTextBox.Text = string.Empty;
+ ProxyPortTextBox.Text = string.Empty;
+ ProxyServerTextBox.Enabled = false;
+ ProxyPortTextBox.Enabled = false;
+ }
+ }
+ }
+}
diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj
index ba6cbec5..c8c47596 100644
--- a/shadowsocks-csharp/shadowsocks-csharp.csproj
+++ b/shadowsocks-csharp/shadowsocks-csharp.csproj
@@ -139,6 +139,7 @@
+