|
@@ -16,9 +16,9 @@ namespace Shadowsocks.View |
|
|
private UpdateChecker updateChecker;
|
|
|
private UpdateChecker updateChecker;
|
|
|
|
|
|
|
|
|
// this is a copy of configuration that we are working on
|
|
|
// this is a copy of configuration that we are working on
|
|
|
private Configuration modifiedConfiguration;
|
|
|
|
|
|
private int oldSelectedIndex = -1;
|
|
|
|
|
|
private bool isFirstRun;
|
|
|
|
|
|
|
|
|
private Configuration _modifiedConfiguration;
|
|
|
|
|
|
private int _oldSelectedIndex = -1;
|
|
|
|
|
|
private bool _isFirstRun;
|
|
|
|
|
|
|
|
|
public ConfigForm(ShadowsocksController controller)
|
|
|
public ConfigForm(ShadowsocksController controller)
|
|
|
{
|
|
|
{
|
|
@@ -66,7 +66,7 @@ namespace Shadowsocks.View |
|
|
notifyIcon1.BalloonTipIcon = ToolTipIcon.Info;
|
|
|
notifyIcon1.BalloonTipIcon = ToolTipIcon.Info;
|
|
|
notifyIcon1.BalloonTipClicked += notifyIcon1_BalloonTipClicked;
|
|
|
notifyIcon1.BalloonTipClicked += notifyIcon1_BalloonTipClicked;
|
|
|
notifyIcon1.ShowBalloonTip(5000);
|
|
|
notifyIcon1.ShowBalloonTip(5000);
|
|
|
isFirstRun = false;
|
|
|
|
|
|
|
|
|
_isFirstRun = false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
void notifyIcon1_BalloonTipClicked(object sender, EventArgs e)
|
|
|
void notifyIcon1_BalloonTipClicked(object sender, EventArgs e)
|
|
@@ -86,7 +86,7 @@ namespace Shadowsocks.View |
|
|
{
|
|
|
{
|
|
|
try
|
|
|
try
|
|
|
{
|
|
|
{
|
|
|
if (oldSelectedIndex == -1 || oldSelectedIndex >= modifiedConfiguration.configs.Count)
|
|
|
|
|
|
|
|
|
if (_oldSelectedIndex == -1 || _oldSelectedIndex >= _modifiedConfiguration.configs.Count)
|
|
|
{
|
|
|
{
|
|
|
return true;
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
@@ -100,7 +100,8 @@ namespace Shadowsocks.View |
|
|
remarks = RemarksTextBox.Text
|
|
|
remarks = RemarksTextBox.Text
|
|
|
};
|
|
|
};
|
|
|
Configuration.CheckServer(server);
|
|
|
Configuration.CheckServer(server);
|
|
|
modifiedConfiguration.configs[oldSelectedIndex] = server;
|
|
|
|
|
|
|
|
|
_modifiedConfiguration.configs[_oldSelectedIndex] = server;
|
|
|
|
|
|
|
|
|
return true;
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
catch (FormatException)
|
|
|
catch (FormatException)
|
|
@@ -116,15 +117,15 @@ namespace Shadowsocks.View |
|
|
|
|
|
|
|
|
private void LoadSelectedServer()
|
|
|
private void LoadSelectedServer()
|
|
|
{
|
|
|
{
|
|
|
if (ServersListBox.SelectedIndex >= 0 && ServersListBox.SelectedIndex < modifiedConfiguration.configs.Count)
|
|
|
|
|
|
|
|
|
if (ServersListBox.SelectedIndex >= 0 && ServersListBox.SelectedIndex < _modifiedConfiguration.configs.Count)
|
|
|
{
|
|
|
{
|
|
|
Server server = modifiedConfiguration.configs[ServersListBox.SelectedIndex];
|
|
|
|
|
|
|
|
|
Server server = _modifiedConfiguration.configs[ServersListBox.SelectedIndex];
|
|
|
|
|
|
|
|
|
IPTextBox.Text = server.server;
|
|
|
IPTextBox.Text = server.server;
|
|
|
ServerPortTextBox.Text = server.server_port.ToString();
|
|
|
ServerPortTextBox.Text = server.server_port.ToString();
|
|
|
PasswordTextBox.Text = server.password;
|
|
|
PasswordTextBox.Text = server.password;
|
|
|
ProxyPortTextBox.Text = server.local_port.ToString();
|
|
|
ProxyPortTextBox.Text = server.local_port.ToString();
|
|
|
EncryptionSelect.Text = server.method == null ? "aes-256-cfb" : server.method;
|
|
|
|
|
|
|
|
|
EncryptionSelect.Text = server.method ?? "aes-256-cfb";
|
|
|
RemarksTextBox.Text = server.remarks;
|
|
|
RemarksTextBox.Text = server.remarks;
|
|
|
ServerGroupBox.Visible = true;
|
|
|
ServerGroupBox.Visible = true;
|
|
|
//IPTextBox.Focus();
|
|
|
//IPTextBox.Focus();
|
|
@@ -138,7 +139,7 @@ namespace Shadowsocks.View |
|
|
private void LoadConfiguration(Configuration configuration)
|
|
|
private void LoadConfiguration(Configuration configuration)
|
|
|
{
|
|
|
{
|
|
|
ServersListBox.Items.Clear();
|
|
|
ServersListBox.Items.Clear();
|
|
|
foreach (Server server in modifiedConfiguration.configs)
|
|
|
|
|
|
|
|
|
foreach (Server server in _modifiedConfiguration.configs)
|
|
|
{
|
|
|
{
|
|
|
ServersListBox.Items.Add(string.IsNullOrEmpty(server.server) ? "New server" : string.IsNullOrEmpty(server.remarks)? server.server + ":" + server.server_port : server.server + ":" + server.server_port + " (" + server.remarks + ")");
|
|
|
ServersListBox.Items.Add(string.IsNullOrEmpty(server.server) ? "New server" : string.IsNullOrEmpty(server.remarks)? server.server + ":" + server.server_port : server.server + ":" + server.server_port + " (" + server.remarks + ")");
|
|
|
}
|
|
|
}
|
|
@@ -146,15 +147,15 @@ namespace Shadowsocks.View |
|
|
|
|
|
|
|
|
private void LoadCurrentConfiguration()
|
|
|
private void LoadCurrentConfiguration()
|
|
|
{
|
|
|
{
|
|
|
modifiedConfiguration = controller.GetConfiguration();
|
|
|
|
|
|
LoadConfiguration(modifiedConfiguration);
|
|
|
|
|
|
oldSelectedIndex = modifiedConfiguration.index;
|
|
|
|
|
|
ServersListBox.SelectedIndex = modifiedConfiguration.index;
|
|
|
|
|
|
|
|
|
_modifiedConfiguration = controller.GetConfiguration();
|
|
|
|
|
|
LoadConfiguration(_modifiedConfiguration);
|
|
|
|
|
|
_oldSelectedIndex = _modifiedConfiguration.index;
|
|
|
|
|
|
ServersListBox.SelectedIndex = _modifiedConfiguration.index;
|
|
|
LoadSelectedServer();
|
|
|
LoadSelectedServer();
|
|
|
|
|
|
|
|
|
UpdateServersMenu();
|
|
|
UpdateServersMenu();
|
|
|
enableItem.Checked = modifiedConfiguration.enabled;
|
|
|
|
|
|
ShareOverLANItem.Checked = modifiedConfiguration.shareOverLan;
|
|
|
|
|
|
|
|
|
enableItem.Checked = _modifiedConfiguration.enabled;
|
|
|
|
|
|
ShareOverLANItem.Checked = _modifiedConfiguration.shareOverLan;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
private void UpdateServersMenu()
|
|
|
private void UpdateServersMenu()
|
|
@@ -193,14 +194,14 @@ namespace Shadowsocks.View |
|
|
}
|
|
|
}
|
|
|
else
|
|
|
else
|
|
|
{
|
|
|
{
|
|
|
isFirstRun = true;
|
|
|
|
|
|
|
|
|
_isFirstRun = true;
|
|
|
}
|
|
|
}
|
|
|
updateChecker.CheckUpdate();
|
|
|
updateChecker.CheckUpdate();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
private void ServersListBox_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
private void ServersListBox_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
{
|
|
|
{
|
|
|
if (oldSelectedIndex == ServersListBox.SelectedIndex)
|
|
|
|
|
|
|
|
|
if (_oldSelectedIndex == ServersListBox.SelectedIndex)
|
|
|
{
|
|
|
{
|
|
|
// we are moving back to oldSelectedIndex or doing a force move
|
|
|
// we are moving back to oldSelectedIndex or doing a force move
|
|
|
return;
|
|
|
return;
|
|
@@ -208,11 +209,11 @@ namespace Shadowsocks.View |
|
|
if (!SaveOldSelectedServer())
|
|
|
if (!SaveOldSelectedServer())
|
|
|
{
|
|
|
{
|
|
|
// why this won't cause stack overflow?
|
|
|
// why this won't cause stack overflow?
|
|
|
ServersListBox.SelectedIndex = oldSelectedIndex;
|
|
|
|
|
|
|
|
|
ServersListBox.SelectedIndex = _oldSelectedIndex;
|
|
|
return;
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
LoadSelectedServer();
|
|
|
LoadSelectedServer();
|
|
|
oldSelectedIndex = ServersListBox.SelectedIndex;
|
|
|
|
|
|
|
|
|
_oldSelectedIndex = ServersListBox.SelectedIndex;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
private void AddButton_Click(object sender, EventArgs e)
|
|
|
private void AddButton_Click(object sender, EventArgs e)
|
|
@@ -222,27 +223,27 @@ namespace Shadowsocks.View |
|
|
return;
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
Server server = Configuration.GetDefaultServer();
|
|
|
Server server = Configuration.GetDefaultServer();
|
|
|
modifiedConfiguration.configs.Add(server);
|
|
|
|
|
|
LoadConfiguration(modifiedConfiguration);
|
|
|
|
|
|
ServersListBox.SelectedIndex = modifiedConfiguration.configs.Count - 1;
|
|
|
|
|
|
oldSelectedIndex = ServersListBox.SelectedIndex;
|
|
|
|
|
|
|
|
|
_modifiedConfiguration.configs.Add(server);
|
|
|
|
|
|
LoadConfiguration(_modifiedConfiguration);
|
|
|
|
|
|
ServersListBox.SelectedIndex = _modifiedConfiguration.configs.Count - 1;
|
|
|
|
|
|
_oldSelectedIndex = ServersListBox.SelectedIndex;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
private void DeleteButton_Click(object sender, EventArgs e)
|
|
|
private void DeleteButton_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
{
|
|
|
oldSelectedIndex = ServersListBox.SelectedIndex;
|
|
|
|
|
|
if (oldSelectedIndex >= 0 && oldSelectedIndex < modifiedConfiguration.configs.Count)
|
|
|
|
|
|
|
|
|
_oldSelectedIndex = ServersListBox.SelectedIndex;
|
|
|
|
|
|
if (_oldSelectedIndex >= 0 && _oldSelectedIndex < _modifiedConfiguration.configs.Count)
|
|
|
{
|
|
|
{
|
|
|
modifiedConfiguration.configs.RemoveAt(oldSelectedIndex);
|
|
|
|
|
|
|
|
|
_modifiedConfiguration.configs.RemoveAt(_oldSelectedIndex);
|
|
|
}
|
|
|
}
|
|
|
if (oldSelectedIndex >= modifiedConfiguration.configs.Count)
|
|
|
|
|
|
|
|
|
if (_oldSelectedIndex >= _modifiedConfiguration.configs.Count)
|
|
|
{
|
|
|
{
|
|
|
// can be -1
|
|
|
// can be -1
|
|
|
oldSelectedIndex = modifiedConfiguration.configs.Count - 1;
|
|
|
|
|
|
|
|
|
_oldSelectedIndex = _modifiedConfiguration.configs.Count - 1;
|
|
|
}
|
|
|
}
|
|
|
ServersListBox.SelectedIndex = oldSelectedIndex;
|
|
|
|
|
|
LoadConfiguration(modifiedConfiguration);
|
|
|
|
|
|
ServersListBox.SelectedIndex = oldSelectedIndex;
|
|
|
|
|
|
|
|
|
ServersListBox.SelectedIndex = _oldSelectedIndex;
|
|
|
|
|
|
LoadConfiguration(_modifiedConfiguration);
|
|
|
|
|
|
ServersListBox.SelectedIndex = _oldSelectedIndex;
|
|
|
LoadSelectedServer();
|
|
|
LoadSelectedServer();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
@@ -258,13 +259,13 @@ namespace Shadowsocks.View |
|
|
|
|
|
|
|
|
private void ShowFirstTimeBalloon()
|
|
|
private void ShowFirstTimeBalloon()
|
|
|
{
|
|
|
{
|
|
|
if (isFirstRun)
|
|
|
|
|
|
|
|
|
if (_isFirstRun)
|
|
|
{
|
|
|
{
|
|
|
notifyIcon1.BalloonTipTitle = "Shadowsocks is here";
|
|
|
notifyIcon1.BalloonTipTitle = "Shadowsocks is here";
|
|
|
notifyIcon1.BalloonTipText = "You can turn on/off Shadowsocks in the context menu";
|
|
|
notifyIcon1.BalloonTipText = "You can turn on/off Shadowsocks in the context menu";
|
|
|
notifyIcon1.BalloonTipIcon = ToolTipIcon.Info;
|
|
|
notifyIcon1.BalloonTipIcon = ToolTipIcon.Info;
|
|
|
notifyIcon1.ShowBalloonTip(0);
|
|
|
notifyIcon1.ShowBalloonTip(0);
|
|
|
isFirstRun = false;
|
|
|
|
|
|
|
|
|
_isFirstRun = false;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
@@ -274,12 +275,12 @@ namespace Shadowsocks.View |
|
|
{
|
|
|
{
|
|
|
return;
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
if (modifiedConfiguration.configs.Count == 0)
|
|
|
|
|
|
|
|
|
if (_modifiedConfiguration.configs.Count == 0)
|
|
|
{
|
|
|
{
|
|
|
MessageBox.Show("Please add at least one server");
|
|
|
MessageBox.Show("Please add at least one server");
|
|
|
return;
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
controller.SaveServers(modifiedConfiguration.configs);
|
|
|
|
|
|
|
|
|
controller.SaveServers(_modifiedConfiguration.configs);
|
|
|
this.Hide();
|
|
|
this.Hide();
|
|
|
ShowFirstTimeBalloon();
|
|
|
ShowFirstTimeBalloon();
|
|
|
}
|
|
|
}
|
|
|