初步重构 Contollers

This commit is contained in:
ChsBuffer
2020-07-09 05:00:56 +08:00
parent f605bfa437
commit 3c0a0d5f80
20 changed files with 592 additions and 1101 deletions

View File

@@ -9,16 +9,16 @@ namespace Netch.Controllers
{
public class HTTPController
{
private bool prevEnabled;
private string prevBypass, prevHTTP, prevPAC;
/// <summary>
/// 实例
/// </summary>
public PrivoxyController pPrivoxyController = new PrivoxyController();
private string prevBypass, prevHTTP, prevPAC;
private bool prevEnabled;
/// <summary>
/// 启动
/// 启动
/// </summary>
/// <param name="server">服务器</param>
/// <param name="mode">模式</param>
@@ -30,10 +30,7 @@ namespace Netch.Controllers
{
if (server.Type == "Socks5")
{
if (!string.IsNullOrWhiteSpace(server.Username) && !string.IsNullOrWhiteSpace(server.Password))
{
return false;
}
if (!string.IsNullOrWhiteSpace(server.Username) && !string.IsNullOrWhiteSpace(server.Password)) return false;
pPrivoxyController.Start(server, mode);
}
@@ -42,17 +39,12 @@ namespace Netch.Controllers
pPrivoxyController.Start(server, mode);
}
if (mode.Type != 5)
{
NativeMethods.SetGlobal($"127.0.0.1:{Global.Settings.HTTPLocalPort}", "<local>");
}
if (mode.Type != 5) NativeMethods.SetGlobal($"127.0.0.1:{Global.Settings.HTTPLocalPort}", "<local>");
}
catch (Exception e)
{
if (MessageBoxX.Show(i18N.Translate("Failed to set the system proxy, it may be caused by the lack of dependent programs. Do you want to jump to Netch's official website to download dependent programs?"), confirm:true) == DialogResult.OK)
{
Process.Start("https://netch.org/#/?id=%e4%be%9d%e8%b5%96");
}
if (MessageBoxX.Show(i18N.Translate("Failed to set the system proxy, it may be caused by the lack of dependent programs. Do you want to jump to Netch's official website to download dependent programs?"), confirm: true) == DialogResult.OK) Process.Start("https://netch.org/#/?id=%e4%be%9d%e8%b5%96");
Logging.Info("设置系统代理失败" + e);
return false;
}
@@ -69,18 +61,16 @@ namespace Netch.Controllers
prevPAC = prevHTTP = prevBypass = "";
return;
}
prevPAC = registry.GetValue("AutoConfigURL")?.ToString() ?? "";
if ((registry.GetValue("ProxyEnable")?.Equals(1) ?? false) || prevPAC != "")
{
prevEnabled = true;
}
if ((registry.GetValue("ProxyEnable")?.Equals(1) ?? false) || prevPAC != "") prevEnabled = true;
prevHTTP = registry.GetValue("ProxyServer")?.ToString() ?? "";
prevBypass = registry.GetValue("ProxyOverride")?.ToString() ?? "";
}
/// <summary>
/// 停止
/// 停止
/// </summary>
public void Stop()
{
@@ -108,4 +98,4 @@ namespace Netch.Controllers
}
}
}
}
}