Browse Source

fixed shadowsocks/shadowsocks-windows/#2371

tags/4.1.7
Stzx 6 years ago
parent
commit
5556a060ab
2 changed files with 19 additions and 3 deletions
  1. +10
    -0
      shadowsocks-csharp/Model/Configuration.cs
  2. +9
    -3
      shadowsocks-csharp/View/ConfigForm.cs

+ 10
- 0
shadowsocks-csharp/Model/Configuration.cs View File

@@ -125,6 +125,16 @@ namespace Shadowsocks.Model
} }
} }
public static Server AddDefaultServerOrServer(Configuration config, Server server = null)
{
if (config != null && config.configs != null)
{
server = (server ?? GetDefaultServer());
config.configs.Add(server);
}
return server;
}
public static Server GetDefaultServer() public static Server GetDefaultServer()
{ {
return new Server(); return new Server();


+ 9
- 3
shadowsocks-csharp/View/ConfigForm.cs View File

@@ -273,8 +273,7 @@ namespace Shadowsocks.View
{ {
return; return;
} }
Server server = Configuration.GetDefaultServer();
_modifiedConfiguration.configs.Add(server);
Configuration.AddDefaultServerOrServer(_modifiedConfiguration);
LoadServerNameListToUI(_modifiedConfiguration); LoadServerNameListToUI(_modifiedConfiguration);
ServersListBox.SelectedIndex = _modifiedConfiguration.configs.Count - 1; ServersListBox.SelectedIndex = _modifiedConfiguration.configs.Count - 1;
_lastSelectedIndex = ServersListBox.SelectedIndex; _lastSelectedIndex = ServersListBox.SelectedIndex;
@@ -282,7 +281,8 @@ namespace Shadowsocks.View
private void DuplicateButton_Click(object sender, EventArgs e) private void DuplicateButton_Click(object sender, EventArgs e)
{ {
if (!ValidateAndSaveSelectedServerDetails())
if (_lastSelectedIndex == -1 || _lastSelectedIndex > _modifiedConfiguration.configs.Count
|| !ValidateAndSaveSelectedServerDetails())
{ {
return; return;
} }
@@ -301,6 +301,10 @@ namespace Shadowsocks.View
{ {
_modifiedConfiguration.configs.RemoveAt(_lastSelectedIndex); _modifiedConfiguration.configs.RemoveAt(_lastSelectedIndex);
} }
if (_modifiedConfiguration.configs.Count == 0)
{
Configuration.AddDefaultServerOrServer(_modifiedConfiguration);
}
if (_lastSelectedIndex >= _modifiedConfiguration.configs.Count) if (_lastSelectedIndex >= _modifiedConfiguration.configs.Count)
{ {
// can be -1 // can be -1
@@ -310,6 +314,8 @@ namespace Shadowsocks.View
LoadServerNameListToUI(_modifiedConfiguration); LoadServerNameListToUI(_modifiedConfiguration);
ServersListBox.SelectedIndex = _lastSelectedIndex; ServersListBox.SelectedIndex = _lastSelectedIndex;
LoadSelectedServerDetails(); LoadSelectedServerDetails();
UpdateButtons();
} }
private void OKButton_Click(object sender, EventArgs e) private void OKButton_Click(object sender, EventArgs e)


Loading…
Cancel
Save