mirror of
https://github.com/netchx/netch.git
synced 2026-03-18 18:13:21 +08:00
102 lines
2.8 KiB
C#
102 lines
2.8 KiB
C#
using System.Collections.Generic;
|
||
using System.Globalization;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using Netch.Utils;
|
||
|
||
namespace Netch.Models
|
||
{
|
||
public class Mode
|
||
{
|
||
/// <summary>
|
||
/// 备注
|
||
/// </summary>
|
||
public string Remark;
|
||
|
||
/// <summary>
|
||
/// 文件相对路径(必须是存在的文件)
|
||
/// </summary>
|
||
public string RelativePath;
|
||
|
||
/// <summary>
|
||
/// 无后缀文件名
|
||
/// </summary>
|
||
public string FileName;
|
||
|
||
/// <summary>
|
||
/// 类型<para />
|
||
/// 0. Socks5 + 进程加速<para />
|
||
/// 1. Socks5 + TUN/TAP 规则内 IP CIDR 加速<para />
|
||
/// 2. Socks5 + TUN/TAP 全局,绕过规则内 IP CIDR<para />
|
||
/// 3. Socks5 + HTTP 代理(设置到系统代理)<para />
|
||
/// 4. Socks5 代理(不设置到系统代理)<para />
|
||
/// 5. Socks5 + HTTP 代理(不设置到系统代理)<para />
|
||
/// </summary>
|
||
public int Type = 0;
|
||
|
||
/// <summary>
|
||
/// 绕过中国(0. 不绕过 1. 绕过)
|
||
/// </summary>
|
||
public bool BypassChina = false;
|
||
|
||
/// <summary>
|
||
/// 规则
|
||
/// </summary>
|
||
public readonly List<string> Rule = new List<string>();
|
||
|
||
/// <summary>
|
||
/// 获取备注
|
||
/// </summary>
|
||
/// <returns>备注</returns>
|
||
public override string ToString()
|
||
{
|
||
return $"[{Type + 1}] {Remark}";
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取模式文件字符串
|
||
/// </summary>
|
||
/// <returns>模式文件字符串</returns>
|
||
public string ToFileString()
|
||
{
|
||
string fileString;
|
||
|
||
switch (Type)
|
||
{
|
||
case 0:
|
||
// 进程模式
|
||
fileString = $"# {Remark}";
|
||
break;
|
||
case 1:
|
||
// TUN/TAP 规则内 IP CIDR,无 Bypass China 设置
|
||
fileString = $"# {Remark}, {Type}, 0";
|
||
break;
|
||
default:
|
||
fileString = $"# {Remark}, {Type}, {(BypassChina ? 1 : 0)}";
|
||
break;
|
||
}
|
||
|
||
fileString += Global.EOF;
|
||
|
||
fileString = Rule.Aggregate(fileString, (current, item) => $"{current}{item}{Global.EOF}");
|
||
// 去除最后的行尾符
|
||
fileString = fileString.Substring(0, fileString.Length - 2);
|
||
|
||
return fileString;
|
||
}
|
||
|
||
public string TypeToString()
|
||
{
|
||
return Type switch
|
||
{
|
||
0 => "Process",
|
||
1 => "TUNTAP",
|
||
2 => "TUNTAP",
|
||
3 => "SYSTEM",
|
||
4 => "S5",
|
||
5 => "S5+HTTP",
|
||
_ => "ERROR",
|
||
};
|
||
}
|
||
}
|
||
} |