From 2a0012824abb0dc5f2cb893ad510a01b9cd9d703 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Mon, 3 Feb 2025 15:06:21 +0800 Subject: [PATCH] Add support for brook custom configuration https://github.com/txthinking/brook https://github.com/txthinking/brook/issues/1372 --- v2rayN/ServiceLib/Enums/ECoreType.cs | 5 +++-- v2rayN/ServiceLib/Global.cs | 5 +++-- v2rayN/ServiceLib/Handler/CoreHandler.cs | 2 +- v2rayN/ServiceLib/Handler/CoreInfoHandler.cs | 19 ++++++++++--------- v2rayN/ServiceLib/Models/CoreInfo.cs | 6 +++--- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/v2rayN/ServiceLib/Enums/ECoreType.cs b/v2rayN/ServiceLib/Enums/ECoreType.cs index cd93e7b9..e3fb7786 100644 --- a/v2rayN/ServiceLib/Enums/ECoreType.cs +++ b/v2rayN/ServiceLib/Enums/ECoreType.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Enums +namespace ServiceLib.Enums { public enum ECoreType { @@ -12,6 +12,7 @@ sing_box = 24, juicity = 25, hysteria2 = 26, + brook = 27, v2rayN = 99 } -} \ No newline at end of file +} diff --git a/v2rayN/ServiceLib/Global.cs b/v2rayN/ServiceLib/Global.cs index 9ea41964..1164c773 100644 --- a/v2rayN/ServiceLib/Global.cs +++ b/v2rayN/ServiceLib/Global.cs @@ -1,4 +1,4 @@ -namespace ServiceLib +namespace ServiceLib { public class Global { @@ -18,6 +18,7 @@ public const string GeoUrl = "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/{0}.dat"; public const string SpeedPingTestUrl = @"https://www.google.com/generate_204"; public const string JuicityCoreUrl = "https://github.com/juicity/juicity/releases"; + public const string BrookCoreUrl = "https://github.com/txthinking/brook/releases"; public const string SingboxRulesetUrl = @"https://raw.githubusercontent.com/2dust/sing-box-rules/rule-set-{0}/{1}.srs"; public const string IPAPIUrl = "https://api.ip.sb/geoip"; @@ -502,4 +503,4 @@ #endregion const } -} \ No newline at end of file +} diff --git a/v2rayN/ServiceLib/Handler/CoreHandler.cs b/v2rayN/ServiceLib/Handler/CoreHandler.cs index 1270d8ca..6247704e 100644 --- a/v2rayN/ServiceLib/Handler/CoreHandler.cs +++ b/v2rayN/ServiceLib/Handler/CoreHandler.cs @@ -225,7 +225,7 @@ namespace ServiceLib.Handler StartInfo = new() { FileName = fileName, - Arguments = string.Format(coreInfo.Arguments, configPath), + Arguments = string.Format(coreInfo.Arguments, coreInfo.AbsolutePath ? Utils.GetConfigPath(configPath) : configPath), WorkingDirectory = Utils.GetConfigPath(), UseShellExecute = false, RedirectStandardOutput = displayLog, diff --git a/v2rayN/ServiceLib/Handler/CoreInfoHandler.cs b/v2rayN/ServiceLib/Handler/CoreInfoHandler.cs index e6b89056..25cdebea 100644 --- a/v2rayN/ServiceLib/Handler/CoreInfoHandler.cs +++ b/v2rayN/ServiceLib/Handler/CoreInfoHandler.cs @@ -76,7 +76,6 @@ namespace ServiceLib.Handler ReleaseApiUrl = Global.V2flyCoreUrl.Replace(Global.GithubUrl, Global.GithubApiUrl), Match = "V2Ray", VersionArg = "-version", - RedirectInfo = true, }, new CoreInfo @@ -88,7 +87,6 @@ namespace ServiceLib.Handler ReleaseApiUrl = Global.V2flyCoreUrl.Replace(Global.GithubUrl, Global.GithubApiUrl), Match = "V2Ray", VersionArg = "version", - RedirectInfo = true, }, new CoreInfo @@ -106,7 +104,6 @@ namespace ServiceLib.Handler DownloadUrlOSXArm64 = Global.XrayCoreUrl + "/download/{0}/Xray-macos-arm64-v8a.zip", Match = "Xray", VersionArg = "-version", - RedirectInfo = true, }, new CoreInfo @@ -124,7 +121,6 @@ namespace ServiceLib.Handler DownloadUrlOSXArm64 = Global.MihomoCoreUrl + "/download/{0}/mihomo-darwin-arm64-{0}.gz", Match = "Mihomo", VersionArg = "-v", - RedirectInfo = true, }, new CoreInfo @@ -133,7 +129,6 @@ namespace ServiceLib.Handler CoreExes = ["hysteria-windows-amd64", "hysteria"], Arguments = "-c {0}", Url = Global.HysteriaCoreUrl, - RedirectInfo = true, }, new CoreInfo @@ -142,7 +137,6 @@ namespace ServiceLib.Handler CoreExes = [ "naive", "naiveproxy"], Arguments = "{0}", Url = Global.NaiveproxyCoreUrl, - RedirectInfo = false, }, new CoreInfo @@ -151,7 +145,6 @@ namespace ServiceLib.Handler CoreExes = ["tuic-client", "tuic"], Arguments = "-c {0}", Url = Global.TuicCoreUrl, - RedirectInfo = true, }, new CoreInfo @@ -160,7 +153,7 @@ namespace ServiceLib.Handler CoreExes = ["sing-box-client", "sing-box"], Arguments = "run -c {0} --disable-color", Url = Global.SingboxCoreUrl, - RedirectInfo = true, + ReleaseApiUrl = Global.SingboxCoreUrl.Replace(Global.GithubUrl, Global.GithubApiUrl), DownloadUrlWin64 = Global.SingboxCoreUrl + "/download/{0}/sing-box-{1}-windows-amd64.zip", DownloadUrlWinArm64 = Global.SingboxCoreUrl + "/download/{0}/sing-box-{1}-windows-arm64.zip", @@ -186,7 +179,15 @@ namespace ServiceLib.Handler CoreExes = ["hysteria-windows-amd64", "hysteria-linux-amd64", "hysteria"], Arguments = "-c {0}", Url = Global.HysteriaCoreUrl, - RedirectInfo = true, + }, + + new CoreInfo + { + CoreType = ECoreType.brook, + CoreExes = ["brook_windows_amd64", "brook_linux_amd64", "brook"], + Arguments = " {0}", + Url = Global.BrookCoreUrl, + AbsolutePath = true, } ]; diff --git a/v2rayN/ServiceLib/Models/CoreInfo.cs b/v2rayN/ServiceLib/Models/CoreInfo.cs index 1afcd0b6..c6d6113c 100644 --- a/v2rayN/ServiceLib/Models/CoreInfo.cs +++ b/v2rayN/ServiceLib/Models/CoreInfo.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models +namespace ServiceLib.Models { [Serializable] public class CoreInfo @@ -16,6 +16,6 @@ public string? DownloadUrlOSXArm64 { get; set; } public string? Match { get; set; } public string? VersionArg { get; set; } - public bool RedirectInfo { get; set; } + public bool AbsolutePath { get; set; } } -} \ No newline at end of file +}