From 0953237e9e9a7aa858671ddd5ac50bd28a99fd40 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sat, 18 Jan 2025 16:01:52 +0800 Subject: [PATCH] Improvements --- v2rayN/ServiceLib/Common/Utils.cs | 2 +- v2rayN/ServiceLib/Global.cs | 435 +++++++++++++++++++---- v2rayN/ServiceLib/Handler/AppHandler.cs | 2 +- v2rayN/ServiceLib/Handler/CoreHandler.cs | 4 +- 4 files changed, 362 insertions(+), 81 deletions(-) diff --git a/v2rayN/ServiceLib/Common/Utils.cs b/v2rayN/ServiceLib/Common/Utils.cs index bae8230d..623cb469 100644 --- a/v2rayN/ServiceLib/Common/Utils.cs +++ b/v2rayN/ServiceLib/Common/Utils.cs @@ -706,7 +706,7 @@ namespace ServiceLib.Common public static string StartupPath() { - if (Utils.IsNonWindows() && Environment.GetEnvironmentVariable("V2RAYN_LOCAL_APPLICATION_DATA") == "1") + if (Utils.IsNonWindows() && Environment.GetEnvironmentVariable(Global.LocalAppData) == "1") { return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "v2rayN"); } diff --git a/v2rayN/ServiceLib/Global.cs b/v2rayN/ServiceLib/Global.cs index 4fabe857..9ea41964 100644 --- a/v2rayN/ServiceLib/Global.cs +++ b/v2rayN/ServiceLib/Global.cs @@ -18,7 +18,6 @@ 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 CustomRoutingListUrl = @"https://raw.githubusercontent.com/2dust/v2rayCustomRoutingList/master/"; 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"; @@ -68,7 +67,6 @@ public const string UserEMail = "t@t.tt"; public const string AutoRunRegPath = @"Software\Microsoft\Windows\CurrentVersion\Run"; public const string AutoRunName = "v2rayNAutoRun"; - public const string CustomIconName = "v2rayN.ico"; public const string SystemProxyExceptionsWindows = "localhost;127.*;10.*;172.16.*;172.17.*;172.18.*;172.19.*;172.20.*;172.21.*;172.22.*;172.23.*;172.24.*;172.25.*;172.26.*;172.27.*;172.28.*;172.29.*;172.30.*;172.31.*;192.168.*"; public const string SystemProxyExceptionsLinux = "localhost,127.0.0.0/8,::1"; public const string RoutingRuleComma = ""; @@ -80,71 +78,82 @@ public const int MinFontSize = 8; public const string RebootAs = "rebootas"; public const string AvaAssets = "avares://v2rayN/Assets/"; + public const string LocalAppData = "V2RAYN_LOCAL_APPLICATION_DATA"; + public const string V2RayLocalAsset = "V2RAY_LOCATION_ASSET"; + public const string XrayLocalAsset = "XRAY_LOCATION_ASSET"; - public static readonly List IEProxyProtocols = new() { - "{ip}:{http_port}", - "socks={ip}:{socks_port}", - "http={ip}:{http_port};https={ip}:{http_port};ftp={ip}:{http_port};socks={ip}:{socks_port}", - "http=http://{ip}:{http_port};https=http://{ip}:{http_port}", - "" - }; + public static readonly List IEProxyProtocols = + [ + "{ip}:{http_port}", + "socks={ip}:{socks_port}", + "http={ip}:{http_port};https={ip}:{http_port};ftp={ip}:{http_port};socks={ip}:{socks_port}", + "http=http://{ip}:{http_port};https=http://{ip}:{http_port}", + "" + ]; - public static readonly List SubConvertUrls = new List { - @"https://sub.xeton.dev/sub?url={0}", - @"https://api.dler.io/sub?url={0}", - @"http://127.0.0.1:25500/sub?url={0}", - "" - }; + public static readonly List SubConvertUrls = + [ + @"https://sub.xeton.dev/sub?url={0}", + @"https://api.dler.io/sub?url={0}", + @"http://127.0.0.1:25500/sub?url={0}", + "" + ]; - public static readonly List SubConvertConfig = new List { - @"https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online.ini" - }; + public static readonly List SubConvertConfig = + [@"https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online.ini"]; - public static readonly List SubConvertTargets = new List { - "", - "mixed", - "v2ray", - "clash", - "ss", - }; + public static readonly List SubConvertTargets = + [ + "", + "mixed", + "v2ray", + "clash", + "ss" + ]; - public static readonly List SpeedTestUrls = new() { + public static readonly List SpeedTestUrls = + [ @"https://speed.cloudflare.com/__down?bytes=100000000", @"https://speed.cloudflare.com/__down?bytes=50000000", @"https://speed.cloudflare.com/__down?bytes=10000000", - @"https://cachefly.cachefly.net/50mb.test", - }; + @"https://cachefly.cachefly.net/50mb.test" + ]; - public static readonly List SpeedPingTestUrls = new() { + public static readonly List SpeedPingTestUrls = + [ @"https://www.google.com/generate_204", @"https://www.gstatic.com/generate_204", @"https://www.apple.com/library/test/success.html", - @"http://www.msftconnecttest.com/connecttest.txt", - }; + @"http://www.msftconnecttest.com/connecttest.txt" + ]; - public static readonly List GeoFilesSources = new() { + public static readonly List GeoFilesSources = + [ "", @"https://github.com/runetfreedom/russia-v2ray-rules-dat/releases/latest/download/{0}.dat", - @"https://cdn.jsdelivr.net/gh/chocolate4u/Iran-v2ray-rules@release/{0}.dat", - }; + @"https://cdn.jsdelivr.net/gh/chocolate4u/Iran-v2ray-rules@release/{0}.dat" + ]; - public static readonly List SingboxRulesetSources = new() { + public static readonly List SingboxRulesetSources = + [ "", @"https://cdn.jsdelivr.net/gh/runetfreedom/russia-v2ray-rules-dat@release/sing-box/rule-set-{0}/{1}.srs", - @"https://cdn.jsdelivr.net/gh/chocolate4u/Iran-sing-box-rules@rule-set/{1}.srs", - }; + @"https://cdn.jsdelivr.net/gh/chocolate4u/Iran-sing-box-rules@rule-set/{1}.srs" + ]; - public static readonly List RoutingRulesSources = new() { + public static readonly List RoutingRulesSources = + [ "", @"https://cdn.jsdelivr.net/gh/runetfreedom/russia-v2ray-custom-routing-list@main/v2rayN/template.json", - @"https://cdn.jsdelivr.net/gh/Chocolate4U/Iran-v2ray-rules@main/v2rayN/template.json", - }; + @"https://cdn.jsdelivr.net/gh/Chocolate4U/Iran-v2ray-rules@main/v2rayN/template.json" + ]; - public static readonly List DNSTemplateSources = new() { + public static readonly List DNSTemplateSources = + [ "", @"https://cdn.jsdelivr.net/gh/runetfreedom/russia-v2ray-custom-routing-list@main/v2rayN/", - @"https://cdn.jsdelivr.net/gh/Chocolate4U/Iran-v2ray-rules@main/v2rayN/", - }; + @"https://cdn.jsdelivr.net/gh/Chocolate4U/Iran-v2ray-rules@main/v2rayN/" + ]; public static readonly Dictionary UserAgentTexts = new() { @@ -182,42 +191,314 @@ {EConfigType.WireGuard,"wireguard"} }; - public static readonly List VmessSecurities = new() { "aes-128-gcm", "chacha20-poly1305", "auto", "none", "zero" }; - public static readonly List SsSecurities = new() { "aes-256-gcm", "aes-128-gcm", "chacha20-poly1305", "chacha20-ietf-poly1305", "none", "plain" }; - public static readonly List SsSecuritiesInXray = new() { "aes-256-gcm", "aes-128-gcm", "chacha20-poly1305", "chacha20-ietf-poly1305", "xchacha20-poly1305", "xchacha20-ietf-poly1305", "none", "plain", "2022-blake3-aes-128-gcm", "2022-blake3-aes-256-gcm", "2022-blake3-chacha20-poly1305" }; - public static readonly List SsSecuritiesInSingbox = new() { "aes-256-gcm", "aes-192-gcm", "aes-128-gcm", "chacha20-ietf-poly1305", "xchacha20-ietf-poly1305", "none", "2022-blake3-aes-128-gcm", "2022-blake3-aes-256-gcm", "2022-blake3-chacha20-poly1305", "aes-128-ctr", "aes-192-ctr", "aes-256-ctr", "aes-128-cfb", "aes-192-cfb", "aes-256-cfb", "rc4-md5", "chacha20-ietf", "xchacha20" }; - public static readonly List Flows = new() { "", "xtls-rprx-vision", "xtls-rprx-vision-udp443" }; - public static readonly List Networks = new() { "tcp", "kcp", "ws", "httpupgrade", "xhttp", "h2", "quic", "grpc" }; - public static readonly List KcpHeaderTypes = new() { "srtp", "utp", "wechat-video", "dtls", "wireguard" }; - public static readonly List CoreTypes = new() { "Xray", "sing_box" }; - public static readonly List DomainStrategies = new() { "AsIs", "IPIfNonMatch", "IPOnDemand" }; - public static readonly List DomainStrategies4Singbox = new() { "ipv4_only", "ipv6_only", "prefer_ipv4", "prefer_ipv6", "" }; - public static readonly List DomainMatchers = new() { "linear", "mph", "" }; - public static readonly List Fingerprints = new() { "chrome", "firefox", "safari", "ios", "android", "edge", "360", "qq", "random", "randomized", "" }; - public static readonly List UserAgent = new() { "chrome", "firefox", "safari", "edge", "none" }; - public static readonly List XhttpMode = new() { "auto", "packet-up", "stream-up", "stream-one" }; + public static readonly List VmessSecurities = + [ + "aes-128-gcm", + "chacha20-poly1305", + "auto", + "none", + "zero" + ]; - public static readonly List AllowInsecure = new() { "true", "false", "" }; - public static readonly List DomainStrategy4Freedoms = new() { "AsIs", "UseIP", "UseIPv4", "UseIPv6", "" }; - public static readonly List SingboxDomainStrategy4Out = new() { "ipv4_only", "prefer_ipv4", "prefer_ipv6", "ipv6_only", "" }; - public static readonly List DomainDNSAddress = ["223.5.5.5", "223.6.6.6", "localhost"]; - public static readonly List SingboxDomainDNSAddress = ["223.5.5.5", "223.6.6.6", "dhcp://auto"]; - public static readonly List Languages = new() { "zh-Hans", "zh-Hant", "en", "fa-Ir", "ru", "hu" }; - public static readonly List Alpns = new() { "h3", "h2", "http/1.1", "h3,h2", "h2,http/1.1", "h3,h2,http/1.1", "" }; - public static readonly List LogLevels = new() { "debug", "info", "warning", "error", "none" }; - public static readonly List InboundTags = new() { "socks", "socks2", "socks3" }; - public static readonly List RuleProtocols = new() { "http", "tls", "bittorrent" }; - public static readonly List RuleNetworks = new() { "", "tcp", "udp", "tcp,udp" }; - public static readonly List destOverrideProtocols = ["http", "tls", "quic", "fakedns", "fakedns+others"]; - public static readonly List TunMtus = new() { "1280", "1408", "1500", "9000" }; - public static readonly List TunStacks = new() { "gvisor", "system", "mixed" }; - public static readonly List PresetMsgFilters = new() { "proxy", "direct", "block", "" }; - public static readonly List SingboxMuxs = new() { "h2mux", "smux", "yamux", "" }; - public static readonly List TuicCongestionControls = new() { "cubic", "new_reno", "bbr" }; + public static readonly List SsSecurities = + [ + "aes-256-gcm", + "aes-128-gcm", + "chacha20-poly1305", + "chacha20-ietf-poly1305", + "none", + "plain" + ]; - public static readonly List allowSelectType = new() { "selector", "urltest", "loadbalance", "fallback" }; - public static readonly List notAllowTestType = new() { "selector", "urltest", "direct", "reject", "compatible", "pass", "loadbalance", "fallback" }; - public static readonly List proxyVehicleType = new() { "file", "http" }; + public static readonly List SsSecuritiesInXray = + [ + "aes-256-gcm", + "aes-128-gcm", + "chacha20-poly1305", + "chacha20-ietf-poly1305", + "xchacha20-poly1305", + "xchacha20-ietf-poly1305", + "none", + "plain", + "2022-blake3-aes-128-gcm", + "2022-blake3-aes-256-gcm", + "2022-blake3-chacha20-poly1305" + ]; + + public static readonly List SsSecuritiesInSingbox = + [ + "aes-256-gcm", + "aes-192-gcm", + "aes-128-gcm", + "chacha20-ietf-poly1305", + "xchacha20-ietf-poly1305", + "none", + "2022-blake3-aes-128-gcm", + "2022-blake3-aes-256-gcm", + "2022-blake3-chacha20-poly1305", + "aes-128-ctr", + "aes-192-ctr", + "aes-256-ctr", + "aes-128-cfb", + "aes-192-cfb", + "aes-256-cfb", + "rc4-md5", + "chacha20-ietf", + "xchacha20" + ]; + + public static readonly List Flows = + [ + "", + "xtls-rprx-vision", + "xtls-rprx-vision-udp443" + ]; + + public static readonly List Networks = + [ + "tcp", + "kcp", + "ws", + "httpupgrade", + "xhttp", + "h2", + "quic", + "grpc" + ]; + + public static readonly List KcpHeaderTypes = + [ + "srtp", + "utp", + "wechat-video", + "dtls", + "wireguard" + ]; + + public static readonly List CoreTypes = + [ + "Xray", + "sing_box" + ]; + + public static readonly List DomainStrategies = + [ + "AsIs", + "IPIfNonMatch", + "IPOnDemand" + ]; + + public static readonly List DomainStrategies4Singbox = + [ + "ipv4_only", + "ipv6_only", + "prefer_ipv4", + "prefer_ipv6", + "" + ]; + + public static readonly List DomainMatchers = + [ + "linear", + "mph", + "" + ]; + + public static readonly List Fingerprints = + [ + "chrome", + "firefox", + "safari", + "ios", + "android", + "edge", + "360", + "qq", + "random", + "randomized", + "" + ]; + + public static readonly List UserAgent = + [ + "chrome", + "firefox", + "safari", + "edge", + "none" + ]; + + public static readonly List XhttpMode = + [ + "auto", + "packet-up", + "stream-up", + "stream-one" + ]; + + public static readonly List AllowInsecure = + [ + "true", + "false", + "" + ]; + + public static readonly List DomainStrategy4Freedoms = + [ + "AsIs", + "UseIP", + "UseIPv4", + "UseIPv6", + "" + ]; + + public static readonly List SingboxDomainStrategy4Out = + [ + "ipv4_only", + "prefer_ipv4", + "prefer_ipv6", + "ipv6_only", + "" + ]; + + public static readonly List DomainDNSAddress = + [ + "223.5.5.5", + "223.6.6.6", + "localhost" + ]; + + public static readonly List SingboxDomainDNSAddress = + [ + "223.5.5.5", + "223.6.6.6", + "dhcp://auto" + ]; + + public static readonly List Languages = + [ + "zh-Hans", + "zh-Hant", + "en", + "fa-Ir", + "ru", + "hu" + ]; + + public static readonly List Alpns = + [ + "h3", + "h2", + "http/1.1", + "h3,h2", + "h2,http/1.1", + "h3,h2,http/1.1", + "" + ]; + + public static readonly List LogLevels = + [ + "debug", + "info", + "warning", + "error", + "none" + ]; + + public static readonly List InboundTags = + [ + "socks", + "socks2", + "socks3" + ]; + + public static readonly List RuleProtocols = + [ + "http", + "tls", + "bittorrent" + ]; + + public static readonly List RuleNetworks = + [ + "", + "tcp", + "udp", + "tcp,udp" + ]; + + public static readonly List destOverrideProtocols = + [ + "http", + "tls", + "quic", + "fakedns", + "fakedns+others" + ]; + + public static readonly List TunMtus = + [ + "1280", + "1408", + "1500", + "9000" + ]; + + public static readonly List TunStacks = + [ + "gvisor", + "system", + "mixed" + ]; + + public static readonly List PresetMsgFilters = + [ + "proxy", + "direct", + "block", + "" + ]; + + public static readonly List SingboxMuxs = + [ + "h2mux", + "smux", + "yamux", + "" + ]; + + public static readonly List TuicCongestionControls = + [ + "cubic", + "new_reno", + "bbr" + ]; + + public static readonly List allowSelectType = + [ + "selector", + "urltest", + "loadbalance", + "fallback" + ]; + + public static readonly List notAllowTestType = + [ + "selector", + "urltest", + "direct", + "reject", + "compatible", + "pass", + "loadbalance", + "fallback" + ]; + + public static readonly List proxyVehicleType = + [ + "file", + "http" + ]; #endregion const } diff --git a/v2rayN/ServiceLib/Handler/AppHandler.cs b/v2rayN/ServiceLib/Handler/AppHandler.cs index 576916d6..a0d6e54f 100644 --- a/v2rayN/ServiceLib/Handler/AppHandler.cs +++ b/v2rayN/ServiceLib/Handler/AppHandler.cs @@ -48,7 +48,7 @@ { if (Utils.IsNonWindows() && Utils.HasWritePermission() == false) { - Environment.SetEnvironmentVariable("V2RAYN_LOCAL_APPLICATION_DATA", "1", EnvironmentVariableTarget.Process); + Environment.SetEnvironmentVariable(Global.LocalAppData, "1", EnvironmentVariableTarget.Process); } Logging.Setup(); diff --git a/v2rayN/ServiceLib/Handler/CoreHandler.cs b/v2rayN/ServiceLib/Handler/CoreHandler.cs index ddc890d8..fd8bed20 100644 --- a/v2rayN/ServiceLib/Handler/CoreHandler.cs +++ b/v2rayN/ServiceLib/Handler/CoreHandler.cs @@ -22,8 +22,8 @@ namespace ServiceLib.Handler _config = config; _updateFunc = updateFunc; - Environment.SetEnvironmentVariable("V2RAY_LOCATION_ASSET", Utils.GetBinPath(""), EnvironmentVariableTarget.Process); - Environment.SetEnvironmentVariable("XRAY_LOCATION_ASSET", Utils.GetBinPath(""), EnvironmentVariableTarget.Process); + Environment.SetEnvironmentVariable(Global.V2RayLocalAsset, Utils.GetBinPath(""), EnvironmentVariableTarget.Process); + Environment.SetEnvironmentVariable(Global.XrayLocalAsset, Utils.GetBinPath(""), EnvironmentVariableTarget.Process); if (Utils.IsNonWindows()) {