Browse Source

do not expose SaveConfig to Views

tags/2.3
clowwindy 10 years ago
parent
commit
7faf2c992b
3 changed files with 42 additions and 31 deletions
  1. +39
    -26
      shadowsocks-csharp/Controller/ShadowsocksController.cs
  2. +1
    -1
      shadowsocks-csharp/View/ConfigForm.Designer.cs
  3. +2
    -4
      shadowsocks-csharp/View/ConfigForm.cs

+ 39
- 26
shadowsocks-csharp/Controller/ShadowsocksController.cs View File

@@ -52,32 +52,6 @@ namespace Shadowsocks.Controller
UpdateSystemProxy(); UpdateSystemProxy();
} }
public void SaveConfig(Configuration newConfig)
{
Configuration.Save(newConfig);
// some logic in configuration updated the config when saving, we need to read it again
_config = Configuration.Load();
pacServer.Stop();
local.Stop();
// don't put polipoRunner.Start() before pacServer.Stop()
// or bind will fail when switching bind address from 0.0.0.0 to 127.0.0.1
// though UseShellExecute is set to true now
// http://stackoverflow.com/questions/10235093/socket-doesnt-close-after-application-exits-if-a-launched-process-is-open
polipoRunner.Stop();
polipoRunner.Start(_config);
local = new Local(_config);
local.Start();
pacServer.Start(_config);
if (ConfigChanged != null)
{
ConfigChanged(this, new EventArgs());
}
}
public Server GetCurrentServer() public Server GetCurrentServer()
{ {
return _config.GetCurrentServer(); return _config.GetCurrentServer();
@@ -89,6 +63,11 @@ namespace Shadowsocks.Controller
return Configuration.Load(); return Configuration.Load();
} }
public void SaveServers(List<Server> servers)
{
_config.configs = servers;
SaveConfig(_config);
}
public void ToggleEnable(bool enabled) public void ToggleEnable(bool enabled)
{ {
@@ -111,6 +90,12 @@ namespace Shadowsocks.Controller
} }
} }
public void SelectServerIndex(int index)
{
_config.index = index;
SaveConfig(_config);
}
public void Stop() public void Stop()
{ {
if (stopped) if (stopped)
@@ -143,6 +128,34 @@ namespace Shadowsocks.Controller
return "ss://" + base64; return "ss://" + base64;
} }
protected void SaveConfig(Configuration newConfig)
{
Configuration.Save(newConfig);
// some logic in configuration updated the config when saving, we need to read it again
_config = Configuration.Load();
pacServer.Stop();
local.Stop();
// don't put polipoRunner.Start() before pacServer.Stop()
// or bind will fail when switching bind address from 0.0.0.0 to 127.0.0.1
// though UseShellExecute is set to true now
// http://stackoverflow.com/questions/10235093/socket-doesnt-close-after-application-exits-if-a-launched-process-is-open
polipoRunner.Stop();
polipoRunner.Start(_config);
local = new Local(_config);
local.Start();
pacServer.Start(_config);
if (ConfigChanged != null)
{
ConfigChanged(this, new EventArgs());
}
}
private void UpdateSystemProxy() private void UpdateSystemProxy()
{ {
if (_config.enabled) if (_config.enabled)


+ 1
- 1
shadowsocks-csharp/View/ConfigForm.Designer.cs View File

@@ -436,7 +436,7 @@
this.MaximizeBox = false; this.MaximizeBox = false;
this.Name = "ConfigForm"; this.Name = "ConfigForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Shadowsocks";
this.Text = "Edit Servers";
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.ConfigForm_FormClosed); this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.ConfigForm_FormClosed);
this.Load += new System.EventHandler(this.ConfigForm_Load); this.Load += new System.EventHandler(this.ConfigForm_Load);
this.Shown += new System.EventHandler(this.ConfigForm_Shown); this.Shown += new System.EventHandler(this.ConfigForm_Shown);


+ 2
- 4
shadowsocks-csharp/View/ConfigForm.cs View File

@@ -258,7 +258,7 @@ namespace Shadowsocks.View
MessageBox.Show("Please add at least one server"); MessageBox.Show("Please add at least one server");
return; return;
} }
controller.SaveConfig(modifiedConfiguration);
controller.SaveServers(modifiedConfiguration.configs);
this.Hide(); this.Hide();
ShowFirstTimeBalloon(); ShowFirstTimeBalloon();
} }
@@ -306,9 +306,7 @@ namespace Shadowsocks.View
private void AServerItem_Click(object sender, EventArgs e) private void AServerItem_Click(object sender, EventArgs e)
{ {
MenuItem item = (MenuItem)sender; MenuItem item = (MenuItem)sender;
Configuration configuration = controller.GetConfiguration();
configuration.index = (int)item.Tag;
controller.SaveConfig(configuration);
controller.SelectServerIndex((int)item.Tag);
} }
private void ShowLogItem_Click(object sender, EventArgs e) private void ShowLogItem_Click(object sender, EventArgs e)


Loading…
Cancel
Save