diff --git a/shadowsocks-csharp/Model/Config.cs b/shadowsocks-csharp/Model/Config.cs index f5c7270f..50a3bcaf 100755 --- a/shadowsocks-csharp/Model/Config.cs +++ b/shadowsocks-csharp/Model/Config.cs @@ -58,8 +58,36 @@ namespace shadowsocks_csharp } } + private static void checkPort(int port) + { + if (port <= 0 || port > 65535) + { + throw new ArgumentException("port out of range"); + } + } + + private static void checkPassword(string password) + { + if (string.IsNullOrEmpty(password)) + { + throw new ArgumentException("password can not be blank"); + } + } + + private static void checkServer(string server) + { + if (string.IsNullOrEmpty(server)) + { + throw new ArgumentException("server can not be blank"); + } + } + public static void Save(Config config) { + checkPort(config.local_port); + checkPort(config.server_port); + checkPassword(config.password); + checkServer(config.server); try { using (StreamWriter sw = new StreamWriter(File.Open(@"config.json", FileMode.Create))) diff --git a/shadowsocks-csharp/View/ConfigForm.cs b/shadowsocks-csharp/View/ConfigForm.cs index b6e6139c..22e86e86 100755 --- a/shadowsocks-csharp/View/ConfigForm.cs +++ b/shadowsocks-csharp/View/ConfigForm.cs @@ -93,11 +93,11 @@ namespace shadowsocks_csharp } catch (FormatException) { - MessageBox.Show("there is format problem"); + MessageBox.Show("illegal port number format"); } catch (Exception ex) { - MessageBox.Show(ex.ToString()); + MessageBox.Show(ex.Message); } }