1/ removed dual empty line 2/ removed tailing spaces 3/ converted tabs into spaces 4/ added some TODO commentstags/2.5.6
@@ -12,7 +12,7 @@ namespace Shadowsocks.Controller | |||||
static I18N() | static I18N() | ||||
{ | { | ||||
Strings = new Dictionary<string, string>(); | Strings = new Dictionary<string, string>(); | ||||
if (System.Globalization.CultureInfo.CurrentCulture.IetfLanguageTag.ToLowerInvariant().StartsWith("zh")) | if (System.Globalization.CultureInfo.CurrentCulture.IetfLanguageTag.ToLowerInvariant().StartsWith("zh")) | ||||
{ | { | ||||
string[] lines = Regex.Split(Resources.cn, "\r\n|\r|\n"); | string[] lines = Regex.Split(Resources.cn, "\r\n|\r|\n"); | ||||
@@ -21,7 +21,7 @@ namespace Shadowsocks.Controller | |||||
sw.AutoFlush = true; | sw.AutoFlush = true; | ||||
Console.SetOut(sw); | Console.SetOut(sw); | ||||
Console.SetError(sw); | Console.SetError(sw); | ||||
return true; | return true; | ||||
} | } | ||||
catch (IOException e) | catch (IOException e) | ||||
@@ -71,7 +71,6 @@ namespace Shadowsocks.Controller | |||||
Console.WriteLine(e); | Console.WriteLine(e); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// Simply extended System.IO.StreamWriter for adding timestamp workaround | // Simply extended System.IO.StreamWriter for adding timestamp workaround | ||||
@@ -77,7 +77,6 @@ namespace Shadowsocks.Controller | |||||
_udpSocket.Bind(localEndPoint); | _udpSocket.Bind(localEndPoint); | ||||
_tcpSocket.Listen(1024); | _tcpSocket.Listen(1024); | ||||
// Start an asynchronous socket to listen for connections. | // Start an asynchronous socket to listen for connections. | ||||
Console.WriteLine("Shadowsocks started"); | Console.WriteLine("Shadowsocks started"); | ||||
_tcpSocket.BeginAccept( | _tcpSocket.BeginAccept( | ||||
@@ -185,7 +184,6 @@ namespace Shadowsocks.Controller | |||||
} | } | ||||
} | } | ||||
private void ReceiveCallback(IAsyncResult ar) | private void ReceiveCallback(IAsyncResult ar) | ||||
{ | { | ||||
object[] state = (object[])ar.AsyncState; | object[] state = (object[])ar.AsyncState; | ||||
@@ -86,7 +86,6 @@ namespace Shadowsocks.Controller | |||||
} | } | ||||
} | } | ||||
public string TouchPACFile() | public string TouchPACFile() | ||||
{ | { | ||||
if (File.Exists(PAC_FILE)) | if (File.Exists(PAC_FILE)) | ||||
@@ -147,7 +147,6 @@ namespace Shadowsocks.Controller | |||||
[DllImport("user32.dll")] | [DllImport("user32.dll")] | ||||
public static extern IntPtr SendMessage(IntPtr hWnd, uint msg, int wParam, int lParam); | public static extern IntPtr SendMessage(IntPtr hWnd, uint msg, int wParam, int lParam); | ||||
public void RefreshTrayArea() | public void RefreshTrayArea() | ||||
{ | { | ||||
IntPtr systemTrayContainerHandle = FindWindow("Shell_TrayWnd", null); | IntPtr systemTrayContainerHandle = FindWindow("Shell_TrayWnd", null); | ||||
@@ -164,7 +163,6 @@ namespace Shadowsocks.Controller | |||||
RefreshTrayArea(notificationAreaHandle); | RefreshTrayArea(notificationAreaHandle); | ||||
} | } | ||||
private static void RefreshTrayArea(IntPtr windowHandle) | private static void RefreshTrayArea(IntPtr windowHandle) | ||||
{ | { | ||||
const uint wmMousemove = 0x0200; | const uint wmMousemove = 0x0200; | ||||
@@ -103,7 +103,6 @@ namespace Shadowsocks.Controller | |||||
} | } | ||||
} | } | ||||
private void StartPipe(IAsyncResult ar) | private void StartPipe(IAsyncResult ar) | ||||
{ | { | ||||
if (_closed) | if (_closed) | ||||
@@ -111,7 +111,7 @@ namespace Shadowsocks.Controller | |||||
private bool connectionShutdown = false; | private bool connectionShutdown = false; | ||||
private bool remoteShutdown = false; | private bool remoteShutdown = false; | ||||
private bool closed = false; | private bool closed = false; | ||||
private object encryptionLock = new object(); | private object encryptionLock = new object(); | ||||
private object decryptionLock = new object(); | private object decryptionLock = new object(); | ||||
@@ -195,7 +195,6 @@ namespace Shadowsocks.Controller | |||||
} | } | ||||
} | } | ||||
private void HandshakeReceive() | private void HandshakeReceive() | ||||
{ | { | ||||
if (closed) | if (closed) | ||||
@@ -265,7 +264,7 @@ namespace Shadowsocks.Controller | |||||
try | try | ||||
{ | { | ||||
int bytesRead = connection.EndReceive(ar); | int bytesRead = connection.EndReceive(ar); | ||||
if (bytesRead >= 3) | if (bytesRead >= 3) | ||||
{ | { | ||||
command = connetionRecvBuffer[1]; | command = connetionRecvBuffer[1]; | ||||
@@ -315,7 +314,6 @@ namespace Shadowsocks.Controller | |||||
private void ReadAll(IAsyncResult ar) | private void ReadAll(IAsyncResult ar) | ||||
{ | { | ||||
if (closed) | if (closed) | ||||
{ | { | ||||
return; | return; | ||||
@@ -390,7 +388,6 @@ namespace Shadowsocks.Controller | |||||
} | } | ||||
IPEndPoint remoteEP = new IPEndPoint(ipAddress, server.server_port); | IPEndPoint remoteEP = new IPEndPoint(ipAddress, server.server_port); | ||||
remote = new Socket(ipAddress.AddressFamily, | remote = new Socket(ipAddress.AddressFamily, | ||||
SocketType.Stream, ProtocolType.Tcp); | SocketType.Stream, ProtocolType.Tcp); | ||||
remote.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true); | remote.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true); | ||||
@@ -592,7 +589,6 @@ namespace Shadowsocks.Controller | |||||
} | } | ||||
remote.BeginSend(connetionSendBuffer, 0, bytesToSend, 0, new AsyncCallback(PipeRemoteSendCallback), null); | remote.BeginSend(connetionSendBuffer, 0, bytesToSend, 0, new AsyncCallback(PipeRemoteSendCallback), null); | ||||
IStrategy strategy = controller.GetCurrentStrategy(); | IStrategy strategy = controller.GetCurrentStrategy(); | ||||
if (strategy != null) | if (strategy != null) | ||||
{ | { | ||||
@@ -651,5 +647,4 @@ namespace Shadowsocks.Controller | |||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } |
@@ -108,9 +108,11 @@ namespace Shadowsocks.Controller | |||||
} | } | ||||
catch (ObjectDisposedException) | catch (ObjectDisposedException) | ||||
{ | { | ||||
// TODO: handle the ObjectDisposedException | |||||
} | } | ||||
catch (Exception) | catch (Exception) | ||||
{ | { | ||||
// TODO: need more think about handle other Exceptions, or should remove this catch(). | |||||
} | } | ||||
finally | finally | ||||
{ | { | ||||
@@ -124,9 +126,11 @@ namespace Shadowsocks.Controller | |||||
} | } | ||||
catch (ObjectDisposedException) | catch (ObjectDisposedException) | ||||
{ | { | ||||
// TODO: handle the ObjectDisposedException | |||||
} | } | ||||
catch (Exception) | catch (Exception) | ||||
{ | { | ||||
// TODO: need more think about handle other Exceptions, or should remove this catch(). | |||||
} | } | ||||
finally | finally | ||||
{ | { | ||||
@@ -134,6 +138,8 @@ namespace Shadowsocks.Controller | |||||
} | } | ||||
} | } | ||||
} | } | ||||
// cc by-sa 3.0 http://stackoverflow.com/a/3719378/1124054 | // cc by-sa 3.0 http://stackoverflow.com/a/3719378/1124054 | ||||
class LRUCache<K, V> where V : UDPRelay.UDPHandler | class LRUCache<K, V> where V : UDPRelay.UDPHandler | ||||
{ | { | ||||
@@ -196,5 +202,4 @@ namespace Shadowsocks.Controller | |||||
public K key; | public K key; | ||||
public V value; | public V value; | ||||
} | } | ||||
} | } |
@@ -53,7 +53,6 @@ namespace Shadowsocks.Controller | |||||
{ | { | ||||
return CompareVersion(ParseVersionFromURL(x), ParseVersionFromURL(y)); | return CompareVersion(ParseVersionFromURL(x), ParseVersionFromURL(y)); | ||||
} | } | ||||
} | } | ||||
private static string ParseVersionFromURL(string url) | private static string ParseVersionFromURL(string url) | ||||
@@ -39,7 +39,7 @@ namespace Shadowsocks.Controller | |||||
public event EventHandler EnableStatusChanged; | public event EventHandler EnableStatusChanged; | ||||
public event EventHandler EnableGlobalChanged; | public event EventHandler EnableGlobalChanged; | ||||
public event EventHandler ShareOverLANStatusChanged; | public event EventHandler ShareOverLANStatusChanged; | ||||
// when user clicked Edit PAC, and PAC file has already created | // when user clicked Edit PAC, and PAC file has already created | ||||
public event EventHandler<PathEventArgs> PACFileReadyToOpen; | public event EventHandler<PathEventArgs> PACFileReadyToOpen; | ||||
public event EventHandler<PathEventArgs> UserRuleFileReadyToOpen; | public event EventHandler<PathEventArgs> UserRuleFileReadyToOpen; | ||||
@@ -363,14 +363,12 @@ namespace Shadowsocks.Controller | |||||
Util.Utils.ReleaseMemory(true); | Util.Utils.ReleaseMemory(true); | ||||
} | } | ||||
protected void SaveConfig(Configuration newConfig) | protected void SaveConfig(Configuration newConfig) | ||||
{ | { | ||||
Configuration.Save(newConfig); | Configuration.Save(newConfig); | ||||
Reload(); | Reload(); | ||||
} | } | ||||
private void UpdateSystemProxy() | private void UpdateSystemProxy() | ||||
{ | { | ||||
if (_config.enabled) | if (_config.enabled) | ||||
@@ -14,17 +14,17 @@ namespace Shadowsocks.Controller.Strategy | |||||
/* | /* | ||||
* IStrategy | * IStrategy | ||||
* | |||||
* | |||||
* Subclasses must be thread-safe | * Subclasses must be thread-safe | ||||
*/ | */ | ||||
public interface IStrategy | public interface IStrategy | ||||
{ | { | ||||
string Name { get; } | string Name { get; } | ||||
string ID { 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(); | void ReloadServers(); | ||||
@@ -112,7 +112,7 @@ namespace Shadowsocks.Controller.Strategy | |||||
).Aggregate((result1, result2) => result1.score > result2.score ? result1 : result2); | ).Aggregate((result1, result2) => result1.score > result2.score ? result1 : result2); | ||||
if (_controller.GetCurrentStrategy().ID == ID && _currentServer != bestResult.server) //output when enabled | 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); | Console.WriteLine("Switch to server: {0} by package loss:{1}", bestResult.server.FriendlyName(), 1 - bestResult.score); | ||||
} | } | ||||
_currentServer = bestResult.server; | _currentServer = bestResult.server; | ||||
@@ -26,7 +26,6 @@ namespace Shadowsocks.Encryption | |||||
protected int keyLen; | protected int keyLen; | ||||
protected int ivLen; | protected int ivLen; | ||||
public IVEncryptor(string method, string password) | public IVEncryptor(string method, string password) | ||||
: base(method, password) | : base(method, password) | ||||
{ | { | ||||
@@ -49,7 +49,6 @@ namespace Shadowsocks.Encryption | |||||
[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] | [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 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; | public const int ARC4_CTX_SIZE = 264; | ||||
[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] | [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] | ||||
@@ -41,7 +41,6 @@ namespace Shadowsocks.Encryption | |||||
outlength = length; | outlength = length; | ||||
} | } | ||||
public override void Decrypt(byte[] buf, int length, byte[] outbuf, out int outlength) | public override void Decrypt(byte[] buf, int length, byte[] outbuf, out int outlength) | ||||
{ | { | ||||
byte[] result = new byte[length]; | byte[] result = new byte[length]; | ||||
@@ -100,7 +99,6 @@ namespace Shadowsocks.Encryption | |||||
return sorted; | return sorted; | ||||
} | } | ||||
public override void Dispose() | public override void Dispose() | ||||
{ | { | ||||
} | } | ||||
@@ -18,7 +18,7 @@ namespace Shadowsocks.View | |||||
// yes this is just a menu view controller | // yes this is just a menu view controller | ||||
// when config form is closed, it moves away from RAM | // when config form is closed, it moves away from RAM | ||||
// and it should just do anything related to the config form | // and it should just do anything related to the config form | ||||
private ShadowsocksController controller; | private ShadowsocksController controller; | ||||
private UpdateChecker updateChecker; | private UpdateChecker updateChecker; | ||||
@@ -520,17 +520,17 @@ namespace Shadowsocks.View | |||||
Process.Start(_urlToOpen); | 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); | controller.ToggleAvailabilityStatistics(AvailabilityStatistics.Checked); | ||||
} | |||||
} | |||||
private void LocalPACItem_Click(object sender, EventArgs e) | private void LocalPACItem_Click(object sender, EventArgs e) | ||||
{ | { | ||||
@@ -242,7 +242,6 @@ namespace Shadowsocks.View | |||||
SetBitmap(bitmap, 255); | SetBitmap(bitmap, 255); | ||||
} | } | ||||
/// <para>Changes the current bitmap with a custom opacity level. Here is where all happens!</para> | /// <para>Changes the current bitmap with a custom opacity level. Here is where all happens!</para> | ||||
public void SetBitmap(Bitmap bitmap, byte opacity) | public void SetBitmap(Bitmap bitmap, byte opacity) | ||||
{ | { | ||||
@@ -288,7 +287,6 @@ namespace Shadowsocks.View | |||||
} | } | ||||
} | } | ||||
protected override CreateParams CreateParams | protected override CreateParams CreateParams | ||||
{ | { | ||||
get | get | ||||