diff --git a/Netch/Controllers/HTTPController.cs b/Netch/Controllers/HTTPController.cs index 72ac8499..b5393993 100644 --- a/Netch/Controllers/HTTPController.cs +++ b/Netch/Controllers/HTTPController.cs @@ -39,7 +39,7 @@ namespace Netch.Controllers if (mode.Type == 3) { - if (mode.BypassChina) + if ((MainController.Server.Type == "Socks5" || MainController.Server.Type == "Trojan") && mode.BypassChina) { //启动PAC服务器 PACServerHandle.InitPACServer("127.0.0.1"); diff --git a/Netch/Controllers/MainController.cs b/Netch/Controllers/MainController.cs index 26f0a7cc..a9137b5d 100644 --- a/Netch/Controllers/MainController.cs +++ b/Netch/Controllers/MainController.cs @@ -24,6 +24,7 @@ namespace Netch.Controllers get => _udpServerController ?? _serverController; set => _udpServerController = value; } + public static Mode Mode; /// TCP or Both Server public static Server Server; @@ -53,6 +54,7 @@ namespace Netch.Controllers { Logging.Info($"启动主控制器: {server.Type} [{mode.Type}]{mode.Remark}"); Server = server; + Mode = mode; if (server is Socks5 && mode.Type == 4) { diff --git a/Netch/Forms/MainForm.MenuStrip.cs b/Netch/Forms/MainForm.MenuStrip.cs index f0692959..2e40e29a 100644 --- a/Netch/Forms/MainForm.MenuStrip.cs +++ b/Netch/Forms/MainForm.MenuStrip.cs @@ -285,18 +285,11 @@ namespace Netch.Forms NotifyTip(i18N.Translate("Updating in the background")); try { - var req = WebUtil.CreateRequest(Global.Settings.GFWLIST); + var req = WebUtil.CreateRequest(Global.Settings.PAC); - string gfwlist = Path.Combine(Global.NetchDir, $"bin\\gfwlist"); string pac = Path.Combine(Global.NetchDir, $"bin\\pac.txt"); - await WebUtil.DownloadFileAsync(req, gfwlist); - - var gfwContent = File.ReadAllText(gfwlist); - List lines = PACUtil.ParseResult(gfwContent); - string abpContent = PACUtil.UnGzip(Resources.abp_js); - abpContent = abpContent.Replace("__RULES__", JsonConvert.SerializeObject(lines, Formatting.Indented)); - File.WriteAllText(pac, abpContent, Encoding.UTF8); + await WebUtil.DownloadFileAsync(req, pac); NotifyTip(i18N.Translate("PAC updated successfully")); } diff --git a/Netch/Forms/MainForm.Status.cs b/Netch/Forms/MainForm.Status.cs index 75add501..ac0a8d7e 100644 --- a/Netch/Forms/MainForm.Status.cs +++ b/Netch/Forms/MainForm.Status.cs @@ -2,7 +2,9 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; +using Netch.Controllers; using Netch.Models; +using Netch.Servers.Socks5; using Netch.Utils; namespace Netch.Forms @@ -68,7 +70,18 @@ namespace Netch.Forms ProfileGroupBox.Enabled = true; - UsedBandwidthLabel.Visible /*= UploadSpeedLabel.Visible*/ = DownloadSpeedLabel.Visible = Global.Flags.IsWindows10Upper; + //Socks5 + Boolean s5BwFlag = true; + if (MainController.Server.Type == "Socks5") + { + Socks5 SocksServer = (Socks5) MainController.Server; + + if (!SocksServer.Auth()) s5BwFlag = false; + } + + //Socks5无身份验证且为网页代理模式时无法统计流量不显示流量状态栏,Socks5有身份验证时将统计V2ray的流量 + if (s5BwFlag || (MainController.Mode.Type == 0 || MainController.Mode.Type == 1 || MainController.Mode.Type == 2)) + UsedBandwidthLabel.Visible /*= UploadSpeedLabel.Visible*/ = DownloadSpeedLabel.Visible = Global.Flags.IsWindows10Upper; break; case State.Stopping: ControlButton.Enabled = false; diff --git a/Netch/Models/Setting.cs b/Netch/Models/Setting.cs index 84fc0815..b87f508a 100644 --- a/Netch/Models/Setting.cs +++ b/Netch/Models/Setting.cs @@ -260,7 +260,7 @@ namespace Netch.Models /// /// GFWList /// - public string GFWLIST = "https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt"; + public string PAC = "https://raw.githubusercontent.com/HMBSbige/Text_Translation/master/ShadowsocksR/ss_white.pac"; /// /// 是否使用DLL启动Shadowsocks diff --git a/Netch/Utils/Bandwidth.cs b/Netch/Utils/Bandwidth.cs index e06c8e69..47d8b16a 100644 --- a/Netch/Utils/Bandwidth.cs +++ b/Netch/Utils/Bandwidth.cs @@ -100,6 +100,7 @@ namespace Netch.Utils Logging.Info("流量统计进程:" + string.Join(",", instances.Select(instance => $"({instance.Id})" + instance.ProcessName).ToArray())); + received = 0; Task.Run(() => { tSession = new TraceEventSession("KernelAndClrEventsSession"); diff --git a/Netch/Utils/HttpProxyHandler/PACUtil.cs b/Netch/Utils/HttpProxyHandler/PACUtil.cs deleted file mode 100644 index 791dd601..00000000 --- a/Netch/Utils/HttpProxyHandler/PACUtil.cs +++ /dev/null @@ -1,56 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.IO; -using System.IO.Compression; -using System.Net; -using System.Text; -using Netch.Forms; -using Netch.Properties; - -namespace Netch.Utils.HttpProxyHandler -{ - /// - /// 提供PAC功能支持 - /// - class PACUtil - { - private static readonly IEnumerable IgnoredLineBegins = new[] {'!', '['}; - - public static List ParseResult(string response) - { - byte[] bytes = Convert.FromBase64String(response); - string content = Encoding.ASCII.GetString(bytes); - List valid_lines = new List(); - using (var sr = new StringReader(content)) - { - foreach (var line in sr.NonWhiteSpaceLines()) - { - if (line.BeginWithAny(IgnoredLineBegins)) - continue; - valid_lines.Add(line); - } - } - return valid_lines; - } - - public static string UnGzip(byte[] buf) - { - byte[] buffer = new byte[1024]; - int n; - using (MemoryStream sb = new MemoryStream()) - { - using (GZipStream input = new GZipStream(new MemoryStream(buf), - CompressionMode.Decompress, - false)) - { - while ((n = input.Read(buffer, 0, buffer.Length)) > 0) - { - sb.Write(buffer, 0, n); - } - } - return System.Text.Encoding.UTF8.GetString(sb.ToArray()); - } - } - } -} \ No newline at end of file diff --git a/binaries b/binaries index 9e6cf791..7b5ce306 160000 --- a/binaries +++ b/binaries @@ -1 +1 @@ -Subproject commit 9e6cf791cec730e1c685c977dd4212a727f3774c +Subproject commit 7b5ce30669a97b655a0ee90741d18d5d275d4204