From f75ffc06fccac8292817763460f016f670a32465 Mon Sep 17 00:00:00 2001 From: celeron533 Date: Wed, 6 Feb 2019 21:34:01 +0800 Subject: [PATCH] Minor updates --- shadowsocks-csharp/Controller/I18N.cs | 7 ++++--- shadowsocks-csharp/Controller/Service/Listener.cs | 13 ++----------- .../Controller/ShadowsocksController.cs | 2 +- shadowsocks-csharp/Data/ja.txt | 2 +- shadowsocks-csharp/Data/zh_CN.txt | 2 +- shadowsocks-csharp/Data/zh_TW.txt | 2 +- shadowsocks-csharp/Model/Configuration.cs | 4 ++-- shadowsocks-csharp/View/HotkeySettingsForm.cs | 2 +- shadowsocks-csharp/View/MenuViewController.cs | 6 +++--- 9 files changed, 16 insertions(+), 24 deletions(-) diff --git a/shadowsocks-csharp/Controller/I18N.cs b/shadowsocks-csharp/Controller/I18N.cs index 45217b7a..b4dd6632 100755 --- a/shadowsocks-csharp/Controller/I18N.cs +++ b/shadowsocks-csharp/Controller/I18N.cs @@ -44,11 +44,12 @@ namespace Shadowsocks.Controller } } - public static string GetString(string key) + public static string GetString(string key, params object[] args) { return _strings.ContainsKey(key) - ? _strings[key] - : key; + ? string.Format(_strings[key], args) + : string.Format(key, args); } + } } diff --git a/shadowsocks-csharp/Controller/Service/Listener.cs b/shadowsocks-csharp/Controller/Service/Listener.cs index 3da7a394..2ad7d4fa 100644 --- a/shadowsocks-csharp/Controller/Service/Listener.cs +++ b/shadowsocks-csharp/Controller/Service/Listener.cs @@ -46,16 +46,7 @@ namespace Shadowsocks.Controller private bool CheckIfPortInUse(int port) { IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties(); - IPEndPoint[] ipEndPoints = ipProperties.GetActiveTcpListeners(); - - foreach (IPEndPoint endPoint in ipEndPoints) - { - if (endPoint.Port == port) - { - return true; - } - } - return false; + return ipProperties.GetActiveTcpListeners().Any(endPoint => endPoint.Port == port); } public void Start(Configuration config) @@ -64,7 +55,7 @@ namespace Shadowsocks.Controller this._shareOverLAN = config.shareOverLan; if (CheckIfPortInUse(_config.localPort)) - throw new Exception(I18N.GetString("Port already in use")); + throw new Exception(I18N.GetString("Port {0} already in use", _config.localPort)); try { diff --git a/shadowsocks-csharp/Controller/ShadowsocksController.cs b/shadowsocks-csharp/Controller/ShadowsocksController.cs index 860d56be..9a9c3a48 100644 --- a/shadowsocks-csharp/Controller/ShadowsocksController.cs +++ b/shadowsocks-csharp/Controller/ShadowsocksController.cs @@ -553,7 +553,7 @@ namespace Shadowsocks.Controller SocketException se = (SocketException)e; if (se.SocketErrorCode == SocketError.AccessDenied) { - e = new Exception(I18N.GetString("Port already in use"), e); + e = new Exception(I18N.GetString("Port {0} already in use", _config.localPort), e); } } Logging.LogUsefulException(e); diff --git a/shadowsocks-csharp/Data/ja.txt b/shadowsocks-csharp/Data/ja.txt index 06ce0513..bd9b9311 100644 --- a/shadowsocks-csharp/Data/ja.txt +++ b/shadowsocks-csharp/Data/ja.txt @@ -113,7 +113,7 @@ Reg Hotkeys At Startup=起動時にホットキーを登録する # Messages Shadowsocks Error: {0}=Shadowsocks エラー: {0} -Port already in use=ポートは既に使用されています。 +Port {0} already in use=ポート番号 {0} は既に使用されています。 Invalid server address=サーバーアドレスが無効です。 Illegal port number format=ポート番号のフォーマットが無効です。 Illegal timeout format=タイムアウト値のフォーマットが無効です。 diff --git a/shadowsocks-csharp/Data/zh_CN.txt b/shadowsocks-csharp/Data/zh_CN.txt index 9cc80ff8..bccb8ff1 100644 --- a/shadowsocks-csharp/Data/zh_CN.txt +++ b/shadowsocks-csharp/Data/zh_CN.txt @@ -113,7 +113,7 @@ Reg Hotkeys At Startup=启动时注册快捷键 # Messages Shadowsocks Error: {0}=Shadowsocks 错误: {0} -Port already in use=端口已被占用 +Port {0} already in use=端口 {0} 已被占用 Invalid server address=非法服务器地址 Illegal port number format=非法端口格式 Illegal timeout format=非法超时格式 diff --git a/shadowsocks-csharp/Data/zh_TW.txt b/shadowsocks-csharp/Data/zh_TW.txt index 703d4c65..035151cf 100644 --- a/shadowsocks-csharp/Data/zh_TW.txt +++ b/shadowsocks-csharp/Data/zh_TW.txt @@ -113,7 +113,7 @@ Reg Hotkeys At Startup=啟動時註冊快速鍵 # Messages Shadowsocks Error: {0}=Shadowsocks 錯誤: {0} -Port already in use=連接埠號碼已被使用 +Port {0} already in use=連接埠號碼 {0} 已被使用 Invalid server address=無效伺服器位址 Illegal port number format=無效連接埠號碼格式 Illegal timeout format=無效逾時格式 diff --git a/shadowsocks-csharp/Model/Configuration.cs b/shadowsocks-csharp/Model/Configuration.cs index 57b847a1..366d087d 100644 --- a/shadowsocks-csharp/Model/Configuration.cs +++ b/shadowsocks-csharp/Model/Configuration.cs @@ -164,8 +164,8 @@ namespace Shadowsocks.Model public static void CheckTimeout(int timeout, int maxTimeout) { if (timeout <= 0 || timeout > maxTimeout) - throw new ArgumentException(string.Format( - I18N.GetString("Timeout is invalid, it should not exceed {0}"), maxTimeout)); + throw new ArgumentException( + I18N.GetString("Timeout is invalid, it should not exceed {0}", maxTimeout)); } } } diff --git a/shadowsocks-csharp/View/HotkeySettingsForm.cs b/shadowsocks-csharp/View/HotkeySettingsForm.cs index 8610e993..d5f44edc 100644 --- a/shadowsocks-csharp/View/HotkeySettingsForm.cs +++ b/shadowsocks-csharp/View/HotkeySettingsForm.cs @@ -185,7 +185,7 @@ namespace Shadowsocks.View switch (result) { case RegResult.ParseError: - MessageBox.Show(string.Format(I18N.GetString("Cannot parse hotkey: {0}"), hotkeyStr)); + MessageBox.Show(I18N.GetString("Cannot parse hotkey: {0}", hotkeyStr)); break; case RegResult.UnregSuccess: label.ResetBackColor(); diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index a0730314..bf5b138a 100644 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -134,7 +134,7 @@ namespace Shadowsocks.View void controller_Errored(object sender, System.IO.ErrorEventArgs e) { - MessageBox.Show(e.GetException().ToString(), String.Format(I18N.GetString("Shadowsocks Error: {0}"), e.GetException().Message)); + MessageBox.Show(e.GetException().ToString(), I18N.GetString("Shadowsocks Error: {0}", e.GetException().Message)); } #region Tray Icon @@ -185,7 +185,7 @@ namespace Shadowsocks.View string text = I18N.GetString("Shadowsocks") + " " + UpdateChecker.Version + "\n" + (enabled ? I18N.GetString("System Proxy On: ") + (global ? I18N.GetString("Global") : I18N.GetString("PAC")) : - String.Format(I18N.GetString("Running: Port {0}"), config.localPort)) // this feedback is very important because they need to know Shadowsocks is running + I18N.GetString("Running: Port {0}", config.localPort)) // this feedback is very important because they need to know Shadowsocks is running + "\n" + serverInfo; if (text.Length > 127) { @@ -371,7 +371,7 @@ namespace Shadowsocks.View { if (updateChecker.NewVersionFound) { - ShowBalloonTip(String.Format(I18N.GetString("Shadowsocks {0} Update Found"), updateChecker.LatestVersionNumber + updateChecker.LatestVersionSuffix), I18N.GetString("Click here to update"), ToolTipIcon.Info, 5000); + ShowBalloonTip(I18N.GetString("Shadowsocks {0} Update Found", updateChecker.LatestVersionNumber + updateChecker.LatestVersionSuffix), I18N.GetString("Click here to update"), ToolTipIcon.Info, 5000); } else if (!_isStartupChecking) {