From c342f191d7641bec88bca5b4c0cedae5fc959b96 Mon Sep 17 00:00:00 2001 From: Student Main Date: Fri, 3 Jan 2020 19:06:29 +0800 Subject: [PATCH] sysproxy now use external exe --- .../Properties/Resources.Designer.cs | 20 ------------------- shadowsocks-csharp/Properties/Resources.resx | 6 ------ .../Util/SystemProxy/Sysproxy.cs | 13 ++++++++---- shadowsocks-csharp/Util/Util.cs | 10 ++++++++++ shadowsocks-csharp/shadowsocks-csharp.csproj | 16 +++++++++++---- 5 files changed, 31 insertions(+), 34 deletions(-) diff --git a/shadowsocks-csharp/Properties/Resources.Designer.cs b/shadowsocks-csharp/Properties/Resources.Designer.cs index b08ec5a9..289d5def 100644 --- a/shadowsocks-csharp/Properties/Resources.Designer.cs +++ b/shadowsocks-csharp/Properties/Resources.Designer.cs @@ -227,26 +227,6 @@ namespace Shadowsocks.Properties { } } - /// - /// 查找 System.Byte[] 类型的本地化资源。 - /// - internal static byte[] sysproxy { - get { - object obj = ResourceManager.GetObject("sysproxy", resourceCulture); - return ((byte[])(obj)); - } - } - - /// - /// 查找 System.Byte[] 类型的本地化资源。 - /// - internal static byte[] sysproxy64 { - get { - object obj = ResourceManager.GetObject("sysproxy64", resourceCulture); - return ((byte[])(obj)); - } - } - /// /// 查找类似 ! Put user rules line by line in this file. ///! See https://adblockplus.org/en/filter-cheatsheet diff --git a/shadowsocks-csharp/Properties/Resources.resx b/shadowsocks-csharp/Properties/Resources.resx index e2532302..a7ee91ff 100755 --- a/shadowsocks-csharp/Properties/Resources.resx +++ b/shadowsocks-csharp/Properties/Resources.resx @@ -151,12 +151,6 @@ ..\Resources\ssw128.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Data\sysproxy.exe;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - ..\Data\sysproxy64.exe;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - ..\data\user-rule.txt;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 diff --git a/shadowsocks-csharp/Util/SystemProxy/Sysproxy.cs b/shadowsocks-csharp/Util/SystemProxy/Sysproxy.cs index 77fa2e68..b928e07c 100644 --- a/shadowsocks-csharp/Util/SystemProxy/Sysproxy.cs +++ b/shadowsocks-csharp/Util/SystemProxy/Sysproxy.cs @@ -65,8 +65,8 @@ namespace Shadowsocks.Util.SystemProxy { try { - FileManager.ByteArrayToFile(Utils.GetTempPath("sysproxy.exe"), - Environment.Is64BitOperatingSystem ? Resources.sysproxy64 : Resources.sysproxy); + //FileManager.ByteArrayToFile(Utils.GetTempPath("sysproxy.exe"), + // Environment.Is64BitOperatingSystem ? Resources.sysproxy64 : Resources.sysproxy); } catch (IOException e) { @@ -134,6 +134,11 @@ namespace Shadowsocks.Util.SystemProxy return true; } + private static string SysproxyName + { + get { return Environment.Is64BitOperatingSystem ? "sysproxy64.exe" : "sysproxy.exe"; } + } + private static void ExecSysproxy(string arguments) { // using event to avoid hanging when redirect standard output/error @@ -145,9 +150,9 @@ namespace Shadowsocks.Util.SystemProxy using (var process = new Process()) { // Configure the process using the StartInfo properties. - process.StartInfo.FileName = Utils.GetTempPath("sysproxy.exe"); + process.StartInfo.FileName = Utils.GetDataPath(SysproxyName); process.StartInfo.Arguments = arguments; - process.StartInfo.WorkingDirectory = Utils.GetTempPath(); + process.StartInfo.WorkingDirectory = Utils.GetDataPath(); process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardError = true; diff --git a/shadowsocks-csharp/Util/Util.cs b/shadowsocks-csharp/Util/Util.cs index 56f1e0b1..9c79b042 100755 --- a/shadowsocks-csharp/Util/Util.cs +++ b/shadowsocks-csharp/Util/Util.cs @@ -55,6 +55,16 @@ namespace Shadowsocks.Util return _tempPath; } + public static string GetDataPath() + { + return Path.Combine(Directory.GetCurrentDirectory(), "Data"); + } + + public static string GetDataPath(string filename) + { + return Path.Combine(GetDataPath(), filename); + } + public enum WindowsThemeMode { Dark, Light } // Support on Windows 10 1903+ diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj index cbb39511..1a93702b 100644 --- a/shadowsocks-csharp/shadowsocks-csharp.csproj +++ b/shadowsocks-csharp/shadowsocks-csharp.csproj @@ -273,13 +273,21 @@ PreserveNewest - - + + PreserveNewest + + + PreserveNewest + PreserveNewest - - + + PreserveNewest + + + PreserveNewest + PreserveNewest