Browse Source

use different namespace

tags/3.2
clowwindy 10 years ago
parent
commit
32cadc3c18
11 changed files with 99 additions and 59 deletions
  1. +55
    -0
      shadowsocks-csharp/Controller/FileManager.cs
  2. +2
    -2
      shadowsocks-csharp/Controller/Local.cs
  3. +1
    -1
      shadowsocks-csharp/Controller/PACServer.cs
  4. +5
    -47
      shadowsocks-csharp/Controller/PolipoRunner.cs
  5. +23
    -2
      shadowsocks-csharp/Controller/ShadowsocksController.cs
  6. +2
    -2
      shadowsocks-csharp/Controller/SystemProxy.cs
  7. +1
    -1
      shadowsocks-csharp/Model/Config.cs
  8. +5
    -2
      shadowsocks-csharp/Program.cs
  9. +1
    -1
      shadowsocks-csharp/View/ConfigForm.Designer.cs
  10. +3
    -1
      shadowsocks-csharp/View/ConfigForm.cs
  11. +1
    -0
      shadowsocks-csharp/shadowsocks-csharp.csproj

+ 55
- 0
shadowsocks-csharp/Controller/FileManager.cs View File

@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Text;
namespace shadowsocks_csharp.Controller
{
public class FileManager
{
public static bool ByteArrayToFile(string fileName, byte[] content)
{
try
{
System.IO.FileStream _FileStream =
new System.IO.FileStream(fileName, System.IO.FileMode.Create,
System.IO.FileAccess.Write);
_FileStream.Write(content, 0, content.Length);
_FileStream.Close();
return true;
}
catch (Exception _Exception)
{
Console.WriteLine("Exception caught in process: {0}",
_Exception.ToString());
}
return false;
}
public static void UncompressFile(string fileName, byte[] content)
{
FileStream destinationFile = File.Create(fileName);
// Because the uncompressed size of the file is unknown,
// we are using an arbitrary buffer size.
byte[] buffer = new byte[4096];
int n;
using (GZipStream input = new GZipStream(new MemoryStream(content),
CompressionMode.Decompress, false))
{
while (true)
{
n = input.Read(buffer, 0, buffer.Length);
if (n == 0)
{
break;
}
destinationFile.Write(buffer, 0, n);
}
}
destinationFile.Close();
}
}
}

+ 2
- 2
shadowsocks-csharp/Controller/Local.cs View File

@@ -4,11 +4,11 @@ using System.Text;
using System.Net.Sockets;
using System.Net;
using shadowsocks_csharp.Encrypt;
using shadowsocks_csharp.Model;
namespace shadowsocks_csharp
namespace shadowsocks_csharp.Controller
{
class Local
{
private Config config;


+ 1
- 1
shadowsocks-csharp/Controller/PACServer.cs View File

@@ -7,7 +7,7 @@ using System.Net;
using System.Net.Sockets;
using System.Text;
namespace shadowsocks_csharp
namespace shadowsocks_csharp.Controller
{
class PACServer
{


+ 5
- 47
shadowsocks-csharp/Controller/PolipoRunner.cs View File

@@ -1,4 +1,5 @@
using shadowsocks_csharp.Properties;
using shadowsocks_csharp.Model;
using shadowsocks_csharp.Properties;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -6,54 +7,11 @@ using System.IO;
using System.IO.Compression;
using System.Text;
namespace shadowsocks_csharp
namespace shadowsocks_csharp.Controller
{
class PolipoRunner
{
private Process process;
private bool ByteArrayToFile(string fileName, byte[] content)
{
try
{
System.IO.FileStream _FileStream =
new System.IO.FileStream(fileName, System.IO.FileMode.Create,
System.IO.FileAccess.Write);
_FileStream.Write(content, 0, content.Length);
_FileStream.Close();
return true;
}
catch (Exception _Exception)
{
Console.WriteLine("Exception caught in process: {0}",
_Exception.ToString());
}
return false;
}
public static void UncompressFile(string fileName, byte[] content)
{
FileStream destinationFile = File.Create(fileName);
// Because the uncompressed size of the file is unknown,
// we are using an arbitrary buffer size.
byte[] buffer = new byte[4096];
int n;
using (GZipStream input = new GZipStream(new MemoryStream(content),
CompressionMode.Decompress, false))
{
while (true)
{
n = input.Read(buffer, 0, buffer.Length);
if (n == 0)
{
break;
}
destinationFile.Write(buffer, 0, n);
}
}
destinationFile.Close();
}
public void Start(Config config)
{
@@ -68,8 +26,8 @@ namespace shadowsocks_csharp
string temppath = Path.GetTempPath();
string polipoConfig = Resources.polipo_config;
polipoConfig = polipoConfig.Replace("__SOCKS_PORT__", config.local_port.ToString());
ByteArrayToFile(temppath + "/polipo.conf", System.Text.Encoding.UTF8.GetBytes(polipoConfig));
UncompressFile(temppath + "/ss_polipo.exe", Resources.polipo_exe);
FileManager.ByteArrayToFile(temppath + "/polipo.conf", System.Text.Encoding.UTF8.GetBytes(polipoConfig));
FileManager.UncompressFile(temppath + "/ss_polipo.exe", Resources.polipo_exe);
process = new Process();
// Configure the process using the StartInfo properties.


+ 23
- 2
shadowsocks-csharp/Controller/ShadowsocksController.cs View File

@@ -1,8 +1,9 @@
using System;
using shadowsocks_csharp.Model;
using System;
using System.Collections.Generic;
using System.Text;
namespace shadowsocks_csharp
namespace shadowsocks_csharp.Controller
{
public class ShadowsocksController
{
@@ -17,8 +18,16 @@ namespace shadowsocks_csharp
private PolipoRunner polipoRunner;
private bool stopped = false;
public class PathEventArgs : EventArgs
{
public string Path;
}
public event EventHandler ConfigChanged;
public event EventHandler EnableStatusChanged;
// when user clicked Edit PAC, and PAC file has already created
public event EventHandler<PathEventArgs> PACFileReadyToOpen;
public ShadowsocksController()
{
@@ -37,6 +46,14 @@ namespace shadowsocks_csharp
{
Config.Save(newConfig);
config = newConfig;
local.Stop();
polipoRunner.Stop();
polipoRunner.Start(config);
local = new Local(config);
local.Start();
if (ConfigChanged != null)
{
ConfigChanged(this, new EventArgs());
@@ -74,6 +91,10 @@ namespace shadowsocks_csharp
}
}
public void TouchPACFile()
{
}
private void updateSystemProxy()
{
if (config.enabled)


+ 2
- 2
shadowsocks-csharp/Controller/SystemProxy.cs View File

@@ -4,9 +4,9 @@ using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace shadowsocks_csharp
namespace shadowsocks_csharp.Controller
{
class SystemProxy
public class SystemProxy
{
[DllImport("wininet.dll")]


+ 1
- 1
shadowsocks-csharp/Model/Config.cs View File

@@ -5,7 +5,7 @@ using System.IO;
using System.Diagnostics;
using SimpleJson;
namespace shadowsocks_csharp
namespace shadowsocks_csharp.Model
{
[Serializable]
public class Config


+ 5
- 2
shadowsocks-csharp/Program.cs View File

@@ -1,4 +1,6 @@
using shadowsocks_csharp.Properties;
using shadowsocks_csharp.Controller;
using shadowsocks_csharp.Properties;
using shadowsocks_csharp.View;
using System;
using System.Collections.Generic;
using System.IO;
@@ -22,7 +24,8 @@ namespace shadowsocks_csharp
{
string tempPath = Path.GetTempPath();
string dllPath = tempPath + "/polarssl.dll";
PolipoRunner.UncompressFile(dllPath, Resources.polarssl_dll);
// TODO: PolipoRunner should not do this job
FileManager.UncompressFile(dllPath, Resources.polarssl_dll);
LoadLibrary(dllPath);
FileStream fs = new FileStream("shadowsocks.log", FileMode.Append);


+ 1
- 1
shadowsocks-csharp/View/ConfigForm.Designer.cs View File

@@ -1,4 +1,4 @@
namespace shadowsocks_csharp
namespace shadowsocks_csharp.View
{
partial class ConfigForm
{


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

@@ -5,8 +5,10 @@ using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using shadowsocks_csharp.Controller;
using shadowsocks_csharp.Model;
namespace shadowsocks_csharp
namespace shadowsocks_csharp.View
{
public partial class ConfigForm : Form
{


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

@@ -81,6 +81,7 @@
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<Compile Include="Controller\FileManager.cs" />
<Compile Include="Encrypt\EncryptorBase.cs" />
<Compile Include="Encrypt\EncryptorFactory.cs" />
<Compile Include="Encrypt\PolarSSL.cs" />


Loading…
Cancel
Save