Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 498e8ed

Browse files
committedSep 16, 2017
to support empty passwd by issue #3
1 parent 781006b commit 498e8ed

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed
 

‎shadowsocks-csharp/Data/cn.txt

+1
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ Illegal port number format=非法端口格式
216216
Please add at least one server=请添加至少一个服务器
217217
Server IP can not be blank=服务器 IP 不能为空
218218
Password can not be blank=密码不能为空
219+
Password are blank=密码为空
219220
Port out of range=端口超出范围
220221
{0} {1} Update Found={0} {1} 更新
221222
Click menu to download=点击菜单项下载

‎shadowsocks-csharp/Data/zh-tw.txt

+1
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ Illegal port number format=非法連接埠格式
204204
Please add at least one server=請添加至少一個伺服器
205205
Server IP can not be blank=伺服器 IP 不能為空
206206
Password can not be blank=密碼不能為空
207+
Password are blank=密碼為空
207208
Port out of range=連接埠超出範圍
208209
{0} {1} Update Found={0} {1} 更新
209210
Click menu to download=點擊菜單項下載

‎shadowsocks-csharp/Model/Configuration.cs

+37-7
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,27 @@ public class GlobalConfiguration
7878
public static string config_password = "";
7979
}
8080

81+
[Serializable()]
82+
class ConfigurationException : System.Exception
83+
{
84+
public ConfigurationException() : base() { }
85+
public ConfigurationException(string message) : base(message) { }
86+
public ConfigurationException(string message, System.Exception inner) : base(message, inner) { }
87+
protected ConfigurationException(System.Runtime.Serialization.SerializationInfo info,
88+
System.Runtime.Serialization.StreamingContext context)
89+
{ }
90+
}
91+
[Serializable()]
92+
class ConfigurationWarning : System.Exception
93+
{
94+
public ConfigurationWarning() : base() { }
95+
public ConfigurationWarning(string message) : base(message) { }
96+
public ConfigurationWarning(string message, System.Exception inner) : base(message, inner) { }
97+
protected ConfigurationWarning(System.Runtime.Serialization.SerializationInfo info,
98+
System.Runtime.Serialization.StreamingContext context)
99+
{ }
100+
}
101+
81102
[Serializable]
82103
public class Configuration
83104
{
@@ -219,7 +240,7 @@ public Server GetCurrentServer(int localPort, ServerSelectStrategy.FilterFunc fi
219240
if (selServer != null)
220241
return selServer.group == server.group;
221242
return false;
222-
} , true);
243+
}, true);
223244
}
224245
else
225246
{
@@ -370,7 +391,15 @@ public static void CheckServer(Server server)
370391
CheckPort(server.server_port);
371392
if (server.server_udp_port != 0)
372393
CheckPort(server.server_udp_port);
373-
CheckPassword(server.password);
394+
try
395+
{
396+
CheckPassword(server.password);
397+
}
398+
catch (ConfigurationWarning cw)
399+
{
400+
server.password = "";
401+
MessageBox.Show(cw.Message, cw.Message, MessageBoxButtons.OK, MessageBoxIcon.Warning);
402+
}
374403
CheckServer(server.server);
375404
}
376405

@@ -619,23 +648,24 @@ public static void CheckPort(int port)
619648
{
620649
if (port <= 0 || port > 65535)
621650
{
622-
throw new ArgumentException(I18N.GetString("Port out of range"));
651+
throw new ConfigurationException(I18N.GetString("Port out of range"));
623652
}
624653
}
625654

626655
private static void CheckPassword(string password)
627656
{
628657
if (string.IsNullOrEmpty(password))
629658
{
630-
throw new ArgumentException(I18N.GetString("Password can not be blank"));
659+
throw new ConfigurationWarning(I18N.GetString("Password are blank"));
660+
//throw new ConfigurationException(I18N.GetString("Password can not be blank"));
631661
}
632662
}
633663

634664
private static void CheckServer(string server)
635665
{
636666
if (string.IsNullOrEmpty(server))
637667
{
638-
throw new ArgumentException(I18N.GetString("Server IP can not be blank"));
668+
throw new ConfigurationException(I18N.GetString("Server IP can not be blank"));
639669
}
640670
}
641671

@@ -777,7 +807,7 @@ public void AddUpload(string server, Int64 size)
777807
if (--saveCounter <= 0)
778808
{
779809
saveCounter = 256;
780-
if ((DateTime.Now - saveTime).TotalMinutes > 10 )
810+
if ((DateTime.Now - saveTime).TotalMinutes > 10)
781811
{
782812
lock (servers)
783813
{
@@ -798,7 +828,7 @@ public void AddDownload(string server, Int64 size)
798828
if (--saveCounter <= 0)
799829
{
800830
saveCounter = 256;
801-
if ((DateTime.Now - saveTime).TotalMinutes > 10 )
831+
if ((DateTime.Now - saveTime).TotalMinutes > 10)
802832
{
803833
lock (servers)
804834
{

0 commit comments

Comments
 (0)
Please sign in to comment.