From aef6be2c8091ce636f2de8b2086f67120c372f92 Mon Sep 17 00:00:00 2001
From: ChsBuffer <33744752+chsbuffer@users.noreply.github.com>
Date: Wed, 29 Jul 2020 14:24:23 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BD=91=E9=A1=B5=E4=BB=A3?=
=?UTF-8?q?=E7=90=86=E5=8F=AF=E8=83=BD=E4=B8=8D=E6=81=A2=E5=A4=8D=E5=8E=9F?=
=?UTF-8?q?=E8=AE=BE=E7=BD=AE=E6=88=96=E4=B8=8D=E5=8F=96=E6=B6=88=E8=AE=BE?=
=?UTF-8?q?=E7=BD=AE=E4=BB=A3=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Netch/Controllers/Mode/HTTPController.cs | 45 ++++++++++++++++--------
1 file changed, 30 insertions(+), 15 deletions(-)
diff --git a/Netch/Controllers/Mode/HTTPController.cs b/Netch/Controllers/Mode/HTTPController.cs
index 0108dab5..87bd61ee 100644
--- a/Netch/Controllers/Mode/HTTPController.cs
+++ b/Netch/Controllers/Mode/HTTPController.cs
@@ -33,7 +33,7 @@ namespace Netch.Controllers
/// 是否启动成功
public override bool Start(Server server, Mode mode)
{
- Task.Run(RecordPrevious);
+ RecordPrevious();
try
{
@@ -63,19 +63,31 @@ namespace Netch.Controllers
private void RecordPrevious()
{
- var registry = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings");
- if (registry == null)
+ try
+ {
+ var registry = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings");
+ if (registry == null)
+ throw new Exception();
+
+ prevPAC = registry.GetValue("AutoConfigURL")?.ToString() ?? "";
+ prevHTTP = registry.GetValue("ProxyServer")?.ToString() ?? "";
+ prevBypass = registry.GetValue("ProxyOverride")?.ToString() ?? "";
+ prevEnabled = registry.GetValue("ProxyEnable")?.Equals(1) ?? false; // HTTP Proxy Enabled
+
+ if (prevHTTP == $"127.0.0.1:{Global.Settings.HTTPLocalPort}")
+ {
+ prevEnabled = false;
+ prevHTTP = "";
+ }
+
+ if (prevPAC != "")
+ prevEnabled = true;
+ }
+ catch
{
prevEnabled = false;
prevPAC = prevHTTP = prevBypass = "";
- return;
}
-
- prevPAC = registry.GetValue("AutoConfigURL")?.ToString() ?? "";
- if ((registry.GetValue("ProxyEnable")?.Equals(1) ?? false) || prevPAC != "") prevEnabled = true;
-
- prevHTTP = registry.GetValue("ProxyServer")?.ToString() ?? "";
- prevBypass = registry.GetValue("ProxyOverride")?.ToString() ?? "";
}
///
@@ -88,12 +100,15 @@ namespace Netch.Controllers
Task.Factory.StartNew(pPrivoxyController.Stop),
Task.Factory.StartNew(() =>
{
- NativeMethods.SetGlobal(prevHTTP, prevBypass);
- if (prevPAC != "")
- NativeMethods.SetURL(prevPAC);
- if (!prevEnabled)
+ if (prevEnabled)
+ {
+ if (prevHTTP != "")
+ NativeMethods.SetGlobal(prevHTTP, prevBypass);
+ if (prevPAC != "")
+ NativeMethods.SetURL(prevPAC);
+ }
+ else
NativeMethods.SetDIRECT();
- prevEnabled = false;
})
};
Task.WaitAll(tasks);