From a05a7822934ed06e8541a9163001af28e7e48c68 Mon Sep 17 00:00:00 2001 From: database64128 Date: Thu, 15 Oct 2020 18:24:49 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9D=8C=20Remove=20ShadowsocksController.GetC?= =?UTF-8?q?onfigurationCopy()=20and=20ServerSharingWindow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/ShadowsocksController.cs | 18 +----- .../System/Hotkeys/HotkeyCallbacks.cs | 11 ++-- shadowsocks-csharp/ServerSharingWindow.xaml | 11 ---- .../ServerSharingWindow.xaml.cs | 27 --------- shadowsocks-csharp/View/ConfigForm.cs | 2 +- shadowsocks-csharp/View/HotkeySettingsForm.cs | 2 +- shadowsocks-csharp/View/LogForm.cs | 6 +- shadowsocks-csharp/View/MenuViewController.cs | 55 +++++++++++-------- shadowsocks-csharp/View/OnlineConfigForm.cs | 2 +- shadowsocks-csharp/View/ProxyForm.cs | 2 +- shadowsocks-csharp/shadowsocks-csharp.csproj | 7 --- 11 files changed, 45 insertions(+), 98 deletions(-) delete mode 100644 shadowsocks-csharp/ServerSharingWindow.xaml delete mode 100644 shadowsocks-csharp/ServerSharingWindow.xaml.cs diff --git a/shadowsocks-csharp/Controller/ShadowsocksController.cs b/shadowsocks-csharp/Controller/ShadowsocksController.cs index 8eaec1b0..61d5458b 100644 --- a/shadowsocks-csharp/Controller/ShadowsocksController.cs +++ b/shadowsocks-csharp/Controller/ShadowsocksController.cs @@ -250,22 +250,8 @@ namespace Shadowsocks.Controller Errored?.Invoke(this, new ErrorEventArgs(e)); } - public Server GetCurrentServer() - { - return _config.GetCurrentServer(); - } - - // always return copy - public Configuration GetConfigurationCopy() - { - return Configuration.Load(); - } - - // always return current instance - public Configuration GetCurrentConfiguration() - { - return _config; - } + public Server GetCurrentServer() => _config.GetCurrentServer(); + public Configuration GetCurrentConfiguration() => _config; public Server GetAServer(IStrategyCallerType type, IPEndPoint localIPEndPoint, EndPoint destEndPoint) { diff --git a/shadowsocks-csharp/Controller/System/Hotkeys/HotkeyCallbacks.cs b/shadowsocks-csharp/Controller/System/Hotkeys/HotkeyCallbacks.cs index 7c94c93c..08f15836 100644 --- a/shadowsocks-csharp/Controller/System/Hotkeys/HotkeyCallbacks.cs +++ b/shadowsocks-csharp/Controller/System/Hotkeys/HotkeyCallbacks.cs @@ -46,21 +46,20 @@ namespace Shadowsocks.Controller.Hotkeys private void SwitchSystemProxyCallback() { - bool enabled = _controller.GetConfigurationCopy().enabled; + bool enabled = _controller.GetCurrentConfiguration().enabled; _controller.ToggleEnable(!enabled); } private void SwitchSystemProxyModeCallback() { - var config = _controller.GetConfigurationCopy(); - if (config.enabled == false) return; - var currStatus = config.global; - _controller.ToggleGlobal(!currStatus); + var config = _controller.GetCurrentConfiguration(); + if (config.enabled) + _controller.ToggleGlobal(!config.global); } private void SwitchAllowLanCallback() { - var status = _controller.GetConfigurationCopy().shareOverLan; + var status = _controller.GetCurrentConfiguration().shareOverLan; _controller.ToggleShareOverLAN(!status); } diff --git a/shadowsocks-csharp/ServerSharingWindow.xaml b/shadowsocks-csharp/ServerSharingWindow.xaml deleted file mode 100644 index 6cc585c3..00000000 --- a/shadowsocks-csharp/ServerSharingWindow.xaml +++ /dev/null @@ -1,11 +0,0 @@ - - - diff --git a/shadowsocks-csharp/ServerSharingWindow.xaml.cs b/shadowsocks-csharp/ServerSharingWindow.xaml.cs deleted file mode 100644 index f48e5eaa..00000000 --- a/shadowsocks-csharp/ServerSharingWindow.xaml.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; - -namespace Shadowsocks -{ - /// - /// Interaction logic for ServerSharingWindow.xaml - /// - public partial class ServerSharingWindow : Window - { - public ServerSharingWindow() - { - InitializeComponent(); - } - } -} diff --git a/shadowsocks-csharp/View/ConfigForm.cs b/shadowsocks-csharp/View/ConfigForm.cs index ab029f7e..3f947851 100755 --- a/shadowsocks-csharp/View/ConfigForm.cs +++ b/shadowsocks-csharp/View/ConfigForm.cs @@ -433,7 +433,7 @@ namespace Shadowsocks.View private void LoadCurrentConfiguration() { - _modifiedConfiguration = controller.GetConfigurationCopy(); + _modifiedConfiguration = controller.GetCurrentConfiguration(); LoadServerNameListToUI(_modifiedConfiguration); _lastSelectedIndex = _modifiedConfiguration.index; diff --git a/shadowsocks-csharp/View/HotkeySettingsForm.cs b/shadowsocks-csharp/View/HotkeySettingsForm.cs index b55e9ef1..58c0f6bd 100644 --- a/shadowsocks-csharp/View/HotkeySettingsForm.cs +++ b/shadowsocks-csharp/View/HotkeySettingsForm.cs @@ -40,7 +40,7 @@ namespace Shadowsocks.View private void LoadCurrentConfiguration() { - _modifiedHotkeyConfig = _controller.GetConfigurationCopy().hotkey; + _modifiedHotkeyConfig = _controller.GetCurrentConfiguration().hotkey; SetConfigToUI(_modifiedHotkeyConfig); } diff --git a/shadowsocks-csharp/View/LogForm.cs b/shadowsocks-csharp/View/LogForm.cs index 06b0f678..9f5efbeb 100644 --- a/shadowsocks-csharp/View/LogForm.cs +++ b/shadowsocks-csharp/View/LogForm.cs @@ -62,7 +62,7 @@ namespace Shadowsocks.View LogMessageTextBox.AppendText("Cannot get the log file name from NLog config file. Please check if the nlog config file exists with corresponding XML nodes."); } - LogViewerConfig config = controller.GetConfigurationCopy().logViewer; + LogViewerConfig config = controller.GetCurrentConfiguration().logViewer; topMostTrigger = config.topMost; wrapTextTrigger = config.wrapText; @@ -244,7 +244,7 @@ namespace Shadowsocks.View timer.Tick += Timer_Tick; timer.Start(); - LogViewerConfig config = controller.GetConfigurationCopy().logViewer; + LogViewerConfig config = controller.GetCurrentConfiguration().logViewer; Height = config.Height; Width = config.Width; @@ -270,7 +270,7 @@ namespace Shadowsocks.View { timer.Stop(); controller.TrafficChanged -= controller_TrafficChanged; - LogViewerConfig config = controller.GetConfigurationCopy().logViewer; + LogViewerConfig config = controller.GetCurrentConfiguration().logViewer; config.topMost = topMostTrigger; config.wrapText = wrapTextTrigger; diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index 1da2ef9b..8ba600ac 100644 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -3,6 +3,7 @@ using Shadowsocks.Controller; using Shadowsocks.Model; using Shadowsocks.Properties; using Shadowsocks.Util; +using Shadowsocks.Views; using System; using System.Diagnostics; using System.Drawing; @@ -65,7 +66,7 @@ namespace Shadowsocks.View private HotkeySettingsForm hotkeySettingsForm; private OnlineConfigForm onlineConfigForm; - private ServerSharingWindow serverSharingWindow; + private System.Windows.Window serverSharingWindow; // color definition for icon color transformation private readonly Color colorMaskBlue = Color.FromArgb(255, 25, 125, 191); @@ -106,7 +107,7 @@ namespace Shadowsocks.View LoadCurrentConfiguration(); - Configuration config = controller.GetConfigurationCopy(); + Configuration config = controller.GetCurrentConfiguration(); if (config.firstRun) { @@ -123,7 +124,7 @@ namespace Shadowsocks.View private void UpdateTrayIconAndNotifyText() { - Configuration config = controller.GetConfigurationCopy(); + Configuration config = controller.GetCurrentConfiguration(); bool enabled = config.enabled; bool global = config.global; @@ -349,7 +350,7 @@ namespace Shadowsocks.View private void LoadCurrentConfiguration() { - Configuration config = controller.GetConfigurationCopy(); + Configuration config = controller.GetCurrentConfiguration(); UpdateServersMenu(); UpdateSystemProxyItemsEnabledStatus(config); ShareOverLANItem.Checked = config.shareOverLan; @@ -537,7 +538,7 @@ namespace Shadowsocks.View private void CheckUpdateForFirstRun() { - Configuration config = controller.GetConfigurationCopy(); + Configuration config = controller.GetCurrentConfiguration(); if (config.firstRun) return; _isStartupChecking = true; @@ -555,7 +556,7 @@ namespace Shadowsocks.View void controller_ShareOverLANStatusChanged(object sender, EventArgs e) { - ShareOverLANItem.Checked = controller.GetConfigurationCopy().shareOverLan; + ShareOverLANItem.Checked = controller.GetCurrentConfiguration().shareOverLan; } private void proxyItem_Click(object sender, EventArgs e) @@ -612,19 +613,19 @@ namespace Shadowsocks.View private void controller_EnableStatusChanged(object sender, EventArgs e) { - disableItem.Checked = !controller.GetConfigurationCopy().enabled; + disableItem.Checked = !controller.GetCurrentConfiguration().enabled; } private void EnableItem_Click(object sender, EventArgs e) { controller.ToggleEnable(false); - Configuration config = controller.GetConfigurationCopy(); + Configuration config = controller.GetCurrentConfiguration(); UpdateSystemProxyItemsEnabledStatus(config); } void controller_EnableGlobalChanged(object sender, EventArgs e) { - globalModeItem.Checked = controller.GetConfigurationCopy().global; + globalModeItem.Checked = controller.GetCurrentConfiguration().global; PACModeItem.Checked = !globalModeItem.Checked; } @@ -647,7 +648,7 @@ namespace Shadowsocks.View { controller.ToggleEnable(true); controller.ToggleGlobal(true); - Configuration config = controller.GetConfigurationCopy(); + Configuration config = controller.GetCurrentConfiguration(); UpdateSystemProxyItemsEnabledStatus(config); } @@ -655,7 +656,7 @@ namespace Shadowsocks.View { controller.ToggleEnable(true); controller.ToggleGlobal(false); - Configuration config = controller.GetConfigurationCopy(); + Configuration config = controller.GetCurrentConfiguration(); UpdateSystemProxyItemsEnabledStatus(config); } @@ -684,7 +685,7 @@ namespace Shadowsocks.View items.Add(strategyCount++, new MenuItem("-")); int serverCount = 0; - Configuration configuration = controller.GetConfigurationCopy(); + Configuration configuration = controller.GetCurrentConfiguration(); foreach (var server in configuration.configs) { try @@ -747,7 +748,13 @@ namespace Shadowsocks.View { if (serverSharingWindow == null) { - serverSharingWindow = new ServerSharingWindow(); + serverSharingWindow = new System.Windows.Window() + { + Title = "Server Sharing", + Height = 400, + Width = 660, + Content = new ServerSharingView() + }; serverSharingWindow.Closed += ServerSharingWindow_Closed; serverSharingWindow.Show(); } @@ -870,11 +877,11 @@ namespace Shadowsocks.View { if (!onlinePACItem.Checked) { - if (string.IsNullOrEmpty(controller.GetConfigurationCopy().pacUrl)) + if (string.IsNullOrEmpty(controller.GetCurrentConfiguration().pacUrl)) { UpdateOnlinePACURLItem_Click(sender, e); } - if (!string.IsNullOrEmpty(controller.GetConfigurationCopy().pacUrl)) + if (!string.IsNullOrEmpty(controller.GetCurrentConfiguration().pacUrl)) { localPACItem.Checked = false; onlinePACItem.Checked = true; @@ -886,7 +893,7 @@ namespace Shadowsocks.View private void UpdateOnlinePACURLItem_Click(object sender, EventArgs e) { - string origPacUrl = controller.GetConfigurationCopy().pacUrl; + string origPacUrl = controller.GetCurrentConfiguration().pacUrl; string pacUrl = Microsoft.VisualBasic.Interaction.InputBox( I18N.GetString("Please input PAC Url"), I18N.GetString("Edit Online PAC URL"), @@ -899,13 +906,13 @@ namespace Shadowsocks.View private void SecureLocalPacUrlToggleItem_Click(object sender, EventArgs e) { - Configuration configuration = controller.GetConfigurationCopy(); + Configuration configuration = controller.GetCurrentConfiguration(); controller.ToggleSecureLocalPac(!configuration.secureLocalPac); } private void RegenerateLocalPacOnUpdateItem_Click(object sender, EventArgs e) { - var config = controller.GetConfigurationCopy(); + var config = controller.GetCurrentConfiguration(); controller.ToggleRegeneratePacOnUpdate(!config.regeneratePacOnUpdate); } @@ -974,12 +981,12 @@ namespace Shadowsocks.View void controller_VerboseLoggingStatusChanged(object sender, EventArgs e) { - VerboseLoggingToggleItem.Checked = controller.GetConfigurationCopy().isVerboseLogging; + VerboseLoggingToggleItem.Checked = controller.GetCurrentConfiguration().isVerboseLogging; } void controller_ShowPluginOutputChanged(object sender, EventArgs e) { - ShowPluginOutputToggleItem.Checked = controller.GetConfigurationCopy().showPluginOutput; + ShowPluginOutputToggleItem.Checked = controller.GetCurrentConfiguration().showPluginOutput; } private void VerboseLoggingToggleItem_Click(object sender, EventArgs e) @@ -1023,28 +1030,28 @@ namespace Shadowsocks.View private void UpdateUpdateMenu() { - Configuration configuration = controller.GetConfigurationCopy(); + Configuration configuration = controller.GetCurrentConfiguration(); autoCheckUpdatesToggleItem.Checked = configuration.autoCheckUpdate; checkPreReleaseToggleItem.Checked = configuration.checkPreRelease; } private void autoCheckUpdatesToggleItem_Click(object sender, EventArgs e) { - Configuration configuration = controller.GetConfigurationCopy(); + Configuration configuration = controller.GetCurrentConfiguration(); controller.ToggleCheckingUpdate(!configuration.autoCheckUpdate); UpdateUpdateMenu(); } private void checkPreReleaseToggleItem_Click(object sender, EventArgs e) { - Configuration configuration = controller.GetConfigurationCopy(); + Configuration configuration = controller.GetCurrentConfiguration(); controller.ToggleCheckingPreRelease(!configuration.checkPreRelease); UpdateUpdateMenu(); } private void checkUpdatesItem_Click(object sender, EventArgs e) { - updateChecker.CheckUpdate(controller.GetConfigurationCopy()); + updateChecker.CheckUpdate(controller.GetCurrentConfiguration()); } private void AboutItem_Click(object sender, EventArgs e) diff --git a/shadowsocks-csharp/View/OnlineConfigForm.cs b/shadowsocks-csharp/View/OnlineConfigForm.cs index fca0ed57..344472da 100644 --- a/shadowsocks-csharp/View/OnlineConfigForm.cs +++ b/shadowsocks-csharp/View/OnlineConfigForm.cs @@ -24,7 +24,7 @@ namespace Shadowsocks.View private void LoadConfig() { - config = controller.GetConfigurationCopy(); + config = controller.GetCurrentConfiguration(); var idx = UrlListBox.SelectedIndex; UrlListBox.Items.Clear(); diff --git a/shadowsocks-csharp/View/ProxyForm.cs b/shadowsocks-csharp/View/ProxyForm.cs index 218f296f..240c38e1 100644 --- a/shadowsocks-csharp/View/ProxyForm.cs +++ b/shadowsocks-csharp/View/ProxyForm.cs @@ -41,7 +41,7 @@ namespace Shadowsocks.View private void LoadCurrentConfiguration() { - _modifiedProxyConfig = controller.GetConfigurationCopy().proxy; + _modifiedProxyConfig = controller.GetCurrentConfiguration().proxy; UseProxyCheckBox.Checked = _modifiedProxyConfig.useProxy; ProxyServerTextBox.Text = _modifiedProxyConfig.proxyServer; ProxyPortTextBox.Text = _modifiedProxyConfig.proxyPort.ToString(); diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj index 6620a009..148fd47a 100644 --- a/shadowsocks-csharp/shadowsocks-csharp.csproj +++ b/shadowsocks-csharp/shadowsocks-csharp.csproj @@ -257,9 +257,6 @@ - - ServerSharingWindow.xaml - @@ -415,10 +412,6 @@ - - Designer - MSBuild:Compile - Designer MSBuild:Compile