do not expose SaveConfig to Views
This commit is contained in:
@@ -52,32 +52,6 @@ namespace Shadowsocks.Controller
|
||||
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()
|
||||
{
|
||||
return _config.GetCurrentServer();
|
||||
@@ -89,6 +63,11 @@ namespace Shadowsocks.Controller
|
||||
return Configuration.Load();
|
||||
}
|
||||
|
||||
public void SaveServers(List<Server> servers)
|
||||
{
|
||||
_config.configs = servers;
|
||||
SaveConfig(_config);
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
if (stopped)
|
||||
@@ -143,6 +128,34 @@ namespace Shadowsocks.Controller
|
||||
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()
|
||||
{
|
||||
if (_config.enabled)
|
||||
|
||||
+1
-1
@@ -436,7 +436,7 @@
|
||||
this.MaximizeBox = false;
|
||||
this.Name = "ConfigForm";
|
||||
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.Load += new System.EventHandler(this.ConfigForm_Load);
|
||||
this.Shown += new System.EventHandler(this.ConfigForm_Shown);
|
||||
|
||||
@@ -258,7 +258,7 @@ namespace Shadowsocks.View
|
||||
MessageBox.Show("Please add at least one server");
|
||||
return;
|
||||
}
|
||||
controller.SaveConfig(modifiedConfiguration);
|
||||
controller.SaveServers(modifiedConfiguration.configs);
|
||||
this.Hide();
|
||||
ShowFirstTimeBalloon();
|
||||
}
|
||||
@@ -306,9 +306,7 @@ namespace Shadowsocks.View
|
||||
private void AServerItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user