diff --git a/shadowsocks-csharp/PolipoRunner.cs b/shadowsocks-csharp/PolipoRunner.cs index b1dbec9a..e99e956d 100755 --- a/shadowsocks-csharp/PolipoRunner.cs +++ b/shadowsocks-csharp/PolipoRunner.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.IO.Compression; using System.Text; namespace shadowsocks_csharp @@ -28,6 +29,32 @@ namespace shadowsocks_csharp } 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) { if (process == null) @@ -42,7 +69,7 @@ namespace shadowsocks_csharp string polipoConfig = Resources.polipo_config; polipoConfig = polipoConfig.Replace("__SOCKS_PORT__", config.local_port.ToString()); ByteArrayToFile(temppath + "/polipo.conf", System.Text.Encoding.UTF8.GetBytes(polipoConfig)); - ByteArrayToFile(temppath + "/ss_polipo.exe", Resources.polipo); + UncompressFile(temppath + "/ss_polipo.exe", Resources.polipo_exe); process = new Process(); // Configure the process using the StartInfo properties. diff --git a/shadowsocks-csharp/Properties/Resources.Designer.cs b/shadowsocks-csharp/Properties/Resources.Designer.cs index b31dd04b..aa55a463 100755 --- a/shadowsocks-csharp/Properties/Resources.Designer.cs +++ b/shadowsocks-csharp/Properties/Resources.Designer.cs @@ -60,16 +60,6 @@ namespace shadowsocks_csharp.Properties { } } - /// - /// Looks up a localized resource of type System.Byte[]. - /// - internal static byte[] polipo { - get { - object obj = ResourceManager.GetObject("polipo", resourceCulture); - return ((byte[])(obj)); - } - } - /// /// Looks up a localized string similar to # Sample configuration file for Polipo. -*-sh-*- /// @@ -95,6 +85,16 @@ namespace shadowsocks_csharp.Properties { } } + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] polipo_exe { + get { + object obj = ResourceManager.GetObject("polipo_exe", resourceCulture); + return ((byte[])(obj)); + } + } + /// /// Looks up a localized string similar to // Generated by gfwlist2pac ///// https://github.com/clowwindy/gfwlist2pac diff --git a/shadowsocks-csharp/Properties/Resources.resx b/shadowsocks-csharp/Properties/Resources.resx index d680b5a0..e1c5f7b4 100755 --- a/shadowsocks-csharp/Properties/Resources.resx +++ b/shadowsocks-csharp/Properties/Resources.resx @@ -118,12 +118,12 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - ..\polipo.exe;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - ..\config.txt;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;gb2312 + + ..\polipo.exe.gz;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + ..\proxy.pac.txt;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;gb2312 diff --git a/shadowsocks-csharp/polipo.exe b/shadowsocks-csharp/polipo.exe deleted file mode 100755 index a85b3cab..00000000 Binary files a/shadowsocks-csharp/polipo.exe and /dev/null differ diff --git a/shadowsocks-csharp/polipo.exe.gz b/shadowsocks-csharp/polipo.exe.gz new file mode 100755 index 00000000..8bda6597 Binary files /dev/null and b/shadowsocks-csharp/polipo.exe.gz differ diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj index 7541b482..f9e61f03 100755 --- a/shadowsocks-csharp/shadowsocks-csharp.csproj +++ b/shadowsocks-csharp/shadowsocks-csharp.csproj @@ -115,6 +115,7 @@ True + SettingsSingleFileGenerator Settings.Designer.cs