featured: save bandwidth in config.json file
This commit is contained in:
@@ -25,19 +25,17 @@ namespace Shadowsocks.Model
|
||||
public bool availabilityStatistics;
|
||||
public bool autoCheckUpdate;
|
||||
public LogViewerConfig logViewer;
|
||||
public long bandwidthIn;
|
||||
public long bandwidthOut;
|
||||
|
||||
private static string CONFIG_FILE = "gui-config.json";
|
||||
|
||||
public Server GetCurrentServer()
|
||||
{
|
||||
if (index >= 0 && index < configs.Count)
|
||||
{
|
||||
return configs[index];
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetDefaultServer();
|
||||
}
|
||||
}
|
||||
|
||||
public static void CheckServer(Server server)
|
||||
@@ -55,24 +53,15 @@ namespace Shadowsocks.Model
|
||||
Configuration config = JsonConvert.DeserializeObject<Configuration>(configContent);
|
||||
config.isDefault = false;
|
||||
if (config.localPort == 0)
|
||||
{
|
||||
config.localPort = 1080;
|
||||
}
|
||||
if (config.index == -1)
|
||||
{
|
||||
if (config.strategy == null)
|
||||
{
|
||||
config.index = 0;
|
||||
}
|
||||
}
|
||||
if (config.index == -1 && config.strategy == null)
|
||||
config.index = 0;
|
||||
return config;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (!(e is FileNotFoundException))
|
||||
{
|
||||
Logging.LogUsefulException(e);
|
||||
}
|
||||
return new Configuration
|
||||
{
|
||||
index = 0,
|
||||
@@ -90,20 +79,11 @@ namespace Shadowsocks.Model
|
||||
public static void Save(Configuration config)
|
||||
{
|
||||
if (config.index >= config.configs.Count)
|
||||
{
|
||||
config.index = config.configs.Count - 1;
|
||||
}
|
||||
if (config.index < -1)
|
||||
{
|
||||
config.index = -1;
|
||||
}
|
||||
if (config.index == -1)
|
||||
{
|
||||
if (config.strategy == null)
|
||||
{
|
||||
config.index = 0;
|
||||
}
|
||||
}
|
||||
if (config.index == -1 && config.strategy == null)
|
||||
config.index = 0;
|
||||
config.isDefault = false;
|
||||
try
|
||||
{
|
||||
@@ -128,42 +108,32 @@ namespace Shadowsocks.Model
|
||||
private static void Assert(bool condition)
|
||||
{
|
||||
if (!condition)
|
||||
{
|
||||
throw new Exception(I18N.GetString("assertion failure"));
|
||||
}
|
||||
}
|
||||
|
||||
public static void CheckPort(int port)
|
||||
{
|
||||
if (port <= 0 || port > 65535)
|
||||
{
|
||||
throw new ArgumentException(I18N.GetString("Port out of range"));
|
||||
}
|
||||
}
|
||||
|
||||
public static void CheckLocalPort(int port)
|
||||
{
|
||||
CheckPort(port);
|
||||
if (port == 8123)
|
||||
{
|
||||
throw new ArgumentException(I18N.GetString("Port can't be 8123"));
|
||||
}
|
||||
}
|
||||
|
||||
private static void CheckPassword(string password)
|
||||
{
|
||||
if (string.IsNullOrEmpty(password))
|
||||
{
|
||||
throw new ArgumentException(I18N.GetString("Password can not be blank"));
|
||||
}
|
||||
}
|
||||
|
||||
private static void CheckServer(string server)
|
||||
{
|
||||
if (string.IsNullOrEmpty(server))
|
||||
{
|
||||
throw new ArgumentException(I18N.GetString("Server IP can not be blank"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user