From 8b0d7604ed7badb5f5229edcd87fef1886552185 Mon Sep 17 00:00:00 2001 From: wzxjohn Date: Sun, 9 Nov 2014 15:01:36 +0800 Subject: [PATCH] add modify detector Don't reload server if config not change. --- shadowsocks-csharp/Controller/ShadowsocksController.cs | 10 ++++++++-- shadowsocks-csharp/View/ConfigForm.Designer.cs | 1 - shadowsocks-csharp/View/ConfigForm.cs | 4 ++-- shadowsocks-csharp/View/QRCodeForm.cs | 4 ++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/shadowsocks-csharp/Controller/ShadowsocksController.cs b/shadowsocks-csharp/Controller/ShadowsocksController.cs index 53ce3753..5bb1b836 100755 --- a/shadowsocks-csharp/Controller/ShadowsocksController.cs +++ b/shadowsocks-csharp/Controller/ShadowsocksController.cs @@ -57,7 +57,7 @@ namespace Shadowsocks.Controller UpdateSystemProxy(); } - + public Server GetCurrentServer() { return _config.GetCurrentServer(); @@ -69,9 +69,10 @@ namespace Shadowsocks.Controller return Configuration.Load(); } - public void SaveServers(List servers) + public void SaveServers(List servers, bool noChange) { _config.configs = servers; + _config.noChange = noChange; SaveConfig(_config); } @@ -89,6 +90,7 @@ namespace Shadowsocks.Controller public void ToggleShareOverLAN(bool enabled) { _config.shareOverLan = enabled; + _config.noChange = false; SaveConfig(_config); if (ShareOverLANStatusChanged != null) { @@ -138,6 +140,10 @@ namespace Shadowsocks.Controller protected void SaveConfig(Configuration newConfig) { Configuration.Save(newConfig); + if (newConfig.noChange) + { + return; + } // some logic in configuration updated the config when saving, we need to read it again _config = Configuration.Load(); diff --git a/shadowsocks-csharp/View/ConfigForm.Designer.cs b/shadowsocks-csharp/View/ConfigForm.Designer.cs index c1187c04..cf874286 100755 --- a/shadowsocks-csharp/View/ConfigForm.Designer.cs +++ b/shadowsocks-csharp/View/ConfigForm.Designer.cs @@ -434,7 +434,6 @@ this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; - this.MinimizeBox = false; this.Name = "ConfigForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Edit Servers"; diff --git a/shadowsocks-csharp/View/ConfigForm.cs b/shadowsocks-csharp/View/ConfigForm.cs index eb2a3d8f..92b49c2b 100755 --- a/shadowsocks-csharp/View/ConfigForm.cs +++ b/shadowsocks-csharp/View/ConfigForm.cs @@ -279,8 +279,8 @@ 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(); } diff --git a/shadowsocks-csharp/View/QRCodeForm.cs b/shadowsocks-csharp/View/QRCodeForm.cs index 12c5b6fd..87bcef50 100755 --- a/shadowsocks-csharp/View/QRCodeForm.cs +++ b/shadowsocks-csharp/View/QRCodeForm.cs @@ -24,12 +24,12 @@ namespace Shadowsocks.View private void GenQR(string ssconfig) { - string qrText = ssconfig; + string qrText = ssconfig; QRCode4CS.Options options = new QRCode4CS.Options(); options.Text = qrText; QRCode4CS.QRCode qrCoded = null; bool success = false; - foreach (var level in new QRErrorCorrectLevel[]{QRErrorCorrectLevel.H, QRErrorCorrectLevel.Q, QRErrorCorrectLevel.M, QRErrorCorrectLevel.L}) + foreach (var level in new QRErrorCorrectLevel[]{QRErrorCorrectLevel.H, QRErrorCorrectLevel.Q, QRErrorCorrectLevel.M, QRErrorCorrectLevel.L}) { for (int i = 3; i < 10; i++) {