Version now change with AssemblyVersion add open on lan option Add an option to choose whether to open on lan or not. add log switch and modify detector Add an option to select whether to open log or not. Add a detector to check whether the server setting changed. small bug Fix a small bug add modify detector Don't reload server if config not change. add about form Add an about form instead of just open link. add log switch and modify detector Add an option to select whether to open log or not. Add a detector to check whether the server setting changed. small bug Fix a small bug add modify detector Don't reload server if config not change.pull/45/head
@@ -1,6 +1,6 @@ | |||
| |||
Microsoft Visual Studio Solution File, Format Version 12.00 | |||
# Visual Studio Express 2012 for Windows Desktop | |||
# Visual Studio 2012 | |||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "shadowsocks-csharp", "shadowsocks-csharp\shadowsocks-csharp.csproj", "{8C02D2F7-7CDB-4D55-9F25-CD03EF4AA062}" | |||
EndProject | |||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test", "test\test.csproj", "{45913187-0685-4903-B250-DCEF0479CD86}" | |||
@@ -10,9 +10,9 @@ namespace Shadowsocks.Controller | |||
{ | |||
class Local | |||
{ | |||
{ | |||
private Server _server; | |||
private bool _shareOverLAN; | |||
private bool _shareOverLAN; | |||
//private Encryptor encryptor; | |||
Socket _listener; | |||
public Local(Configuration config) | |||
@@ -26,7 +26,7 @@ namespace Shadowsocks.Controller | |||
{ | |||
try | |||
{ | |||
// Create a TCP/IP socket. | |||
// Create a TCP/IP socket. | |||
_listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); | |||
_listener.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); | |||
IPEndPoint localEndPoint = null; | |||
@@ -36,7 +36,7 @@ namespace Shadowsocks.Controller | |||
} | |||
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. | |||
@@ -221,7 +221,7 @@ namespace Shadowsocks.Controller | |||
// reject socks 4 | |||
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 | |||
{ | |||
@@ -235,7 +235,7 @@ namespace Shadowsocks.Controller | |||
} | |||
} | |||
private void handshakeSendCallback(IAsyncResult ar) | |||
private void HandshakeSendCallback(IAsyncResult ar) | |||
{ | |||
try | |||
{ | |||
@@ -267,7 +267,7 @@ namespace Shadowsocks.Controller | |||
if (bytesRead > 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 | |||
{ | |||
@@ -282,15 +282,15 @@ namespace Shadowsocks.Controller | |||
} | |||
private void startPipe(IAsyncResult ar) | |||
private void StartPipe(IAsyncResult ar) | |||
{ | |||
try | |||
{ | |||
connection.EndReceive(ar); | |||
remote.BeginReceive(remoteRecvBuffer, 0, RecvSize, 0, | |||
new AsyncCallback(pipeRemoteReceiveCallback), null); | |||
new AsyncCallback(PipeRemoteReceiveCallback), null); | |||
connection.BeginReceive(connetionRecvBuffer, 0, RecvSize, 0, | |||
new AsyncCallback(pipeConnectionReceiveCallback), null); | |||
new AsyncCallback(PipeConnectionReceiveCallback), null); | |||
} | |||
catch (Exception e) | |||
{ | |||
@@ -299,7 +299,7 @@ namespace Shadowsocks.Controller | |||
} | |||
} | |||
private void pipeRemoteReceiveCallback(IAsyncResult ar) | |||
private void PipeRemoteReceiveCallback(IAsyncResult ar) | |||
{ | |||
try | |||
@@ -310,7 +310,7 @@ namespace Shadowsocks.Controller | |||
{ | |||
int 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 | |||
{ | |||
@@ -325,7 +325,7 @@ namespace Shadowsocks.Controller | |||
} | |||
} | |||
private void pipeConnectionReceiveCallback(IAsyncResult ar) | |||
private void PipeConnectionReceiveCallback(IAsyncResult ar) | |||
{ | |||
try | |||
@@ -336,7 +336,7 @@ namespace Shadowsocks.Controller | |||
{ | |||
int 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 | |||
{ | |||
@@ -350,13 +350,13 @@ namespace Shadowsocks.Controller | |||
} | |||
} | |||
private void pipeRemoteSendCallback(IAsyncResult ar) | |||
private void PipeRemoteSendCallback(IAsyncResult ar) | |||
{ | |||
try | |||
{ | |||
remote.EndSend(ar); | |||
connection.BeginReceive(this.connetionRecvBuffer, 0, RecvSize, 0, | |||
new AsyncCallback(pipeConnectionReceiveCallback), null); | |||
new AsyncCallback(PipeConnectionReceiveCallback), null); | |||
} | |||
catch (Exception e) | |||
{ | |||
@@ -365,13 +365,13 @@ namespace Shadowsocks.Controller | |||
} | |||
} | |||
private void pipeConnectionSendCallback(IAsyncResult ar) | |||
private void PipeConnectionSendCallback(IAsyncResult ar) | |||
{ | |||
try | |||
{ | |||
connection.EndSend(ar); | |||
remote.BeginReceive(this.remoteRecvBuffer, 0, RecvSize, 0, | |||
new AsyncCallback(pipeRemoteReceiveCallback), null); | |||
new AsyncCallback(PipeRemoteReceiveCallback), null); | |||
} | |||
catch (Exception e) | |||
{ | |||
@@ -15,6 +15,7 @@ namespace Shadowsocks.Controller | |||
{ | |||
private static int PORT = 8090; | |||
private static string PAC_FILE = "pac.txt"; | |||
public bool openOnLan; | |||
Socket _listener; | |||
FileSystemWatcher watcher; | |||
@@ -12,6 +12,7 @@ namespace Shadowsocks.Controller | |||
class PolipoRunner | |||
{ | |||
private Process _process; | |||
public bool openOnLan; | |||
public void Start(Configuration configuration) | |||
{ | |||
@@ -31,10 +32,10 @@ namespace Shadowsocks.Controller | |||
Console.WriteLine(e.ToString()); | |||
} | |||
} | |||
string temppath = Path.GetTempPath(); | |||
string temppath = Path.GetTempPath(); | |||
string polipoConfig = Resources.polipo_config; | |||
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.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.Collections.Generic; | |||
using System.Text; | |||
@@ -34,6 +35,21 @@ namespace Shadowsocks.Controller | |||
public ShadowsocksController() | |||
{ | |||
_config = Configuration.Load(); | |||
if (_config.enableLog) | |||
{ | |||
SetLog(); | |||
} | |||
<<<<<<< HEAD | |||
======= | |||
openOnLan = _config.openOnLan; | |||
polipoRunner = new PolipoRunner(); | |||
polipoRunner.openOnLan = openOnLan; | |||
polipoRunner.Start(_config.GetCurrentServer()); | |||
local = new Local(_config.GetCurrentServer()); | |||
local.openOnLan = openOnLan; | |||
>>>>>>> 835265b... add log switch and modify detector | |||
polipoRunner = new PolipoRunner(); | |||
polipoRunner.Start(_config); | |||
local = new Local(_config); | |||
@@ -52,6 +68,39 @@ namespace Shadowsocks.Controller | |||
UpdateSystemProxy(); | |||
} | |||
<<<<<<< HEAD | |||
======= | |||
public void SaveConfig(Configuration newConfig) | |||
{ | |||
Configuration.Save(newConfig); | |||
if (newConfig.noChange && newConfig.openOnLan == openOnLan) | |||
{ | |||
return; | |||
} | |||
// some logic in configuration updated the config when saving, we need to read it again | |||
_config = Configuration.Load(); | |||
openOnLan = _config.openOnLan; | |||
local.Stop(); | |||
polipoRunner.Stop(); | |||
polipoRunner.openOnLan = openOnLan; | |||
polipoRunner.Start(_config.GetCurrentServer()); | |||
local = new Local(_config.GetCurrentServer()); | |||
local.openOnLan = openOnLan; | |||
local.Start(); | |||
pacServer.Stop(); | |||
pacServer.openOnLan = openOnLan; | |||
pacServer.Start(); | |||
if (ConfigChanged != null) | |||
{ | |||
ConfigChanged(this, new EventArgs()); | |||
} | |||
} | |||
>>>>>>> 835265b... add log switch and modify detector | |||
public Server GetCurrentServer() | |||
{ | |||
return _config.GetCurrentServer(); | |||
@@ -63,9 +112,10 @@ namespace Shadowsocks.Controller | |||
return Configuration.Load(); | |||
} | |||
public void SaveServers(List<Server> servers) | |||
public void SaveServers(List<Server> servers, bool noChange) | |||
{ | |||
_config.configs = servers; | |||
_config.noChange = noChange; | |||
SaveConfig(_config); | |||
} | |||
@@ -83,6 +133,7 @@ namespace Shadowsocks.Controller | |||
public void ToggleShareOverLAN(bool enabled) | |||
{ | |||
_config.shareOverLan = enabled; | |||
_config.noChange = false; | |||
SaveConfig(_config); | |||
if (ShareOverLANStatusChanged != null) | |||
{ | |||
@@ -132,6 +183,10 @@ namespace Shadowsocks.Controller | |||
protected void SaveConfig(Configuration newConfig) | |||
{ | |||
Configuration.Save(newConfig); | |||
if (newConfig.noChange) | |||
{ | |||
return; | |||
} | |||
// some logic in configuration updated the config when saving, we need to read it again | |||
_config = Configuration.Load(); | |||
@@ -173,5 +228,22 @@ namespace Shadowsocks.Controller | |||
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 shareOverLan; | |||
public bool isDefault; | |||
public bool openOnLan; | |||
public bool enableLog; | |||
public bool noChange; | |||
private static string CONFIG_FILE = "gui-config.json"; | |||
@@ -46,15 +46,18 @@ namespace Shadowsocks | |||
Console.WriteLine(e.ToString()); | |||
} | |||
LoadLibrary(dllPath); | |||
<<<<<<< HEAD | |||
Logging.OpenLogFile(); | |||
======= | |||
Logging.OpenLogFile(); | |||
>>>>>>> 835265b... add log switch and modify detector | |||
Application.EnableVisualStyles(); | |||
Application.SetCompatibleTextRenderingDefault(false); | |||
ShadowsocksController controller = new ShadowsocksController(); | |||
// TODO run without a main form to save RAM | |||
Application.Run(new ConfigForm(controller)); | |||
} | |||
} | |||
} | |||
@@ -0,0 +1,105 @@ | |||
namespace Shadowsocks.View | |||
{ | |||
partial class AboutForm | |||
{ | |||
/// <summary> | |||
/// Required designer variable. | |||
/// </summary> | |||
private System.ComponentModel.IContainer components = null; | |||
/// <summary> | |||
/// Clean up any resources being used. | |||
/// </summary> | |||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> | |||
protected override void Dispose(bool disposing) | |||
{ | |||
if (disposing && (components != null)) | |||
{ | |||
components.Dispose(); | |||
} | |||
base.Dispose(disposing); | |||
} | |||
#region Windows Form Designer generated code | |||
/// <summary> | |||
/// Required method for Designer support - do not modify | |||
/// the contents of this method with the code editor. | |||
/// </summary> | |||
private void InitializeComponent() | |||
{ | |||
this.titleLabel = new System.Windows.Forms.Label(); | |||
this.versionLabel = new System.Windows.Forms.Label(); | |||
this.authorLabel = new System.Windows.Forms.Label(); | |||
this.githubLabel = new System.Windows.Forms.LinkLabel(); | |||
this.SuspendLayout(); | |||
// | |||
// titleLabel | |||
// | |||
this.titleLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); | |||
this.titleLabel.Location = new System.Drawing.Point(12, 40); | |||
this.titleLabel.Name = "titleLabel"; | |||
this.titleLabel.Size = new System.Drawing.Size(260, 23); | |||
this.titleLabel.TabIndex = 0; | |||
this.titleLabel.Text = "Shadowsocks for Windows"; | |||
this.titleLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; | |||
// | |||
// versionLabel | |||
// | |||
this.versionLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); | |||
this.versionLabel.Location = new System.Drawing.Point(12, 84); | |||
this.versionLabel.Name = "versionLabel"; | |||
this.versionLabel.Size = new System.Drawing.Size(260, 23); | |||
this.versionLabel.TabIndex = 0; | |||
this.versionLabel.Text = "Version: 2.0.4.0"; | |||
this.versionLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; | |||
// | |||
// authorLabel | |||
// | |||
this.authorLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); | |||
this.authorLabel.Location = new System.Drawing.Point(12, 139); | |||
this.authorLabel.Name = "authorLabel"; | |||
this.authorLabel.Size = new System.Drawing.Size(260, 23); | |||
this.authorLabel.TabIndex = 0; | |||
this.authorLabel.Text = "By: clowwindy"; | |||
this.authorLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; | |||
// | |||
// githubLabel | |||
// | |||
this.githubLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); | |||
this.githubLabel.Location = new System.Drawing.Point(13, 201); | |||
this.githubLabel.Name = "githubLabel"; | |||
this.githubLabel.Size = new System.Drawing.Size(259, 23); | |||
this.githubLabel.TabIndex = 1; | |||
this.githubLabel.TabStop = true; | |||
this.githubLabel.Text = "GitHub"; | |||
this.githubLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; | |||
this.githubLabel.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.githubLabel_LinkClicked); | |||
// | |||
// AboutForm | |||
// | |||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); | |||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; | |||
this.ClientSize = new System.Drawing.Size(284, 261); | |||
this.Controls.Add(this.githubLabel); | |||
this.Controls.Add(this.authorLabel); | |||
this.Controls.Add(this.versionLabel); | |||
this.Controls.Add(this.titleLabel); | |||
this.MaximizeBox = false; | |||
this.MinimizeBox = false; | |||
this.Name = "AboutForm"; | |||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; | |||
this.Text = "About"; | |||
this.Load += new System.EventHandler(this.AboutForm_Load); | |||
this.ResumeLayout(false); | |||
} | |||
#endregion | |||
private System.Windows.Forms.Label titleLabel; | |||
private System.Windows.Forms.Label versionLabel; | |||
private System.Windows.Forms.Label authorLabel; | |||
private System.Windows.Forms.LinkLabel githubLabel; | |||
} | |||
} |
@@ -0,0 +1,33 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.ComponentModel; | |||
using System.Data; | |||
using System.Diagnostics; | |||
using System.Drawing; | |||
using System.Reflection; | |||
using System.Text; | |||
using System.Windows.Forms; | |||
namespace Shadowsocks.View | |||
{ | |||
public partial class AboutForm : Form | |||
{ | |||
public AboutForm() | |||
{ | |||
InitializeComponent(); | |||
} | |||
private void githubLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) | |||
{ | |||
string url = "https://github.com/clowwindy/shadowsocks-csharp"; | |||
System.Diagnostics.Process.Start(url); | |||
} | |||
private void AboutForm_Load(object sender, EventArgs e) | |||
{ | |||
Assembly assembly = Assembly.GetExecutingAssembly(); | |||
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location); | |||
string version = fvi.FileVersion; | |||
versionLabel.Text = "Version: " + version; | |||
} | |||
} | |||
} |
@@ -0,0 +1,120 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<root> | |||
<!-- | |||
Microsoft ResX Schema | |||
Version 2.0 | |||
The primary goals of this format is to allow a simple XML format | |||
that is mostly human readable. The generation and parsing of the | |||
various data types are done through the TypeConverter classes | |||
associated with the data types. | |||
Example: | |||
... ado.net/XML headers & schema ... | |||
<resheader name="resmimetype">text/microsoft-resx</resheader> | |||
<resheader name="version">2.0</resheader> | |||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> | |||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> | |||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> | |||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> | |||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> | |||
<value>[base64 mime encoded serialized .NET Framework object]</value> | |||
</data> | |||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> | |||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> | |||
<comment>This is a comment</comment> | |||
</data> | |||
There are any number of "resheader" rows that contain simple | |||
name/value pairs. | |||
Each data row contains a name, and value. The row also contains a | |||
type or mimetype. Type corresponds to a .NET class that support | |||
text/value conversion through the TypeConverter architecture. | |||
Classes that don't support this are serialized and stored with the | |||
mimetype set. | |||
The mimetype is used for serialized objects, and tells the | |||
ResXResourceReader how to depersist the object. This is currently not | |||
extensible. For a given mimetype the value must be set accordingly: | |||
Note - application/x-microsoft.net.object.binary.base64 is the format | |||
that the ResXResourceWriter will generate, however the reader can | |||
read any of the formats listed below. | |||
mimetype: application/x-microsoft.net.object.binary.base64 | |||
value : The object must be serialized with | |||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter | |||
: and then encoded with base64 encoding. | |||
mimetype: application/x-microsoft.net.object.soap.base64 | |||
value : The object must be serialized with | |||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter | |||
: and then encoded with base64 encoding. | |||
mimetype: application/x-microsoft.net.object.bytearray.base64 | |||
value : The object must be serialized into a byte array | |||
: using a System.ComponentModel.TypeConverter | |||
: and then encoded with base64 encoding. | |||
--> | |||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> | |||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> | |||
<xsd:element name="root" msdata:IsDataSet="true"> | |||
<xsd:complexType> | |||
<xsd:choice maxOccurs="unbounded"> | |||
<xsd:element name="metadata"> | |||
<xsd:complexType> | |||
<xsd:sequence> | |||
<xsd:element name="value" type="xsd:string" minOccurs="0" /> | |||
</xsd:sequence> | |||
<xsd:attribute name="name" use="required" type="xsd:string" /> | |||
<xsd:attribute name="type" type="xsd:string" /> | |||
<xsd:attribute name="mimetype" type="xsd:string" /> | |||
<xsd:attribute ref="xml:space" /> | |||
</xsd:complexType> | |||
</xsd:element> | |||
<xsd:element name="assembly"> | |||
<xsd:complexType> | |||
<xsd:attribute name="alias" type="xsd:string" /> | |||
<xsd:attribute name="name" type="xsd:string" /> | |||
</xsd:complexType> | |||
</xsd:element> | |||
<xsd:element name="data"> | |||
<xsd:complexType> | |||
<xsd:sequence> | |||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> | |||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> | |||
</xsd:sequence> | |||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> | |||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> | |||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> | |||
<xsd:attribute ref="xml:space" /> | |||
</xsd:complexType> | |||
</xsd:element> | |||
<xsd:element name="resheader"> | |||
<xsd:complexType> | |||
<xsd:sequence> | |||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> | |||
</xsd:sequence> | |||
<xsd:attribute name="name" type="xsd:string" use="required" /> | |||
</xsd:complexType> | |||
</xsd:element> | |||
</xsd:choice> | |||
</xsd:complexType> | |||
</xsd:element> | |||
</xsd:schema> | |||
<resheader name="resmimetype"> | |||
<value>text/microsoft-resx</value> | |||
</resheader> | |||
<resheader name="version"> | |||
<value>2.0</value> | |||
</resheader> | |||
<resheader name="reader"> | |||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | |||
</resheader> | |||
<resheader name="writer"> | |||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | |||
</resheader> | |||
</root> |
@@ -66,6 +66,14 @@ | |||
this.AddButton = new System.Windows.Forms.Button(); | |||
this.ServerGroupBox = new System.Windows.Forms.GroupBox(); | |||
this.ServersListBox = new System.Windows.Forms.ListBox(); | |||
<<<<<<< HEAD | |||
<<<<<<< HEAD | |||
======= | |||
this.openOnLanBox = new System.Windows.Forms.CheckBox(); | |||
this.enableLogBox = new System.Windows.Forms.CheckBox(); | |||
>>>>>>> 835265b... add log switch and modify detector | |||
======= | |||
>>>>>>> 7d539d3... add modify detector | |||
this.tableLayoutPanel1.SuspendLayout(); | |||
this.panel1.SuspendLayout(); | |||
this.panel3.SuspendLayout(); | |||
@@ -418,6 +426,33 @@ | |||
this.ServersListBox.TabIndex = 5; | |||
this.ServersListBox.SelectedIndexChanged += new System.EventHandler(this.ServersListBox_SelectedIndexChanged); | |||
// | |||
<<<<<<< HEAD | |||
<<<<<<< HEAD | |||
======= | |||
// openOnLanBox | |||
// | |||
this.openOnLanBox.AutoSize = true; | |||
this.openOnLanBox.Location = new System.Drawing.Point(16, 260); | |||
this.openOnLanBox.Name = "openOnLanBox"; | |||
this.openOnLanBox.Size = new System.Drawing.Size(90, 17); | |||
this.openOnLanBox.TabIndex = 7; | |||
this.openOnLanBox.Text = "Open On Lan"; | |||
this.openOnLanBox.UseVisualStyleBackColor = true; | |||
// | |||
// enableLogBox | |||
// | |||
this.enableLogBox.AutoSize = true; | |||
this.enableLogBox.Location = new System.Drawing.Point(112, 260); | |||
this.enableLogBox.Name = "enableLogBox"; | |||
this.enableLogBox.Size = new System.Drawing.Size(80, 17); | |||
this.enableLogBox.TabIndex = 7; | |||
this.enableLogBox.Text = "Enable Log"; | |||
this.enableLogBox.UseVisualStyleBackColor = true; | |||
this.enableLogBox.CheckedChanged += new System.EventHandler(this.enableLogBox_CheckedChanged); | |||
// | |||
>>>>>>> 835265b... add log switch and modify detector | |||
======= | |||
>>>>>>> 7d539d3... add modify detector | |||
// ConfigForm | |||
// | |||
this.AcceptButton = this.OKButton; | |||
@@ -426,6 +461,14 @@ | |||
this.AutoSize = true; | |||
this.CancelButton = this.MyCancelButton; | |||
this.ClientSize = new System.Drawing.Size(489, 286); | |||
<<<<<<< HEAD | |||
<<<<<<< HEAD | |||
======= | |||
this.Controls.Add(this.enableLogBox); | |||
this.Controls.Add(this.openOnLanBox); | |||
>>>>>>> 835265b... add log switch and modify detector | |||
======= | |||
>>>>>>> 7d539d3... add modify detector | |||
this.Controls.Add(this.ServersListBox); | |||
this.Controls.Add(this.ServerGroupBox); | |||
this.Controls.Add(this.panel1); | |||
@@ -487,8 +530,18 @@ | |||
private System.Windows.Forms.TextBox RemarksTextBox; | |||
private System.Windows.Forms.Label label6; | |||
private System.Windows.Forms.MenuItem QRCodeItem; | |||
<<<<<<< HEAD | |||
<<<<<<< HEAD | |||
private System.Windows.Forms.MenuItem ShowLogItem; | |||
private System.Windows.Forms.MenuItem ShareOverLANItem; | |||
======= | |||
private System.Windows.Forms.CheckBox openOnLanBox; | |||
private System.Windows.Forms.CheckBox enableLogBox; | |||
>>>>>>> 835265b... add log switch and modify detector | |||
======= | |||
private System.Windows.Forms.MenuItem ShowLogItem; | |||
private System.Windows.Forms.MenuItem ShareOverLANItem; | |||
>>>>>>> 7d539d3... add modify detector | |||
} | |||
} | |||
@@ -12,13 +12,15 @@ namespace Shadowsocks.View | |||
{ | |||
public partial class ConfigForm : Form | |||
{ | |||
private ShadowsocksController controller; | |||
private UpdateChecker updateChecker; | |||
private ShadowsocksController controller; | |||
private UpdateChecker updateChecker; | |||
private AboutForm aboutForm; | |||
// 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) | |||
{ | |||
@@ -82,11 +84,11 @@ namespace Shadowsocks.View | |||
IPTextBox.Focus(); | |||
} | |||
private bool SaveOldSelectedServer() | |||
private bool SaveOldSelectedServer(object sender) | |||
{ | |||
try | |||
{ | |||
if (oldSelectedIndex == -1 || oldSelectedIndex >= modifiedConfiguration.configs.Count) | |||
if (_oldSelectedIndex == -1 || _oldSelectedIndex >= _modifiedConfiguration.configs.Count) | |||
{ | |||
return true; | |||
} | |||
@@ -100,7 +102,27 @@ namespace Shadowsocks.View | |||
remarks = RemarksTextBox.Text | |||
}; | |||
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; | |||
} | |||
catch (FormatException) | |||
@@ -116,15 +138,15 @@ namespace Shadowsocks.View | |||
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; | |||
ServerPortTextBox.Text = server.server_port.ToString(); | |||
PasswordTextBox.Text = server.password; | |||
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; | |||
ServerGroupBox.Visible = true; | |||
//IPTextBox.Focus(); | |||
@@ -138,7 +160,7 @@ namespace Shadowsocks.View | |||
private void LoadConfiguration(Configuration configuration) | |||
{ | |||
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 + ")"); | |||
} | |||
@@ -146,15 +168,16 @@ namespace Shadowsocks.View | |||
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(); | |||
UpdateServersMenu(); | |||
enableItem.Checked = modifiedConfiguration.enabled; | |||
ShareOverLANItem.Checked = modifiedConfiguration.shareOverLan; | |||
enableItem.Checked = _modifiedConfiguration.enabled; | |||
ShareOverLANItem.Checked = _modifiedConfiguration.shareOverLan; | |||
} | |||
private void UpdateServersMenu() | |||
@@ -193,56 +216,56 @@ namespace Shadowsocks.View | |||
} | |||
else | |||
{ | |||
isFirstRun = true; | |||
_isFirstRun = true; | |||
} | |||
updateChecker.CheckUpdate(); | |||
} | |||
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 | |||
return; | |||
} | |||
if (!SaveOldSelectedServer()) | |||
if (!SaveOldSelectedServer(sender)) | |||
{ | |||
// why this won't cause stack overflow? | |||
ServersListBox.SelectedIndex = oldSelectedIndex; | |||
ServersListBox.SelectedIndex = _oldSelectedIndex; | |||
return; | |||
} | |||
LoadSelectedServer(); | |||
oldSelectedIndex = ServersListBox.SelectedIndex; | |||
_oldSelectedIndex = ServersListBox.SelectedIndex; | |||
} | |||
private void AddButton_Click(object sender, EventArgs e) | |||
{ | |||
if (!SaveOldSelectedServer()) | |||
if (!SaveOldSelectedServer(sender)) | |||
{ | |||
return; | |||
} | |||
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) | |||
{ | |||
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 | |||
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(); | |||
} | |||
@@ -258,28 +281,28 @@ namespace Shadowsocks.View | |||
private void ShowFirstTimeBalloon() | |||
{ | |||
if (isFirstRun) | |||
if (_isFirstRun) | |||
{ | |||
notifyIcon1.BalloonTipTitle = "Shadowsocks is here"; | |||
notifyIcon1.BalloonTipText = "You can turn on/off Shadowsocks in the context menu"; | |||
notifyIcon1.BalloonTipIcon = ToolTipIcon.Info; | |||
notifyIcon1.ShowBalloonTip(0); | |||
isFirstRun = false; | |||
_isFirstRun = false; | |||
} | |||
} | |||
private void OKButton_Click(object sender, EventArgs e) | |||
{ | |||
if (!SaveOldSelectedServer()) | |||
if (!SaveOldSelectedServer(sender)) | |||
{ | |||
return; | |||
} | |||
if (modifiedConfiguration.configs.Count == 0) | |||
if (_modifiedConfiguration.configs.Count == 0) | |||
{ | |||
MessageBox.Show("Please add at least one server"); | |||
return; | |||
return; | |||
} | |||
controller.SaveServers(modifiedConfiguration.configs); | |||
controller.SaveServers(_modifiedConfiguration.configs, _modifiedConfiguration.noChange); | |||
this.Hide(); | |||
ShowFirstTimeBalloon(); | |||
} | |||
@@ -298,7 +321,9 @@ namespace Shadowsocks.View | |||
private void AboutItem_Click(object sender, EventArgs e) | |||
{ | |||
Process.Start("https://github.com/clowwindy/shadowsocks-csharp"); | |||
aboutForm = new AboutForm(); | |||
aboutForm.Show(); | |||
//Process.Start("https://github.com/clowwindy/shadowsocks-csharp"); | |||
} | |||
private void notifyIcon1_DoubleClick(object sender, EventArgs e) | |||
@@ -24,12 +24,22 @@ namespace Shadowsocks.View | |||
private void GenQR(string ssconfig) | |||
{ | |||
string qrText = ssconfig; | |||
<<<<<<< HEAD | |||
string qrText = ssconfig; | |||
QRCode4CS.Options options = new QRCode4CS.Options(); | |||
options.Text = qrText; | |||
QRCode4CS.QRCode qrCoded = null; | |||
bool success = false; | |||
foreach (var level in new QRErrorCorrectLevel[]{QRErrorCorrectLevel.H, QRErrorCorrectLevel.Q, QRErrorCorrectLevel.M, QRErrorCorrectLevel.L}) | |||
foreach (var level in new QRErrorCorrectLevel[]{QRErrorCorrectLevel.H, QRErrorCorrectLevel.Q, QRErrorCorrectLevel.M, QRErrorCorrectLevel.L}) | |||
======= | |||
string qrText = ssconfig; | |||
QRCode4CS.QRCode qrCoded = new QRCode4CS.QRCode(6, QRErrorCorrectLevel.L); | |||
qrCoded.AddData(qrText); | |||
qrCoded.Make(); | |||
int blockSize = 5; | |||
Bitmap drawArea = new Bitmap((qrCoded.GetModuleCount() * blockSize), (qrCoded.GetModuleCount() * blockSize)); | |||
for (int row = 0; row < qrCoded.GetModuleCount(); row++) | |||
>>>>>>> 7d539d3... add modify detector | |||
{ | |||
for (int i = 3; i < 10; i++) | |||
{ | |||
@@ -62,8 +62,8 @@ | |||
<Reference Include="System" /> | |||
<Reference Include="System.Data" /> | |||
<Reference Include="System.Drawing" /> | |||
<Reference Include="System.Windows.Forms" /> | |||
<Reference Include="System.XML" /> | |||
<Reference Include="System.Windows.Forms" /> | |||
<Reference Include="System.XML" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<Compile Include="3rd\QRCodeCS.cs" /> | |||
@@ -80,6 +80,12 @@ | |||
<Compile Include="Controller\PACServer.cs" /> | |||
<Compile Include="Model\Server.cs" /> | |||
<Compile Include="Model\Configuration.cs" /> | |||
<Compile Include="View\AboutForm.cs"> | |||
<SubType>Form</SubType> | |||
</Compile> | |||
<Compile Include="View\AboutForm.Designer.cs"> | |||
<DependentUpon>AboutForm.cs</DependentUpon> | |||
</Compile> | |||
<Compile Include="View\ConfigForm.cs"> | |||
<SubType>Form</SubType> | |||
</Compile> | |||
@@ -98,6 +104,9 @@ | |||
<Compile Include="View\QRCodeForm.Designer.cs"> | |||
<DependentUpon>QRCodeForm.cs</DependentUpon> | |||
</Compile> | |||
<EmbeddedResource Include="View\AboutForm.resx"> | |||
<DependentUpon>AboutForm.cs</DependentUpon> | |||
</EmbeddedResource> | |||
<EmbeddedResource Include="View\ConfigForm.resx"> | |||
<DependentUpon>ConfigForm.cs</DependentUpon> | |||
<SubType>Designer</SubType> | |||