From 797e34997f078fa2129b777f8770d999bb087cfe Mon Sep 17 00:00:00 2001
From: ChsBuffer <33744752+chsbuffer@users.noreply.github.com>
Date: Sun, 5 Jul 2020 12:21:35 +0800
Subject: [PATCH] Cleanup code
---
Netch/Controllers/DNSController.cs | 12 +-
Netch/Controllers/HTTPController.cs | 18 +-
Netch/Controllers/MainController.cs | 16 +-
Netch/Controllers/NFController.cs | 85 +++---
Netch/Controllers/NTTController.cs | 18 +-
Netch/Controllers/PrivoxyController.cs | 3 +-
Netch/Controllers/SSController.cs | 44 +--
Netch/Controllers/SSRController.cs | 32 ++-
Netch/Controllers/TUNTAPController.cs | 48 ++--
Netch/Controllers/TrojanController.cs | 37 +--
Netch/Controllers/UpdateChecker.cs | 6 +-
Netch/Controllers/VMessController.cs | 96 ++++---
Netch/Forms/AboutForm.cs | 7 +-
Netch/Forms/GlobalBypassIPForm.cs | 19 +-
Netch/Forms/MainForm.cs | 369 +++++++++++++------------
Netch/Forms/Mode/Process.cs | 64 ++---
Netch/Forms/Server/Shadowsocks.cs | 21 +-
Netch/Forms/Server/ShadowsocksR.cs | 25 +-
Netch/Forms/Server/Socks5.cs | 17 +-
Netch/Forms/Server/Trojan.cs | 15 +-
Netch/Forms/Server/Vmess.cs | 37 +--
Netch/Forms/SettingForm.cs | 104 ++++---
Netch/Forms/SubscribeForm.cs | 50 ++--
Netch/Netch.cs | 22 +-
Netch/Utils/Bandwidth.cs | 23 +-
Netch/Utils/Configuration.cs | 14 +-
Netch/Utils/ShareLink.cs | 30 +-
27 files changed, 633 insertions(+), 599 deletions(-)
diff --git a/Netch/Controllers/DNSController.cs b/Netch/Controllers/DNSController.cs
index b0564eb6..38de1625 100644
--- a/Netch/Controllers/DNSController.cs
+++ b/Netch/Controllers/DNSController.cs
@@ -1,8 +1,8 @@
-using Netch.Forms;
-using Netch.Utils;
-using System;
+using System;
using System.Diagnostics;
using System.IO;
+using Netch.Forms;
+using Netch.Utils;
namespace Netch.Controllers
{
@@ -19,7 +19,7 @@ namespace Netch.Controllers
///
public bool Start()
{
- MainForm.Instance.StatusText($"{Utils.i18N.Translate("Starting dns Service")}");
+ MainForm.Instance.StatusText($"{i18N.Translate("Starting dns Service")}");
try
{
if (!File.Exists("bin\\unbound.exe") && !File.Exists("bin\\unbound-service.conf") && !File.Exists("bin\\forward-zone.conf"))
@@ -43,7 +43,7 @@ namespace Netch.Controllers
}
catch (Exception)
{
- Utils.Logging.Info("dns-unbound 进程出错");
+ Logging.Info("dns-unbound 进程出错");
Stop();
return false;
}
@@ -64,7 +64,7 @@ namespace Netch.Controllers
}
catch (Exception e)
{
- Utils.Logging.Info(e.ToString());
+ Logging.Info(e.ToString());
}
}
diff --git a/Netch/Controllers/HTTPController.cs b/Netch/Controllers/HTTPController.cs
index 18cffa88..4a3e8e34 100644
--- a/Netch/Controllers/HTTPController.cs
+++ b/Netch/Controllers/HTTPController.cs
@@ -1,7 +1,9 @@
-using Netch.Utils;
-using System;
+using System;
+using System.Diagnostics;
using System.Windows.Forms;
using Microsoft.Win32;
+using Netch.Models;
+using Netch.Utils;
namespace Netch.Controllers
{
@@ -21,7 +23,7 @@ namespace Netch.Controllers
/// 服务器
/// 模式
/// 是否启动成功
- public bool Start(Models.Server server, Models.Mode mode)
+ public bool Start(Server server, Mode mode)
{
try
{
@@ -60,11 +62,11 @@ namespace Netch.Controllers
}
catch (Exception e)
{
- if (System.Windows.Forms.MessageBox.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?"), i18N.Translate("Information"), MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
+ if (MessageBox.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?"), i18N.Translate("Information"), MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
{
- System.Diagnostics.Process.Start("https://netch.org/#/?id=%e4%be%9d%e8%b5%96");
+ Process.Start("https://netch.org/#/?id=%e4%be%9d%e8%b5%96");
}
- Utils.Logging.Info("设置系统代理失败" + e.ToString());
+ Logging.Info("设置系统代理失败" + e);
return false;
}
@@ -103,7 +105,7 @@ namespace Netch.Controllers
}
catch (Exception e)
{
- Utils.Logging.Info(e.ToString());
+ Logging.Info(e.ToString());
}
NativeMethods.SetGlobal(prevHTTP, prevBypass);
@@ -127,7 +129,7 @@ namespace Netch.Controllers
}
catch (Exception e)
{
- Utils.Logging.Info(e.ToString());
+ Logging.Info(e.ToString());
}
}
}
diff --git a/Netch/Controllers/MainController.cs b/Netch/Controllers/MainController.cs
index 11ff46c0..fb023f63 100644
--- a/Netch/Controllers/MainController.cs
+++ b/Netch/Controllers/MainController.cs
@@ -1,16 +1,18 @@
-using Netch.Forms;
-using System;
+using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
+using Netch.Forms;
+using Netch.Models;
+using Netch.Utils;
namespace Netch.Controllers
{
public class MainController
{
[DllImport("dnsapi", EntryPoint = "DnsFlushResolverCache")]
- public static extern UInt32 FlushDNSResolverCache();
+ public static extern uint FlushDNSResolverCache();
public static Process GetProcess()
{
var process = new Process();
@@ -72,7 +74,7 @@ namespace Netch.Controllers
/// 服务器
/// 模式
/// 是否启动成功
- public bool Start(Models.Server server, Models.Mode mode)
+ public bool Start(Server server, Mode mode)
{
FlushDNSResolverCache();
@@ -139,8 +141,8 @@ namespace Netch.Controllers
result = pNFController.Start(server, mode, false);
if (!result)
{
- MainForm.Instance.StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Restarting Redirector")}");
- Utils.Logging.Info("正常启动失败后尝试停止驱动服务再重新启动");
+ MainForm.Instance.StatusText($"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Restarting Redirector")}");
+ Logging.Info("正常启动失败后尝试停止驱动服务再重新启动");
//正常启动失败后尝试停止驱动服务再重新启动
result = pNFController.Start(server, mode, true);
}
@@ -274,7 +276,7 @@ namespace Netch.Controllers
}
catch (Exception e)
{
- Utils.Logging.Info(e.Message);
+ Logging.Info(e.Message);
result = false;
}
return result;
diff --git a/Netch/Controllers/NFController.cs b/Netch/Controllers/NFController.cs
index 5f22ce00..6b2e42d2 100644
--- a/Netch/Controllers/NFController.cs
+++ b/Netch/Controllers/NFController.cs
@@ -1,10 +1,13 @@
-using Netch.Forms;
-using System;
+using System;
using System.Diagnostics;
using System.IO;
using System.ServiceProcess;
using System.Threading;
using System.Threading.Tasks;
+using Netch.Forms;
+using Netch.Models;
+using Netch.Utils;
+using nfapinet;
namespace Netch.Controllers
{
@@ -30,7 +33,7 @@ namespace Netch.Controllers
///
/// 当前状态
///
- public Models.State State = Models.State.Waiting;
+ public State State = State.Waiting;
// 生成驱动文件路径
public string driverPath = string.Format("{0}\\drivers\\netfilter2.sys", Environment.SystemDirectory);
@@ -42,10 +45,10 @@ namespace Netch.Controllers
/// 模式
/// 先停止驱动服务再重新启动
/// 是否成功
- public bool Start(Models.Server server, Models.Mode mode, bool StopServiceAndRestart)
+ public bool Start(Server server, Mode mode, bool StopServiceAndRestart)
{
if (!StopServiceAndRestart)
- MainForm.Instance.StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Starting Redirector")}");
+ MainForm.Instance.StatusText($"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Starting Redirector")}");
if (!File.Exists("bin\\Redirector.exe"))
{
@@ -73,17 +76,17 @@ namespace Netch.Controllers
driverName = "Win-7.sys";
break;
default:
- Utils.Logging.Info($"不支持的系统版本:{version}");
+ Logging.Info($"不支持的系统版本:{version}");
return false;
}
// 检查驱动版本号
- FileVersionInfo SystemfileVerInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(driverPath);
- FileVersionInfo BinFileVerInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(string.Format("bin\\{0}", driverName));
+ var SystemfileVerInfo = FileVersionInfo.GetVersionInfo(driverPath);
+ var BinFileVerInfo = FileVersionInfo.GetVersionInfo(string.Format("bin\\{0}", driverName));
if (!SystemfileVerInfo.FileVersion.Equals(BinFileVerInfo.FileVersion))
{
- Utils.Logging.Info("开始更新驱动");
+ Logging.Info("开始更新驱动");
// 需要更新驱动
try
{
@@ -93,18 +96,18 @@ namespace Netch.Controllers
service.Stop();
service.WaitForStatus(ServiceControllerStatus.Stopped);
}
- nfapinet.NFAPI.nf_unRegisterDriver("netfilter2");
+ NFAPI.nf_unRegisterDriver("netfilter2");
//删除老驱动
File.Delete(driverPath);
if (!InstallDriver())
return false;
- Utils.Logging.Info($"驱动更新完毕,当前驱动版本:{BinFileVerInfo.FileVersion}");
+ Logging.Info($"驱动更新完毕,当前驱动版本:{BinFileVerInfo.FileVersion}");
}
catch (Exception)
{
- Utils.Logging.Info($"更新驱动出错");
+ Logging.Info("更新驱动出错");
}
}
@@ -127,23 +130,23 @@ namespace Netch.Controllers
// 防止其他程序占用 重置 NF 百万连接数限制
service.Stop();
service.WaitForStatus(ServiceControllerStatus.Stopped);
- MainForm.Instance.StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Starting netfilter2 Service")}");
+ MainForm.Instance.StatusText($"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Starting netfilter2 Service")}");
service.Start();
}
else if (service.Status == ServiceControllerStatus.Stopped)
{
- MainForm.Instance.StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Starting netfilter2 Service")}");
+ MainForm.Instance.StatusText($"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Starting netfilter2 Service")}");
service.Start();
}
}
catch (Exception e)
{
- Utils.Logging.Info(e.ToString());
+ Logging.Info(e.ToString());
- var result = nfapinet.NFAPI.nf_registerDriver("netfilter2");
- if (result != nfapinet.NF_STATUS.NF_STATUS_SUCCESS)
+ var result = NFAPI.nf_registerDriver("netfilter2");
+ if (result != NF_STATUS.NF_STATUS_SUCCESS)
{
- Utils.Logging.Info($"注册驱动失败,返回值:{result}");
+ Logging.Info($"注册驱动失败,返回值:{result}");
return false;
}
}
@@ -166,10 +169,10 @@ namespace Netch.Controllers
}
else
{
- var result = Utils.DNS.Lookup(server.Hostname);
+ var result = DNS.Lookup(server.Hostname);
if (result == null)
{
- Utils.Logging.Info("无法解析服务器 IP 地址");
+ Logging.Info("无法解析服务器 IP 地址");
return false;
}
@@ -186,10 +189,10 @@ namespace Netch.Controllers
}
Instance.StartInfo.Arguments += $" -t {Global.Settings.RedirectorTCPPort}";
- Utils.Logging.Info(Instance.StartInfo.Arguments);
+ Logging.Info(Instance.StartInfo.Arguments);
Instance.OutputDataReceived += OnOutputDataReceived;
Instance.ErrorDataReceived += OnOutputDataReceived;
- State = Models.State.Starting;
+ State = State.Starting;
Instance.Start();
Instance.BeginOutputReadLine();
Instance.BeginErrorReadLine();
@@ -198,13 +201,13 @@ namespace Netch.Controllers
{
Thread.Sleep(1000);
- if (State == Models.State.Started)
+ if (State == State.Started)
{
return true;
}
}
- Utils.Logging.Info("NF 进程启动超时");
+ Logging.Info("NF 进程启动超时");
Stop();
return false;
}
@@ -224,13 +227,13 @@ namespace Netch.Controllers
}
catch (Exception e)
{
- Utils.Logging.Info(e.ToString());
+ Logging.Info(e.ToString());
}
}
public bool InstallDriver()
{
- Utils.Logging.Info("安装驱动中");
+ Logging.Info("安装驱动中");
// 生成系统版本
var version = $"{Environment.OSVersion.Version.Major.ToString()}.{Environment.OSVersion.Version.Minor.ToString()}";
@@ -241,35 +244,35 @@ namespace Netch.Controllers
{
case "10.0":
File.Copy("bin\\Win-10.sys", driverPath);
- Utils.Logging.Info("已复制 Win10 驱动");
+ Logging.Info("已复制 Win10 驱动");
break;
case "6.3":
case "6.2":
File.Copy("bin\\Win-8.sys", driverPath);
- Utils.Logging.Info("已复制 Win8 驱动");
+ Logging.Info("已复制 Win8 驱动");
break;
case "6.1":
case "6.0":
File.Copy("bin\\Win-7.sys", driverPath);
- Utils.Logging.Info("已复制 Win7 驱动");
+ Logging.Info("已复制 Win7 驱动");
break;
default:
- Utils.Logging.Info($"不支持的系统版本:{version}");
+ Logging.Info($"不支持的系统版本:{version}");
return false;
}
}
catch (Exception e)
{
- Utils.Logging.Info("复制驱动文件失败");
- Utils.Logging.Info(e.ToString());
+ Logging.Info("复制驱动文件失败");
+ Logging.Info(e.ToString());
return false;
}
- MainForm.Instance.StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Register driver")}");
+ MainForm.Instance.StatusText($"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Register driver")}");
// 注册驱动文件
- var result = nfapinet.NFAPI.nf_registerDriver("netfilter2");
- if (result != nfapinet.NF_STATUS.NF_STATUS_SUCCESS)
+ var result = NFAPI.nf_registerDriver("netfilter2");
+ if (result != NF_STATUS.NF_STATUS_SUCCESS)
{
- Utils.Logging.Info($"注册驱动失败,返回值:{result}");
+ Logging.Info($"注册驱动失败,返回值:{result}");
return false;
}
return true;
@@ -281,22 +284,22 @@ namespace Netch.Controllers
{
File.AppendAllText("logging\\redirector.log", string.Format("{0}\r\n", e.Data));
- if (State == Models.State.Starting)
+ if (State == State.Starting)
{
if (Instance.HasExited)
{
- State = Models.State.Stopped;
+ State = State.Stopped;
}
else if (e.Data.Contains("Started"))
{
- State = Models.State.Started;
+ State = State.Started;
}
else if (e.Data.Contains("Failed") || e.Data.Contains("Unable"))
{
- State = Models.State.Stopped;
+ State = State.Stopped;
}
}
- else if (State == Models.State.Started)
+ else if (State == State.Started)
{
if (e.Data.StartsWith("[APP][Bandwidth]"))
{
diff --git a/Netch/Controllers/NTTController.cs b/Netch/Controllers/NTTController.cs
index 2871f6ae..637c4c42 100644
--- a/Netch/Controllers/NTTController.cs
+++ b/Netch/Controllers/NTTController.cs
@@ -1,8 +1,10 @@
-using Netch.Forms;
-using System;
+using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
+using Netch.Forms;
+using Netch.Models;
+using Netch.Utils;
namespace Netch.Controllers
{
@@ -16,7 +18,7 @@ namespace Netch.Controllers
///
/// 当前状态
///
- public Models.State State = Models.State.Waiting;
+ public State State = State.Waiting;
///
/// 启动NatTypeTester
@@ -25,7 +27,7 @@ namespace Netch.Controllers
public (bool, string, string, string) Start()
{
Thread.Sleep(1000);
- MainForm.Instance.NatTypeStatusText($"{Utils.i18N.Translate("Starting NatTester")}");
+ MainForm.Instance.NatTypeStatusText($"{i18N.Translate("Starting NatTester")}");
try
{
if (!File.Exists("bin\\NTT.exe"))
@@ -41,13 +43,13 @@ namespace Netch.Controllers
Instance.OutputDataReceived += OnOutputDataReceived;
Instance.ErrorDataReceived += OnOutputDataReceived;
- State = Models.State.Starting;
+ State = State.Starting;
Instance.Start();
Instance.BeginOutputReadLine();
Instance.BeginErrorReadLine();
Instance.WaitForExit();
- string[] result = File.ReadAllText("logging\\NTT.log").ToString().Split('#');
+ var result = File.ReadAllText("logging\\NTT.log").Split('#');
var natType = result[0];
var localEnd = result[1];
var publicEnd = result[2];
@@ -57,7 +59,7 @@ namespace Netch.Controllers
}
catch (Exception)
{
- Utils.Logging.Info("NTT 进程出错");
+ Logging.Info("NTT 进程出错");
Stop();
return (false, null, null, null);
}
@@ -78,7 +80,7 @@ namespace Netch.Controllers
}
catch (Exception e)
{
- Utils.Logging.Info(e.ToString());
+ Logging.Info(e.ToString());
}
}
diff --git a/Netch/Controllers/PrivoxyController.cs b/Netch/Controllers/PrivoxyController.cs
index e71ec014..4a2cf7d7 100644
--- a/Netch/Controllers/PrivoxyController.cs
+++ b/Netch/Controllers/PrivoxyController.cs
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics;
using System.IO;
+using Netch.Models;
namespace Netch.Controllers
{
@@ -17,7 +18,7 @@ namespace Netch.Controllers
/// 服务器
/// 模式
/// 是否启动成功
- public bool Start(Models.Server server, Models.Mode mode)
+ public bool Start(Server server, Mode mode)
{
foreach (var proc in Process.GetProcessesByName("Privoxy"))
{
diff --git a/Netch/Controllers/SSController.cs b/Netch/Controllers/SSController.cs
index 31251108..674bfbae 100644
--- a/Netch/Controllers/SSController.cs
+++ b/Netch/Controllers/SSController.cs
@@ -1,11 +1,11 @@
-using Netch.Forms;
-using Netch.Utils;
-using System;
+using System;
using System.Diagnostics;
using System.IO;
-using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
+using Netch.Forms;
+using Netch.Models;
+using Netch.Utils;
namespace Netch.Controllers
{
@@ -19,7 +19,7 @@ namespace Netch.Controllers
///
/// 当前状态
///
- public Models.State State = Models.State.Waiting;
+ public State State = State.Waiting;
///
/// 启动
@@ -27,22 +27,22 @@ namespace Netch.Controllers
/// 服务器
/// 模式
/// 是否启动成功
- public bool Start(Models.Server server, Models.Mode mode)
+ public bool Start(Server server, Mode mode)
{
- MainForm.Instance.StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Starting Shadowsocks")}");
+ MainForm.Instance.StatusText($"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Starting Shadowsocks")}");
File.Delete("logging\\shadowsocks.log");
//从DLL启动Shaowsocks
if (Global.Settings.BootShadowsocksFromDLL && (mode.Type == 0 || mode.Type == 1 || mode.Type == 2 || mode.Type == 3))
{
- State = Models.State.Starting;
+ State = State.Starting;
var client = Encoding.UTF8.GetBytes($"0.0.0.0:{Global.Settings.Socks5LocalPort}");
var remote = Encoding.UTF8.GetBytes($"{server.Hostname}:{server.Port}");
var passwd = Encoding.UTF8.GetBytes($"{server.Password}");
var method = Encoding.UTF8.GetBytes($"{server.EncryptMethod}");
if (!NativeMethods.Shadowsocks.Info(client, remote, passwd, method))
{
- State = Models.State.Stopped;
+ State = State.Stopped;
Logging.Info("DLL SS INFO 设置失败!");
return false;
}
@@ -50,12 +50,12 @@ namespace Netch.Controllers
if (!NativeMethods.Shadowsocks.Start())
{
- State = Models.State.Stopped;
+ State = State.Stopped;
Logging.Info("DLL SS 启动失败!");
return false;
}
Logging.Info("DLL SS 启动成功!");
- State = Models.State.Started;
+ State = State.Started;
return true;
}
@@ -83,7 +83,7 @@ namespace Netch.Controllers
Instance.OutputDataReceived += OnOutputDataReceived;
Instance.ErrorDataReceived += OnOutputDataReceived;
- State = Models.State.Starting;
+ State = State.Starting;
Instance.Start();
Instance.BeginOutputReadLine();
Instance.BeginErrorReadLine();
@@ -91,21 +91,21 @@ namespace Netch.Controllers
{
Thread.Sleep(10);
- if (State == Models.State.Started)
+ if (State == State.Started)
{
return true;
}
- if (State == Models.State.Stopped)
+ if (State == State.Stopped)
{
- Utils.Logging.Info("SS 进程启动失败");
+ Logging.Info("SS 进程启动失败");
Stop();
return false;
}
}
- Utils.Logging.Info("SS 进程启动超时");
+ Logging.Info("SS 进程启动超时");
Stop();
return false;
}
@@ -131,7 +131,7 @@ namespace Netch.Controllers
}
catch (Exception e)
{
- Utils.Logging.Info(e.ToString());
+ Logging.Info(e.ToString());
}
}
@@ -143,26 +143,26 @@ namespace Netch.Controllers
{
File.AppendAllText("logging\\shadowsocks.log", $"{e.Data}\r\n");
- if (State == Models.State.Starting)
+ if (State == State.Starting)
{
if (Instance.HasExited)
{
- State = Models.State.Stopped;
+ State = State.Stopped;
}
else if (e.Data.Contains("listening at"))
{
- State = Models.State.Started;
+ State = State.Started;
}
else if (e.Data.Contains("Invalid config path") || e.Data.Contains("usage") || e.Data.Contains("plugin service exit unexpectedly"))
{
- State = Models.State.Stopped;
+ State = State.Stopped;
}
}
}
}
catch (Exception ec)
{
- Logging.Info("写入Shadowsocks日志失败" + ec.ToString());
+ Logging.Info("写入Shadowsocks日志失败" + ec);
}
}
}
diff --git a/Netch/Controllers/SSRController.cs b/Netch/Controllers/SSRController.cs
index f1b74721..d2475b46 100644
--- a/Netch/Controllers/SSRController.cs
+++ b/Netch/Controllers/SSRController.cs
@@ -1,8 +1,10 @@
-using Netch.Forms;
-using System;
+using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
+using Netch.Forms;
+using Netch.Models;
+using Netch.Utils;
namespace Netch.Controllers
{
@@ -16,7 +18,7 @@ namespace Netch.Controllers
///
/// 当前状态
///
- public Models.State State = Models.State.Waiting;
+ public State State = State.Waiting;
///
/// 启动
@@ -24,9 +26,9 @@ namespace Netch.Controllers
/// 服务器
/// 模式
/// 是否启动成功
- public bool Start(Models.Server server, Models.Mode mode)
+ public bool Start(Server server, Mode mode)
{
- MainForm.Instance.StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Starting ShadowsocksR")}");
+ MainForm.Instance.StatusText($"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Starting ShadowsocksR")}");
File.Delete("logging\\shadowsocksr.log");
@@ -69,7 +71,7 @@ namespace Netch.Controllers
Instance.OutputDataReceived += OnOutputDataReceived;
Instance.ErrorDataReceived += OnOutputDataReceived;
- State = Models.State.Starting;
+ State = State.Starting;
Instance.Start();
Instance.BeginOutputReadLine();
Instance.BeginErrorReadLine();
@@ -77,21 +79,21 @@ namespace Netch.Controllers
{
Thread.Sleep(10);
- if (State == Models.State.Started)
+ if (State == State.Started)
{
return true;
}
- if (State == Models.State.Stopped)
+ if (State == State.Stopped)
{
- Utils.Logging.Info("SSR 进程启动失败");
+ Logging.Info("SSR 进程启动失败");
Stop();
return false;
}
}
- Utils.Logging.Info("SSR 进程启动超时");
+ Logging.Info("SSR 进程启动超时");
Stop();
return false;
}
@@ -111,7 +113,7 @@ namespace Netch.Controllers
}
catch (Exception e)
{
- Utils.Logging.Info(e.ToString());
+ Logging.Info(e.ToString());
}
}
@@ -121,19 +123,19 @@ namespace Netch.Controllers
{
File.AppendAllText("logging\\shadowsocksr.log", $"{e.Data}\r\n");
- if (State == Models.State.Starting)
+ if (State == State.Starting)
{
if (Instance.HasExited)
{
- State = Models.State.Stopped;
+ State = State.Stopped;
}
else if (e.Data.Contains("listening at"))
{
- State = Models.State.Started;
+ State = State.Started;
}
else if (e.Data.Contains("Invalid config path") || e.Data.Contains("usage"))
{
- State = Models.State.Stopped;
+ State = State.Stopped;
}
}
}
diff --git a/Netch/Controllers/TUNTAPController.cs b/Netch/Controllers/TUNTAPController.cs
index e9ab419d..f9cead05 100644
--- a/Netch/Controllers/TUNTAPController.cs
+++ b/Netch/Controllers/TUNTAPController.cs
@@ -1,12 +1,14 @@
-using Netch.Forms;
-using Netch.Utils;
-using System;
+using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;
+using Netch.Forms;
+using Netch.Models;
+using Netch.Properties;
+using Netch.Utils;
namespace Netch.Controllers
{
@@ -20,7 +22,7 @@ namespace Netch.Controllers
///
/// 当前状态
///
- public Models.State State = Models.State.Waiting;
+ public State State = State.Waiting;
///
/// 服务器 IP 地址
@@ -30,8 +32,8 @@ namespace Netch.Controllers
///
/// 保存传入的规则
///
- public Models.Server SavedServer = new Models.Server();
- public Models.Mode SavedMode = new Models.Mode();
+ public Server SavedServer = new Server();
+ public Mode SavedMode = new Mode();
///
/// 本地 DNS 服务控制器
@@ -39,7 +41,7 @@ namespace Netch.Controllers
public DNSController pDNSController = new DNSController();
// ByPassLan IP
- List BypassLanIPs = new List() { "10.0.0.0/8", "172.16.0.0/16", "192.168.0.0/16" };
+ List BypassLanIPs = new List { "10.0.0.0/8", "172.16.0.0/16", "192.168.0.0/16" };
///
/// 配置 TUNTAP 适配器
@@ -59,7 +61,7 @@ namespace Netch.Controllers
}
// 搜索出口
- return Utils.Configuration.SearchOutbounds();
+ return Configuration.SearchOutbounds();
}
///
@@ -67,7 +69,7 @@ namespace Netch.Controllers
///
public bool SetupBypass()
{
- MainForm.Instance.StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("SetupBypass")}");
+ MainForm.Instance.StatusText($"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("SetupBypass")}");
Logging.Info("设置绕行规则 → 设置让服务器 IP 走直连");
// 让服务器 IP 走直连
foreach (var address in ServerAddresses)
@@ -82,7 +84,7 @@ namespace Netch.Controllers
if (SavedMode.BypassChina)
{
Logging.Info("设置绕行规则 → 处理模式的绕过中国");
- using (var sr = new StringReader(Encoding.UTF8.GetString(Properties.Resources.CNIP)))
+ using (var sr = new StringReader(Encoding.UTF8.GetString(Resources.CNIP)))
{
string text;
@@ -142,7 +144,7 @@ namespace Netch.Controllers
// 创建默认路由
if (!NativeMethods.CreateRoute("0.0.0.0", 0, Global.Settings.TUNTAP.Gateway, Global.TUNTAP.Index, 10))
{
- State = Models.State.Stopped;
+ State = State.Stopped;
foreach (var address in ServerAddresses)
{
@@ -209,7 +211,7 @@ namespace Netch.Controllers
Logging.Info("设置绕行规则 → 处理自定义 DNS 代理");
if (Global.Settings.TUNTAP.UseCustomDNS)
{
- string dns = "";
+ var dns = "";
foreach (var value in Global.Settings.TUNTAP.DNS)
{
dns += value;
@@ -296,7 +298,7 @@ namespace Netch.Controllers
{
if (Global.Settings.TUNTAP.UseCustomDNS)
{
- string dns = "";
+ var dns = "";
foreach (var value in Global.Settings.TUNTAP.DNS)
{
dns += value;
@@ -343,7 +345,7 @@ namespace Netch.Controllers
if (SavedMode.BypassChina)
{
- using (var sr = new StringReader(Encoding.UTF8.GetString(Properties.Resources.CNIP)))
+ using (var sr = new StringReader(Encoding.UTF8.GetString(Resources.CNIP)))
{
string text;
@@ -371,9 +373,9 @@ namespace Netch.Controllers
///
/// 配置
/// 是否成功
- public bool Start(Models.Server server, Models.Mode mode)
+ public bool Start(Server server, Mode mode)
{
- MainForm.Instance.StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Starting Tap")}");
+ MainForm.Instance.StatusText($"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Starting Tap")}");
foreach (var proc in Process.GetProcessesByName("tun2socks"))
{
try
@@ -459,7 +461,7 @@ namespace Netch.Controllers
Logging.Info(Instance.StartInfo.Arguments);
- State = Models.State.Starting;
+ State = State.Starting;
Instance.Start();
Instance.BeginErrorReadLine();
Instance.BeginOutputReadLine();
@@ -469,12 +471,12 @@ namespace Netch.Controllers
{
Thread.Sleep(10);
- if (State == Models.State.Started)
+ if (State == State.Started)
{
return true;
}
- if (State == Models.State.Stopped)
+ if (State == State.Stopped)
{
Stop();
return false;
@@ -503,7 +505,7 @@ namespace Netch.Controllers
}
catch (Exception e)
{
- Utils.Logging.Info(e.ToString());
+ Logging.Info(e.ToString());
}
}
@@ -513,15 +515,15 @@ namespace Netch.Controllers
{
File.AppendAllText("logging\\tun2socks.log", string.Format("{0}\r\n", e.Data.Trim()));
- if (State == Models.State.Starting)
+ if (State == State.Starting)
{
if (e.Data.Contains("Running"))
{
- State = Models.State.Started;
+ State = State.Started;
}
else if (e.Data.Contains("failed") || e.Data.Contains("invalid vconfig file"))
{
- State = Models.State.Stopped;
+ State = State.Stopped;
}
}
}
diff --git a/Netch/Controllers/TrojanController.cs b/Netch/Controllers/TrojanController.cs
index 9e07f277..96a191fb 100644
--- a/Netch/Controllers/TrojanController.cs
+++ b/Netch/Controllers/TrojanController.cs
@@ -2,10 +2,11 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
-using System.Linq;
-using System.Text;
using System.Threading;
-using System.Threading.Tasks;
+using Netch.Forms;
+using Netch.Models;
+using Netch.Utils;
+using Newtonsoft.Json;
namespace Netch.Controllers
{
@@ -19,7 +20,7 @@ namespace Netch.Controllers
///
/// 当前状态
///
- public Models.State State = Models.State.Waiting;
+ public State State = State.Waiting;
///
/// 启动
@@ -27,9 +28,9 @@ namespace Netch.Controllers
/// 服务器
/// 模式
/// 是否启动成功
- public bool Start(Models.Server server, Models.Mode mode)
+ public bool Start(Server server, Mode mode)
{
- Forms.MainForm.Instance.StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Starting Trojan")}");
+ MainForm.Instance.StatusText($"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Starting Trojan")}");
File.Delete("logging\\trojan.log");
if (!File.Exists("bin\\Trojan.exe"))
@@ -37,13 +38,13 @@ namespace Netch.Controllers
return false;
}
- File.WriteAllText("data\\last.json", Newtonsoft.Json.JsonConvert.SerializeObject(new Models.Trojan()
+ File.WriteAllText("data\\last.json", JsonConvert.SerializeObject(new Trojan
{
local_addr = Global.Settings.LocalAddress,
local_port = Global.Settings.Socks5LocalPort,
remote_addr = server.Hostname,
remote_port = server.Port,
- password = new List()
+ password = new List
{
server.Password
}
@@ -55,7 +56,7 @@ namespace Netch.Controllers
Instance.OutputDataReceived += OnOutputDataReceived;
Instance.ErrorDataReceived += OnOutputDataReceived;
- State = Models.State.Starting;
+ State = State.Starting;
Instance.Start();
Instance.BeginOutputReadLine();
Instance.BeginErrorReadLine();
@@ -63,21 +64,21 @@ namespace Netch.Controllers
{
Thread.Sleep(10);
- if (State == Models.State.Started)
+ if (State == State.Started)
{
return true;
}
- if (State == Models.State.Stopped)
+ if (State == State.Stopped)
{
- Utils.Logging.Info("Trojan 进程启动失败");
+ Logging.Info("Trojan 进程启动失败");
Stop();
return false;
}
}
- Utils.Logging.Info("Trojan 进程启动超时");
+ Logging.Info("Trojan 进程启动超时");
Stop();
return false;
}
@@ -97,7 +98,7 @@ namespace Netch.Controllers
}
catch (Exception e)
{
- Utils.Logging.Info(e.ToString());
+ Logging.Info(e.ToString());
}
}
@@ -107,19 +108,19 @@ namespace Netch.Controllers
{
File.AppendAllText("logging\\trojan.log", $"{e.Data}\r\n");
- if (State == Models.State.Starting)
+ if (State == State.Starting)
{
if (Instance.HasExited)
{
- State = Models.State.Stopped;
+ State = State.Stopped;
}
else if (e.Data.Contains("started"))
{
- State = Models.State.Started;
+ State = State.Started;
}
else if (e.Data.Contains("exiting"))
{
- State = Models.State.Stopped;
+ State = State.Stopped;
}
}
}
diff --git a/Netch/Controllers/UpdateChecker.cs b/Netch/Controllers/UpdateChecker.cs
index 8770d2ed..dc7234f8 100644
--- a/Netch/Controllers/UpdateChecker.cs
+++ b/Netch/Controllers/UpdateChecker.cs
@@ -1,10 +1,10 @@
-using Netch.Models.GitHubRelease;
-using Newtonsoft.Json;
-using System;
+using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net.Http;
using System.Threading.Tasks;
+using Netch.Models.GitHubRelease;
+using Newtonsoft.Json;
namespace Netch.Controllers
{
diff --git a/Netch/Controllers/VMessController.cs b/Netch/Controllers/VMessController.cs
index 338203fc..68e555b6 100644
--- a/Netch/Controllers/VMessController.cs
+++ b/Netch/Controllers/VMessController.cs
@@ -1,9 +1,13 @@
-using Netch.Forms;
-using System;
+using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading;
+using Netch.Forms;
+using Netch.Models;
+using Netch.Utils;
+using Newtonsoft.Json;
+using VMess = Netch.Models.Information.VMess;
namespace Netch.Controllers
{
@@ -17,7 +21,7 @@ namespace Netch.Controllers
///
/// 当前状态
///
- public Models.State State = Models.State.Waiting;
+ public State State = State.Waiting;
///
/// 启动
@@ -25,40 +29,40 @@ namespace Netch.Controllers
/// 服务器
/// 模式
/// 是否启动成功
- public bool Start(Models.Server server, Models.Mode mode)
+ public bool Start(Server server, Mode mode)
{
- MainForm.Instance.StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Starting V2ray")}");
+ MainForm.Instance.StatusText($"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Starting V2ray")}");
if (!File.Exists("bin\\v2ray.exe") || !File.Exists("bin\\v2ctl.exe"))
{
return false;
}
- File.WriteAllText("data\\last.json", Newtonsoft.Json.JsonConvert.SerializeObject(new Models.Information.VMess.Config
+ File.WriteAllText("data\\last.json", JsonConvert.SerializeObject(new VMess.Config
{
- inbounds = new List
+ inbounds = new List
{
- new Models.Information.VMess.Inbounds
+ new VMess.Inbounds
{
- settings = new Models.Information.VMess.InboundSettings(),
+ settings = new VMess.InboundSettings(),
port = Global.Settings.Socks5LocalPort,
listen = Global.Settings.LocalAddress
}
},
- outbounds = new List
+ outbounds = new List
{
- new Models.Information.VMess.Outbounds
+ new VMess.Outbounds
{
- settings = new Models.Information.VMess.OutboundSettings
+ settings = new VMess.OutboundSettings
{
- vnext = new List
+ vnext = new List
{
- new Models.Information.VMess.VNext
+ new VMess.VNext
{
address = server.Hostname,
port = server.Port,
- users = new List
+ users = new List
{
- new Models.Information.VMess.User
+ new VMess.User
{
id = server.UserID,
alterId = server.AlterID,
@@ -68,80 +72,80 @@ namespace Netch.Controllers
}
}
},
- streamSettings = new Models.Information.VMess.StreamSettings
+ streamSettings = new VMess.StreamSettings
{
network = server.TransferProtocol,
security = server.TLSSecure ? "tls" : "",
- wsSettings = server.TransferProtocol == "ws" ? new Models.Information.VMess.WebSocketSettings
+ wsSettings = server.TransferProtocol == "ws" ? new VMess.WebSocketSettings
{
path = server.Path == "" ? "/" : server.Path,
- headers = new Models.Information.VMess.WSHeaders
+ headers = new VMess.WSHeaders
{
Host = server.Host == "" ? server.Hostname : server.Host
}
} : null,
- tcpSettings = server.FakeType == "http" ? new Models.Information.VMess.TCPSettings
+ tcpSettings = server.FakeType == "http" ? new VMess.TCPSettings
{
- header = new Models.Information.VMess.TCPHeaders
+ header = new VMess.TCPHeaders
{
type = server.FakeType,
- request = new Models.Information.VMess.TCPRequest
+ request = new VMess.TCPRequest
{
path = server.Path == "" ? "/" : server.Path,
- headers = new Models.Information.VMess.TCPRequestHeaders
+ headers = new VMess.TCPRequestHeaders
{
Host = server.Host == "" ? server.Hostname : server.Host
}
}
}
} : null,
- kcpSettings = server.TransferProtocol == "kcp" ? new Models.Information.VMess.KCPSettings
+ kcpSettings = server.TransferProtocol == "kcp" ? new VMess.KCPSettings
{
- header = new Models.Information.VMess.TCPHeaders
+ header = new VMess.TCPHeaders
{
type = server.FakeType
}
} : null,
- quicSettings = server.TransferProtocol == "quic" ? new Models.Information.VMess.QUICSettings
+ quicSettings = server.TransferProtocol == "quic" ? new VMess.QUICSettings
{
security = server.QUICSecure,
key = server.QUICSecret,
- header = new Models.Information.VMess.TCPHeaders
+ header = new VMess.TCPHeaders
{
type = server.FakeType
}
} : null,
- httpSettings = server.TransferProtocol == "h2" ? new Models.Information.VMess.HTTPSettings
+ httpSettings = server.TransferProtocol == "h2" ? new VMess.HTTPSettings
{
host = server.Host == "" ? server.Hostname : server.Host,
path = server.Path == "" ? "/" : server.Path
} : null,
- tlsSettings = new Models.Information.VMess.TLSSettings
+ tlsSettings = new VMess.TLSSettings
{
allowInsecure = true,
serverName = server.Host == "" ? server.Hostname : server.Host
}
},
- mux = new Models.Information.VMess.OutboundMux
+ mux = new VMess.OutboundMux
{
enabled = server.UseMux
}
},
- (mode.Type==0||mode.Type==1||mode.Type==2) ? new Models.Information.VMess.Outbounds
+ (mode.Type==0||mode.Type==1||mode.Type==2) ? new VMess.Outbounds
{
tag = "TUNTAP",
protocol = "freedom"
- }: new Models.Information.VMess.Outbounds
+ }: new VMess.Outbounds
{
tag = "direct",
protocol = "freedom"
}
},
- routing = new Models.Information.VMess.Routing
+ routing = new VMess.Routing
{
- rules = new List
+ rules = new List
{
- mode.BypassChina ? new Models.Information.VMess.RoutingRules
+ mode.BypassChina ? new VMess.RoutingRules
{
type = "field",
ip = new List
@@ -155,7 +159,7 @@ namespace Netch.Controllers
"geosite:cn"
},
outboundTag = "direct"
- } : new Models.Information.VMess.RoutingRules
+ } : new VMess.RoutingRules
{
type = "field",
ip = new List
@@ -184,7 +188,7 @@ namespace Netch.Controllers
Instance.OutputDataReceived += OnOutputDataReceived;
Instance.ErrorDataReceived += OnOutputDataReceived;
- State = Models.State.Starting;
+ State = State.Starting;
Instance.Start();
Instance.BeginOutputReadLine();
Instance.BeginErrorReadLine();
@@ -192,7 +196,7 @@ namespace Netch.Controllers
{
Thread.Sleep(10);
- if (State == Models.State.Started)
+ if (State == State.Started)
{
if (File.Exists("data\\last.json"))
{
@@ -201,16 +205,16 @@ namespace Netch.Controllers
return true;
}
- if (State == Models.State.Stopped)
+ if (State == State.Stopped)
{
- Utils.Logging.Info("V2Ray 进程启动失败");
+ Logging.Info("V2Ray 进程启动失败");
Stop();
return false;
}
}
- Utils.Logging.Info("V2Ray 进程启动超时");
+ Logging.Info("V2Ray 进程启动超时");
Stop();
return false;
}
@@ -230,7 +234,7 @@ namespace Netch.Controllers
}
catch (Exception e)
{
- Utils.Logging.Info(e.ToString());
+ Logging.Info(e.ToString());
}
}
@@ -240,19 +244,19 @@ namespace Netch.Controllers
{
File.AppendAllText("logging\\v2ray.log", $"{e.Data}\r\n");
- if (State == Models.State.Starting)
+ if (State == State.Starting)
{
if (Instance.HasExited)
{
- State = Models.State.Stopped;
+ State = State.Stopped;
}
else if (e.Data.Contains("started"))
{
- State = Models.State.Started;
+ State = State.Started;
}
else if (e.Data.Contains("config file not readable") || e.Data.Contains("failed to"))
{
- State = Models.State.Stopped;
+ State = State.Stopped;
}
}
}
diff --git a/Netch/Forms/AboutForm.cs b/Netch/Forms/AboutForm.cs
index 14af4251..e26c6e02 100644
--- a/Netch/Forms/AboutForm.cs
+++ b/Netch/Forms/AboutForm.cs
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics;
using System.Windows.Forms;
+using Netch.Utils;
namespace Netch.Forms
{
@@ -13,9 +14,9 @@ namespace Netch.Forms
private void AboutForm_Load(object sender, EventArgs e)
{
- Text = Utils.i18N.Translate(Text);
- ChannelLabel.Text = Utils.i18N.Translate(ChannelLabel.Text);
- SponsorGroupBox.Text = Utils.i18N.Translate(SponsorGroupBox.Text);
+ Text = i18N.Translate(Text);
+ ChannelLabel.Text = i18N.Translate(ChannelLabel.Text);
+ SponsorGroupBox.Text = i18N.Translate(SponsorGroupBox.Text);
}
private void AboutForm_FormClosing(object sender, FormClosingEventArgs e)
diff --git a/Netch/Forms/GlobalBypassIPForm.cs b/Netch/Forms/GlobalBypassIPForm.cs
index e5844141..dc8e4a0b 100644
--- a/Netch/Forms/GlobalBypassIPForm.cs
+++ b/Netch/Forms/GlobalBypassIPForm.cs
@@ -1,6 +1,7 @@
using System;
using System.Net;
using System.Windows.Forms;
+using Netch.Utils;
namespace Netch.Forms
{
@@ -13,10 +14,10 @@ namespace Netch.Forms
private void GlobalBypassIPForm_Load(object sender, EventArgs e)
{
- Text = Utils.i18N.Translate(Text);
- AddButton.Text = Utils.i18N.Translate(AddButton.Text);
- DeleteButton.Text = Utils.i18N.Translate(DeleteButton.Text);
- ControlButton.Text = Utils.i18N.Translate(ControlButton.Text);
+ Text = i18N.Translate(Text);
+ AddButton.Text = i18N.Translate(AddButton.Text);
+ DeleteButton.Text = i18N.Translate(DeleteButton.Text);
+ ControlButton.Text = i18N.Translate(ControlButton.Text);
IPListBox.Items.AddRange(Global.Settings.BypassIPs.ToArray());
@@ -42,12 +43,12 @@ namespace Netch.Forms
}
else
{
- MessageBox.Show(Utils.i18N.Translate("Please enter a correct IP address"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Please enter a correct IP address"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else
{
- MessageBox.Show(Utils.i18N.Translate("Please enter an IP"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Please enter an IP"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
@@ -59,7 +60,7 @@ namespace Netch.Forms
}
else
{
- MessageBox.Show(Utils.i18N.Translate("Please select an IP"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Please select an IP"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
@@ -71,8 +72,8 @@ namespace Netch.Forms
Global.Settings.BypassIPs.Add(ip as string);
}
- Utils.Configuration.Save();
- MessageBox.Show(Utils.i18N.Translate("Saved"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ Configuration.Save();
+ MessageBox.Show(i18N.Translate("Saved"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
Close();
}
}
diff --git a/Netch/Forms/MainForm.cs b/Netch/Forms/MainForm.cs
index 17eca10c..bd8fe2ea 100644
--- a/Netch/Forms/MainForm.cs
+++ b/Netch/Forms/MainForm.cs
@@ -1,16 +1,23 @@
-using Microsoft.Win32;
-using Netch.Controllers;
-using Netch.Utils;
using System;
using System.Collections.Generic;
-using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
+using System.Net;
using System.ServiceProcess;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
+using Microsoft.Win32;
+using Netch.Controllers;
+using Netch.Forms.Mode;
+using Netch.Forms.Server;
+using Netch.Models;
+using Netch.Utils;
+using nfapinet;
+using Trojan = Netch.Forms.Server.Trojan;
+using VMess = Netch.Forms.Server.VMess;
+using WebClient = Netch.Override.WebClient;
namespace Netch.Forms
{
@@ -19,7 +26,7 @@ namespace Netch.Forms
///
/// 当前状态
///
- public Models.State State = Models.State.Waiting;
+ public State State = State.Waiting;
///
/// 主控制器
@@ -46,7 +53,7 @@ namespace Netch.Forms
///
/// 主窗体的静态实例
///
- public static MainForm Instance = null;
+ public static MainForm Instance;
public MainForm()
@@ -54,7 +61,7 @@ namespace Netch.Forms
InitializeComponent();
// 监听电源事件
- SystemEvents.PowerModeChanged += new PowerModeChangedEventHandler(SystemEvents_PowerModeChanged);
+ SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
CheckForIllegalCrossThreadCalls = false;
// MenuStrip.Renderer = new Override.ToolStripProfessionalRender();
@@ -68,7 +75,7 @@ namespace Netch.Forms
void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)
{
//不对Netch命令等待状态的电源事件做任何处理
- if (!State.Equals(Models.State.Waiting))
+ if (!State.Equals(State.Waiting))
{
switch (e.Mode)
{
@@ -91,7 +98,7 @@ namespace Netch.Forms
{
NotifyIcon.ShowBalloonTip(5,
UpdateChecker.Name,
- $"{Utils.i18N.Translate(@"New version available")}{Utils.i18N.Translate(@": ")}{updater.LatestVersionNumber}",
+ $"{i18N.Translate(@"New version available")}{i18N.Translate(@": ")}{updater.LatestVersionNumber}",
ToolTipIcon.Info);
};
updater.Check(false, false);
@@ -132,51 +139,51 @@ namespace Netch.Forms
public void InitText(bool isStarted)
{
- ServerToolStripMenuItem.Text = Utils.i18N.Translate("Server");
- ImportServersFromClipboardToolStripMenuItem.Text = Utils.i18N.Translate("Import Servers From Clipboard");
- AddSocks5ServerToolStripMenuItem.Text = Utils.i18N.Translate("Add [Socks5] Server");
- AddShadowsocksServerToolStripMenuItem.Text = Utils.i18N.Translate("Add [Shadowsocks] Server");
- AddShadowsocksRServerToolStripMenuItem.Text = Utils.i18N.Translate("Add [ShadowsocksR] Server");
- AddVMessServerToolStripMenuItem.Text = Utils.i18N.Translate("Add [VMess] Server");
- AddTrojanServerToolStripMenuItem.Text = Utils.i18N.Translate("Add [Trojan] Server");
- ModeToolStripMenuItem.Text = Utils.i18N.Translate("Mode");
- CreateProcessModeToolStripMenuItem.Text = Utils.i18N.Translate("Create Process Mode");
- SubscribeToolStripMenuItem.Text = Utils.i18N.Translate("Subscribe");
- ManageSubscribeLinksToolStripMenuItem.Text = Utils.i18N.Translate("Manage Subscribe Links");
- UpdateServersFromSubscribeLinksToolStripMenuItem.Text = Utils.i18N.Translate("Update Servers From Subscribe Links");
- OptionsToolStripMenuItem.Text = Utils.i18N.Translate("Options");
- ReloadModesToolStripMenuItem.Text = Utils.i18N.Translate("Reload Modes");
- RestartServiceToolStripMenuItem.Text = Utils.i18N.Translate("Restart Service");
- UninstallServiceToolStripMenuItem.Text = Utils.i18N.Translate("Uninstall Service");
- CleanDNSCacheToolStripMenuItem.Text = Utils.i18N.Translate("Clean DNS Cache");
- UpdateACLToolStripMenuItem.Text = Utils.i18N.Translate("Update ACL");
- updateACLWithProxyToolStripMenuItem.Text = Utils.i18N.Translate("Update ACL with proxy");
- reinstallTapDriverToolStripMenuItem.Text = Utils.i18N.Translate("Reinstall TUN/TAP driver");
- OpenDirectoryToolStripMenuItem.Text = Utils.i18N.Translate("Open Directory");
- AboutToolStripButton.Text = Utils.i18N.Translate("About");
- VersionLabel.Text = Utils.i18N.Translate("xxx");
- exitToolStripMenuItem.Text = Utils.i18N.Translate("Exit");
- RelyToolStripMenuItem.Text = Utils.i18N.Translate("Unable to start? Click me to download");
- ConfigurationGroupBox.Text = Utils.i18N.Translate("Configuration");
- ProfileLabel.Text = Utils.i18N.Translate("Profile");
- ModeLabel.Text = Utils.i18N.Translate("Mode");
- ServerLabel.Text = Utils.i18N.Translate("Server");
- UsedBandwidthLabel.Text = Utils.i18N.Translate("Used: 0 KB");
- DownloadSpeedLabel.Text = Utils.i18N.Translate("↓: 0 KB/s");
- UploadSpeedLabel.Text = Utils.i18N.Translate("↑: 0 KB/s");
+ ServerToolStripMenuItem.Text = i18N.Translate("Server");
+ ImportServersFromClipboardToolStripMenuItem.Text = i18N.Translate("Import Servers From Clipboard");
+ AddSocks5ServerToolStripMenuItem.Text = i18N.Translate("Add [Socks5] Server");
+ AddShadowsocksServerToolStripMenuItem.Text = i18N.Translate("Add [Shadowsocks] Server");
+ AddShadowsocksRServerToolStripMenuItem.Text = i18N.Translate("Add [ShadowsocksR] Server");
+ AddVMessServerToolStripMenuItem.Text = i18N.Translate("Add [VMess] Server");
+ AddTrojanServerToolStripMenuItem.Text = i18N.Translate("Add [Trojan] Server");
+ ModeToolStripMenuItem.Text = i18N.Translate("Mode");
+ CreateProcessModeToolStripMenuItem.Text = i18N.Translate("Create Process Mode");
+ SubscribeToolStripMenuItem.Text = i18N.Translate("Subscribe");
+ ManageSubscribeLinksToolStripMenuItem.Text = i18N.Translate("Manage Subscribe Links");
+ UpdateServersFromSubscribeLinksToolStripMenuItem.Text = i18N.Translate("Update Servers From Subscribe Links");
+ OptionsToolStripMenuItem.Text = i18N.Translate("Options");
+ ReloadModesToolStripMenuItem.Text = i18N.Translate("Reload Modes");
+ RestartServiceToolStripMenuItem.Text = i18N.Translate("Restart Service");
+ UninstallServiceToolStripMenuItem.Text = i18N.Translate("Uninstall Service");
+ CleanDNSCacheToolStripMenuItem.Text = i18N.Translate("Clean DNS Cache");
+ UpdateACLToolStripMenuItem.Text = i18N.Translate("Update ACL");
+ updateACLWithProxyToolStripMenuItem.Text = i18N.Translate("Update ACL with proxy");
+ reinstallTapDriverToolStripMenuItem.Text = i18N.Translate("Reinstall TUN/TAP driver");
+ OpenDirectoryToolStripMenuItem.Text = i18N.Translate("Open Directory");
+ AboutToolStripButton.Text = i18N.Translate("About");
+ VersionLabel.Text = i18N.Translate("xxx");
+ exitToolStripMenuItem.Text = i18N.Translate("Exit");
+ RelyToolStripMenuItem.Text = i18N.Translate("Unable to start? Click me to download");
+ ConfigurationGroupBox.Text = i18N.Translate("Configuration");
+ ProfileLabel.Text = i18N.Translate("Profile");
+ ModeLabel.Text = i18N.Translate("Mode");
+ ServerLabel.Text = i18N.Translate("Server");
+ UsedBandwidthLabel.Text = i18N.Translate("Used: 0 KB");
+ DownloadSpeedLabel.Text = i18N.Translate("↓: 0 KB/s");
+ UploadSpeedLabel.Text = i18N.Translate("↑: 0 KB/s");
if (!isStarted)
{
- UsedBandwidthLabel.Text = $@"{Utils.i18N.Translate("Used")}{Utils.i18N.Translate(": ")}0 KB";
- StatusLabel.Text = $@"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Waiting for command")}";
- ControlButton.Text = Utils.i18N.Translate("Start");
+ UsedBandwidthLabel.Text = $@"{i18N.Translate("Used")}{i18N.Translate(": ")}0 KB";
+ StatusLabel.Text = $@"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Waiting for command")}";
+ ControlButton.Text = i18N.Translate("Start");
}
- NotifyIcon.Text = Utils.i18N.Translate("Netch");
- ShowMainFormToolStripButton.Text = Utils.i18N.Translate("Show");
- ExitToolStripButton.Text = Utils.i18N.Translate("Exit");
- SettingsButton.Text = Utils.i18N.Translate("Settings");
- ProfileGroupBox.Text = Utils.i18N.Translate("Profiles");
+ NotifyIcon.Text = i18N.Translate("Netch");
+ ShowMainFormToolStripButton.Text = i18N.Translate("Show");
+ ExitToolStripButton.Text = i18N.Translate("Exit");
+ SettingsButton.Text = i18N.Translate("Settings");
+ ProfileGroupBox.Text = i18N.Translate("Profiles");
// 加载翻译
VersionLabel.Text = UpdateChecker.Version;
@@ -229,7 +236,7 @@ namespace Netch.Forms
if (splited.Length >= 1)
{
- mode.Remark = Utils.i18N.Translate(splited[0].Trim());
+ mode.Remark = i18N.Translate(splited[0].Trim());
}
if (splited.Length >= 2)
@@ -323,7 +330,7 @@ namespace Netch.Forms
Global.Settings.ModeComboBoxSelectedIndex = ModeComboBox.Items.IndexOf(ModeComboBox.SelectedItem);
}
}
- Utils.Configuration.Save();
+ Configuration.Save();
}
private void ComboBox_DrawItem(object sender, DrawItemEventArgs e)
@@ -333,7 +340,7 @@ namespace Netch.Forms
var cbx = sender as ComboBox;
- var eWidth = (int)ServerComboBox.Width / 10;
+ var eWidth = ServerComboBox.Width / 10;
// 绘制背景颜色
e.Graphics.FillRectangle(new SolidBrush(Color.White), e.Bounds);
@@ -417,7 +424,7 @@ namespace Netch.Forms
{
while (true)
{
- if (State == Models.State.Waiting || State == Models.State.Stopped)
+ if (State == State.Waiting || State == State.Stopped)
{
TestServer();
@@ -445,7 +452,7 @@ namespace Netch.Forms
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
- if (e.CloseReason == CloseReason.UserClosing && State != Models.State.Terminating)
+ if (e.CloseReason == CloseReason.UserClosing && State != State.Terminating)
{
// 取消"关闭窗口"事件
e.Cancel = true; // 取消关闭窗体
@@ -462,7 +469,7 @@ namespace Netch.Forms
// 显示提示语
NotifyIcon.ShowBalloonTip(5,
UpdateChecker.Name,
- Utils.i18N.Translate("Netch is now minimized to the notification bar, double click this icon to restore."),
+ i18N.Translate("Netch is now minimized to the notification bar, double click this icon to restore."),
ToolTipIcon.Info);
IsFirstOpened = false;
@@ -483,7 +490,7 @@ namespace Netch.Forms
var texts = Clipboard.GetText();
if (!string.IsNullOrWhiteSpace(texts))
{
- var result = Utils.ShareLink.Parse(texts);
+ var result = ShareLink.Parse(texts);
if (result != null)
{
@@ -491,47 +498,47 @@ namespace Netch.Forms
}
else
{
- MessageBox.Show(Utils.i18N.Translate("Import servers error!"), Utils.i18N.Translate("Error"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
+ MessageBox.Show(i18N.Translate("Import servers error!"), i18N.Translate("Error"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
InitServer();
- Utils.Configuration.Save();
+ Configuration.Save();
}
}
private void AddSocks5ServerToolStripMenuItem_Click(object sender, EventArgs e)
{
- new Server.Socks5().Show();
+ new Socks5().Show();
Hide();
}
private void AddShadowsocksServerToolStripMenuItem_Click(object sender, EventArgs e)
{
- new Server.Shadowsocks().Show();
+ new Shadowsocks().Show();
Hide();
}
private void AddShadowsocksRServerToolStripMenuItem_Click(object sender, EventArgs e)
{
- new Server.ShadowsocksR().Show();
+ new ShadowsocksR().Show();
Hide();
}
private void AddVMessServerToolStripMenuItem_Click(object sender, EventArgs e)
{
- new Server.VMess().Show();
+ new VMess().Show();
Hide();
}
private void AddTrojanServerToolStripMenuItem_Click(object sender, EventArgs e)
{
- new Server.Trojan().Show();
+ new Trojan().Show();
Hide();
}
private void CreateProcessModeToolStripButton_Click(object sender, EventArgs e)
{
- new Mode.Process().Show();
+ new Process().Show();
Hide();
}
@@ -556,7 +563,7 @@ namespace Netch.Forms
// 当前 ServerComboBox 中至少有一项
if (ServerComboBox.SelectedIndex == -1)
{
- MessageBox.Show(Utils.i18N.Translate("Please select a server first"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Please select a server first"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
MenuStrip.Enabled = ConfigurationGroupBox.Enabled = ControlButton.Enabled = SettingsButton.Enabled = false;
@@ -565,7 +572,7 @@ namespace Netch.Forms
if (Global.Settings.SubscribeLink.Count > 0)
{
- StatusLabel.Text = $"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Starting update subscription")}";
+ StatusLabel.Text = $"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Starting update subscription")}";
DeletePictureBox.Enabled = false;
UpdateServersFromSubscribeLinksToolStripMenuItem.Enabled = false;
@@ -583,7 +590,7 @@ namespace Netch.Forms
}
foreach (var item in Global.Settings.SubscribeLink)
{
- using var client = new Override.WebClient();
+ using var client = new WebClient();
try
{
if (!string.IsNullOrEmpty(item.UserAgent))
@@ -597,14 +604,14 @@ namespace Netch.Forms
if (Global.Settings.UseProxyToUpdateSubscription)
{
- client.Proxy = new System.Net.WebProxy($"http://127.0.0.1:{Global.Settings.HTTPLocalPort}");
+ client.Proxy = new WebProxy($"http://127.0.0.1:{Global.Settings.HTTPLocalPort}");
}
var response = client.DownloadString(item.Link);
try
{
- response = Utils.ShareLink.URLSafeBase64Decode(response);
+ response = ShareLink.URLSafeBase64Decode(response);
}
catch (Exception)
{
@@ -612,7 +619,7 @@ namespace Netch.Forms
}
Global.Settings.Server = Global.Settings.Server.Where(server => server.Group != item.Remark).ToList();
- var result = Utils.ShareLink.Parse(response);
+ var result = ShareLink.Parse(response);
if (result != null)
{
@@ -623,14 +630,14 @@ namespace Netch.Forms
Global.Settings.Server.AddRange(result);
NotifyIcon.ShowBalloonTip(5,
UpdateChecker.Name,
- string.Format(Utils.i18N.Translate("Update {1} server(s) from {0}"), item.Remark, result.Count),
+ string.Format(i18N.Translate("Update {1} server(s) from {0}"), item.Remark, result.Count),
ToolTipIcon.Info);
}
else
{
NotifyIcon.ShowBalloonTip(5,
UpdateChecker.Name,
- string.Format(Utils.i18N.Translate("Update servers error from {0}"), item.Remark),
+ string.Format(i18N.Translate("Update servers error from {0}"), item.Remark),
ToolTipIcon.Error);
}
}
@@ -644,12 +651,12 @@ namespace Netch.Forms
if (Global.Settings.UseProxyToUpdateSubscription)
{
MenuStrip.Enabled = ConfigurationGroupBox.Enabled = ControlButton.Enabled = SettingsButton.Enabled = true;
- ControlButton.Text = Utils.i18N.Translate("Start");
+ ControlButton.Text = i18N.Translate("Start");
MainController.Stop();
NatTypeStatusLabel.Text = "";
}
- Utils.Configuration.Save();
- StatusLabel.Text = $"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Subscription updated")}";
+ Configuration.Save();
+ StatusLabel.Text = $"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Subscription updated")}";
}).ContinueWith(task =>
{
BeginInvoke(new Action(() =>
@@ -660,19 +667,19 @@ namespace Netch.Forms
NotifyIcon.ShowBalloonTip(5,
UpdateChecker.Name,
- Utils.i18N.Translate("Updating in the background"),
+ i18N.Translate("Updating in the background"),
ToolTipIcon.Info);
}
else
{
- MessageBox.Show(Utils.i18N.Translate("No subscription link"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("No subscription link"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void RestartServiceToolStripMenuItem_Click(object sender, EventArgs e)
{
Enabled = false;
- StatusLabel.Text = $"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Restarting service")}";
+ StatusLabel.Text = $"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Restarting service")}";
Task.Run(() =>
{
@@ -694,10 +701,10 @@ namespace Netch.Forms
}
catch (Exception)
{
- nfapinet.NFAPI.nf_registerDriver("netfilter2");
+ NFAPI.nf_registerDriver("netfilter2");
}
- MessageBox.Show(this, Utils.i18N.Translate("Service has been restarted"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(this, i18N.Translate("Service has been restarted"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
Enabled = true;
});
}
@@ -705,7 +712,7 @@ namespace Netch.Forms
private void UninstallServiceToolStripMenuItem_Click(object sender, EventArgs e)
{
Enabled = false;
- StatusLabel.Text = $"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Uninstalling Service")}";
+ StatusLabel.Text = $"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Uninstalling Service")}";
Task.Run(() =>
{
@@ -728,20 +735,20 @@ namespace Netch.Forms
try
{
- nfapinet.NFAPI.nf_unRegisterDriver("netfilter2");
+ NFAPI.nf_unRegisterDriver("netfilter2");
File.Delete(driver);
- MessageBox.Show(this, Utils.i18N.Translate("Service has been uninstalled"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(this, i18N.Translate("Service has been uninstalled"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
- MessageBox.Show(this, Utils.i18N.Translate("Error") + Utils.i18N.Translate(": ") + ex, Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(this, i18N.Translate("Error") + i18N.Translate(": ") + ex, i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else
{
- MessageBox.Show(this, Utils.i18N.Translate("Service has been uninstalled"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(this, i18N.Translate("Service has been uninstalled"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Enabled = true;
@@ -756,7 +763,7 @@ namespace Netch.Forms
{
InitMode();
- MessageBox.Show(this, Utils.i18N.Translate("Modes have been reload"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(this, i18N.Translate("Modes have been reload"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
Enabled = true;
});
}
@@ -766,17 +773,17 @@ namespace Netch.Forms
Enabled = false;
Task.Run(() =>
{
- Utils.DNS.Cache.Clear();
+ DNS.Cache.Clear();
- MessageBox.Show(this, Utils.i18N.Translate("DNS cache cleanup succeeded"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
- StatusLabel.Text = $"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("DNS cache cleanup succeeded")}";
+ MessageBox.Show(this, i18N.Translate("DNS cache cleanup succeeded"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ StatusLabel.Text = $"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("DNS cache cleanup succeeded")}";
Enabled = true;
});
}
private void VersionLabel_Click(object sender, EventArgs e)
{
- Process.Start($"https://github.com/{UpdateChecker.Owner}/{UpdateChecker.Repo}/releases");
+ System.Diagnostics.Process.Start($"https://github.com/{UpdateChecker.Owner}/{UpdateChecker.Repo}/releases");
}
private void EditPictureBox_Click(object sender, EventArgs e)
@@ -788,19 +795,19 @@ namespace Netch.Forms
switch (Global.Settings.Server[ServerComboBox.SelectedIndex].Type)
{
case "Socks5":
- new Server.Socks5(ServerComboBox.SelectedIndex).Show();
+ new Socks5(ServerComboBox.SelectedIndex).Show();
break;
case "SS":
- new Server.Shadowsocks(ServerComboBox.SelectedIndex).Show();
+ new Shadowsocks(ServerComboBox.SelectedIndex).Show();
break;
case "SSR":
- new Server.ShadowsocksR(ServerComboBox.SelectedIndex).Show();
+ new ShadowsocksR(ServerComboBox.SelectedIndex).Show();
break;
case "VMess":
- new Server.VMess(ServerComboBox.SelectedIndex).Show();
+ new VMess(ServerComboBox.SelectedIndex).Show();
break;
case "Trojan":
- new Server.Trojan(ServerComboBox.SelectedIndex).Show();
+ new Trojan(ServerComboBox.SelectedIndex).Show();
break;
default:
return;
@@ -810,7 +817,7 @@ namespace Netch.Forms
}
else
{
- MessageBox.Show(Utils.i18N.Translate("Please select a server first"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Please select a server first"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
@@ -828,27 +835,27 @@ namespace Netch.Forms
{
ServerComboBox.SelectedIndex = index != 0 ? index - 1 : index;
}
- Utils.Configuration.Save();
+ Configuration.Save();
}
else
{
- MessageBox.Show(Utils.i18N.Translate("Please select a server first"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Please select a server first"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void SpeedPictureBox_Click(object sender, EventArgs e)
{
Enabled = false;
- StatusLabel.Text = $"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Testing")}";
+ StatusLabel.Text = $"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Testing")}";
Task.Run(() =>
{
TestServer();
Enabled = true;
- StatusLabel.Text = $"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Test done")}";
+ StatusLabel.Text = $"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Test done")}";
Refresh();
- Utils.Configuration.Save();
+ Configuration.Save();
});
}
@@ -861,19 +868,19 @@ namespace Netch.Forms
public void ControlFun()
{
SaveConfigs();
- if (State == Models.State.Waiting || State == Models.State.Stopped)
+ if (State == State.Waiting || State == State.Stopped)
{
// 当前 ServerComboBox 中至少有一项
if (ServerComboBox.SelectedIndex == -1)
{
- MessageBox.Show(Utils.i18N.Translate("Please select a server first"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Please select a server first"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
// 当前 ModeComboBox 中至少有一项
if (ModeComboBox.SelectedIndex == -1)
{
- MessageBox.Show(Utils.i18N.Translate("Please select an mode first"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Please select an mode first"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
@@ -892,8 +899,8 @@ namespace Netch.Forms
ModeComboBox.Enabled = false;
ControlButton.Text = "...";
- StatusLabel.Text = $"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Starting")}";
- State = Models.State.Starting;
+ StatusLabel.Text = $"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Starting")}";
+ State = State.Starting;
Task.Run(() =>
{
@@ -912,7 +919,7 @@ namespace Netch.Forms
//LastDownloadBandwidth = 0;
//UploadSpeedLabel.Text = "↑: 0 KB/s";
DownloadSpeedLabel.Text = "↑↓: 0 KB/s";
- UsedBandwidthLabel.Text = $"{Utils.i18N.Translate("Used")}{Utils.i18N.Translate(": ")}0 KB";
+ UsedBandwidthLabel.Text = $"{i18N.Translate("Used")}{i18N.Translate(": ")}0 KB";
UsedBandwidthLabel.Visible = UploadSpeedLabel.Visible = DownloadSpeedLabel.Visible = true;
@@ -932,7 +939,7 @@ namespace Netch.Forms
// 显示提示语
NotifyIcon.ShowBalloonTip(5,
UpdateChecker.Name,
- Utils.i18N.Translate("Netch is now minimized to the notification bar, double click this icon to restore."),
+ i18N.Translate("Netch is now minimized to the notification bar, double click this icon to restore."),
ToolTipIcon.Info);
IsFirstOpened = false;
@@ -942,7 +949,7 @@ namespace Netch.Forms
}
ControlButton.Enabled = true;
- ControlButton.Text = Utils.i18N.Translate("Stop");
+ ControlButton.Text = i18N.Translate("Stop");
if (mode.Type != 3 && mode.Type != 5)
{
@@ -951,16 +958,16 @@ namespace Netch.Forms
if (Global.Settings.LocalAddress == "0.0.0.0")
{
- StatusLabel.Text = $"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Started")} ({Utils.i18N.Translate("Allow other Devices to connect")} Socks5 {Utils.i18N.Translate("Local Port")}{Utils.i18N.Translate(": ")}{Global.Settings.Socks5LocalPort})";
+ StatusLabel.Text = $"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Started")} ({i18N.Translate("Allow other Devices to connect")} Socks5 {i18N.Translate("Local Port")}{i18N.Translate(": ")}{Global.Settings.Socks5LocalPort})";
}
else
{
- StatusLabel.Text = $"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Started")} (Socks5 {Utils.i18N.Translate("Local Port")}{Utils.i18N.Translate(": ")}{Global.Settings.Socks5LocalPort}{")"}";
+ StatusLabel.Text = $"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Started")} (Socks5 {i18N.Translate("Local Port")}{i18N.Translate(": ")}{Global.Settings.Socks5LocalPort}{")"}";
}
}
else
{
- StatusLabel.Text = $"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Started")}";
+ StatusLabel.Text = $"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Started")}";
}
}
else
@@ -968,24 +975,24 @@ namespace Netch.Forms
if (server.Type != "Socks5")
{
if (Global.Settings.LocalAddress == "0.0.0.0")
- StatusLabel.Text = $"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Started")} ({Utils.i18N.Translate("Allow other Devices to connect")} Socks5 {Utils.i18N.Translate("Local Port")}{Utils.i18N.Translate(": ")}{Global.Settings.Socks5LocalPort} | HTTP {Utils.i18N.Translate("Local Port")}{Utils.i18N.Translate(": ")}{Global.Settings.HTTPLocalPort}{")"}";
+ StatusLabel.Text = $"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Started")} ({i18N.Translate("Allow other Devices to connect")} Socks5 {i18N.Translate("Local Port")}{i18N.Translate(": ")}{Global.Settings.Socks5LocalPort} | HTTP {i18N.Translate("Local Port")}{i18N.Translate(": ")}{Global.Settings.HTTPLocalPort}{")"}";
else
{
- StatusLabel.Text = $"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Started")} (Socks5 {Utils.i18N.Translate("Local Port")}{Utils.i18N.Translate(": ")}{Global.Settings.Socks5LocalPort} | HTTP {Utils.i18N.Translate("Local Port")}{Utils.i18N.Translate(": ")}{Global.Settings.HTTPLocalPort})";
+ StatusLabel.Text = $"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Started")} (Socks5 {i18N.Translate("Local Port")}{i18N.Translate(": ")}{Global.Settings.Socks5LocalPort} | HTTP {i18N.Translate("Local Port")}{i18N.Translate(": ")}{Global.Settings.HTTPLocalPort})";
}
}
else
{
if (Global.Settings.LocalAddress == "0.0.0.0")
- StatusLabel.Text = $"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Started")} ({Utils.i18N.Translate("Allow other Devices to connect")} HTTP {Utils.i18N.Translate("Local Port")}{Utils.i18N.Translate(": ")}{Global.Settings.HTTPLocalPort}{")"}";
+ StatusLabel.Text = $"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Started")} ({i18N.Translate("Allow other Devices to connect")} HTTP {i18N.Translate("Local Port")}{i18N.Translate(": ")}{Global.Settings.HTTPLocalPort}{")"}";
else
{
- StatusLabel.Text = $"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Started")} (HTTP {Utils.i18N.Translate("Local Port")}{Utils.i18N.Translate(": ")}{Global.Settings.HTTPLocalPort})";
+ StatusLabel.Text = $"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Started")} (HTTP {i18N.Translate("Local Port")}{i18N.Translate(": ")}{Global.Settings.HTTPLocalPort})";
}
}
}
- State = Models.State.Started;
+ State = State.Started;
if (Global.Settings.StartedTcping)
{
// 自动检测延迟
@@ -993,7 +1000,7 @@ namespace Netch.Forms
{
while (true)
{
- if (State == Models.State.Started)
+ if (State == State.Started)
{
server.Test();
// 重载服务器列表
@@ -1023,9 +1030,9 @@ namespace Netch.Forms
//隐藏NTT测试
NatTypeStatusLabel.Visible = false;
- ControlButton.Text = Utils.i18N.Translate("Start");
- StatusLabel.Text = $"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Start failed")}";
- State = Models.State.Stopped;
+ ControlButton.Text = i18N.Translate("Start");
+ StatusLabel.Text = $"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Start failed")}";
+ State = State.Stopped;
}
});
}
@@ -1034,8 +1041,8 @@ namespace Netch.Forms
ControlButton.Enabled = false;
ControlButton.Text = "...";
- StatusLabel.Text = $"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Stopping")}";
- State = Models.State.Stopping;
+ StatusLabel.Text = $"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Stopping")}";
+ State = State.Stopping;
MenuStrip.Enabled = ConfigurationGroupBox.Enabled = SettingsButton.Enabled = true;
@@ -1053,7 +1060,7 @@ namespace Netch.Forms
LastDownloadBandwidth = 0;
UploadSpeedLabel.Text = "↑: 0 KB/s";
DownloadSpeedLabel.Text = "↓: 0 KB/s";
- UsedBandwidthLabel.Text = $"{Utils.i18N.Translate("Used")}{Utils.i18N.Translate(": ")}0 KB";
+ UsedBandwidthLabel.Text = $"{i18N.Translate("Used")}{i18N.Translate(": ")}0 KB";
UsedBandwidthLabel.Visible = UploadSpeedLabel.Visible = DownloadSpeedLabel.Visible = false;
ControlButton.Enabled = true;
@@ -1069,9 +1076,9 @@ namespace Netch.Forms
//隐藏NTT测试
NatTypeStatusLabel.Visible = false;
- ControlButton.Text = Utils.i18N.Translate("Start");
- StatusLabel.Text = $"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Stopped")}";
- State = Models.State.Stopped;
+ ControlButton.Text = i18N.Translate("Start");
+ StatusLabel.Text = $"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Stopped")}";
+ State = State.Stopped;
TestServer();
});
@@ -1094,12 +1101,12 @@ namespace Netch.Forms
private void ExitToolStripButton_Click(object sender, EventArgs e)
{
// 当前状态如果不是已停止状态
- if (State != Models.State.Waiting && State != Models.State.Stopped)
+ if (State != State.Waiting && State != State.Stopped)
{
// 如果未勾选退出时停止,要求先点击停止按钮
if (!Global.Settings.StopWhenExited)
{
- MessageBox.Show(Utils.i18N.Translate("Please press Stop button first"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Please press Stop button first"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
Visible = true;
ShowInTaskbar = true; // 显示在系统任务栏
@@ -1115,7 +1122,7 @@ namespace Netch.Forms
SaveConfigs();
- State = Models.State.Terminating;
+ State = State.Terminating;
NotifyIcon.Visible = false;
Close();
Dispose();
@@ -1149,9 +1156,9 @@ namespace Netch.Forms
{
try
{
- UsedBandwidthLabel.Text = $"{Utils.i18N.Translate("Used")}{Utils.i18N.Translate(": ")}{Utils.Bandwidth.Compute(download)}";
+ UsedBandwidthLabel.Text = $"{i18N.Translate("Used")}{i18N.Translate(": ")}{Bandwidth.Compute(download)}";
//UploadSpeedLabel.Text = $"↑: {Utils.Bandwidth.Compute(upload - LastUploadBandwidth)}/s";
- DownloadSpeedLabel.Text = $"↑↓: {Utils.Bandwidth.Compute(download - LastDownloadBandwidth)}/s";
+ DownloadSpeedLabel.Text = $"↑↓: {Bandwidth.Compute(download - LastDownloadBandwidth)}/s";
//LastUploadBandwidth = upload;
LastDownloadBandwidth = download;
@@ -1170,9 +1177,9 @@ namespace Netch.Forms
{
return;
}
- UsedBandwidthLabel.Text = $"{Utils.i18N.Translate("Used")}{Utils.i18N.Translate(": ")}{Utils.Bandwidth.Compute(upload + download)}";
- UploadSpeedLabel.Text = $"↑: {Utils.Bandwidth.Compute(upload - LastUploadBandwidth)}/s";
- DownloadSpeedLabel.Text = $"↓: {Utils.Bandwidth.Compute(download - LastDownloadBandwidth)}/s";
+ UsedBandwidthLabel.Text = $"{i18N.Translate("Used")}{i18N.Translate(": ")}{Bandwidth.Compute(upload + download)}";
+ UploadSpeedLabel.Text = $"↑: {Bandwidth.Compute(upload - LastUploadBandwidth)}/s";
+ DownloadSpeedLabel.Text = $"↓: {Bandwidth.Compute(download - LastDownloadBandwidth)}/s";
LastUploadBandwidth = upload;
LastDownloadBandwidth = download;
@@ -1193,15 +1200,15 @@ namespace Netch.Forms
{
if (ServerComboBox.SelectedIndex == -1)
{
- MessageBox.Show(Utils.i18N.Translate("Please select a server first"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Please select a server first"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if (ModeComboBox.SelectedIndex == -1)
{
- MessageBox.Show(Utils.i18N.Translate("Please select an mode first"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Please select an mode first"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if (ProfileNameText.Text == "")
{
- MessageBox.Show(Utils.i18N.Translate("Please enter a profile name first"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Please enter a profile name first"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
@@ -1211,9 +1218,9 @@ namespace Netch.Forms
}
else
{
- if (ProfileButtons[index].Text == Utils.i18N.Translate("Error") || ProfileButtons[index].Text == Utils.i18N.Translate("None"))
+ if (ProfileButtons[index].Text == i18N.Translate("Error") || ProfileButtons[index].Text == i18N.Translate("None"))
{
- MessageBox.Show(Utils.i18N.Translate("No saved profile here. Save a profile first by Ctrl+Click on the button"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("No saved profile here. Save a profile first by Ctrl+Click on the button"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
try
@@ -1222,7 +1229,7 @@ namespace Netch.Forms
// start the profile
var need2ndStart = true;
- if (State == Models.State.Waiting || State == Models.State.Stopped)
+ if (State == State.Waiting || State == State.Stopped)
{
need2ndStart = false;
}
@@ -1233,7 +1240,7 @@ namespace Netch.Forms
{
Task.Run(() =>
{
- while (State != Models.State.Stopped)
+ while (State != State.Stopped)
{
Thread.Sleep(200);
}
@@ -1246,10 +1253,10 @@ namespace Netch.Forms
{
Task.Run(() =>
{
- Utils.Logging.Info(ee.Message);
- ProfileButtons[index].Text = Utils.i18N.Translate("Error");
+ Logging.Info(ee.Message);
+ ProfileButtons[index].Text = i18N.Translate("Error");
Thread.Sleep(1200);
- ProfileButtons[index].Text = Utils.i18N.Translate("None");
+ ProfileButtons[index].Text = i18N.Translate("None");
});
}
@@ -1299,7 +1306,7 @@ namespace Netch.Forms
while (Global.Settings.Profiles.Count < numProfile)
{
- Global.Settings.Profiles.Add(new Models.Profile());
+ Global.Settings.Profiles.Add(new Profile());
}
// buttons
@@ -1310,7 +1317,7 @@ namespace Netch.Forms
b.Location = new Point(i * 100, 0);
b.Click += ProfileButton_Click;
b.Dock = DockStyle.Fill;
- b.Text = !Global.Settings.Profiles[i].IsDummy ? Global.Settings.Profiles[i].ProfileName : Utils.i18N.Translate("None");
+ b.Text = !Global.Settings.Profiles[i].IsDummy ? Global.Settings.Profiles[i].ProfileName : i18N.Translate("None");
ProfileButtons.Add(b);
}
@@ -1371,7 +1378,7 @@ namespace Netch.Forms
var selectedMode = (Models.Mode)ModeComboBox.SelectedItem;
var name = ProfileNameText.Text;
- Global.Settings.Profiles[index] = new Models.Profile(selectedServer, selectedMode, name);
+ Global.Settings.Profiles[index] = new Profile(selectedServer, selectedMode, name);
}
@@ -1386,7 +1393,7 @@ namespace Netch.Forms
if (selectedMode.Type == 0)
{
//Process.Start(Environment.CurrentDirectory + "\\mode\\" + selectedMode.FileName + ".txt");
- Mode.Process process = new Mode.Process(selectedMode);
+ var process = new Process(selectedMode);
process.Text = "Edit Process Mode";
process.Show();
Hide();
@@ -1394,7 +1401,7 @@ namespace Netch.Forms
}
else
{
- MessageBox.Show(Utils.i18N.Translate("Please select an mode first"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Please select an mode first"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
@@ -1415,11 +1422,11 @@ namespace Netch.Forms
ModeComboBox.Items.AddRange(array);
SelectLastMode();
- Utils.Configuration.Save();
+ Configuration.Save();
}
else
{
- MessageBox.Show(Utils.i18N.Translate("Please select an mode first"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Please select an mode first"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
@@ -1432,7 +1439,7 @@ namespace Netch.Forms
try
{
//听说巨硬BUG经常会炸,所以Catch一下 :D
- Clipboard.SetText(Utils.ShareLink.GetShareLink(selectedMode));
+ Clipboard.SetText(ShareLink.GetShareLink(selectedMode));
}
catch (Exception)
{
@@ -1441,7 +1448,7 @@ namespace Netch.Forms
}
else
{
- MessageBox.Show(Utils.i18N.Translate("Please select a server first"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Please select a server first"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
public void StatusText(string text)
@@ -1454,23 +1461,23 @@ namespace Netch.Forms
if (!string.IsNullOrWhiteSpace(text))
{
text = text.Trim();
- NatTypeStatusLabel.Text = "NAT" + Utils.i18N.Translate(": ") + text;
+ NatTypeStatusLabel.Text = "NAT" + i18N.Translate(": ") + text;
}
else
{
- NatTypeStatusLabel.Text = "NAT" + Utils.i18N.Translate(": ") + Utils.i18N.Translate("Test failed");
+ NatTypeStatusLabel.Text = "NAT" + i18N.Translate(": ") + i18N.Translate("Test failed");
}
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
// 当前状态如果不是已停止状态
- if (State != Models.State.Waiting && State != Models.State.Stopped)
+ if (State != State.Waiting && State != State.Stopped)
{
// 如果未勾选退出时停止,要求先点击停止按钮
if (!Global.Settings.StopWhenExited)
{
- MessageBox.Show(Utils.i18N.Translate("Please press Stop button first"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Please press Stop button first"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
Visible = true;
ShowInTaskbar = true; // 显示在系统任务栏
@@ -1486,7 +1493,7 @@ namespace Netch.Forms
SaveConfigs();
- State = Models.State.Terminating;
+ State = State.Terminating;
NotifyIcon.Visible = false;
Close();
Dispose();
@@ -1495,8 +1502,8 @@ namespace Netch.Forms
private void updateACLToolStripMenuItem_Click(object sender, EventArgs e)
{
- StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Starting update ACL")}");
- using var client = new Override.WebClient();
+ StatusText($"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Starting update ACL")}");
+ using var client = new WebClient();
client.DownloadFileTaskAsync(Global.Settings.ACL, "bin\\default.acl");
client.DownloadFileCompleted += ((sender, args) =>
@@ -1507,18 +1514,18 @@ namespace Netch.Forms
if (args.Error == null)
{
NotifyIcon.ShowBalloonTip(5,
- UpdateChecker.Name, Utils.i18N.Translate("ACL updated successfully"),
+ UpdateChecker.Name, i18N.Translate("ACL updated successfully"),
ToolTipIcon.Info);
}
else
{
- Utils.Logging.Info("ACL 更新失败!" + args.Error);
- MessageBox.Show(Utils.i18N.Translate("ACL update failed") + "\n" + args.Error);
+ Logging.Info("ACL 更新失败!" + args.Error);
+ MessageBox.Show(i18N.Translate("ACL update failed") + "\n" + args.Error);
}
}
finally
{
- StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Waiting for command")}");
+ StatusText($"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Waiting for command")}");
}
});
}
@@ -1531,7 +1538,7 @@ namespace Netch.Forms
// 当前 ServerComboBox 中至少有一项
if (ServerComboBox.SelectedIndex == -1)
{
- MessageBox.Show(Utils.i18N.Translate("Please select a server first"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Please select a server first"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
MenuStrip.Enabled = ConfigurationGroupBox.Enabled = ControlButton.Enabled = SettingsButton.Enabled = false;
@@ -1548,30 +1555,30 @@ namespace Netch.Forms
MainController = new MainController();
MainController.Start(ServerComboBox.SelectedItem as Models.Server, mode);
- using var client = new Override.WebClient();
+ using var client = new WebClient();
- client.Proxy = new System.Net.WebProxy($"http://127.0.0.1:{Global.Settings.HTTPLocalPort}");
+ client.Proxy = new WebProxy($"http://127.0.0.1:{Global.Settings.HTTPLocalPort}");
- StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Updating in the background")}");
+ StatusText($"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Updating in the background")}");
try
{
client.DownloadFile(Global.Settings.ACL, "bin\\default.acl");
NotifyIcon.ShowBalloonTip(5,
- UpdateChecker.Name, Utils.i18N.Translate("ACL updated successfully"),
+ UpdateChecker.Name, i18N.Translate("ACL updated successfully"),
ToolTipIcon.Info);
}
catch (Exception e)
{
- Utils.Logging.Info("使用代理更新 ACL 失败!" + e.Message);
- MessageBox.Show(Utils.i18N.Translate("ACL update failed") + "\n" + e.Message);
+ Logging.Info("使用代理更新 ACL 失败!" + e.Message);
+ MessageBox.Show(i18N.Translate("ACL update failed") + "\n" + e.Message);
}
finally
{
updateACLWithProxyToolStripMenuItem.Enabled = true;
MenuStrip.Enabled = ConfigurationGroupBox.Enabled = ControlButton.Enabled = SettingsButton.Enabled = true;
- ControlButton.Text = Utils.i18N.Translate("Start");
- StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Waiting for command")}");
+ ControlButton.Text = i18N.Translate("Start");
+ StatusText($"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Waiting for command")}");
MainController.Stop();
}
});
@@ -1581,26 +1588,26 @@ namespace Netch.Forms
{
Task.Run(() =>
{
- StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Reinstalling TUN/TAP driver")}");
+ StatusText($"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Reinstalling TUN/TAP driver")}");
Enabled = false;
try
{
Configuration.deltapall();
Configuration.addtap();
NotifyIcon.ShowBalloonTip(5,
- UpdateChecker.Name, Utils.i18N.Translate("Reinstall TUN/TAP driver successfully"),
+ UpdateChecker.Name, i18N.Translate("Reinstall TUN/TAP driver successfully"),
ToolTipIcon.Info);
}
catch
{
NotifyIcon.ShowBalloonTip(5,
- UpdateChecker.Name, Utils.i18N.Translate("Reinstall TUN/TAP driver failed"),
+ UpdateChecker.Name, i18N.Translate("Reinstall TUN/TAP driver failed"),
ToolTipIcon.Error);
}
finally
{
- ControlButton.Text = Utils.i18N.Translate("Start");
- StatusText($"{Utils.i18N.Translate("Status")}{Utils.i18N.Translate(": ")}{Utils.i18N.Translate("Waiting for command")}");
+ ControlButton.Text = i18N.Translate("Start");
+ StatusText($"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Waiting for command")}");
Enabled = true;
}
});
@@ -1608,7 +1615,7 @@ namespace Netch.Forms
private void RelyToolStripMenuItem_Click(object sender, EventArgs e)
{
- Process.Start($"https://mega.nz/file/9OQ1EazJ#0pjJ3xt57AVLr29vYEEv15GSACtXVQOGlEOPpi_2Ico");
+ System.Diagnostics.Process.Start("https://mega.nz/file/9OQ1EazJ#0pjJ3xt57AVLr29vYEEv15GSACtXVQOGlEOPpi_2Ico");
}
private void MainForm_VisibleChanged(object sender, EventArgs e)
@@ -1619,7 +1626,7 @@ namespace Netch.Forms
if (i18N.LangCode!=Global.Settings.Language)
{
i18N.Load(Global.Settings.Language);
- InitText(State == Models.State.Started);
+ InitText(State == State.Started);
}
if (ProfileButtons.Count != Global.Settings.ProfileCount)
diff --git a/Netch/Forms/Mode/Process.cs b/Netch/Forms/Mode/Process.cs
index 397be8c0..dab1f9c1 100644
--- a/Netch/Forms/Mode/Process.cs
+++ b/Netch/Forms/Mode/Process.cs
@@ -1,16 +1,18 @@
-using Microsoft.WindowsAPICodePack.Dialogs;
-using System;
+using System;
+using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
+using Microsoft.WindowsAPICodePack.Dialogs;
+using Netch.Utils;
namespace Netch.Forms.Mode
{
public partial class Process : Form
{
//用于判断当前窗口是否为编辑模式
- private Boolean EditMode = false;
+ private bool EditMode;
//被编辑模式坐标
- private Models.Mode EditMode_Old = null;
+ private Models.Mode EditMode_Old;
///
/// 编辑模式
///
@@ -23,7 +25,7 @@ namespace Netch.Forms.Mode
CheckForIllegalCrossThreadCalls = false;
EditMode_Old = mode;
- this.Text = "Edit Process Mode";
+ Text = "Edit Process Mode";
//循环填充已有规则
mode.Rule.ForEach(i => RuleListBox.Items.Add(i));
@@ -67,7 +69,7 @@ namespace Netch.Forms.Mode
return;
}
- var DirStack = new System.Collections.Generic.Stack();
+ var DirStack = new Stack();
DirStack.Push(DirName);
while (DirStack.Count > 0)
@@ -89,16 +91,16 @@ namespace Netch.Forms.Mode
private void ModeForm_Load(object sender, EventArgs e)
{
- Text = Utils.i18N.Translate(Text);
- ConfigurationGroupBox.Text = Utils.i18N.Translate(ConfigurationGroupBox.Text);
- RemarkLabel.Text = Utils.i18N.Translate(RemarkLabel.Text);
- FilenameLabel.Text = Utils.i18N.Translate(FilenameLabel.Text);
- UseCustomFilenameBox.Text = Utils.i18N.Translate(UseCustomFilenameBox.Text);
- StaySameButton.Text = Utils.i18N.Translate(StaySameButton.Text);
- TimeDataButton.Text = Utils.i18N.Translate(TimeDataButton.Text);
- AddButton.Text = Utils.i18N.Translate(AddButton.Text);
- ScanButton.Text = Utils.i18N.Translate(ScanButton.Text);
- ControlButton.Text = Utils.i18N.Translate(ControlButton.Text);
+ Text = i18N.Translate(Text);
+ ConfigurationGroupBox.Text = i18N.Translate(ConfigurationGroupBox.Text);
+ RemarkLabel.Text = i18N.Translate(RemarkLabel.Text);
+ FilenameLabel.Text = i18N.Translate(FilenameLabel.Text);
+ UseCustomFilenameBox.Text = i18N.Translate(UseCustomFilenameBox.Text);
+ StaySameButton.Text = i18N.Translate(StaySameButton.Text);
+ TimeDataButton.Text = i18N.Translate(TimeDataButton.Text);
+ AddButton.Text = i18N.Translate(AddButton.Text);
+ ScanButton.Text = i18N.Translate(ScanButton.Text);
+ ControlButton.Text = i18N.Translate(ControlButton.Text);
if (Global.Settings.ModeFileNameType == 0)
{
@@ -130,12 +132,12 @@ namespace Netch.Forms.Mode
///
private void RuleListBox_MouseUp(object sender, MouseEventArgs e)
{
- ContextMenuStrip strip = new ContextMenuStrip();
- strip.Items.Add(Utils.i18N.Translate("Delete"));
+ var strip = new ContextMenuStrip();
+ strip.Items.Add(i18N.Translate("Delete"));
if (e.Button == MouseButtons.Right)
{
- strip.Show(this.RuleListBox, e.Location);//鼠标右键按下弹出菜单
- strip.MouseClick += new MouseEventHandler(deleteRule_Click);
+ strip.Show(RuleListBox, e.Location);//鼠标右键按下弹出菜单
+ strip.MouseClick += deleteRule_Click;
}
}
void deleteRule_Click(object sender, EventArgs e)
@@ -165,7 +167,7 @@ namespace Netch.Forms.Mode
}
else
{
- MessageBox.Show(Utils.i18N.Translate("Please enter an process name (xxx.exe)"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Please enter an process name (xxx.exe)"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
@@ -175,7 +177,7 @@ namespace Netch.Forms.Mode
{
IsFolderPicker = true,
Multiselect = false,
- Title = Utils.i18N.Translate("Select a folder"),
+ Title = i18N.Translate("Select a folder"),
AddToMostRecentlyUsedList = false,
EnsurePathExists = true,
NavigateToShortcut = true
@@ -183,7 +185,7 @@ namespace Netch.Forms.Mode
if (dialog.ShowDialog(Win32Native.GetForegroundWindow()) == CommonFileDialogResult.Ok)
{
ScanDirectory(dialog.FileName);
- MessageBox.Show(Utils.i18N.Translate("Scan completed"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Scan completed"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
@@ -220,14 +222,14 @@ namespace Netch.Forms.Mode
File.WriteAllText(Path.Combine("mode", FilenameTextBox.Text) + ".txt", text);
- MessageBox.Show(Utils.i18N.Translate("Mode updated successfully"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Mode updated successfully"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
Global.MainForm.UpdateMode(mode, EditMode_Old);
Close();
}
else
{
- MessageBox.Show(Utils.i18N.Translate("Unable to add empty rule"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Unable to add empty rule"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else
@@ -250,13 +252,13 @@ namespace Netch.Forms.Mode
FilenameTextBox.Text = ((long)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds).ToString();
}
- Utils.Configuration.Save();
+ Configuration.Save();
if (!string.IsNullOrWhiteSpace(RemarkTextBox.Text))
{
if (Global.Settings.ModeFileNameType == 0 && string.IsNullOrWhiteSpace(FilenameTextBox.Text))
{
- MessageBox.Show(Utils.i18N.Translate("Please enter a mode filename"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Please enter a mode filename"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
var ModeFilename = Path.Combine("mode", FilenameTextBox.Text);
@@ -264,7 +266,7 @@ namespace Netch.Forms.Mode
// 如果文件已存在,返回
if (File.Exists(ModeFilename + ".txt"))
{
- MessageBox.Show(Utils.i18N.Translate("File already exists.\n Please Change the filename"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("File already exists.\n Please Change the filename"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
@@ -295,19 +297,19 @@ namespace Netch.Forms.Mode
File.WriteAllText(ModeFilename + ".txt", text);
- MessageBox.Show(Utils.i18N.Translate("Mode added successfully"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Mode added successfully"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
Global.MainForm.AddMode(mode);
Close();
}
else
{
- MessageBox.Show(Utils.i18N.Translate("Unable to add empty rule"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Unable to add empty rule"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else
{
- MessageBox.Show(Utils.i18N.Translate("Please enter a mode remark"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Please enter a mode remark"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
diff --git a/Netch/Forms/Server/Shadowsocks.cs b/Netch/Forms/Server/Shadowsocks.cs
index 3e006ed3..7c199311 100644
--- a/Netch/Forms/Server/Shadowsocks.cs
+++ b/Netch/Forms/Server/Shadowsocks.cs
@@ -2,6 +2,7 @@
using System.Drawing;
using System.Text.RegularExpressions;
using System.Windows.Forms;
+using Netch.Utils;
namespace Netch.Forms.Server
{
@@ -22,14 +23,14 @@ namespace Netch.Forms.Server
private void Shadowsocks_Load(object sender, EventArgs e)
{
- ConfigurationGroupBox.Text = Utils.i18N.Translate(ConfigurationGroupBox.Text);
- RemarkLabel.Text = Utils.i18N.Translate(RemarkLabel.Text);
- AddressLabel.Text = Utils.i18N.Translate(AddressLabel.Text);
- PasswordLabel.Text = Utils.i18N.Translate(PasswordLabel.Text);
- EncryptMethodLabel.Text = Utils.i18N.Translate(EncryptMethodLabel.Text);
- PluginLabel.Text = Utils.i18N.Translate(PluginLabel.Text);
- PluginOptionsLabel.Text = Utils.i18N.Translate(PluginOptionsLabel.Text);
- ControlButton.Text = Utils.i18N.Translate(ControlButton.Text);
+ ConfigurationGroupBox.Text = i18N.Translate(ConfigurationGroupBox.Text);
+ RemarkLabel.Text = i18N.Translate(RemarkLabel.Text);
+ AddressLabel.Text = i18N.Translate(AddressLabel.Text);
+ PasswordLabel.Text = i18N.Translate(PasswordLabel.Text);
+ EncryptMethodLabel.Text = i18N.Translate(EncryptMethodLabel.Text);
+ PluginLabel.Text = i18N.Translate(PluginLabel.Text);
+ PluginOptionsLabel.Text = i18N.Translate(PluginOptionsLabel.Text);
+ ControlButton.Text = i18N.Translate(ControlButton.Text);
foreach (var encrypt in Global.EncryptMethods.SS)
{
@@ -119,8 +120,8 @@ namespace Netch.Forms.Server
};
}
- Utils.Configuration.Save();
- MessageBox.Show(Utils.i18N.Translate("Saved"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ Configuration.Save();
+ MessageBox.Show(i18N.Translate("Saved"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
Global.MainForm.InitServer();
Close();
}
diff --git a/Netch/Forms/Server/ShadowsocksR.cs b/Netch/Forms/Server/ShadowsocksR.cs
index 969f0cf8..f12f5a65 100644
--- a/Netch/Forms/Server/ShadowsocksR.cs
+++ b/Netch/Forms/Server/ShadowsocksR.cs
@@ -2,6 +2,7 @@
using System.Drawing;
using System.Text.RegularExpressions;
using System.Windows.Forms;
+using Netch.Utils;
namespace Netch.Forms.Server
{
@@ -22,16 +23,16 @@ namespace Netch.Forms.Server
private void ShadowsocksR_Load(object sender, EventArgs e)
{
- ConfigurationGroupBox.Text = Utils.i18N.Translate(ConfigurationGroupBox.Text);
- RemarkLabel.Text = Utils.i18N.Translate(RemarkLabel.Text);
- AddressLabel.Text = Utils.i18N.Translate(AddressLabel.Text);
- PasswordLabel.Text = Utils.i18N.Translate(PasswordLabel.Text);
- EncryptMethodLabel.Text = Utils.i18N.Translate(EncryptMethodLabel.Text);
- ProtocolLabel.Text = Utils.i18N.Translate(ProtocolLabel.Text);
- ProtocolParamLabel.Text = Utils.i18N.Translate(ProtocolParamLabel.Text);
- OBFSLabel.Text = Utils.i18N.Translate(OBFSLabel.Text);
- OBFSParamLabel.Text = Utils.i18N.Translate(OBFSParamLabel.Text);
- ControlButton.Text = Utils.i18N.Translate(ControlButton.Text);
+ ConfigurationGroupBox.Text = i18N.Translate(ConfigurationGroupBox.Text);
+ RemarkLabel.Text = i18N.Translate(RemarkLabel.Text);
+ AddressLabel.Text = i18N.Translate(AddressLabel.Text);
+ PasswordLabel.Text = i18N.Translate(PasswordLabel.Text);
+ EncryptMethodLabel.Text = i18N.Translate(EncryptMethodLabel.Text);
+ ProtocolLabel.Text = i18N.Translate(ProtocolLabel.Text);
+ ProtocolParamLabel.Text = i18N.Translate(ProtocolParamLabel.Text);
+ OBFSLabel.Text = i18N.Translate(OBFSLabel.Text);
+ OBFSParamLabel.Text = i18N.Translate(OBFSParamLabel.Text);
+ ControlButton.Text = i18N.Translate(ControlButton.Text);
foreach (var encrypt in Global.EncryptMethods.SSR)
{
@@ -139,8 +140,8 @@ namespace Netch.Forms.Server
};
}
- Utils.Configuration.Save();
- MessageBox.Show(Utils.i18N.Translate("Saved"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ Configuration.Save();
+ MessageBox.Show(i18N.Translate("Saved"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
Global.MainForm.InitServer();
Close();
}
diff --git a/Netch/Forms/Server/Socks5.cs b/Netch/Forms/Server/Socks5.cs
index d864cd5d..95116237 100644
--- a/Netch/Forms/Server/Socks5.cs
+++ b/Netch/Forms/Server/Socks5.cs
@@ -2,6 +2,7 @@
using System.Drawing;
using System.Text.RegularExpressions;
using System.Windows.Forms;
+using Netch.Utils;
namespace Netch.Forms.Server
{
@@ -22,12 +23,12 @@ namespace Netch.Forms.Server
private void Shadowsocks_Load(object sender, EventArgs e)
{
- ConfigurationGroupBox.Text = Utils.i18N.Translate(ConfigurationGroupBox.Text);
- RemarkLabel.Text = Utils.i18N.Translate(RemarkLabel.Text);
- AddressLabel.Text = Utils.i18N.Translate(AddressLabel.Text);
- UsernameLabel.Text = Utils.i18N.Translate(UsernameLabel.Text);
- PasswordLabel.Text = Utils.i18N.Translate(PasswordLabel.Text);
- ControlButton.Text = Utils.i18N.Translate(ControlButton.Text);
+ ConfigurationGroupBox.Text = i18N.Translate(ConfigurationGroupBox.Text);
+ RemarkLabel.Text = i18N.Translate(RemarkLabel.Text);
+ AddressLabel.Text = i18N.Translate(AddressLabel.Text);
+ UsernameLabel.Text = i18N.Translate(UsernameLabel.Text);
+ PasswordLabel.Text = i18N.Translate(PasswordLabel.Text);
+ ControlButton.Text = i18N.Translate(ControlButton.Text);
if (Index != -1)
{
@@ -102,8 +103,8 @@ namespace Netch.Forms.Server
};
}
- Utils.Configuration.Save();
- MessageBox.Show(Utils.i18N.Translate("Saved"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ Configuration.Save();
+ MessageBox.Show(i18N.Translate("Saved"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
Global.MainForm.InitServer();
Close();
}
diff --git a/Netch/Forms/Server/Trojan.cs b/Netch/Forms/Server/Trojan.cs
index 4c821c46..26c3c168 100644
--- a/Netch/Forms/Server/Trojan.cs
+++ b/Netch/Forms/Server/Trojan.cs
@@ -2,6 +2,7 @@
using System.Drawing;
using System.Text.RegularExpressions;
using System.Windows.Forms;
+using Netch.Utils;
namespace Netch.Forms.Server
{
@@ -22,11 +23,11 @@ namespace Netch.Forms.Server
private void Trojan_Load(object sender, EventArgs e)
{
- ConfigurationGroupBox.Text = Utils.i18N.Translate(ConfigurationGroupBox.Text);
- RemarkLabel.Text = Utils.i18N.Translate(RemarkLabel.Text);
- AddressLabel.Text = Utils.i18N.Translate(AddressLabel.Text);
- PasswordLabel.Text = Utils.i18N.Translate(PasswordLabel.Text);
- ControlButton.Text = Utils.i18N.Translate(ControlButton.Text);
+ ConfigurationGroupBox.Text = i18N.Translate(ConfigurationGroupBox.Text);
+ RemarkLabel.Text = i18N.Translate(RemarkLabel.Text);
+ AddressLabel.Text = i18N.Translate(AddressLabel.Text);
+ PasswordLabel.Text = i18N.Translate(PasswordLabel.Text);
+ ControlButton.Text = i18N.Translate(ControlButton.Text);
if (Index != -1)
{
@@ -98,8 +99,8 @@ namespace Netch.Forms.Server
};
}
- Utils.Configuration.Save();
- MessageBox.Show(Utils.i18N.Translate("Saved"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ Configuration.Save();
+ MessageBox.Show(i18N.Translate("Saved"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
Global.MainForm.InitServer();
Close();
}
diff --git a/Netch/Forms/Server/Vmess.cs b/Netch/Forms/Server/Vmess.cs
index cc97f835..77743577 100644
--- a/Netch/Forms/Server/Vmess.cs
+++ b/Netch/Forms/Server/Vmess.cs
@@ -2,6 +2,7 @@
using System.Drawing;
using System.Text.RegularExpressions;
using System.Windows.Forms;
+using Netch.Utils;
namespace Netch.Forms.Server
{
@@ -43,21 +44,21 @@ namespace Netch.Forms.Server
private void VMess_Load(object sender, EventArgs e)
{
- ConfigurationGroupBox.Text = Utils.i18N.Translate(ConfigurationGroupBox.Text);
- RemarkLabel.Text = Utils.i18N.Translate(RemarkLabel.Text);
- AddressLabel.Text = Utils.i18N.Translate(AddressLabel.Text);
- UserIDLabel.Text = Utils.i18N.Translate(UserIDLabel.Text);
- AlterIDLabel.Text = Utils.i18N.Translate(AlterIDLabel.Text);
- EncryptMethodLabel.Text = Utils.i18N.Translate(EncryptMethodLabel.Text);
- TransferProtocolLabel.Text = Utils.i18N.Translate(TransferProtocolLabel.Text);
- FakeTypeLabel.Text = Utils.i18N.Translate(FakeTypeLabel.Text);
- HostLabel.Text = Utils.i18N.Translate(HostLabel.Text);
- PathLabel.Text = Utils.i18N.Translate(PathLabel.Text);
- QUICSecurityLabel.Text = Utils.i18N.Translate(QUICSecurityLabel.Text);
- QUICSecretLabel.Text = Utils.i18N.Translate(QUICSecretLabel.Text);
- TLSSecureCheckBox.Text = Utils.i18N.Translate(TLSSecureCheckBox.Text);
- UseMuxCheckBox.Text = Utils.i18N.Translate(UseMuxCheckBox.Text);
- ControlButton.Text = Utils.i18N.Translate(ControlButton.Text);
+ ConfigurationGroupBox.Text = i18N.Translate(ConfigurationGroupBox.Text);
+ RemarkLabel.Text = i18N.Translate(RemarkLabel.Text);
+ AddressLabel.Text = i18N.Translate(AddressLabel.Text);
+ UserIDLabel.Text = i18N.Translate(UserIDLabel.Text);
+ AlterIDLabel.Text = i18N.Translate(AlterIDLabel.Text);
+ EncryptMethodLabel.Text = i18N.Translate(EncryptMethodLabel.Text);
+ TransferProtocolLabel.Text = i18N.Translate(TransferProtocolLabel.Text);
+ FakeTypeLabel.Text = i18N.Translate(FakeTypeLabel.Text);
+ HostLabel.Text = i18N.Translate(HostLabel.Text);
+ PathLabel.Text = i18N.Translate(PathLabel.Text);
+ QUICSecurityLabel.Text = i18N.Translate(QUICSecurityLabel.Text);
+ QUICSecretLabel.Text = i18N.Translate(QUICSecretLabel.Text);
+ TLSSecureCheckBox.Text = i18N.Translate(TLSSecureCheckBox.Text);
+ UseMuxCheckBox.Text = i18N.Translate(UseMuxCheckBox.Text);
+ ControlButton.Text = i18N.Translate(ControlButton.Text);
foreach (var encrypt in Global.EncryptMethods.VMess)
{
@@ -118,7 +119,7 @@ namespace Netch.Forms.Server
}
if (AlterIDTextBox.Text == "")
{
- MessageBox.Show(Utils.i18N.Translate("Please fill in alterID"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Please fill in alterID"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (Index == -1)
@@ -165,8 +166,8 @@ namespace Netch.Forms.Server
};
}
- Utils.Configuration.Save();
- MessageBox.Show(Utils.i18N.Translate("Saved"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ Configuration.Save();
+ MessageBox.Show(i18N.Translate("Saved"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
Global.MainForm.InitServer();
Close();
}
diff --git a/Netch/Forms/SettingForm.cs b/Netch/Forms/SettingForm.cs
index b8f6a050..300838ba 100644
--- a/Netch/Forms/SettingForm.cs
+++ b/Netch/Forms/SettingForm.cs
@@ -1,10 +1,8 @@
-using Netch.Models.SSD;
-using System;
-using System.Globalization;
-using System.IO;
+using System;
+using System.Collections.Generic;
using System.Net;
-using System.Text;
using System.Windows.Forms;
+using Netch.Utils;
using TaskScheduler;
namespace Netch.Forms
@@ -48,18 +46,18 @@ namespace Netch.Forms
private void InitText()
{
- Text = Utils.i18N.Translate(Text);
- PortGroupBox.Text = Utils.i18N.Translate(PortGroupBox.Text);
- AllowDevicesCheckBox.Text = Utils.i18N.Translate(AllowDevicesCheckBox.Text);
- TUNTAPAddressLabel.Text = Utils.i18N.Translate(TUNTAPAddressLabel.Text);
- TUNTAPNetmaskLabel.Text = Utils.i18N.Translate(TUNTAPNetmaskLabel.Text);
- TUNTAPGatewayLabel.Text = Utils.i18N.Translate(TUNTAPGatewayLabel.Text);
- UseCustomDNSCheckBox.Text = Utils.i18N.Translate(UseCustomDNSCheckBox.Text);
- ProxyDNSCheckBox.Text = Utils.i18N.Translate(ProxyDNSCheckBox.Text);
- UseFakeDNSCheckBox.Text = Utils.i18N.Translate(UseFakeDNSCheckBox.Text);
- GlobalBypassIPsButton.Text = Utils.i18N.Translate(GlobalBypassIPsButton.Text);
- ControlButton.Text = Utils.i18N.Translate(ControlButton.Text);
- BootShadowsocksFromDLLCheckBox.Text = Utils.i18N.Translate(BootShadowsocksFromDLLCheckBox.Text);
+ Text = i18N.Translate(Text);
+ PortGroupBox.Text = i18N.Translate(PortGroupBox.Text);
+ AllowDevicesCheckBox.Text = i18N.Translate(AllowDevicesCheckBox.Text);
+ TUNTAPAddressLabel.Text = i18N.Translate(TUNTAPAddressLabel.Text);
+ TUNTAPNetmaskLabel.Text = i18N.Translate(TUNTAPNetmaskLabel.Text);
+ TUNTAPGatewayLabel.Text = i18N.Translate(TUNTAPGatewayLabel.Text);
+ UseCustomDNSCheckBox.Text = i18N.Translate(UseCustomDNSCheckBox.Text);
+ ProxyDNSCheckBox.Text = i18N.Translate(ProxyDNSCheckBox.Text);
+ UseFakeDNSCheckBox.Text = i18N.Translate(UseFakeDNSCheckBox.Text);
+ GlobalBypassIPsButton.Text = i18N.Translate(GlobalBypassIPsButton.Text);
+ ControlButton.Text = i18N.Translate(ControlButton.Text);
+ BootShadowsocksFromDLLCheckBox.Text = i18N.Translate(BootShadowsocksFromDLLCheckBox.Text);
ExitWhenClosedCheckBox.Checked = Global.Settings.ExitWhenClosed;
StopWhenExitedCheckBox.Checked = Global.Settings.StopWhenExited;
@@ -83,30 +81,30 @@ namespace Netch.Forms
ProxyDNSCheckBox.Checked = Global.Settings.TUNTAP.ProxyDNS;
UseFakeDNSCheckBox.Checked = Global.Settings.TUNTAP.UseFakeDNS;
- BehaviorGroupBox.Text = Utils.i18N.Translate(BehaviorGroupBox.Text);
- ExitWhenClosedCheckBox.Text = Utils.i18N.Translate(ExitWhenClosedCheckBox.Text);
- StopWhenExitedCheckBox.Text = Utils.i18N.Translate(StopWhenExitedCheckBox.Text);
- StartWhenOpenedCheckBox.Text = Utils.i18N.Translate(StartWhenOpenedCheckBox.Text);
- MinimizeWhenStartedCheckBox.Text = Utils.i18N.Translate(MinimizeWhenStartedCheckBox.Text);
- RunAtStartup.Text = Utils.i18N.Translate(RunAtStartup.Text);
- CheckUpdateWhenOpenedCheckBox.Text = Utils.i18N.Translate(CheckUpdateWhenOpenedCheckBox.Text);
- ProfileCount_Label.Text = Utils.i18N.Translate(ProfileCount_Label.Text);
- DelayTestAfterStartup_Label.Text = Utils.i18N.Translate(DelayTestAfterStartup_Label.Text);
- EnableStartedTcping_CheckBox.Text = Utils.i18N.Translate(EnableStartedTcping_CheckBox.Text);
- DetectionInterval_Label.Text = Utils.i18N.Translate(DetectionInterval_Label.Text);
- DelayTestAfterStartup_Label.Text = Utils.i18N.Translate(DelayTestAfterStartup_Label.Text);
- STUNServerLabel.Text = Utils.i18N.Translate(STUNServerLabel.Text);
- STUNServerPortLabel.Text = Utils.i18N.Translate(STUNServerPortLabel.Text);
+ BehaviorGroupBox.Text = i18N.Translate(BehaviorGroupBox.Text);
+ ExitWhenClosedCheckBox.Text = i18N.Translate(ExitWhenClosedCheckBox.Text);
+ StopWhenExitedCheckBox.Text = i18N.Translate(StopWhenExitedCheckBox.Text);
+ StartWhenOpenedCheckBox.Text = i18N.Translate(StartWhenOpenedCheckBox.Text);
+ MinimizeWhenStartedCheckBox.Text = i18N.Translate(MinimizeWhenStartedCheckBox.Text);
+ RunAtStartup.Text = i18N.Translate(RunAtStartup.Text);
+ CheckUpdateWhenOpenedCheckBox.Text = i18N.Translate(CheckUpdateWhenOpenedCheckBox.Text);
+ ProfileCount_Label.Text = i18N.Translate(ProfileCount_Label.Text);
+ DelayTestAfterStartup_Label.Text = i18N.Translate(DelayTestAfterStartup_Label.Text);
+ EnableStartedTcping_CheckBox.Text = i18N.Translate(EnableStartedTcping_CheckBox.Text);
+ DetectionInterval_Label.Text = i18N.Translate(DetectionInterval_Label.Text);
+ DelayTestAfterStartup_Label.Text = i18N.Translate(DelayTestAfterStartup_Label.Text);
+ STUNServerLabel.Text = i18N.Translate(STUNServerLabel.Text);
+ STUNServerPortLabel.Text = i18N.Translate(STUNServerPortLabel.Text);
ProfileCount_TextBox.Text = Global.Settings.ProfileCount.ToString();
- STUN_ServerTextBox.Text = Global.Settings.STUN_Server.ToString();
+ STUN_ServerTextBox.Text = Global.Settings.STUN_Server;
STUN_ServerPortTextBox.Text = Global.Settings.STUN_Server_Port.ToString();
- AclLabel.Text = Utils.i18N.Translate(AclLabel.Text);
- AclAddr.Text = Global.Settings.ACL.ToString();
+ AclLabel.Text = i18N.Translate(AclLabel.Text);
+ AclAddr.Text = Global.Settings.ACL;
- LanguageLabel.Text = Utils.i18N.Translate(LanguageLabel.Text);
- LanguageComboBox.Items.AddRange(Utils.i18N.TranslatesList.ToArray());
+ LanguageLabel.Text = i18N.Translate(LanguageLabel.Text);
+ LanguageComboBox.Items.AddRange(i18N.TranslatesList.ToArray());
LanguageComboBox.SelectedItem = Global.Settings.Language;
}
@@ -176,10 +174,10 @@ namespace Netch.Forms
Global.Settings.Language = LanguageComboBox.SelectedItem.ToString();
// 开机自启判断
- TaskSchedulerClass scheduler = new TaskSchedulerClass();
- scheduler.Connect(null, null, null, null);
- ITaskFolder folder = scheduler.GetFolder("\\");
- bool taskIsExists = false;
+ var scheduler = new TaskSchedulerClass();
+ scheduler.Connect();
+ var folder = scheduler.GetFolder("\\");
+ var taskIsExists = false;
try
{
folder.GetTask("Netch Startup");
@@ -192,14 +190,14 @@ namespace Netch.Forms
if (taskIsExists)
folder.DeleteTask("Netch Startup", 0);
- ITaskDefinition task = scheduler.NewTask(0);
+ var task = scheduler.NewTask(0);
task.RegistrationInfo.Author = "Netch";
task.RegistrationInfo.Description = "Netch run at startup.";
task.Principal.RunLevel = _TASK_RUNLEVEL.TASK_RUNLEVEL_HIGHEST;
task.Triggers.Create(_TASK_TRIGGER_TYPE2.TASK_TRIGGER_LOGON);
- IExecAction action = (IExecAction)task.Actions.Create(_TASK_ACTION_TYPE.TASK_ACTION_EXEC);
- action.Path = System.Windows.Forms.Application.ExecutablePath;
+ var action = (IExecAction)task.Actions.Create(_TASK_ACTION_TYPE.TASK_ACTION_EXEC);
+ action.Path = Application.ExecutablePath;
task.Settings.ExecutionTimeLimit = "PT0S";
@@ -230,7 +228,7 @@ namespace Netch.Forms
catch (FormatException)
{
Socks5PortTextBox.Text = Global.Settings.Socks5LocalPort.ToString();
- MessageBox.Show(Utils.i18N.Translate("Port value illegal. Try again."), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Port value illegal. Try again."), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
@@ -251,7 +249,7 @@ namespace Netch.Forms
catch (FormatException)
{
HTTPPortTextBox.Text = Global.Settings.HTTPLocalPort.ToString();
- MessageBox.Show(Utils.i18N.Translate("Port value illegal. Try again."), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Port value illegal. Try again."), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
@@ -272,7 +270,7 @@ namespace Netch.Forms
catch (FormatException)
{
RedirectorTextBox.Text = Global.Settings.RedirectorTCPPort.ToString();
- MessageBox.Show(Utils.i18N.Translate("Port value illegal. Try again."), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Port value illegal. Try again."), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
@@ -292,7 +290,7 @@ namespace Netch.Forms
var Netmask = IPAddress.Parse(TUNTAPNetmaskTextBox.Text);
var Gateway = IPAddress.Parse(TUNTAPGatewayTextBox.Text);
- var DNS = new System.Collections.Generic.List();
+ var DNS = new List();
foreach (var ip in TUNTAPDNSTextBox.Text.Split(','))
{
DNS.Add(IPAddress.Parse(ip));
@@ -300,7 +298,7 @@ namespace Netch.Forms
}
catch (FormatException)
{
- MessageBox.Show(Utils.i18N.Translate("IP address format illegal. Try again."), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("IP address format illegal. Try again."), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
TUNTAPAddressTextBox.Text = Global.Settings.TUNTAP.Address;
TUNTAPNetmaskTextBox.Text = Global.Settings.TUNTAP.Netmask;
@@ -334,7 +332,7 @@ namespace Netch.Forms
catch (FormatException)
{
ProfileCount_TextBox.Text = Global.Settings.ProfileCount.ToString();
- MessageBox.Show(Utils.i18N.Translate("ProfileCount value illegal. Try again."), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("ProfileCount value illegal. Try again."), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
@@ -357,7 +355,7 @@ namespace Netch.Forms
catch (FormatException)
{
ProfileCount_TextBox.Text = Global.Settings.ProfileCount.ToString();
- MessageBox.Show(Utils.i18N.Translate("STUN_ServerPort value illegal. Try again."), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("STUN_ServerPort value illegal. Try again."), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
@@ -379,7 +377,7 @@ namespace Netch.Forms
catch (FormatException)
{
ProfileCount_TextBox.Text = Global.Settings.ProfileCount.ToString();
- MessageBox.Show(Utils.i18N.Translate("Detection interval value illegal. Try again."), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Detection interval value illegal. Try again."), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
@@ -400,8 +398,8 @@ namespace Netch.Forms
Global.Settings.TUNTAP.ProxyDNS = ProxyDNSCheckBox.Checked;
Global.Settings.TUNTAP.UseFakeDNS = UseFakeDNSCheckBox.Checked;
- Utils.Configuration.Save();
- MessageBox.Show(Utils.i18N.Translate("Saved"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ Configuration.Save();
+ MessageBox.Show(i18N.Translate("Saved"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
Close();
}
}
diff --git a/Netch/Forms/SubscribeForm.cs b/Netch/Forms/SubscribeForm.cs
index d64a3711..812d847b 100644
--- a/Netch/Forms/SubscribeForm.cs
+++ b/Netch/Forms/SubscribeForm.cs
@@ -1,8 +1,8 @@
-using Netch.Utils;
-using System;
+using System;
using System.Collections.Generic;
-using System.Text.RegularExpressions;
using System.Windows.Forms;
+using Netch.Models;
+using Netch.Utils;
namespace Netch.Forms
{
@@ -38,16 +38,16 @@ namespace Netch.Forms
private void SubscribeForm_Load(object sender, EventArgs e)
{
- Text = Utils.i18N.Translate(Text);
- RemarkColumnHeader.Text = Utils.i18N.Translate(RemarkColumnHeader.Text);
- LinkColumnHeader.Text = Utils.i18N.Translate(LinkColumnHeader.Text);
- UseSelectedServerCheckBox.Text = Utils.i18N.Translate(UseSelectedServerCheckBox.Text);
- DeleteToolStripMenuItem.Text = Utils.i18N.Translate(DeleteToolStripMenuItem.Text);
- CopyLinkToolStripMenuItem.Text = Utils.i18N.Translate(CopyLinkToolStripMenuItem.Text);
- RemarkLabel.Text = Utils.i18N.Translate(RemarkLabel.Text);
- LinkLabel.Text = Utils.i18N.Translate(LinkLabel.Text);
- AddButton.Text = Utils.i18N.Translate(AddButton.Text);
- ControlButton.Text = Utils.i18N.Translate(ControlButton.Text);
+ Text = i18N.Translate(Text);
+ RemarkColumnHeader.Text = i18N.Translate(RemarkColumnHeader.Text);
+ LinkColumnHeader.Text = i18N.Translate(LinkColumnHeader.Text);
+ UseSelectedServerCheckBox.Text = i18N.Translate(UseSelectedServerCheckBox.Text);
+ DeleteToolStripMenuItem.Text = i18N.Translate(DeleteToolStripMenuItem.Text);
+ CopyLinkToolStripMenuItem.Text = i18N.Translate(CopyLinkToolStripMenuItem.Text);
+ RemarkLabel.Text = i18N.Translate(RemarkLabel.Text);
+ LinkLabel.Text = i18N.Translate(LinkLabel.Text);
+ AddButton.Text = i18N.Translate(AddButton.Text);
+ ControlButton.Text = i18N.Translate(ControlButton.Text);
UserAgentTextBox.Text = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36";
@@ -83,7 +83,7 @@ namespace Netch.Forms
}
private void DeleteToolStripMenuItem_Click(object sender, EventArgs e)
{
- if (MessageBox.Show(Utils.i18N.Translate("Delete or not ? Will clean up the corresponding group of items in the server list"), Utils.i18N.Translate("Information"), MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
+ if (MessageBox.Show(i18N.Translate("Delete or not ? Will clean up the corresponding group of items in the server list"), i18N.Translate("Information"), MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
{
if (SubscribeLinkListView.SelectedItems.Count > 0)
{
@@ -128,14 +128,14 @@ namespace Netch.Forms
{
//是否为新增订阅
var saveFlag = true;
- Global.Settings.SubscribeLink.ForEach((subitem) =>
+ Global.Settings.SubscribeLink.ForEach(subitem =>
{
if (subitem.Link.Equals(LinkTextBox.Text))
{
if (!subitem.Remark.Equals(RemarkTextBox.Text))
{
//修改了订阅备注,修改旧订阅服务器
- Global.Settings.Server.ForEach((serverItem) =>
+ Global.Settings.Server.ForEach(serverItem =>
{
try
{
@@ -159,16 +159,14 @@ namespace Netch.Forms
subitem.UserAgent = UserAgentTextBox.Text;
saveFlag = false;
- Utils.Configuration.Save();
+ Configuration.Save();
Global.Settings.UseProxyToUpdateSubscription = UseSelectedServerCheckBox.Checked;
- MessageBox.Show(Utils.i18N.Translate("Successfully saved"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
-
- return;
+ MessageBox.Show(i18N.Translate("Successfully saved"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
});
if (saveFlag)
{
- Global.Settings.SubscribeLink.Add(new Models.SubscribeLink
+ Global.Settings.SubscribeLink.Add(new SubscribeLink
{
Remark = RemarkTextBox.Text,
Link = LinkTextBox.Text,
@@ -184,25 +182,25 @@ namespace Netch.Forms
}
else
{
- MessageBox.Show(Utils.i18N.Translate("Links must start with http:// or https://"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Links must start with http:// or https://"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else
{
- MessageBox.Show(Utils.i18N.Translate("Link can not be empty"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Link can not be empty"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else
{
- MessageBox.Show(Utils.i18N.Translate("Remark can not be empty"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Remark can not be empty"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void ControlButton_Click(object sender, EventArgs e)
{
- Utils.Configuration.Save();
+ Configuration.Save();
Global.Settings.UseProxyToUpdateSubscription = UseSelectedServerCheckBox.Checked;
- MessageBox.Show(Utils.i18N.Translate("Successfully saved"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Successfully saved"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
Close();
}
///
diff --git a/Netch/Netch.cs b/Netch/Netch.cs
index dde5b823..3f59d94e 100644
--- a/Netch/Netch.cs
+++ b/Netch/Netch.cs
@@ -1,9 +1,9 @@
using System;
-using System.Globalization;
using System.IO;
-using System.Text;
using System.Threading;
using System.Windows.Forms;
+using Netch.Forms;
+using Netch.Utils;
namespace Netch
{
@@ -24,14 +24,14 @@ namespace Netch
// 清理上一次的日志文件,防止淤积占用磁盘空间
if (Directory.Exists("logging"))
{
- DirectoryInfo directory = new DirectoryInfo("logging");
+ var directory = new DirectoryInfo("logging");
- foreach (FileInfo file in directory.GetFiles())
+ foreach (var file in directory.GetFiles())
{
file.Delete();
}
- foreach (DirectoryInfo dir in directory.GetDirectories())
+ foreach (var dir in directory.GetDirectories())
{
dir.Delete(true);
}
@@ -50,19 +50,19 @@ namespace Netch
}
// 加载配置
- Utils.Configuration.Load();
+ Configuration.Load();
// 加载语言
- Utils.i18N.Load(Global.Settings.Language);
+ i18N.Load(Global.Settings.Language);
// 记录当前系统语言
- Utils.Logging.Info($"当前语言:{Global.Settings.Language}");
+ Logging.Info($"当前语言:{Global.Settings.Language}");
// 检查是否已经运行
if (!mutex.WaitOne(0, false))
{
// 弹出提示
- MessageBox.Show(Utils.i18N.Translate("Netch is already running"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show(i18N.Translate("Netch is already running"), i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
// 退出进程
Environment.Exit(1);
@@ -76,7 +76,7 @@ namespace Netch
{
// 弹出提示
- MessageBox.Show($"{Utils.i18N.Translate("Netch is not compatible with your system.")}\n{Utils.i18N.Translate("Current arch of Netch:")} {PROC}\n{Utils.i18N.Translate("Current arch of system:")} {OS}", Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show($"{i18N.Translate("Netch is not compatible with your system.")}\n{i18N.Translate("Current arch of Netch:")} {PROC}\n{i18N.Translate("Current arch of system:")} {OS}", i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
// 退出进程
Environment.Exit(1);
@@ -88,7 +88,7 @@ namespace Netch
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(Global.MainForm = new Forms.MainForm());
+ Application.Run(Global.MainForm = new MainForm());
}
}
diff --git a/Netch/Utils/Bandwidth.cs b/Netch/Utils/Bandwidth.cs
index 7c3f96c0..5ee6daf7 100644
--- a/Netch/Utils/Bandwidth.cs
+++ b/Netch/Utils/Bandwidth.cs
@@ -1,19 +1,18 @@
-using Microsoft.Diagnostics.Tracing.Parsers;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Threading.Tasks;
+using Microsoft.Diagnostics.Tracing.Parsers;
using Microsoft.Diagnostics.Tracing.Session;
using Netch.Controllers;
using Netch.Forms;
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-using System.Threading.Tasks;
+using Netch.Models;
namespace Netch.Utils
{
public static class Bandwidth
{
- public static int received = 0;
+ public static int received;
///
/// 计算流量
@@ -36,20 +35,20 @@ namespace Netch.Utils
result = 0;
}
- return string.Format("{0} {1}", System.Math.Round(result, 2), units[i]);
+ return string.Format("{0} {1}", Math.Round(result, 2), units[i]);
}
///
/// 根据程序名统计流量
///
///
- public static void NetTraffic(Models.Server server, Models.Mode mode, MainController mainController)
+ public static void NetTraffic(Server server, Mode mode, MainController mainController)
{
var counterLock = new object();
//int sent = 0;
//var processList = Process.GetProcessesByName(ProcessName).Select(p => p.Id).ToHashSet();
- List processList = new List();
+ var processList = new List();
if (server.Type.Equals("Socks5") && mainController.pHTTPController != null)
{
@@ -121,7 +120,7 @@ namespace Netch.Utils
MainForm.Instance.OnBandwidthUpdated(0);
received = 0;
}
- while (MainForm.Instance.State != Models.State.Stopped)
+ while (MainForm.Instance.State != State.Stopped)
{
Task.Delay(1000).Wait();
lock (counterLock)
diff --git a/Netch/Utils/Configuration.cs b/Netch/Utils/Configuration.cs
index e471aa2f..d9531358 100644
--- a/Netch/Utils/Configuration.cs
+++ b/Netch/Utils/Configuration.cs
@@ -6,6 +6,8 @@ using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Threading;
using System.Windows.Forms;
+using Netch.Models;
+using Newtonsoft.Json;
namespace Netch.Utils
{
@@ -30,13 +32,13 @@ namespace Netch.Utils
{
try
{
- Global.Settings = Newtonsoft.Json.JsonConvert.DeserializeObject(File.ReadAllText(SETTINGS_JSON));
+ Global.Settings = JsonConvert.DeserializeObject(File.ReadAllText(SETTINGS_JSON));
if (Global.Settings.Server != null && Global.Settings.Server.Count > 0)
{
// 如果是旧版 Server 类,使用旧版 Server 类进行读取
if (Global.Settings.Server[0].Hostname == null)
{
- var LegacySettingConfig = Newtonsoft.Json.JsonConvert.DeserializeObject(File.ReadAllText(SETTINGS_JSON));
+ var LegacySettingConfig = JsonConvert.DeserializeObject(File.ReadAllText(SETTINGS_JSON));
for (var i = 0; i < LegacySettingConfig.Server.Count; i++)
{
Global.Settings.Server[i].Hostname = LegacySettingConfig.Server[i].Address;
@@ -59,7 +61,7 @@ namespace Netch.Utils
}
}
- catch (Newtonsoft.Json.JsonException)
+ catch (JsonException)
{
}
@@ -84,7 +86,7 @@ namespace Netch.Utils
{
Directory.CreateDirectory(DATA_DIR);
}
- File.WriteAllText(SETTINGS_JSON, Newtonsoft.Json.JsonConvert.SerializeObject(Global.Settings, Newtonsoft.Json.Formatting.Indented));
+ File.WriteAllText(SETTINGS_JSON, JsonConvert.SerializeObject(Global.Settings, Formatting.Indented));
}
///
@@ -200,7 +202,7 @@ namespace Netch.Utils
{
Logging.Info("正在安装 TUN/TAP 适配器");
//安装Tap Driver
- Process installProcess = new Process();
+ var installProcess = new Process();
installProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
installProcess.StartInfo.FileName = Path.Combine("bin/tap-driver", "addtap.bat");
installProcess.Start();
@@ -213,7 +215,7 @@ namespace Netch.Utils
public static void deltapall()
{
Logging.Info("正在卸载 TUN/TAP 适配器");
- Process installProcess = new Process();
+ var installProcess = new Process();
installProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
installProcess.StartInfo.FileName = Path.Combine("bin/tap-driver", "deltapall.bat");
installProcess.Start();
diff --git a/Netch/Utils/ShareLink.cs b/Netch/Utils/ShareLink.cs
index f9b6d567..fab0f872 100644
--- a/Netch/Utils/ShareLink.cs
+++ b/Netch/Utils/ShareLink.cs
@@ -1,12 +1,14 @@
-using Netch.Models;
-using Netch.Models.SS;
-using Newtonsoft.Json;
-using System;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
+using Netch.Models;
+using Netch.Models.SS;
+using Netch.Models.SSD;
+using Newtonsoft.Json;
+using Server = Netch.Models.Server;
namespace Netch.Utils
{
@@ -36,9 +38,9 @@ namespace Netch.Utils
///
/// 需要获取分享链接的服务器
/// 解码后的字符串
- public static string GetShareLink(Models.Server server)
+ public static string GetShareLink(Server server)
{
- string retLinkStr = "";
+ var retLinkStr = "";
switch (server.Type)
{
case "Socks5":
@@ -54,12 +56,12 @@ namespace Netch.Utils
case "SSR":
// https://github.com/shadowsocksr-backup/shadowsocks-rss/wiki/SSR-QRcode-scheme
// ssr://base64(host:port:protocol:method:obfs:base64pass/?obfsparam=base64param&protoparam=base64param&remarks=base64remarks&group=base64group&udpport=0&uot=0)
- string paraStr = string.Format("/?obfsparam={0}&protoparam={1}&remarks={2}", URLSafeBase64Encode(server.OBFSParam), URLSafeBase64Encode(server.ProtocolParam), URLSafeBase64Encode(server.Remark));
+ var paraStr = string.Format("/?obfsparam={0}&protoparam={1}&remarks={2}", URLSafeBase64Encode(server.OBFSParam), URLSafeBase64Encode(server.ProtocolParam), URLSafeBase64Encode(server.Remark));
retLinkStr = "ssr://" + URLSafeBase64Encode(string.Format("{0}:{1}:{2}:{3}:{4}:{5}{6}", server.Hostname, server.Port, server.Protocol, server.EncryptMethod, server.OBFS, URLSafeBase64Encode(server.Password), paraStr));
break;
case "VMess":
- string vmessJson = Newtonsoft.Json.JsonConvert.SerializeObject(new
+ var vmessJson = JsonConvert.SerializeObject(new
{
v = "2",
ps = server.Remark,
@@ -267,7 +269,7 @@ namespace Netch.Utils
}
else if (text.StartsWith("ssd://"))
{
- var json = JsonConvert.DeserializeObject(URLSafeBase64Decode(text.Substring(6)));
+ var json = JsonConvert.DeserializeObject(URLSafeBase64Decode(text.Substring(6)));
foreach (var server in json.servers)
{
@@ -495,10 +497,10 @@ namespace Netch.Utils
}
byte[] emoji_bytes = { 240, 159 };
- foreach (Server node in list)
+ foreach (var node in list)
{
var remark = Encoding.UTF8.GetBytes(node.Remark);
- int start_index = 0;
+ var start_index = 0;
while (remark.Length > start_index + 1 && remark[start_index] == emoji_bytes[0] && remark[start_index + 1] == emoji_bytes[1])
start_index += 4;
node.Remark = Encoding.UTF8.GetString(remark.Skip(start_index).ToArray()).Trim();
@@ -512,7 +514,7 @@ namespace Netch.Utils
{
return "";
}
- byte[] bytes = Convert.FromBase64String(value);
+ var bytes = Convert.FromBase64String(value);
return Encoding.UTF8.GetString(bytes);
}
public static string ToBase64String(string value)
@@ -521,7 +523,7 @@ namespace Netch.Utils
{
return "";
}
- byte[] bytes = Encoding.UTF8.GetBytes(value);
+ var bytes = Encoding.UTF8.GetBytes(value);
return Convert.ToBase64String(bytes);
}
@@ -594,7 +596,7 @@ namespace Netch.Utils
{
Server_Udp_Port = ushort.Parse(params_dict["udpport"]);
}*/
- Server server = new Server();
+ var server = new Server();
server.Type = "SSR";
server.Hostname = serverAddr;
server.Port = Server_Port;