Browse Source

add Config class

tags/2.3
clowwindy 11 years ago
parent
commit
e523cbe3fa
5 changed files with 82 additions and 6 deletions
  1. +56
    -0
      shadowsocks-csharp/Config.cs
  2. +4
    -3
      shadowsocks-csharp/Encryptor.cs
  3. +7
    -1
      shadowsocks-csharp/Local.cs
  4. +3
    -1
      shadowsocks-csharp/Program.cs
  5. +12
    -1
      shadowsocks-csharp/shadowsocks-csharp.csproj

+ 56
- 0
shadowsocks-csharp/Config.cs View File

@@ -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);
}
}
}
}

+ 4
- 3
shadowsocks-csharp/Encryptor.cs View File

@@ -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;


+ 7
- 1
shadowsocks-csharp/Local.cs View File

@@ -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)
{


+ 3
- 1
shadowsocks-csharp/Program.cs View File

@@ -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();
}
}
}

+ 12
- 1
shadowsocks-csharp/shadowsocks-csharp.csproj View File

@@ -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>


Loading…
Cancel
Save