From 3e35882fee3495a38ce5e44bf8816b629b6a5aa0 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Tue, 10 Dec 2019 11:22:13 +0800 Subject: [PATCH] add ieproxy --- v2rayN/v2rayN/Forms/MainForm.cs | 12 ++---- v2rayN/v2rayN/Global.cs | 2 + v2rayN/v2rayN/Handler/StatisticsHandler.cs | 30 +++++++------- .../HttpProxyHandler/HttpProxyHandle.cs | 12 +++--- .../v2rayN/HttpProxyHandler/ProxySetting.cs | 40 ++++++++++++++----- 5 files changed, 56 insertions(+), 40 deletions(-) diff --git a/v2rayN/v2rayN/Forms/MainForm.cs b/v2rayN/v2rayN/Forms/MainForm.cs index bef32c86..11160913 100644 --- a/v2rayN/v2rayN/Forms/MainForm.cs +++ b/v2rayN/v2rayN/Forms/MainForm.cs @@ -9,6 +9,7 @@ using v2rayN.Handler; using v2rayN.HttpProxyHandler; using v2rayN.Mode; using v2rayN.Base; +using v2rayN.Tool; namespace v2rayN.Forms { @@ -1178,15 +1179,8 @@ namespace v2rayN.Forms string fileName = downloadHandle.DownloadFileName; fileName = Utils.GetPath(fileName); - using (ZipArchive archive = ZipFile.OpenRead(fileName)) - { - foreach (ZipArchiveEntry entry in archive.Entries) - { - if (entry.Length == 0) - continue; - entry.ExtractToFile(Utils.GetPath(entry.Name), true); - } - } + FileManager.ZipExtractToFile(fileName); + AppendText(false, UIRes.I18N("MsgUpdateV2rayCoreSuccessfullyMore")); Global.reloadV2ray = true; diff --git a/v2rayN/v2rayN/Global.cs b/v2rayN/v2rayN/Global.cs index 929d7624..3cdfadea 100644 --- a/v2rayN/v2rayN/Global.cs +++ b/v2rayN/v2rayN/Global.cs @@ -161,6 +161,8 @@ namespace v2rayN slow = 3000 } public const string StatisticLogOverall = "StatisticLogOverall.json"; + + public const string IEProxyExceptions = ";localhost;127.*;10.*;172.16.*;172.17.*;172.18.*;172.19.*;172.20.*;172.21.*;172.22.*;172.23.*;172.24.*;172.25.*;172.26.*;172.27.*;172.28.*;172.29.*;172.30.*;172.31.*;172.32.*"; #endregion diff --git a/v2rayN/v2rayN/Handler/StatisticsHandler.cs b/v2rayN/v2rayN/Handler/StatisticsHandler.cs index 1827685a..8d5a3a24 100644 --- a/v2rayN/v2rayN/Handler/StatisticsHandler.cs +++ b/v2rayN/v2rayN/Handler/StatisticsHandler.cs @@ -43,22 +43,22 @@ namespace v2rayN.Handler public StatisticsHandler(Mode.Config config, Action> update) { - try - { - if (Environment.Is64BitOperatingSystem) - { - FileManager.UncompressFile(Utils.GetPath("grpc_csharp_ext.x64.dll"), Resources.grpc_csharp_ext_x64_dll); - } - else - { - FileManager.UncompressFile(Utils.GetPath("grpc_csharp_ext.x86.dll"), Resources.grpc_csharp_ext_x86_dll); - } - } - catch (IOException ex) - { - Utils.SaveLog(ex.Message, ex); + //try + //{ + // if (Environment.Is64BitOperatingSystem) + // { + // FileManager.UncompressFile(Utils.GetPath("grpc_csharp_ext.x64.dll"), Resources.grpc_csharp_ext_x64_dll); + // } + // else + // { + // FileManager.UncompressFile(Utils.GetPath("grpc_csharp_ext.x86.dll"), Resources.grpc_csharp_ext_x86_dll); + // } + //} + //catch (IOException ex) + //{ + // Utils.SaveLog(ex.Message, ex); - } + //} config_ = config; Enable = config.enableStatistics; diff --git a/v2rayN/v2rayN/HttpProxyHandler/HttpProxyHandle.cs b/v2rayN/v2rayN/HttpProxyHandler/HttpProxyHandle.cs index 716d213e..e87cfcf4 100644 --- a/v2rayN/v2rayN/HttpProxyHandler/HttpProxyHandle.cs +++ b/v2rayN/v2rayN/HttpProxyHandler/HttpProxyHandle.cs @@ -6,7 +6,7 @@ namespace v2rayN.HttpProxyHandler /// /// 系统代理(http)总处理 /// 启动privoxy提供http协议 - /// 使用SysProxy设置IE系统代理或者PAC模式 + /// 设置IE系统代理或者PAC模式 /// class HttpProxyHandle { @@ -31,31 +31,31 @@ namespace v2rayN.HttpProxyHandler if (type == 1) { //PACServerHandle.Stop(); - SysProxyHandle.SetIEProxy(true, true, $"{Global.Loopback}:{port}", null); + ProxySetting.SetProxy($"{Global.Loopback}:{port}", Global.IEProxyExceptions, 2); } else if (type == 2) { string pacUrl = GetPacUrl(); - SysProxyHandle.SetIEProxy(true, false, null, pacUrl); + ProxySetting.SetProxy(pacUrl, "", 4); //PACServerHandle.Stop(); PACServerHandle.Init(config); } else if (type == 3) { //PACServerHandle.Stop(); - SysProxyHandle.SetIEProxy(false, false, null, null); + ProxySetting.UnsetProxy(); } else if (type == 4) { string pacUrl = GetPacUrl(); - SysProxyHandle.SetIEProxy(false, false, null, null); + ProxySetting.UnsetProxy(); //PACServerHandle.Stop(); PACServerHandle.Init(config); } } else { - SysProxyHandle.SetIEProxy(false, false, null, null); + ProxySetting.UnsetProxy(); //PACServerHandle.Stop(); } } diff --git a/v2rayN/v2rayN/HttpProxyHandler/ProxySetting.cs b/v2rayN/v2rayN/HttpProxyHandler/ProxySetting.cs index 638a1131..9dcc9cbd 100644 --- a/v2rayN/v2rayN/HttpProxyHandler/ProxySetting.cs +++ b/v2rayN/v2rayN/HttpProxyHandler/ProxySetting.cs @@ -8,26 +8,46 @@ namespace v2rayN.HttpProxyHandler { public static bool UnsetProxy() { - return SetProxy(null, null); - } - public static bool SetProxy(string strProxy) - { - return SetProxy(strProxy, null); + return SetProxy(null, null, 1); } - public static bool SetProxy(string strProxy, string exceptions) + public static bool SetProxy(string strProxy, string exceptions, int type) { InternetPerConnOptionList list = new InternetPerConnOptionList(); - int optionCount = Utils.IsNullOrEmpty(strProxy) ? 1 : (Utils.IsNullOrEmpty(exceptions) ? 2 : 3); + int optionCount = 1; + if (type == 1) + { + optionCount = 1; + } + else if (type == 2 || type == 4) + { + optionCount = Utils.IsNullOrEmpty(exceptions) ? 2 : 3; + } + + int m_Int = (int)PerConnFlags.PROXY_TYPE_DIRECT; + PerConnOption m_Option = PerConnOption.INTERNET_PER_CONN_FLAGS; + if (type == 2) + { + m_Int = (int)(PerConnFlags.PROXY_TYPE_DIRECT | PerConnFlags.PROXY_TYPE_PROXY); + m_Option = PerConnOption.INTERNET_PER_CONN_PROXY_SERVER; + } + else if (type == 4) + { + m_Int = (int)(PerConnFlags.PROXY_TYPE_DIRECT | PerConnFlags.PROXY_TYPE_AUTO_PROXY_URL); + m_Option = PerConnOption.INTERNET_PER_CONN_AUTOCONFIG_URL; + } + + //int optionCount = Utils.IsNullOrEmpty(strProxy) ? 1 : (Utils.IsNullOrEmpty(exceptions) ? 2 : 3); InternetConnectionOption[] options = new InternetConnectionOption[optionCount]; // USE a proxy server ... options[0].m_Option = PerConnOption.INTERNET_PER_CONN_FLAGS; - options[0].m_Value.m_Int = (int)((optionCount < 2) ? PerConnFlags.PROXY_TYPE_DIRECT : (PerConnFlags.PROXY_TYPE_DIRECT | PerConnFlags.PROXY_TYPE_PROXY)); + //options[0].m_Value.m_Int = (int)((optionCount < 2) ? PerConnFlags.PROXY_TYPE_DIRECT : (PerConnFlags.PROXY_TYPE_DIRECT | PerConnFlags.PROXY_TYPE_PROXY)); + options[0].m_Value.m_Int = m_Int; // use THIS proxy server if (optionCount > 1) { - options[1].m_Option = PerConnOption.INTERNET_PER_CONN_PROXY_SERVER; + options[1].m_Option = m_Option; options[1].m_Value.m_StringPtr = Marshal.StringToHGlobalAuto(strProxy); // except for these addresses ... if (optionCount > 2) @@ -181,7 +201,7 @@ namespace v2rayN.HttpProxyHandler string ProxyServer = rk.GetValue("ProxyServer").ToString(); rk.Close(); return ProxyServer; - + } } }