@@ -10,9 +10,9 @@ namespace Shadowsocks.Controller | |||||
{ | { | ||||
class Local | class Local | ||||
{ | |||||
{ | |||||
private Server _server; | private Server _server; | ||||
private bool _shareOverLAN; | |||||
private bool _shareOverLAN; | |||||
//private Encryptor encryptor; | //private Encryptor encryptor; | ||||
Socket _listener; | Socket _listener; | ||||
public Local(Configuration config) | public Local(Configuration config) | ||||
@@ -26,7 +26,7 @@ namespace Shadowsocks.Controller | |||||
{ | { | ||||
try | try | ||||
{ | { | ||||
// Create a TCP/IP socket. | |||||
// Create a TCP/IP socket. | |||||
_listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); | _listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); | ||||
_listener.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); | _listener.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); | ||||
IPEndPoint localEndPoint = null; | IPEndPoint localEndPoint = null; | ||||
@@ -36,7 +36,7 @@ namespace Shadowsocks.Controller | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
localEndPoint = new IPEndPoint(IPAddress.Loopback, _server.local_port); | |||||
localEndPoint = new IPEndPoint(IPAddress.Loopback, _server.local_port); | |||||
} | } | ||||
// Bind the socket to the local endpoint and listen for incoming connections. | // Bind the socket to the local endpoint and listen for incoming connections. | ||||
@@ -221,7 +221,7 @@ namespace Shadowsocks.Controller | |||||
// reject socks 4 | // reject socks 4 | ||||
response = new byte[]{ 0, 91 }; | response = new byte[]{ 0, 91 }; | ||||
} | } | ||||
connection.BeginSend(response, 0, response.Length, 0, new AsyncCallback(handshakeSendCallback), null); | |||||
connection.BeginSend(response, 0, response.Length, 0, new AsyncCallback(HandshakeSendCallback), null); | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
@@ -235,7 +235,7 @@ namespace Shadowsocks.Controller | |||||
} | } | ||||
} | } | ||||
private void handshakeSendCallback(IAsyncResult ar) | |||||
private void HandshakeSendCallback(IAsyncResult ar) | |||||
{ | { | ||||
try | try | ||||
{ | { | ||||
@@ -267,7 +267,7 @@ namespace Shadowsocks.Controller | |||||
if (bytesRead > 0) | if (bytesRead > 0) | ||||
{ | { | ||||
byte[] response = { 5, 0, 0, 1, 0, 0, 0, 0, 0, 0 }; | byte[] response = { 5, 0, 0, 1, 0, 0, 0, 0, 0, 0 }; | ||||
connection.BeginSend(response, 0, response.Length, 0, new AsyncCallback(startPipe), null); | |||||
connection.BeginSend(response, 0, response.Length, 0, new AsyncCallback(StartPipe), null); | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
@@ -282,15 +282,15 @@ namespace Shadowsocks.Controller | |||||
} | } | ||||
private void startPipe(IAsyncResult ar) | |||||
private void StartPipe(IAsyncResult ar) | |||||
{ | { | ||||
try | try | ||||
{ | { | ||||
connection.EndReceive(ar); | connection.EndReceive(ar); | ||||
remote.BeginReceive(remoteRecvBuffer, 0, RecvSize, 0, | remote.BeginReceive(remoteRecvBuffer, 0, RecvSize, 0, | ||||
new AsyncCallback(pipeRemoteReceiveCallback), null); | |||||
new AsyncCallback(PipeRemoteReceiveCallback), null); | |||||
connection.BeginReceive(connetionRecvBuffer, 0, RecvSize, 0, | connection.BeginReceive(connetionRecvBuffer, 0, RecvSize, 0, | ||||
new AsyncCallback(pipeConnectionReceiveCallback), null); | |||||
new AsyncCallback(PipeConnectionReceiveCallback), null); | |||||
} | } | ||||
catch (Exception e) | catch (Exception e) | ||||
{ | { | ||||
@@ -299,7 +299,7 @@ namespace Shadowsocks.Controller | |||||
} | } | ||||
} | } | ||||
private void pipeRemoteReceiveCallback(IAsyncResult ar) | |||||
private void PipeRemoteReceiveCallback(IAsyncResult ar) | |||||
{ | { | ||||
try | try | ||||
@@ -310,7 +310,7 @@ namespace Shadowsocks.Controller | |||||
{ | { | ||||
int bytesToSend; | int bytesToSend; | ||||
encryptor.Decrypt(remoteRecvBuffer, bytesRead, remoteSendBuffer, out bytesToSend); | encryptor.Decrypt(remoteRecvBuffer, bytesRead, remoteSendBuffer, out bytesToSend); | ||||
connection.BeginSend(remoteSendBuffer, 0, bytesToSend, 0, new AsyncCallback(pipeConnectionSendCallback), null); | |||||
connection.BeginSend(remoteSendBuffer, 0, bytesToSend, 0, new AsyncCallback(PipeConnectionSendCallback), null); | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
@@ -325,7 +325,7 @@ namespace Shadowsocks.Controller | |||||
} | } | ||||
} | } | ||||
private void pipeConnectionReceiveCallback(IAsyncResult ar) | |||||
private void PipeConnectionReceiveCallback(IAsyncResult ar) | |||||
{ | { | ||||
try | try | ||||
@@ -336,7 +336,7 @@ namespace Shadowsocks.Controller | |||||
{ | { | ||||
int bytesToSend; | int bytesToSend; | ||||
encryptor.Encrypt(connetionRecvBuffer, bytesRead, connetionSendBuffer, out bytesToSend); | encryptor.Encrypt(connetionRecvBuffer, bytesRead, connetionSendBuffer, out bytesToSend); | ||||
remote.BeginSend(connetionSendBuffer, 0, bytesToSend, 0, new AsyncCallback(pipeRemoteSendCallback), null); | |||||
remote.BeginSend(connetionSendBuffer, 0, bytesToSend, 0, new AsyncCallback(PipeRemoteSendCallback), null); | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
@@ -350,13 +350,13 @@ namespace Shadowsocks.Controller | |||||
} | } | ||||
} | } | ||||
private void pipeRemoteSendCallback(IAsyncResult ar) | |||||
private void PipeRemoteSendCallback(IAsyncResult ar) | |||||
{ | { | ||||
try | try | ||||
{ | { | ||||
remote.EndSend(ar); | remote.EndSend(ar); | ||||
connection.BeginReceive(this.connetionRecvBuffer, 0, RecvSize, 0, | connection.BeginReceive(this.connetionRecvBuffer, 0, RecvSize, 0, | ||||
new AsyncCallback(pipeConnectionReceiveCallback), null); | |||||
new AsyncCallback(PipeConnectionReceiveCallback), null); | |||||
} | } | ||||
catch (Exception e) | catch (Exception e) | ||||
{ | { | ||||
@@ -365,13 +365,13 @@ namespace Shadowsocks.Controller | |||||
} | } | ||||
} | } | ||||
private void pipeConnectionSendCallback(IAsyncResult ar) | |||||
private void PipeConnectionSendCallback(IAsyncResult ar) | |||||
{ | { | ||||
try | try | ||||
{ | { | ||||
connection.EndSend(ar); | connection.EndSend(ar); | ||||
remote.BeginReceive(this.remoteRecvBuffer, 0, RecvSize, 0, | remote.BeginReceive(this.remoteRecvBuffer, 0, RecvSize, 0, | ||||
new AsyncCallback(pipeRemoteReceiveCallback), null); | |||||
new AsyncCallback(PipeRemoteReceiveCallback), null); | |||||
} | } | ||||
catch (Exception e) | catch (Exception e) | ||||
{ | { | ||||
@@ -31,10 +31,10 @@ namespace Shadowsocks.Controller | |||||
Console.WriteLine(e.ToString()); | Console.WriteLine(e.ToString()); | ||||
} | } | ||||
} | } | ||||
string temppath = Path.GetTempPath(); | |||||
string temppath = Path.GetTempPath(); | |||||
string polipoConfig = Resources.polipo_config; | string polipoConfig = Resources.polipo_config; | ||||
polipoConfig = polipoConfig.Replace("__SOCKS_PORT__", server.local_port.ToString()); | polipoConfig = polipoConfig.Replace("__SOCKS_PORT__", server.local_port.ToString()); | ||||
polipoConfig = polipoConfig.Replace("__POLIPO_BIND_IP__", configuration.shareOverLan ? "0.0.0.0" : "127.0.0.1"); | |||||
polipoConfig = polipoConfig.Replace("__POLIPO_BIND_IP__", configuration.shareOverLan ? "0.0.0.0" : "127.0.0.1"); | |||||
FileManager.ByteArrayToFile(temppath + "/polipo.conf", System.Text.Encoding.UTF8.GetBytes(polipoConfig)); | FileManager.ByteArrayToFile(temppath + "/polipo.conf", System.Text.Encoding.UTF8.GetBytes(polipoConfig)); | ||||
FileManager.UncompressFile(temppath + "/ss_polipo.exe", Resources.polipo_exe); | FileManager.UncompressFile(temppath + "/ss_polipo.exe", Resources.polipo_exe); | ||||
@@ -1,4 +1,5 @@ | |||||
using Shadowsocks.Model; | |||||
using System.IO; | |||||
using Shadowsocks.Model; | |||||
using System; | using System; | ||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Text; | using System.Text; | ||||
@@ -18,6 +19,7 @@ namespace Shadowsocks.Controller | |||||
private Configuration _config; | private Configuration _config; | ||||
private PolipoRunner polipoRunner; | private PolipoRunner polipoRunner; | ||||
private bool stopped = false; | private bool stopped = false; | ||||
private bool openOnLan; | |||||
public class PathEventArgs : EventArgs | public class PathEventArgs : EventArgs | ||||
{ | { | ||||
@@ -34,15 +36,21 @@ namespace Shadowsocks.Controller | |||||
public ShadowsocksController() | public ShadowsocksController() | ||||
{ | { | ||||
_config = Configuration.Load(); | _config = Configuration.Load(); | ||||
polipoRunner = new PolipoRunner(); | |||||
if (_config.enableLog) | |||||
{ | |||||
SetLog(); | |||||
} | |||||
openOnLan = _config.openOnLan; | |||||
polipoRunner = new PolipoRunner(); | |||||
polipoRunner.Start(_config); | polipoRunner.Start(_config); | ||||
local = new Local(_config); | |||||
local = new Local(_config); | |||||
try | try | ||||
{ | { | ||||
local.Start(); | local.Start(); | ||||
pacServer = new PACServer(); | pacServer = new PACServer(); | ||||
pacServer.PACFileChanged += pacServer_PACFileChanged; | |||||
pacServer.Start(_config); | |||||
pacServer.PACFileChanged += pacServer_PACFileChanged; | |||||
pacServer.Start(_config); | |||||
} | } | ||||
catch (Exception e) | catch (Exception e) | ||||
{ | { | ||||
@@ -51,7 +59,7 @@ namespace Shadowsocks.Controller | |||||
UpdateSystemProxy(); | UpdateSystemProxy(); | ||||
} | } | ||||
public Server GetCurrentServer() | public Server GetCurrentServer() | ||||
{ | { | ||||
return _config.GetCurrentServer(); | return _config.GetCurrentServer(); | ||||
@@ -63,9 +71,10 @@ namespace Shadowsocks.Controller | |||||
return Configuration.Load(); | return Configuration.Load(); | ||||
} | } | ||||
public void SaveServers(List<Server> servers) | |||||
public void SaveServers(List<Server> servers, bool noChange) | |||||
{ | { | ||||
_config.configs = servers; | _config.configs = servers; | ||||
_config.noChange = noChange; | |||||
SaveConfig(_config); | SaveConfig(_config); | ||||
} | } | ||||
@@ -83,6 +92,7 @@ namespace Shadowsocks.Controller | |||||
public void ToggleShareOverLAN(bool enabled) | public void ToggleShareOverLAN(bool enabled) | ||||
{ | { | ||||
_config.shareOverLan = enabled; | _config.shareOverLan = enabled; | ||||
_config.noChange = false; | |||||
SaveConfig(_config); | SaveConfig(_config); | ||||
if (ShareOverLANStatusChanged != null) | if (ShareOverLANStatusChanged != null) | ||||
{ | { | ||||
@@ -132,6 +142,10 @@ namespace Shadowsocks.Controller | |||||
protected void SaveConfig(Configuration newConfig) | protected void SaveConfig(Configuration newConfig) | ||||
{ | { | ||||
Configuration.Save(newConfig); | Configuration.Save(newConfig); | ||||
if (newConfig.noChange) | |||||
{ | |||||
return; | |||||
} | |||||
// some logic in configuration updated the config when saving, we need to read it again | // some logic in configuration updated the config when saving, we need to read it again | ||||
_config = Configuration.Load(); | _config = Configuration.Load(); | ||||
@@ -173,5 +187,22 @@ namespace Shadowsocks.Controller | |||||
UpdateSystemProxy(); | UpdateSystemProxy(); | ||||
} | } | ||||
private void SetLog() | |||||
{ | |||||
try | |||||
{ | |||||
FileStream fs = new FileStream("shadowsocks.log", FileMode.Append); | |||||
TextWriter tmp = Console.Out; | |||||
StreamWriter sw = new StreamWriter(fs); | |||||
sw.AutoFlush = true; | |||||
Console.SetOut(sw); | |||||
Console.SetError(sw); | |||||
} | |||||
catch (IOException e) | |||||
{ | |||||
Console.WriteLine(e.ToString()); | |||||
} | |||||
} | |||||
} | } | ||||
} | } |
@@ -17,6 +17,9 @@ namespace Shadowsocks.Model | |||||
public bool enabled; | public bool enabled; | ||||
public bool shareOverLan; | public bool shareOverLan; | ||||
public bool isDefault; | public bool isDefault; | ||||
public bool openOnLan; | |||||
public bool enableLog; | |||||
public bool noChange; | |||||
private static string CONFIG_FILE = "gui-config.json"; | private static string CONFIG_FILE = "gui-config.json"; | ||||
@@ -46,15 +46,14 @@ namespace Shadowsocks | |||||
Console.WriteLine(e.ToString()); | Console.WriteLine(e.ToString()); | ||||
} | } | ||||
LoadLibrary(dllPath); | LoadLibrary(dllPath); | ||||
Logging.OpenLogFile(); | |||||
Logging.OpenLogFile(); | |||||
Application.EnableVisualStyles(); | Application.EnableVisualStyles(); | ||||
Application.SetCompatibleTextRenderingDefault(false); | Application.SetCompatibleTextRenderingDefault(false); | ||||
ShadowsocksController controller = new ShadowsocksController(); | ShadowsocksController controller = new ShadowsocksController(); | ||||
// TODO run without a main form to save RAM | // TODO run without a main form to save RAM | ||||
Application.Run(new ConfigForm(controller)); | Application.Run(new ConfigForm(controller)); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -15,9 +15,10 @@ namespace Shadowsocks.View | |||||
private ShadowsocksController controller; | private ShadowsocksController controller; | ||||
// 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 Configuration _oldConfiguration; | |||||
private int _oldSelectedIndex = -1; | |||||
private bool _isFirstRun; | |||||
public ConfigForm(ShadowsocksController controller) | public ConfigForm(ShadowsocksController controller) | ||||
{ | { | ||||
@@ -63,11 +64,11 @@ namespace Shadowsocks.View | |||||
IPTextBox.Focus(); | IPTextBox.Focus(); | ||||
} | } | ||||
private bool SaveOldSelectedServer() | |||||
private bool SaveOldSelectedServer(object sender) | |||||
{ | { | ||||
try | try | ||||
{ | { | ||||
if (oldSelectedIndex == -1 || oldSelectedIndex >= modifiedConfiguration.configs.Count) | |||||
if (_oldSelectedIndex == -1 || _oldSelectedIndex >= _modifiedConfiguration.configs.Count) | |||||
{ | { | ||||
return true; | return true; | ||||
} | } | ||||
@@ -81,7 +82,27 @@ namespace Shadowsocks.View | |||||
remarks = RemarksTextBox.Text | remarks = RemarksTextBox.Text | ||||
}; | }; | ||||
Configuration.CheckServer(server); | Configuration.CheckServer(server); | ||||
modifiedConfiguration.configs[oldSelectedIndex] = server; | |||||
_modifiedConfiguration.configs[_oldSelectedIndex] = server; | |||||
if (sender.Equals(OKButton)) | |||||
{ | |||||
if (_oldConfiguration.configs[_oldConfiguration.index].server == | |||||
_modifiedConfiguration.configs[_oldSelectedIndex].server && | |||||
_oldConfiguration.configs[_oldConfiguration.index].server_port == | |||||
_modifiedConfiguration.configs[_oldSelectedIndex].server_port && | |||||
_oldConfiguration.configs[_oldConfiguration.index].password == | |||||
_modifiedConfiguration.configs[_oldSelectedIndex].password && | |||||
_oldConfiguration.configs[_oldConfiguration.index].local_port == | |||||
_modifiedConfiguration.configs[_oldSelectedIndex].local_port) | |||||
{ | |||||
_modifiedConfiguration.noChange = true; | |||||
} | |||||
else | |||||
{ | |||||
_modifiedConfiguration.noChange = false; | |||||
_oldConfiguration = _modifiedConfiguration; | |||||
} | |||||
} | |||||
return true; | return true; | ||||
} | } | ||||
catch (FormatException) | catch (FormatException) | ||||
@@ -97,15 +118,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(); | ||||
@@ -119,7 +140,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 + ")"); | ||||
} | } | ||||
@@ -127,15 +148,16 @@ namespace Shadowsocks.View | |||||
private void LoadCurrentConfiguration() | private void LoadCurrentConfiguration() | ||||
{ | { | ||||
modifiedConfiguration = controller.GetConfiguration(); | |||||
LoadConfiguration(modifiedConfiguration); | |||||
oldSelectedIndex = modifiedConfiguration.index; | |||||
ServersListBox.SelectedIndex = modifiedConfiguration.index; | |||||
_modifiedConfiguration = controller.GetConfiguration(); | |||||
_oldConfiguration = _modifiedConfiguration; | |||||
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() | ||||
@@ -174,55 +196,55 @@ namespace Shadowsocks.View | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
isFirstRun = true; | |||||
_isFirstRun = true; | |||||
} | } | ||||
} | } | ||||
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; | ||||
} | } | ||||
if (!SaveOldSelectedServer()) | |||||
if (!SaveOldSelectedServer(sender)) | |||||
{ | { | ||||
// 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) | ||||
{ | { | ||||
if (!SaveOldSelectedServer()) | |||||
if (!SaveOldSelectedServer(sender)) | |||||
{ | { | ||||
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(); | ||||
} | } | ||||
@@ -238,27 +260,27 @@ 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.ShowBalloonTip(0); | notifyIcon1.ShowBalloonTip(0); | ||||
isFirstRun = false; | |||||
_isFirstRun = false; | |||||
} | } | ||||
} | } | ||||
private void OKButton_Click(object sender, EventArgs e) | private void OKButton_Click(object sender, EventArgs e) | ||||
{ | { | ||||
if (!SaveOldSelectedServer()) | |||||
if (!SaveOldSelectedServer(sender)) | |||||
{ | { | ||||
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, _modifiedConfiguration.noChange); | |||||
this.Hide(); | this.Hide(); | ||||
ShowFirstTimeBalloon(); | ShowFirstTimeBalloon(); | ||||
} | } | ||||
@@ -327,5 +349,13 @@ namespace Shadowsocks.View | |||||
qrCodeForm.Icon = this.Icon; | qrCodeForm.Icon = this.Icon; | ||||
qrCodeForm.Show(); | qrCodeForm.Show(); | ||||
} | } | ||||
private void enableLogBox_CheckedChanged(object sender, EventArgs e) | |||||
{ | |||||
if (this.Visible) | |||||
{ | |||||
MessageBox.Show("This option only works on next startup."); | |||||
} | |||||
} | |||||
} | } | ||||
} | } |