2 fixes, 1 feature, 1 code beautifytags/2.5.6
@@ -12,7 +12,7 @@ namespace Shadowsocks.Controller | |||
static I18N() | |||
{ | |||
Strings = new Dictionary<string, string>(); | |||
if (System.Globalization.CultureInfo.CurrentCulture.IetfLanguageTag.ToLowerInvariant().StartsWith("zh")) | |||
{ | |||
string[] lines = Regex.Split(Resources.cn, "\r\n|\r|\n"); | |||
@@ -21,7 +21,7 @@ namespace Shadowsocks.Controller | |||
sw.AutoFlush = true; | |||
Console.SetOut(sw); | |||
Console.SetError(sw); | |||
return true; | |||
} | |||
catch (IOException e) | |||
@@ -71,7 +71,6 @@ namespace Shadowsocks.Controller | |||
Console.WriteLine(e); | |||
} | |||
} | |||
} | |||
// Simply extended System.IO.StreamWriter for adding timestamp workaround | |||
@@ -77,7 +77,6 @@ namespace Shadowsocks.Controller | |||
_udpSocket.Bind(localEndPoint); | |||
_tcpSocket.Listen(1024); | |||
// Start an asynchronous socket to listen for connections. | |||
Console.WriteLine("Shadowsocks started"); | |||
_tcpSocket.BeginAccept( | |||
@@ -185,7 +184,6 @@ namespace Shadowsocks.Controller | |||
} | |||
} | |||
private void ReceiveCallback(IAsyncResult ar) | |||
{ | |||
object[] state = (object[])ar.AsyncState; | |||
@@ -86,7 +86,6 @@ namespace Shadowsocks.Controller | |||
} | |||
} | |||
public string TouchPACFile() | |||
{ | |||
if (File.Exists(PAC_FILE)) | |||
@@ -147,7 +147,6 @@ namespace Shadowsocks.Controller | |||
[DllImport("user32.dll")] | |||
public static extern IntPtr SendMessage(IntPtr hWnd, uint msg, int wParam, int lParam); | |||
public void RefreshTrayArea() | |||
{ | |||
IntPtr systemTrayContainerHandle = FindWindow("Shell_TrayWnd", null); | |||
@@ -164,7 +163,6 @@ namespace Shadowsocks.Controller | |||
RefreshTrayArea(notificationAreaHandle); | |||
} | |||
private static void RefreshTrayArea(IntPtr windowHandle) | |||
{ | |||
const uint wmMousemove = 0x0200; | |||
@@ -103,7 +103,6 @@ namespace Shadowsocks.Controller | |||
} | |||
} | |||
private void StartPipe(IAsyncResult ar) | |||
{ | |||
if (_closed) | |||
@@ -111,7 +111,7 @@ namespace Shadowsocks.Controller | |||
private bool connectionShutdown = false; | |||
private bool remoteShutdown = false; | |||
private bool closed = false; | |||
private object encryptionLock = new object(); | |||
private object decryptionLock = new object(); | |||
@@ -195,7 +195,6 @@ namespace Shadowsocks.Controller | |||
} | |||
} | |||
private void HandshakeReceive() | |||
{ | |||
if (closed) | |||
@@ -265,7 +264,7 @@ namespace Shadowsocks.Controller | |||
try | |||
{ | |||
int bytesRead = connection.EndReceive(ar); | |||
if (bytesRead >= 3) | |||
{ | |||
command = connetionRecvBuffer[1]; | |||
@@ -315,7 +314,6 @@ namespace Shadowsocks.Controller | |||
private void ReadAll(IAsyncResult ar) | |||
{ | |||
if (closed) | |||
{ | |||
return; | |||
@@ -390,7 +388,6 @@ namespace Shadowsocks.Controller | |||
} | |||
IPEndPoint remoteEP = new IPEndPoint(ipAddress, server.server_port); | |||
remote = new Socket(ipAddress.AddressFamily, | |||
SocketType.Stream, ProtocolType.Tcp); | |||
remote.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true); | |||
@@ -592,7 +589,6 @@ namespace Shadowsocks.Controller | |||
} | |||
remote.BeginSend(connetionSendBuffer, 0, bytesToSend, 0, new AsyncCallback(PipeRemoteSendCallback), null); | |||
IStrategy strategy = controller.GetCurrentStrategy(); | |||
if (strategy != null) | |||
{ | |||
@@ -651,5 +647,4 @@ namespace Shadowsocks.Controller | |||
} | |||
} | |||
} | |||
} |
@@ -108,9 +108,11 @@ namespace Shadowsocks.Controller | |||
} | |||
catch (ObjectDisposedException) | |||
{ | |||
// TODO: handle the ObjectDisposedException | |||
} | |||
catch (Exception) | |||
{ | |||
// TODO: need more think about handle other Exceptions, or should remove this catch(). | |||
} | |||
finally | |||
{ | |||
@@ -124,9 +126,11 @@ namespace Shadowsocks.Controller | |||
} | |||
catch (ObjectDisposedException) | |||
{ | |||
// TODO: handle the ObjectDisposedException | |||
} | |||
catch (Exception) | |||
{ | |||
// TODO: need more think about handle other Exceptions, or should remove this catch(). | |||
} | |||
finally | |||
{ | |||
@@ -134,6 +138,8 @@ namespace Shadowsocks.Controller | |||
} | |||
} | |||
} | |||
// cc by-sa 3.0 http://stackoverflow.com/a/3719378/1124054 | |||
class LRUCache<K, V> where V : UDPRelay.UDPHandler | |||
{ | |||
@@ -196,5 +202,4 @@ namespace Shadowsocks.Controller | |||
public K key; | |||
public V value; | |||
} | |||
} |
@@ -53,7 +53,6 @@ namespace Shadowsocks.Controller | |||
{ | |||
return CompareVersion(ParseVersionFromURL(x), ParseVersionFromURL(y)); | |||
} | |||
} | |||
private static string ParseVersionFromURL(string url) | |||
@@ -39,7 +39,7 @@ namespace Shadowsocks.Controller | |||
public event EventHandler EnableStatusChanged; | |||
public event EventHandler EnableGlobalChanged; | |||
public event EventHandler ShareOverLANStatusChanged; | |||
// when user clicked Edit PAC, and PAC file has already created | |||
public event EventHandler<PathEventArgs> PACFileReadyToOpen; | |||
public event EventHandler<PathEventArgs> UserRuleFileReadyToOpen; | |||
@@ -363,14 +363,12 @@ namespace Shadowsocks.Controller | |||
Util.Utils.ReleaseMemory(true); | |||
} | |||
protected void SaveConfig(Configuration newConfig) | |||
{ | |||
Configuration.Save(newConfig); | |||
Reload(); | |||
} | |||
private void UpdateSystemProxy() | |||
{ | |||
if (_config.enabled) | |||
@@ -14,17 +14,17 @@ namespace Shadowsocks.Controller.Strategy | |||
/* | |||
* IStrategy | |||
* | |||
* | |||
* Subclasses must be thread-safe | |||
*/ | |||
public interface IStrategy | |||
{ | |||
string Name { get; } | |||
string ID { get; } | |||
/* | |||
* Called when servers need to be reloaded, i.e. new configuration saved | |||
* Called when servers need to be reloaded, i.e. new configuration saved | |||
*/ | |||
void ReloadServers(); | |||
@@ -112,7 +112,7 @@ namespace Shadowsocks.Controller.Strategy | |||
).Aggregate((result1, result2) => result1.score > result2.score ? result1 : result2); | |||
if (_controller.GetCurrentStrategy().ID == ID && _currentServer != bestResult.server) //output when enabled | |||
{ | |||
{ | |||
Console.WriteLine("Switch to server: {0} by package loss:{1}", bestResult.server.FriendlyName(), 1 - bestResult.score); | |||
} | |||
_currentServer = bestResult.server; | |||
@@ -42,8 +42,8 @@ Remarks=备注 | |||
OK=确定 | |||
Cancel=取消 | |||
New server=未配置的服务器 | |||
Move &Up=上移 | |||
Move D&own=下移 | |||
Move &Up=上移(&U) | |||
Move D&own=下移(&O) | |||
# QRCode Form | |||
@@ -26,7 +26,6 @@ namespace Shadowsocks.Encryption | |||
protected int keyLen; | |||
protected int ivLen; | |||
public IVEncryptor(string method, string password) | |||
: base(method, password) | |||
{ | |||
@@ -49,7 +49,6 @@ namespace Shadowsocks.Encryption | |||
[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] | |||
public extern static int aes_crypt_cfb128(IntPtr ctx, int mode, int length, ref int iv_off, byte[] iv, byte[] input, byte[] output); | |||
public const int ARC4_CTX_SIZE = 264; | |||
[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] | |||
@@ -41,7 +41,6 @@ namespace Shadowsocks.Encryption | |||
outlength = length; | |||
} | |||
public override void Decrypt(byte[] buf, int length, byte[] outbuf, out int outlength) | |||
{ | |||
byte[] result = new byte[length]; | |||
@@ -100,7 +99,6 @@ namespace Shadowsocks.Encryption | |||
return sorted; | |||
} | |||
public override void Dispose() | |||
{ | |||
} | |||
@@ -18,7 +18,7 @@ namespace Shadowsocks.View | |||
// this is a copy of configuration that we are working on | |||
private Configuration _modifiedConfiguration; | |||
private int _oldSelectedIndex = -1; | |||
private int _lastSelectedIndex = -1; | |||
public ConfigForm(ShadowsocksController controller) | |||
{ | |||
@@ -72,7 +72,7 @@ namespace Shadowsocks.View | |||
{ | |||
try | |||
{ | |||
if (_oldSelectedIndex == -1 || _oldSelectedIndex >= _modifiedConfiguration.configs.Count) | |||
if (_lastSelectedIndex == -1 || _lastSelectedIndex >= _modifiedConfiguration.configs.Count) | |||
{ | |||
return true; | |||
} | |||
@@ -87,7 +87,7 @@ namespace Shadowsocks.View | |||
int localPort = int.Parse(ProxyPortTextBox.Text); | |||
Configuration.CheckServer(server); | |||
Configuration.CheckLocalPort(localPort); | |||
_modifiedConfiguration.configs[_oldSelectedIndex] = server; | |||
_modifiedConfiguration.configs[_lastSelectedIndex] = server; | |||
_modifiedConfiguration.localPort = localPort; | |||
return true; | |||
@@ -131,12 +131,12 @@ namespace Shadowsocks.View | |||
{ | |||
_modifiedConfiguration = controller.GetConfigurationCopy(); | |||
LoadConfiguration(_modifiedConfiguration); | |||
_oldSelectedIndex = _modifiedConfiguration.index; | |||
if (_oldSelectedIndex < 0) | |||
_lastSelectedIndex = _modifiedConfiguration.index; | |||
if (_lastSelectedIndex < 0) | |||
{ | |||
_oldSelectedIndex = 0; | |||
_lastSelectedIndex = 0; | |||
} | |||
ServersListBox.SelectedIndex = _oldSelectedIndex; | |||
ServersListBox.SelectedIndex = _lastSelectedIndex; | |||
UpdateMoveUpAndDownButton(); | |||
LoadSelectedServer(); | |||
} | |||
@@ -148,7 +148,11 @@ namespace Shadowsocks.View | |||
private void ServersListBox_SelectedIndexChanged(object sender, EventArgs e) | |||
{ | |||
if (_oldSelectedIndex == ServersListBox.SelectedIndex) | |||
if (!ServersListBox.CanSelect) | |||
{ | |||
return; | |||
} | |||
if (_lastSelectedIndex == ServersListBox.SelectedIndex) | |||
{ | |||
// we are moving back to oldSelectedIndex or doing a force move | |||
return; | |||
@@ -156,12 +160,13 @@ namespace Shadowsocks.View | |||
if (!SaveOldSelectedServer()) | |||
{ | |||
// why this won't cause stack overflow? | |||
ServersListBox.SelectedIndex = _oldSelectedIndex; | |||
ServersListBox.SelectedIndex = _lastSelectedIndex; | |||
return; | |||
} | |||
ServersListBox.Items[_lastSelectedIndex] = _modifiedConfiguration.configs[_lastSelectedIndex].FriendlyName(); | |||
UpdateMoveUpAndDownButton(); | |||
LoadSelectedServer(); | |||
_oldSelectedIndex = ServersListBox.SelectedIndex; | |||
_lastSelectedIndex = ServersListBox.SelectedIndex; | |||
} | |||
private void AddButton_Click(object sender, EventArgs e) | |||
@@ -174,29 +179,30 @@ namespace Shadowsocks.View | |||
_modifiedConfiguration.configs.Add(server); | |||
LoadConfiguration(_modifiedConfiguration); | |||
ServersListBox.SelectedIndex = _modifiedConfiguration.configs.Count - 1; | |||
_oldSelectedIndex = ServersListBox.SelectedIndex; | |||
_lastSelectedIndex = ServersListBox.SelectedIndex; | |||
} | |||
private void DeleteButton_Click(object sender, EventArgs e) | |||
{ | |||
_oldSelectedIndex = ServersListBox.SelectedIndex; | |||
if (_oldSelectedIndex >= 0 && _oldSelectedIndex < _modifiedConfiguration.configs.Count) | |||
_lastSelectedIndex = ServersListBox.SelectedIndex; | |||
if (_lastSelectedIndex >= 0 && _lastSelectedIndex < _modifiedConfiguration.configs.Count) | |||
{ | |||
_modifiedConfiguration.configs.RemoveAt(_oldSelectedIndex); | |||
_modifiedConfiguration.configs.RemoveAt(_lastSelectedIndex); | |||
} | |||
if (_oldSelectedIndex >= _modifiedConfiguration.configs.Count) | |||
if (_lastSelectedIndex >= _modifiedConfiguration.configs.Count) | |||
{ | |||
// can be -1 | |||
_oldSelectedIndex = _modifiedConfiguration.configs.Count - 1; | |||
_lastSelectedIndex = _modifiedConfiguration.configs.Count - 1; | |||
} | |||
ServersListBox.SelectedIndex = _oldSelectedIndex; | |||
ServersListBox.SelectedIndex = _lastSelectedIndex; | |||
LoadConfiguration(_modifiedConfiguration); | |||
ServersListBox.SelectedIndex = _oldSelectedIndex; | |||
ServersListBox.SelectedIndex = _lastSelectedIndex; | |||
LoadSelectedServer(); | |||
} | |||
private void OKButton_Click(object sender, EventArgs e) | |||
{ | |||
Server server = controller.GetCurrentServer(); | |||
if (!SaveOldSelectedServer()) | |||
{ | |||
return; | |||
@@ -206,9 +212,8 @@ namespace Shadowsocks.View | |||
MessageBox.Show(I18N.GetString("Please add at least one server")); | |||
return; | |||
} | |||
int index = _modifiedConfiguration.index; | |||
controller.SaveServers(_modifiedConfiguration.configs, _modifiedConfiguration.localPort); | |||
controller.SelectServerIndex(index); | |||
controller.SelectServerIndex(_modifiedConfiguration.configs.IndexOf(server)); | |||
this.Close(); | |||
} | |||
@@ -238,9 +243,11 @@ namespace Shadowsocks.View | |||
_modifiedConfiguration.index += step; | |||
ServersListBox.BeginUpdate(); | |||
_oldSelectedIndex = index + step; | |||
ServersListBox.Enabled = false; | |||
_lastSelectedIndex = index + step; | |||
ServersListBox.Items.Remove(item); | |||
ServersListBox.Items.Insert(index + step, item); | |||
ServersListBox.Enabled = true; | |||
ServersListBox.SelectedIndex = index + step; | |||
ServersListBox.EndUpdate(); | |||
@@ -290,6 +297,5 @@ namespace Shadowsocks.View | |||
MoveConfigItem(+1); // +1 means move forward | |||
} | |||
} | |||
} | |||
} |
@@ -18,7 +18,7 @@ namespace Shadowsocks.View | |||
// yes this is just a menu view controller | |||
// when config form is closed, it moves away from RAM | |||
// and it should just do anything related to the config form | |||
private ShadowsocksController controller; | |||
private UpdateChecker updateChecker; | |||
@@ -520,17 +520,17 @@ namespace Shadowsocks.View | |||
Process.Start(_urlToOpen); | |||
} | |||
private void AutoStartupItem_Click(object sender, EventArgs e) { | |||
AutoStartupItem.Checked = !AutoStartupItem.Checked; | |||
if (!AutoStartup.Set(AutoStartupItem.Checked)) { | |||
MessageBox.Show(I18N.GetString("Failed to update registry")); | |||
} | |||
} | |||
private void AutoStartupItem_Click(object sender, EventArgs e) { | |||
AutoStartupItem.Checked = !AutoStartupItem.Checked; | |||
if (!AutoStartup.Set(AutoStartupItem.Checked)) { | |||
MessageBox.Show(I18N.GetString("Failed to update registry")); | |||
} | |||
} | |||
private void AvailabilityStatisticsItem_Click(object sender, EventArgs e) { | |||
AvailabilityStatistics.Checked = !AvailabilityStatistics.Checked; | |||
private void AvailabilityStatisticsItem_Click(object sender, EventArgs e) { | |||
AvailabilityStatistics.Checked = !AvailabilityStatistics.Checked; | |||
controller.ToggleAvailabilityStatistics(AvailabilityStatistics.Checked); | |||
} | |||
} | |||
private void LocalPACItem_Click(object sender, EventArgs e) | |||
{ | |||
@@ -242,7 +242,6 @@ namespace Shadowsocks.View | |||
SetBitmap(bitmap, 255); | |||
} | |||
/// <para>Changes the current bitmap with a custom opacity level. Here is where all happens!</para> | |||
public void SetBitmap(Bitmap bitmap, byte opacity) | |||
{ | |||
@@ -288,7 +287,6 @@ namespace Shadowsocks.View | |||
} | |||
} | |||
protected override CreateParams CreateParams | |||
{ | |||
get | |||