add Config class
This commit is contained in:
Executable
+56
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace shadowsocks_csharp
|
||||
{
|
||||
[Serializable]
|
||||
public class Config
|
||||
{
|
||||
public string server;
|
||||
public int server_port;
|
||||
public int local_port;
|
||||
public string password;
|
||||
|
||||
public static Config Load()
|
||||
{
|
||||
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Config));
|
||||
try
|
||||
{
|
||||
using (FileStream fs = File.OpenRead(@"config.json"))
|
||||
{
|
||||
Config config = ser.ReadObject(fs) as Config;
|
||||
return config;
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
return new Config
|
||||
{
|
||||
server = "127.0.0.1",
|
||||
server_port = 8388,
|
||||
local_port = 1080,
|
||||
password = "foobar!"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static void Save(Config config)
|
||||
{
|
||||
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Config));
|
||||
try
|
||||
{
|
||||
using (FileStream fs = File.Open(@"config.json",FileMode.Create))
|
||||
{
|
||||
ser.WriteObject(fs, config);
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
Console.Error.WriteLine(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,11 +10,12 @@ namespace shadowsocks_csharp
|
||||
public byte[] encryptTable = new byte[256];
|
||||
public byte[] decryptTable = new byte[256];
|
||||
|
||||
private Int64 compare(byte x, byte y, UInt64 a, int i) {
|
||||
return (Int64)(a % (UInt64)(x + i)) - (Int64)(a % (UInt64)(y + i));
|
||||
private long compare(byte x, byte y, ulong a, int i)
|
||||
{
|
||||
return (long)(a % (ulong)(x + i)) - (long)(a % (ulong)(y + i));
|
||||
}
|
||||
|
||||
private byte[] mergeSort(byte[] array, UInt64 a, int j)
|
||||
private byte[] mergeSort(byte[] array, ulong a, int j)
|
||||
{
|
||||
if (array.Length == 1)
|
||||
return array;
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace shadowsocks_csharp
|
||||
{
|
||||
private int port;
|
||||
private Encryptor encryptor;
|
||||
Socket listener;
|
||||
public Local(int port)
|
||||
{
|
||||
this.port = port;
|
||||
@@ -23,7 +24,7 @@ namespace shadowsocks_csharp
|
||||
{
|
||||
|
||||
// Create a TCP/IP socket.
|
||||
Socket listener = new Socket(AddressFamily.InterNetwork,
|
||||
listener = new Socket(AddressFamily.InterNetwork,
|
||||
SocketType.Stream, ProtocolType.Tcp);
|
||||
IPEndPoint localEndPoint = new IPEndPoint(0, port);
|
||||
|
||||
@@ -40,6 +41,11 @@ namespace shadowsocks_csharp
|
||||
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
listener.Close();
|
||||
}
|
||||
|
||||
|
||||
public void AcceptCallback(IAsyncResult ar)
|
||||
{
|
||||
|
||||
@@ -12,10 +12,12 @@ namespace shadowsocks_csharp
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
new Local(1081).Start();
|
||||
Local local = new Local(1081);
|
||||
local.Start();
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new Form1());
|
||||
local.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>shadowsocks_csharp</RootNamespace>
|
||||
<AssemblyName>shadowsocks-csharp</AssemblyName>
|
||||
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<StartupObject>
|
||||
</StartupObject>
|
||||
@@ -35,13 +35,23 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Deployment" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Runtime.Serialization">
|
||||
<RequiredTargetFramework>3.0</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.ServiceModel.Web">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Config.cs" />
|
||||
<Compile Include="Encryptor.cs" />
|
||||
<Compile Include="Form1.cs">
|
||||
<SubType>Form</SubType>
|
||||
@@ -54,6 +64,7 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<EmbeddedResource Include="Form1.resx">
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
|
||||
Reference in New Issue
Block a user