@@ -6,6 +6,7 @@ using System.Net; | |||||
using System.Diagnostics; | using System.Diagnostics; | ||||
using System.Text; | using System.Text; | ||||
using Shadowsocks.Util; | using Shadowsocks.Util; | ||||
using Shadowsocks.Util.SystemProxy; | |||||
namespace Shadowsocks.Controller | namespace Shadowsocks.Controller | ||||
{ | { | ||||
@@ -145,6 +146,24 @@ namespace Shadowsocks.Controller | |||||
{ | { | ||||
Info(e); | Info(e); | ||||
} | } | ||||
} | |||||
else if (e is ProxyException) | |||||
{ | |||||
var ex = (ProxyException)e; | |||||
switch (ex.Type) | |||||
{ | |||||
case ProxyExceptionType.FailToRun: | |||||
case ProxyExceptionType.QueryReturnMalformed: | |||||
case ProxyExceptionType.SysproxyExitError: | |||||
Error($"sysproxy - {ex.Type.ToString()}:{ex.Message}"); | |||||
break; | |||||
case ProxyExceptionType.QueryReturnEmpty: | |||||
case ProxyExceptionType.Unspecific: | |||||
Error($"sysproxy - {ex.Type.ToString()}"); | |||||
break; | |||||
} | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
@@ -1,4 +1,5 @@ | |||||
using System; | using System; | ||||
using System.Windows.Forms; | |||||
using Shadowsocks.Model; | using Shadowsocks.Model; | ||||
using Shadowsocks.Util.SystemProxy; | using Shadowsocks.Util.SystemProxy; | ||||
@@ -6,6 +7,8 @@ namespace Shadowsocks.Controller | |||||
{ | { | ||||
public static class SystemProxy | public static class SystemProxy | ||||
{ | { | ||||
private static bool failed = false; | |||||
private static string GetTimestamp(DateTime value) | private static string GetTimestamp(DateTime value) | ||||
{ | { | ||||
return value.ToString("yyyyMMddHHmmssfff"); | return value.ToString("yyyyMMddHHmmssfff"); | ||||
@@ -13,6 +16,7 @@ namespace Shadowsocks.Controller | |||||
public static void Update(Configuration config, bool forceDisable, PACServer pacSrv) | public static void Update(Configuration config, bool forceDisable, PACServer pacSrv) | ||||
{ | { | ||||
if (failed) return; | |||||
bool global = config.global; | bool global = config.global; | ||||
bool enabled = config.enabled; | bool enabled = config.enabled; | ||||
@@ -51,6 +55,19 @@ namespace Shadowsocks.Controller | |||||
catch (ProxyException ex) | catch (ProxyException ex) | ||||
{ | { | ||||
Logging.LogUsefulException(ex); | Logging.LogUsefulException(ex); | ||||
switch (ex.Type) | |||||
{ | |||||
case ProxyExceptionType.FailToRun: | |||||
MessageBox.Show(I18N.GetString("Error when running sysproxy, check your proxy config"), I18N.GetString("Shadowsocks")); | |||||
break; | |||||
case ProxyExceptionType.QueryReturnMalformed: | |||||
case ProxyExceptionType.QueryReturnEmpty: | |||||
MessageBox.Show(I18N.GetString("Can't query proxy config, check your proxy config"), I18N.GetString("Shadowsocks")); | |||||
break; | |||||
case ProxyExceptionType.SysproxyExitError: | |||||
MessageBox.Show(I18N.GetString("Sysproxy return a error:") + ex.Message, I18N.GetString("Shadowsocks")); | |||||
break; | |||||
} | |||||
} | } | ||||
} | } | ||||
} | } |
@@ -148,3 +148,7 @@ Proxy handshake failed=プロキシ ハンドシェイクに失敗しました | |||||
Register hotkey failed=ホットキーの登錄に失敗しました。 | Register hotkey failed=ホットキーの登錄に失敗しました。 | ||||
Cannot parse hotkey: {0}=ホットキーを解析できません: {0} | Cannot parse hotkey: {0}=ホットキーを解析できません: {0} | ||||
Timeout is invalid, it should not exceed {0}=タイムアウト値が無効です。{0} 以下の値を指定して下さい。 | Timeout is invalid, it should not exceed {0}=タイムアウト値が無効です。{0} 以下の値を指定して下さい。 | ||||
Error when running sysproxy, check your proxy config=执行sysproxy时发生错误,请检查你的系统代理设置 | |||||
Can't query proxy config, check your proxy config=无法解析代理配置,请检查你的系统代理设置 | |||||
Sysproxy return a error:=sysproxy报告了一个错误: |
@@ -148,3 +148,7 @@ Proxy handshake failed=代理握手失败 | |||||
Register hotkey failed=注册快捷键失败 | Register hotkey failed=注册快捷键失败 | ||||
Cannot parse hotkey: {0}=解析快捷键失败: {0} | Cannot parse hotkey: {0}=解析快捷键失败: {0} | ||||
Timeout is invalid, it should not exceed {0}=超时无效,不应超过 {0} | Timeout is invalid, it should not exceed {0}=超时无效,不应超过 {0} | ||||
Error when running sysproxy, check your proxy config=执行sysproxy时发生错误,请检查你的系统代理设置 | |||||
Can't query proxy config, check your proxy config=无法解析代理配置,请检查你的系统代理设置 | |||||
Sysproxy return a error:=sysproxy报告了一个错误: |
@@ -148,3 +148,7 @@ Proxy handshake failed=Proxy 交握失敗 | |||||
Register hotkey failed=註冊快速鍵失敗 | Register hotkey failed=註冊快速鍵失敗 | ||||
Cannot parse hotkey: {0}=剖析快速鍵失敗: {0} | Cannot parse hotkey: {0}=剖析快速鍵失敗: {0} | ||||
Timeout is invalid, it should not exceed {0}=逾時無效,不應超過 {0} | Timeout is invalid, it should not exceed {0}=逾時無效,不應超過 {0} | ||||
Error when running sysproxy, check your proxy config=执行sysproxy时发生错误,请检查你的系统代理设置 | |||||
Can't query proxy config, check your proxy config=无法解析代理配置,请检查你的系统代理设置 | |||||
Sysproxy return a error:=sysproxy报告了一个错误: |
@@ -7,8 +7,20 @@ using System.Threading.Tasks; | |||||
namespace Shadowsocks.Util.SystemProxy | namespace Shadowsocks.Util.SystemProxy | ||||
{ | { | ||||
enum ProxyExceptionType | |||||
{ | |||||
Unspecific, | |||||
FailToRun, | |||||
QueryReturnEmpty, | |||||
SysproxyExitError, | |||||
QueryReturnMalformed | |||||
} | |||||
class ProxyException : Exception | class ProxyException : Exception | ||||
{ | { | ||||
// provide more specific information about exception | |||||
public ProxyExceptionType Type { get; } | |||||
public ProxyException() | public ProxyException() | ||||
{ | { | ||||
} | } | ||||
@@ -24,5 +36,24 @@ namespace Shadowsocks.Util.SystemProxy | |||||
protected ProxyException(SerializationInfo info, StreamingContext context) : base(info, context) | protected ProxyException(SerializationInfo info, StreamingContext context) : base(info, context) | ||||
{ | { | ||||
} | } | ||||
public ProxyException(ProxyExceptionType type) | |||||
{ | |||||
this.Type = type; | |||||
} | |||||
public ProxyException(ProxyExceptionType type, string message) : base(message) | |||||
{ | |||||
this.Type = type; | |||||
} | |||||
public ProxyException(ProxyExceptionType type, string message, Exception innerException) : base(message, innerException) | |||||
{ | |||||
this.Type = type; | |||||
} | |||||
protected ProxyException(ProxyExceptionType type, SerializationInfo info, StreamingContext context) : base(info, context) | |||||
{ | |||||
this.Type = type; | |||||
} | |||||
} | } | ||||
} | } |
@@ -1,12 +1,12 @@ | |||||
using System; | |||||
using Newtonsoft.Json; | |||||
using Shadowsocks.Controller; | |||||
using Shadowsocks.Model; | |||||
using Shadowsocks.Properties; | |||||
using System; | |||||
using System.Diagnostics; | using System.Diagnostics; | ||||
using System.IO; | using System.IO; | ||||
using System.Text; | using System.Text; | ||||
using System.Threading; | using System.Threading; | ||||
using Shadowsocks.Controller; | |||||
using Shadowsocks.Properties; | |||||
using Shadowsocks.Model; | |||||
using Newtonsoft.Json; | |||||
namespace Shadowsocks.Util.SystemProxy | namespace Shadowsocks.Util.SystemProxy | ||||
{ | { | ||||
@@ -132,13 +132,21 @@ namespace Shadowsocks.Util.SystemProxy | |||||
error.AppendLine(e.Data); | error.AppendLine(e.Data); | ||||
} | } | ||||
}; | }; | ||||
try | |||||
{ | |||||
process.Start(); | |||||
process.Start(); | |||||
process.BeginErrorReadLine(); | |||||
process.BeginOutputReadLine(); | |||||
process.BeginErrorReadLine(); | |||||
process.BeginOutputReadLine(); | |||||
process.WaitForExit(); | |||||
} | |||||
catch (System.ComponentModel.Win32Exception e) | |||||
{ | |||||
// log the arguements | |||||
throw new ProxyException(ProxyExceptionType.FailToRun, process.StartInfo.Arguments, e); | |||||
} | |||||
process.WaitForExit(); | |||||
var stderr = error.ToString(); | var stderr = error.ToString(); | ||||
var stdout = output.ToString(); | var stdout = output.ToString(); | ||||
@@ -146,7 +154,7 @@ namespace Shadowsocks.Util.SystemProxy | |||||
var exitCode = process.ExitCode; | var exitCode = process.ExitCode; | ||||
if (exitCode != (int)RET_ERRORS.RET_NO_ERROR) | if (exitCode != (int)RET_ERRORS.RET_NO_ERROR) | ||||
{ | { | ||||
throw new ProxyException(stderr); | |||||
throw new ProxyException(ProxyExceptionType.SysproxyExitError, stderr); | |||||
} | } | ||||
if (arguments == "query") | if (arguments == "query") | ||||
@@ -154,7 +162,7 @@ namespace Shadowsocks.Util.SystemProxy | |||||
if (stdout.IsNullOrWhiteSpace() || stdout.IsNullOrEmpty()) | if (stdout.IsNullOrWhiteSpace() || stdout.IsNullOrEmpty()) | ||||
{ | { | ||||
// we cannot get user settings | // we cannot get user settings | ||||
throw new ProxyException("failed to query wininet settings"); | |||||
throw new ProxyException(ProxyExceptionType.QueryReturnEmpty); | |||||
} | } | ||||
_queryStr = stdout; | _queryStr = stdout; | ||||
} | } | ||||
@@ -210,10 +218,10 @@ namespace Shadowsocks.Util.SystemProxy | |||||
// still fail, throw exception with string hexdump | // still fail, throw exception with string hexdump | ||||
if (userSettingsArr.Length != 4) | if (userSettingsArr.Length != 4) | ||||
{ | { | ||||
throw new ProxyException("Unexpected sysproxy output:" + BitConverter.ToString(strByte)); | |||||
throw new ProxyException(ProxyExceptionType.QueryReturnMalformed, BitConverter.ToString(strByte)); | |||||
} | } | ||||
} | } | ||||
_userSettings.Flags = userSettingsArr[0]; | _userSettings.Flags = userSettingsArr[0]; | ||||
// handle output from WinINET | // handle output from WinINET | ||||