Browse Source

input validation

tags/2.3
clowwindy 10 years ago
parent
commit
0859d03f4d
2 changed files with 30 additions and 2 deletions
  1. +28
    -0
      shadowsocks-csharp/Model/Config.cs
  2. +2
    -2
      shadowsocks-csharp/View/ConfigForm.cs

+ 28
- 0
shadowsocks-csharp/Model/Config.cs View File

@@ -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)))


+ 2
- 2
shadowsocks-csharp/View/ConfigForm.cs View File

@@ -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);
}
}


Loading…
Cancel
Save