Browse Source

add modify detector

Add a detector to check whether the server setting changed.
pull/44/head
wzxjohn 10 years ago
parent
commit
9eac4abd20
2 changed files with 17 additions and 7 deletions
  1. +12
    -6
      shadowsocks-csharp/Controller/ShadowsocksController.cs
  2. +5
    -1
      shadowsocks-csharp/View/ConfigForm.cs

+ 12
- 6
shadowsocks-csharp/Controller/ShadowsocksController.cs View File

@@ -42,15 +42,15 @@ namespace Shadowsocks.Controller
}
openOnLan = _config.openOnLan;
polipoRunner = new PolipoRunner();
polipoRunner = new PolipoRunner();
polipoRunner.Start(_config);
local = new Local(_config);
local = new Local(_config);
try
{
local.Start();
pacServer = new PACServer();
pacServer.PACFileChanged += pacServer_PACFileChanged;
pacServer.Start(_config);
pacServer.PACFileChanged += pacServer_PACFileChanged;
pacServer.Start(_config);
}
catch (Exception e)
{
@@ -59,7 +59,7 @@ namespace Shadowsocks.Controller
UpdateSystemProxy();
}
public Server GetCurrentServer()
{
return _config.GetCurrentServer();
@@ -71,9 +71,10 @@ namespace Shadowsocks.Controller
return Configuration.Load();
}
public void SaveServers(List<Server> servers)
public void SaveServers(List<Server> servers, bool noChange)
{
_config.configs = servers;
_config.noChange = noChange;
SaveConfig(_config);
}
@@ -91,6 +92,7 @@ namespace Shadowsocks.Controller
public void ToggleShareOverLAN(bool enabled)
{
_config.shareOverLan = enabled;
_config.noChange = false;
SaveConfig(_config);
if (ShareOverLANStatusChanged != null)
{
@@ -142,6 +144,10 @@ namespace Shadowsocks.Controller
Configuration.Save(newConfig);
// some logic in configuration updated the config when saving, we need to read it again
_config = Configuration.Load();
if (newConfig.noChange)
{
return;
}
pacServer.Stop();
local.Stop();


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

@@ -122,6 +122,10 @@ namespace Shadowsocks.View
_oldConfiguration = _modifiedConfiguration;
}
}
else
{
_modifiedConfiguration.noChange = false;
}
return true;
}
catch (FormatException)
@@ -301,7 +305,7 @@ namespace Shadowsocks.View
MessageBox.Show("Please add at least one server");
return;
}
controller.SaveServers(_modifiedConfiguration.configs);
controller.SaveServers(_modifiedConfiguration.configs, _modifiedConfiguration.noChange);
this.Hide();
ShowFirstTimeBalloon();
}


Loading…
Cancel
Save