From 61635db5b5f4fd4c33f13d99d20728a51d4b200e Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Tue, 17 Sep 2024 16:52:41 +0800 Subject: [PATCH] Add IsNotEmpty function --- v2rayN/ServiceLib/Common/DownloaderHelper.cs | 2 +- v2rayN/ServiceLib/Common/FileManager.cs | 4 +- v2rayN/ServiceLib/Common/HttpClientHelper.cs | 2 +- v2rayN/ServiceLib/Common/Utils.cs | 5 +++ v2rayN/ServiceLib/Handler/ConfigHandler.cs | 22 +++++----- .../Handler/CoreConfig/CoreConfigClash.cs | 4 +- .../Handler/CoreConfig/CoreConfigSingbox.cs | 36 ++++++++-------- .../Handler/CoreConfig/CoreConfigV2ray.cs | 42 +++++++++---------- v2rayN/ServiceLib/Handler/CoreHandler.cs | 4 +- v2rayN/ServiceLib/Handler/DownloadHandler.cs | 8 ++-- v2rayN/ServiceLib/Handler/Fmt/BaseFmt.cs | 38 ++++++++--------- v2rayN/ServiceLib/Handler/Fmt/Hysteria2Fmt.cs | 8 ++-- .../ServiceLib/Handler/Fmt/ShadowsocksFmt.cs | 6 +-- v2rayN/ServiceLib/Handler/Fmt/SocksFmt.cs | 2 +- v2rayN/ServiceLib/Handler/Fmt/TrojanFmt.cs | 2 +- v2rayN/ServiceLib/Handler/Fmt/TuicFmt.cs | 6 +-- v2rayN/ServiceLib/Handler/Fmt/VLESSFmt.cs | 4 +- v2rayN/ServiceLib/Handler/Fmt/VmessFmt.cs | 6 +-- v2rayN/ServiceLib/Handler/Fmt/WireguardFmt.cs | 10 ++--- v2rayN/ServiceLib/Handler/LazyConfig.cs | 4 +- v2rayN/ServiceLib/Handler/ProfileExHandler.cs | 2 +- .../Handler/Statistics/StatisticsSingbox.cs | 2 +- v2rayN/ServiceLib/Handler/UpdateHandler.cs | 12 +++--- .../ViewModels/AddServer2ViewModel.cs | 2 +- .../ViewModels/ClashConnectionsViewModel.cs | 4 +- .../ViewModels/ClashProxiesViewModel.cs | 18 ++++---- .../ViewModels/DNSSettingViewModel.cs | 6 +-- v2rayN/ServiceLib/ViewModels/MsgViewModel.cs | 2 +- .../ViewModels/ProfilesViewModel.cs | 4 +- .../ViewModels/RoutingRuleDetailsViewModel.cs | 2 +- .../ViewModels/ThemeSettingViewModel.cs | 2 +- .../v2rayN/Converters/MaterialDesignFonts.cs | 2 +- .../ViewModels/ThemeSettingViewModel.cs | 2 +- 33 files changed, 140 insertions(+), 135 deletions(-) diff --git a/v2rayN/ServiceLib/Common/DownloaderHelper.cs b/v2rayN/ServiceLib/Common/DownloaderHelper.cs index ed5867c3ff..986912d750 100644 --- a/v2rayN/ServiceLib/Common/DownloaderHelper.cs +++ b/v2rayN/ServiceLib/Common/DownloaderHelper.cs @@ -18,7 +18,7 @@ public class DownloaderHelper Uri uri = new(url); //Authorization Header var headers = new WebHeaderCollection(); - if (!Utils.IsNullOrEmpty(uri.UserInfo)) + if (Utils.IsNotEmpty(uri.UserInfo)) { headers.Add(HttpRequestHeader.Authorization, "Basic " + Utils.Base64Encode(uri.UserInfo)); } diff --git a/v2rayN/ServiceLib/Common/FileManager.cs b/v2rayN/ServiceLib/Common/FileManager.cs index 014393a75b..4eb97a517e 100644 --- a/v2rayN/ServiceLib/Common/FileManager.cs +++ b/v2rayN/ServiceLib/Common/FileManager.cs @@ -82,7 +82,7 @@ public static bool ZipExtractToFile(string fileName, string toPath, string ignor } try { - if (!Utils.IsNullOrEmpty(ignoredName) && entry.Name.Contains(ignoredName)) + if (Utils.IsNotEmpty(ignoredName) && entry.Name.Contains(ignoredName)) { continue; } @@ -157,7 +157,7 @@ public static void CopyDirectory(string sourceDir, string destinationDir, bool r // Get the files in the source directory and copy to the destination directory foreach (FileInfo file in dir.GetFiles()) { - if (!Utils.IsNullOrEmpty(ignoredName) && file.Name.Contains(ignoredName)) + if (Utils.IsNotEmpty(ignoredName) && file.Name.Contains(ignoredName)) { continue; } diff --git a/v2rayN/ServiceLib/Common/HttpClientHelper.cs b/v2rayN/ServiceLib/Common/HttpClientHelper.cs index dd730dbff3..bd671feec1 100644 --- a/v2rayN/ServiceLib/Common/HttpClientHelper.cs +++ b/v2rayN/ServiceLib/Common/HttpClientHelper.cs @@ -22,7 +22,7 @@ public class HttpClientHelper public async Task TryGetAsync(string url) { - if (string.IsNullOrEmpty(url)) + if (Utils.IsNullOrEmpty(url)) return null; try diff --git a/v2rayN/ServiceLib/Common/Utils.cs b/v2rayN/ServiceLib/Common/Utils.cs index 9830213c69..8e2fb95636 100644 --- a/v2rayN/ServiceLib/Common/Utils.cs +++ b/v2rayN/ServiceLib/Common/Utils.cs @@ -417,6 +417,11 @@ public static bool IsNullOrEmpty(string? text) return false; } + public static bool IsNotEmpty(string? text) + { + return !string.IsNullOrEmpty(text); + } + /// /// 验证IP地址是否合法 /// diff --git a/v2rayN/ServiceLib/Handler/ConfigHandler.cs b/v2rayN/ServiceLib/Handler/ConfigHandler.cs index f949e5ce71..8e72799f9f 100644 --- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs +++ b/v2rayN/ServiceLib/Handler/ConfigHandler.cs @@ -23,7 +23,7 @@ public static int LoadConfig(ref Config? config) { //载入配置文件 var result = Utils.LoadResource(Utils.GetConfigPath(configRes)); - if (!Utils.IsNullOrEmpty(result)) + if (Utils.IsNotEmpty(result)) { //转成Json config = JsonUtils.Deserialize(result); @@ -1007,7 +1007,7 @@ public static int AddVlessServer(Config config, ProfileItem profileItem, bool to { return -1; } - if (!Utils.IsNullOrEmpty(profileItem.security) && profileItem.security != Global.None) + if (Utils.IsNotEmpty(profileItem.security) && profileItem.security != Global.None) { profileItem.security = Global.None; } @@ -1045,7 +1045,7 @@ public static int AddServerCommon(Config config, ProfileItem profileItem, bool t { profileItem.configVersion = 2; - if (!Utils.IsNullOrEmpty(profileItem.streamSecurity)) + if (Utils.IsNotEmpty(profileItem.streamSecurity)) { if (profileItem.streamSecurity != Global.StreamSecurity && profileItem.streamSecurity != Global.StreamSecurityReality) @@ -1065,7 +1065,7 @@ public static int AddServerCommon(Config config, ProfileItem profileItem, bool t } } - if (!Utils.IsNullOrEmpty(profileItem.network) && !Global.Networks.Contains(profileItem.network)) + if (Utils.IsNotEmpty(profileItem.network) && !Global.Networks.Contains(profileItem.network)) { profileItem.network = Global.DefaultNetwork; } @@ -1186,7 +1186,7 @@ private static int AddBatchServers(Config config, string strData, string subid, string subFilter = string.Empty; //remove sub items - if (isSub && !Utils.IsNullOrEmpty(subid)) + if (isSub && Utils.IsNotEmpty(subid)) { RemoveServerViaSubid(config, subid, isSub); subFilter = LazyConfig.Instance.GetSubItem(subid)?.filter ?? ""; @@ -1219,7 +1219,7 @@ private static int AddBatchServers(Config config, string strData, string subid, } //exist sub items - if (isSub && !Utils.IsNullOrEmpty(subid)) + if (isSub && Utils.IsNotEmpty(subid)) { var existItem = lstOriSub?.FirstOrDefault(t => t.isSub == isSub && config.uiItem.enableUpdateSubOnlyRemarksExist ? t.remarks == profileItem.remarks : CompareProfileItem(t, profileItem, true)); @@ -1241,7 +1241,7 @@ private static int AddBatchServers(Config config, string strData, string subid, } } //filter - if (!Utils.IsNullOrEmpty(subFilter)) + if (Utils.IsNotEmpty(subFilter)) { if (!Regex.IsMatch(profileItem.remarks, subFilter)) { @@ -1305,7 +1305,7 @@ private static int AddBatchServers4Custom(Config config, string strData, string } if (lstProfiles != null && lstProfiles.Count > 0) { - if (isSub && !Utils.IsNullOrEmpty(subid)) + if (isSub && Utils.IsNotEmpty(subid)) { RemoveServerViaSubid(config, subid, isSub); } @@ -1361,7 +1361,7 @@ private static int AddBatchServers4Custom(Config config, string strData, string return -1; } - if (isSub && !Utils.IsNullOrEmpty(subid)) + if (isSub && Utils.IsNotEmpty(subid)) { RemoveServerViaSubid(config, subid, isSub); } @@ -1389,7 +1389,7 @@ private static int AddBatchServers4SsSIP008(Config config, string strData, strin return -1; } - if (isSub && !Utils.IsNullOrEmpty(subid)) + if (isSub && Utils.IsNotEmpty(subid)) { RemoveServerViaSubid(config, subid, isSub); } @@ -1421,7 +1421,7 @@ public static int AddBatchServers(Config config, string strData, string subid, b return -1; } List? lstOriSub = null; - if (isSub && !Utils.IsNullOrEmpty(subid)) + if (isSub && Utils.IsNotEmpty(subid)) { lstOriSub = LazyConfig.Instance.ProfileItems(subid); } diff --git a/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigClash.cs b/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigClash.cs index 9e84f8efd5..95647599ad 100644 --- a/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigClash.cs +++ b/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigClash.cs @@ -43,7 +43,7 @@ public int GenerateClientCustomConfig(ProfileItem node, string? fileName, out st } string addressFileName = node.address; - if (string.IsNullOrEmpty(addressFileName)) + if (Utils.IsNullOrEmpty(addressFileName)) { msg = ResUI.FailedGetDefaultConfiguration; return -1; @@ -117,7 +117,7 @@ public int GenerateClientCustomConfig(ProfileItem node, string? fileName, out st if (_config.tunModeItem.enableTun) { string tun = Utils.GetEmbedText(Global.ClashTunYaml); - if (!string.IsNullOrEmpty(tun)) + if (Utils.IsNotEmpty(tun)) { var tunContent = YamlUtils.FromYaml>(tun); if (tunContent != null) diff --git a/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigSingbox.cs b/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigSingbox.cs index 86d835b666..69836040de 100644 --- a/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigSingbox.cs +++ b/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigSingbox.cs @@ -370,7 +370,7 @@ public int GenerateClientCustomConfig(ProfileItem node, string? fileName, out st } string addressFileName = node.address; - if (string.IsNullOrEmpty(addressFileName)) + if (Utils.IsNullOrEmpty(addressFileName)) { msg = ResUI.FailedGetDefaultConfiguration; return -1; @@ -489,7 +489,7 @@ private int GenInbounds(SingboxConfig singboxConfig) if (_config.routingBasicItem.enableRoutingAdvanced) { var routing = ConfigHandler.GetDefaultRouting(_config); - if (!Utils.IsNullOrEmpty(routing.domainStrategy4Singbox)) + if (Utils.IsNotEmpty(routing.domainStrategy4Singbox)) { inbound.domain_strategy = routing.domainStrategy4Singbox; } @@ -512,7 +512,7 @@ private int GenInbounds(SingboxConfig singboxConfig) singboxConfig.inbounds.Add(inbound4); //auth - if (!Utils.IsNullOrEmpty(_config.inbound[0].user) && !Utils.IsNullOrEmpty(_config.inbound[0].pass)) + if (Utils.IsNotEmpty(_config.inbound[0].user) && Utils.IsNotEmpty(_config.inbound[0].pass)) { inbound3.users = new() { new() { username = _config.inbound[0].user, password = _config.inbound[0].pass } }; inbound4.users = new() { new() { username = _config.inbound[0].user, password = _config.inbound[0].pass } }; @@ -604,8 +604,8 @@ private int GenOutbound(ProfileItem node, Outbound4Sbox outbound) case EConfigType.Socks: { outbound.version = "5"; - if (!Utils.IsNullOrEmpty(node.security) - && !Utils.IsNullOrEmpty(node.id)) + if (Utils.IsNotEmpty(node.security) + && Utils.IsNotEmpty(node.id)) { outbound.username = node.security; outbound.password = node.id; @@ -614,8 +614,8 @@ private int GenOutbound(ProfileItem node, Outbound4Sbox outbound) } case EConfigType.Http: { - if (!Utils.IsNullOrEmpty(node.security) - && !Utils.IsNullOrEmpty(node.id)) + if (Utils.IsNotEmpty(node.security) + && Utils.IsNotEmpty(node.id)) { outbound.username = node.security; outbound.password = node.id; @@ -649,7 +649,7 @@ private int GenOutbound(ProfileItem node, Outbound4Sbox outbound) { outbound.password = node.id; - if (!Utils.IsNullOrEmpty(node.path)) + if (Utils.IsNotEmpty(node.path)) { outbound.obfs = new() { @@ -695,7 +695,7 @@ private int GenOutboundMux(ProfileItem node, Outbound4Sbox outbound) { try { - if (_config.coreBasicItem.muxEnabled && !Utils.IsNullOrEmpty(_config.mux4SboxItem.protocol)) + if (_config.coreBasicItem.muxEnabled && Utils.IsNotEmpty(_config.mux4SboxItem.protocol)) { var mux = new Multiplex4Sbox() { @@ -721,11 +721,11 @@ private int GenOutboundTls(ProfileItem node, Outbound4Sbox outbound) if (node.streamSecurity == Global.StreamSecurityReality || node.streamSecurity == Global.StreamSecurity) { var server_name = string.Empty; - if (!Utils.IsNullOrEmpty(node.sni)) + if (Utils.IsNotEmpty(node.sni)) { server_name = node.sni; } - else if (!Utils.IsNullOrEmpty(node.requestHost)) + else if (Utils.IsNotEmpty(node.requestHost)) { server_name = Utils.String2List(node.requestHost)[0]; } @@ -736,7 +736,7 @@ private int GenOutboundTls(ProfileItem node, Outbound4Sbox outbound) insecure = Utils.ToBool(node.allowInsecure.IsNullOrEmpty() ? _config.coreBasicItem.defAllowInsecure.ToString().ToLower() : node.allowInsecure), alpn = node.GetAlpn(), }; - if (!Utils.IsNullOrEmpty(node.fingerprint)) + if (Utils.IsNotEmpty(node.fingerprint)) { tls.utls = new Utls4Sbox() { @@ -798,7 +798,7 @@ private int GenOutboundTransport(ProfileItem node, Outbound4Sbox outbound) case nameof(ETransport.ws): transport.type = nameof(ETransport.ws); transport.path = Utils.IsNullOrEmpty(node.path) ? null : node.path; - if (!Utils.IsNullOrEmpty(node.requestHost)) + if (Utils.IsNotEmpty(node.requestHost)) { transport.headers = new() { @@ -1020,7 +1020,7 @@ private int GenRoutingUserRule(RulesItem item, List rules) outbound = item.outboundTag, }; - if (!Utils.IsNullOrEmpty(item.port)) + if (Utils.IsNotEmpty(item.port)) { if (item.port.Contains("-")) { @@ -1031,7 +1031,7 @@ private int GenRoutingUserRule(RulesItem item, List rules) rule.port = new List { Utils.ToInt(item.port) }; } } - if (!Utils.IsNullOrEmpty(item.network)) + if (Utils.IsNotEmpty(item.network)) { rule.network = Utils.String2List(item.network); } @@ -1221,7 +1221,7 @@ private int GenDnsDomains(ProfileItem? node, SingboxConfig singboxConfig, DNSIte }); var lstDomain = singboxConfig.outbounds - .Where(t => !Utils.IsNullOrEmpty(t.server) && Utils.IsDomain(t.server)) + .Where(t => Utils.IsNotEmpty(t.server) && Utils.IsDomain(t.server)) .Select(t => t.server) .Distinct() .ToList(); @@ -1324,10 +1324,10 @@ static void AddRuleSets(List ruleSets, List? rule_set) if (_config.routingBasicItem.enableRoutingAdvanced) { var routing = ConfigHandler.GetDefaultRouting(_config); - if (!Utils.IsNullOrEmpty(routing.customRulesetPath4Singbox)) + if (Utils.IsNotEmpty(routing.customRulesetPath4Singbox)) { var result = Utils.LoadResource(routing.customRulesetPath4Singbox); - if (!Utils.IsNullOrEmpty(result)) + if (Utils.IsNotEmpty(result)) { customRulesets = (JsonUtils.Deserialize>(result) ?? []) .Where(t => t.tag != null) diff --git a/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigV2ray.cs b/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigV2ray.cs index e7239cb708..15e5bcc0e7 100644 --- a/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigV2ray.cs +++ b/v2rayN/ServiceLib/Handler/CoreConfig/CoreConfigV2ray.cs @@ -392,7 +392,7 @@ private int GenInbounds(V2rayConfig v2rayConfig) v2rayConfig.inbounds.Add(inbound4); //auth - if (!Utils.IsNullOrEmpty(_config.inbound[0].user) && !Utils.IsNullOrEmpty(_config.inbound[0].pass)) + if (Utils.IsNotEmpty(_config.inbound[0].user) && Utils.IsNotEmpty(_config.inbound[0].pass)) { inbound3.settings.auth = "password"; inbound3.settings.accounts = new List { new AccountsItem4Ray() { user = _config.inbound[0].user, pass = _config.inbound[0].pass } }; @@ -453,7 +453,7 @@ private int GenRouting(V2rayConfig v2rayConfig) var routing = ConfigHandler.GetDefaultRouting(_config); if (routing != null) { - if (!Utils.IsNullOrEmpty(routing.domainStrategy)) + if (Utils.IsNotEmpty(routing.domainStrategy)) { v2rayConfig.routing.domainStrategy = routing.domainStrategy; } @@ -550,7 +550,7 @@ private int GenRoutingUserRule(RulesItem4Ray? rule, V2rayConfig v2rayConfig) } if (!hasDomainIp) { - if (!Utils.IsNullOrEmpty(rule.port) + if (Utils.IsNotEmpty(rule.port) || rule.protocol?.Count > 0 || rule.inboundTag?.Count > 0 ) @@ -660,8 +660,8 @@ private int GenOutbound(ProfileItem node, Outbounds4Ray outbound) serversItem.method = null; serversItem.password = null; - if (!Utils.IsNullOrEmpty(node.security) - && !Utils.IsNullOrEmpty(node.id)) + if (Utils.IsNotEmpty(node.security) + && Utils.IsNotEmpty(node.id)) { SocksUsersItem4Ray socksUsersItem = new() { @@ -712,7 +712,7 @@ private int GenOutbound(ProfileItem node, Outbounds4Ray outbound) if (node.streamSecurity == Global.StreamSecurityReality || node.streamSecurity == Global.StreamSecurity) { - if (!Utils.IsNullOrEmpty(node.flow)) + if (Utils.IsNotEmpty(node.flow)) { usersItem.flow = node.flow; @@ -818,11 +818,11 @@ private int GenBoundStreamSettings(ProfileItem node, StreamSettings4Ray streamSe alpn = node.GetAlpn(), fingerprint = node.fingerprint.IsNullOrEmpty() ? _config.coreBasicItem.defFingerprint : node.fingerprint }; - if (!Utils.IsNullOrEmpty(sni)) + if (Utils.IsNotEmpty(sni)) { tlsSettings.serverName = sni; } - else if (!Utils.IsNullOrEmpty(host)) + else if (Utils.IsNotEmpty(host)) { tlsSettings.serverName = Utils.String2List(host)[0]; } @@ -867,7 +867,7 @@ private int GenBoundStreamSettings(ProfileItem node, StreamSettings4Ray streamSe { type = node.headerType }; - if (!Utils.IsNullOrEmpty(node.path)) + if (Utils.IsNotEmpty(node.path)) { kcpSettings.seed = node.path; } @@ -878,15 +878,15 @@ private int GenBoundStreamSettings(ProfileItem node, StreamSettings4Ray streamSe WsSettings4Ray wsSettings = new(); wsSettings.headers = new Headers4Ray(); string path = node.path; - if (!Utils.IsNullOrEmpty(host)) + if (Utils.IsNotEmpty(host)) { wsSettings.headers.Host = host; } - if (!Utils.IsNullOrEmpty(path)) + if (Utils.IsNotEmpty(path)) { wsSettings.path = path; } - if (!Utils.IsNullOrEmpty(useragent)) + if (Utils.IsNotEmpty(useragent)) { wsSettings.headers.UserAgent = useragent; } @@ -897,11 +897,11 @@ private int GenBoundStreamSettings(ProfileItem node, StreamSettings4Ray streamSe case nameof(ETransport.httpupgrade): HttpupgradeSettings4Ray httpupgradeSettings = new(); - if (!Utils.IsNullOrEmpty(node.path)) + if (Utils.IsNotEmpty(node.path)) { httpupgradeSettings.path = node.path; } - if (!Utils.IsNullOrEmpty(host)) + if (Utils.IsNotEmpty(host)) { httpupgradeSettings.host = host; } @@ -916,11 +916,11 @@ private int GenBoundStreamSettings(ProfileItem node, StreamSettings4Ray streamSe maxConcurrentUploads = 10 }; - if (!Utils.IsNullOrEmpty(node.path)) + if (Utils.IsNotEmpty(node.path)) { splithttpSettings.path = node.path; } - if (!Utils.IsNullOrEmpty(host)) + if (Utils.IsNotEmpty(host)) { splithttpSettings.host = host; } @@ -931,7 +931,7 @@ private int GenBoundStreamSettings(ProfileItem node, StreamSettings4Ray streamSe case nameof(ETransport.h2): HttpSettings4Ray httpSettings = new(); - if (!Utils.IsNullOrEmpty(host)) + if (Utils.IsNotEmpty(host)) { httpSettings.host = Utils.String2List(host); } @@ -954,7 +954,7 @@ private int GenBoundStreamSettings(ProfileItem node, StreamSettings4Ray streamSe streamSettings.quicSettings = quicsettings; if (node.streamSecurity == Global.StreamSecurity) { - if (!Utils.IsNullOrEmpty(sni)) + if (Utils.IsNotEmpty(sni)) { streamSettings.tlsSettings.serverName = sni; } @@ -1000,7 +1000,7 @@ private int GenBoundStreamSettings(ProfileItem node, StreamSettings4Ray streamSe request = request.Replace("$requestUserAgent$", $"\"{useragent}\""); //Path string pathHttp = @"/"; - if (!Utils.IsNullOrEmpty(node.path)) + if (Utils.IsNotEmpty(node.path)) { string[] arrPath = node.path.Split(','); pathHttp = string.Join("\",\"", arrPath); @@ -1033,7 +1033,7 @@ private int GenDns(ProfileItem? node, V2rayConfig v2rayConfig) } //Outbound Freedom domainStrategy - if (!Utils.IsNullOrEmpty(domainStrategy4Freedom)) + if (Utils.IsNotEmpty(domainStrategy4Freedom)) { var outbound = v2rayConfig.outbounds[1]; outbound.settings.domainStrategy = domainStrategy4Freedom; @@ -1157,7 +1157,7 @@ private int GenMoreOutbounds(ProfileItem node, V2rayConfig v2rayConfig) { //fragment proxy if (_config.coreBasicItem.enableFragment - && !Utils.IsNullOrEmpty(v2rayConfig.outbounds[0].streamSettings?.security)) + && Utils.IsNotEmpty(v2rayConfig.outbounds[0].streamSettings?.security)) { var fragmentOutbound = new Outbounds4Ray { diff --git a/v2rayN/ServiceLib/Handler/CoreHandler.cs b/v2rayN/ServiceLib/Handler/CoreHandler.cs index bb97d37599..d17b3cdbba 100644 --- a/v2rayN/ServiceLib/Handler/CoreHandler.cs +++ b/v2rayN/ServiceLib/Handler/CoreHandler.cs @@ -302,7 +302,7 @@ private void ShowMsg(bool notify, string msg) { proc.OutputDataReceived += (sender, e) => { - if (!Utils.IsNullOrEmpty(e.Data)) + if (Utils.IsNotEmpty(e.Data)) { string msg = e.Data + Environment.NewLine; ShowMsg(false, msg); @@ -310,7 +310,7 @@ private void ShowMsg(bool notify, string msg) }; proc.ErrorDataReceived += (sender, e) => { - if (!Utils.IsNullOrEmpty(e.Data)) + if (Utils.IsNotEmpty(e.Data)) { string msg = e.Data + Environment.NewLine; ShowMsg(false, msg); diff --git a/v2rayN/ServiceLib/Handler/DownloadHandler.cs b/v2rayN/ServiceLib/Handler/DownloadHandler.cs index d2811a4e80..c05b992874 100644 --- a/v2rayN/ServiceLib/Handler/DownloadHandler.cs +++ b/v2rayN/ServiceLib/Handler/DownloadHandler.cs @@ -117,7 +117,7 @@ await DownloaderHelper.Instance.DownloadFileAsync(webProxy, try { var result1 = await DownloadStringAsync(url, blProxy, userAgent); - if (!Utils.IsNullOrEmpty(result1)) + if (Utils.IsNotEmpty(result1)) { return result1; } @@ -135,7 +135,7 @@ await DownloaderHelper.Instance.DownloadFileAsync(webProxy, try { var result2 = await DownloadStringViaDownloader(url, blProxy, userAgent); - if (!Utils.IsNullOrEmpty(result2)) + if (Utils.IsNotEmpty(result2)) { return result2; } @@ -155,7 +155,7 @@ await DownloaderHelper.Instance.DownloadFileAsync(webProxy, using var wc = new WebClient(); wc.Proxy = GetWebProxy(blProxy); var result3 = await wc.DownloadStringTaskAsync(url); - if (!Utils.IsNullOrEmpty(result3)) + if (Utils.IsNotEmpty(result3)) { return result3; } @@ -197,7 +197,7 @@ await DownloaderHelper.Instance.DownloadFileAsync(webProxy, Uri uri = new(url); //Authorization Header - if (!Utils.IsNullOrEmpty(uri.UserInfo)) + if (Utils.IsNotEmpty(uri.UserInfo)) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Utils.Base64Encode(uri.UserInfo)); } diff --git a/v2rayN/ServiceLib/Handler/Fmt/BaseFmt.cs b/v2rayN/ServiceLib/Handler/Fmt/BaseFmt.cs index 5205067bab..3372cfc542 100644 --- a/v2rayN/ServiceLib/Handler/Fmt/BaseFmt.cs +++ b/v2rayN/ServiceLib/Handler/Fmt/BaseFmt.cs @@ -16,12 +16,12 @@ protected static string GetIpv6(string address) protected static int GetStdTransport(ProfileItem item, string? securityDef, ref Dictionary dicQuery) { - if (!Utils.IsNullOrEmpty(item.flow)) + if (Utils.IsNotEmpty(item.flow)) { dicQuery.Add("flow", item.flow); } - if (!Utils.IsNullOrEmpty(item.streamSecurity)) + if (Utils.IsNotEmpty(item.streamSecurity)) { dicQuery.Add("security", item.streamSecurity); } @@ -32,27 +32,27 @@ protected static int GetStdTransport(ProfileItem item, string? securityDef, ref dicQuery.Add("security", securityDef); } } - if (!Utils.IsNullOrEmpty(item.sni)) + if (Utils.IsNotEmpty(item.sni)) { dicQuery.Add("sni", item.sni); } - if (!Utils.IsNullOrEmpty(item.alpn)) + if (Utils.IsNotEmpty(item.alpn)) { dicQuery.Add("alpn", Utils.UrlEncode(item.alpn)); } - if (!Utils.IsNullOrEmpty(item.fingerprint)) + if (Utils.IsNotEmpty(item.fingerprint)) { dicQuery.Add("fp", Utils.UrlEncode(item.fingerprint)); } - if (!Utils.IsNullOrEmpty(item.publicKey)) + if (Utils.IsNotEmpty(item.publicKey)) { dicQuery.Add("pbk", Utils.UrlEncode(item.publicKey)); } - if (!Utils.IsNullOrEmpty(item.shortId)) + if (Utils.IsNotEmpty(item.shortId)) { dicQuery.Add("sid", Utils.UrlEncode(item.shortId)); } - if (!Utils.IsNullOrEmpty(item.spiderX)) + if (Utils.IsNotEmpty(item.spiderX)) { dicQuery.Add("spx", Utils.UrlEncode(item.spiderX)); } @@ -61,21 +61,21 @@ protected static int GetStdTransport(ProfileItem item, string? securityDef, ref dicQuery.Add("allowInsecure", "1"); } - dicQuery.Add("type", !Utils.IsNullOrEmpty(item.network) ? item.network : nameof(ETransport.tcp)); + dicQuery.Add("type", Utils.IsNotEmpty(item.network) ? item.network : nameof(ETransport.tcp)); switch (item.network) { case nameof(ETransport.tcp): - dicQuery.Add("headerType", !Utils.IsNullOrEmpty(item.headerType) ? item.headerType : Global.None); - if (!Utils.IsNullOrEmpty(item.requestHost)) + dicQuery.Add("headerType", Utils.IsNotEmpty(item.headerType) ? item.headerType : Global.None); + if (Utils.IsNotEmpty(item.requestHost)) { dicQuery.Add("host", Utils.UrlEncode(item.requestHost)); } break; case nameof(ETransport.kcp): - dicQuery.Add("headerType", !Utils.IsNullOrEmpty(item.headerType) ? item.headerType : Global.None); - if (!Utils.IsNullOrEmpty(item.path)) + dicQuery.Add("headerType", Utils.IsNotEmpty(item.headerType) ? item.headerType : Global.None); + if (Utils.IsNotEmpty(item.path)) { dicQuery.Add("seed", Utils.UrlEncode(item.path)); } @@ -84,11 +84,11 @@ protected static int GetStdTransport(ProfileItem item, string? securityDef, ref case nameof(ETransport.ws): case nameof(ETransport.httpupgrade): case nameof(ETransport.splithttp): - if (!Utils.IsNullOrEmpty(item.requestHost)) + if (Utils.IsNotEmpty(item.requestHost)) { dicQuery.Add("host", Utils.UrlEncode(item.requestHost)); } - if (!Utils.IsNullOrEmpty(item.path)) + if (Utils.IsNotEmpty(item.path)) { dicQuery.Add("path", Utils.UrlEncode(item.path)); } @@ -97,24 +97,24 @@ protected static int GetStdTransport(ProfileItem item, string? securityDef, ref case nameof(ETransport.http): case nameof(ETransport.h2): dicQuery["type"] = nameof(ETransport.http); - if (!Utils.IsNullOrEmpty(item.requestHost)) + if (Utils.IsNotEmpty(item.requestHost)) { dicQuery.Add("host", Utils.UrlEncode(item.requestHost)); } - if (!Utils.IsNullOrEmpty(item.path)) + if (Utils.IsNotEmpty(item.path)) { dicQuery.Add("path", Utils.UrlEncode(item.path)); } break; case nameof(ETransport.quic): - dicQuery.Add("headerType", !Utils.IsNullOrEmpty(item.headerType) ? item.headerType : Global.None); + dicQuery.Add("headerType", Utils.IsNotEmpty(item.headerType) ? item.headerType : Global.None); dicQuery.Add("quicSecurity", Utils.UrlEncode(item.requestHost)); dicQuery.Add("key", Utils.UrlEncode(item.path)); break; case nameof(ETransport.grpc): - if (!Utils.IsNullOrEmpty(item.path)) + if (Utils.IsNotEmpty(item.path)) { dicQuery.Add("authority", Utils.UrlEncode(item.requestHost)); dicQuery.Add("serviceName", Utils.UrlEncode(item.path)); diff --git a/v2rayN/ServiceLib/Handler/Fmt/Hysteria2Fmt.cs b/v2rayN/ServiceLib/Handler/Fmt/Hysteria2Fmt.cs index 145a907e80..5f877858ef 100644 --- a/v2rayN/ServiceLib/Handler/Fmt/Hysteria2Fmt.cs +++ b/v2rayN/ServiceLib/Handler/Fmt/Hysteria2Fmt.cs @@ -31,20 +31,20 @@ public class Hysteria2Fmt : BaseFmt string url = string.Empty; string remark = string.Empty; - if (!Utils.IsNullOrEmpty(item.remarks)) + if (Utils.IsNotEmpty(item.remarks)) { remark = "#" + Utils.UrlEncode(item.remarks); } var dicQuery = new Dictionary(); - if (!Utils.IsNullOrEmpty(item.sni)) + if (Utils.IsNotEmpty(item.sni)) { dicQuery.Add("sni", item.sni); } - if (!Utils.IsNullOrEmpty(item.alpn)) + if (Utils.IsNotEmpty(item.alpn)) { dicQuery.Add("alpn", Utils.UrlEncode(item.alpn)); } - if (!Utils.IsNullOrEmpty(item.path)) + if (Utils.IsNotEmpty(item.path)) { dicQuery.Add("obfs", "salamander"); dicQuery.Add("obfs-password", Utils.UrlEncode(item.path)); diff --git a/v2rayN/ServiceLib/Handler/Fmt/ShadowsocksFmt.cs b/v2rayN/ServiceLib/Handler/Fmt/ShadowsocksFmt.cs index 98460640c0..93c387f674 100644 --- a/v2rayN/ServiceLib/Handler/Fmt/ShadowsocksFmt.cs +++ b/v2rayN/ServiceLib/Handler/Fmt/ShadowsocksFmt.cs @@ -30,7 +30,7 @@ public class ShadowsocksFmt : BaseFmt string url = string.Empty; string remark = string.Empty; - if (!Utils.IsNullOrEmpty(item.remarks)) + if (Utils.IsNotEmpty(item.remarks)) { remark = "#" + Utils.UrlEncode(item.remarks); } @@ -59,7 +59,7 @@ public class ShadowsocksFmt : BaseFmt ProfileItem item = new(); var base64 = match.Groups["base64"].Value.TrimEnd('/'); var tag = match.Groups["tag"].Value; - if (!Utils.IsNullOrEmpty(tag)) + if (Utils.IsNotEmpty(tag)) { item.remarks = Utils.UrlDecode(tag); } @@ -128,7 +128,7 @@ public class ShadowsocksFmt : BaseFmt { //obfs-host exists var obfsHost = queryParameters["plugin"]?.Split(';').FirstOrDefault(t => t.Contains("obfs-host")); - if (queryParameters["plugin"].Contains("obfs=http") && !Utils.IsNullOrEmpty(obfsHost)) + if (queryParameters["plugin"].Contains("obfs=http") && Utils.IsNotEmpty(obfsHost)) { obfsHost = obfsHost?.Replace("obfs-host=", ""); item.network = Global.DefaultNetwork; diff --git a/v2rayN/ServiceLib/Handler/Fmt/SocksFmt.cs b/v2rayN/ServiceLib/Handler/Fmt/SocksFmt.cs index de5ef5c866..aab73da9c3 100644 --- a/v2rayN/ServiceLib/Handler/Fmt/SocksFmt.cs +++ b/v2rayN/ServiceLib/Handler/Fmt/SocksFmt.cs @@ -28,7 +28,7 @@ public class SocksFmt : BaseFmt string url = string.Empty; string remark = string.Empty; - if (!Utils.IsNullOrEmpty(item.remarks)) + if (Utils.IsNotEmpty(item.remarks)) { remark = "#" + Utils.UrlEncode(item.remarks); } diff --git a/v2rayN/ServiceLib/Handler/Fmt/TrojanFmt.cs b/v2rayN/ServiceLib/Handler/Fmt/TrojanFmt.cs index d32e1f56b4..51f08524ac 100644 --- a/v2rayN/ServiceLib/Handler/Fmt/TrojanFmt.cs +++ b/v2rayN/ServiceLib/Handler/Fmt/TrojanFmt.cs @@ -30,7 +30,7 @@ public class TrojanFmt : BaseFmt string url = string.Empty; string remark = string.Empty; - if (!Utils.IsNullOrEmpty(item.remarks)) + if (Utils.IsNotEmpty(item.remarks)) { remark = "#" + Utils.UrlEncode(item.remarks); } diff --git a/v2rayN/ServiceLib/Handler/Fmt/TuicFmt.cs b/v2rayN/ServiceLib/Handler/Fmt/TuicFmt.cs index 2f473681f5..02268e6e66 100644 --- a/v2rayN/ServiceLib/Handler/Fmt/TuicFmt.cs +++ b/v2rayN/ServiceLib/Handler/Fmt/TuicFmt.cs @@ -36,16 +36,16 @@ public class TuicFmt : BaseFmt string url = string.Empty; string remark = string.Empty; - if (!Utils.IsNullOrEmpty(item.remarks)) + if (Utils.IsNotEmpty(item.remarks)) { remark = "#" + Utils.UrlEncode(item.remarks); } var dicQuery = new Dictionary(); - if (!Utils.IsNullOrEmpty(item.sni)) + if (Utils.IsNotEmpty(item.sni)) { dicQuery.Add("sni", item.sni); } - if (!Utils.IsNullOrEmpty(item.alpn)) + if (Utils.IsNotEmpty(item.alpn)) { dicQuery.Add("alpn", Utils.UrlEncode(item.alpn)); } diff --git a/v2rayN/ServiceLib/Handler/Fmt/VLESSFmt.cs b/v2rayN/ServiceLib/Handler/Fmt/VLESSFmt.cs index f4d3b570b4..fdcc34d33c 100644 --- a/v2rayN/ServiceLib/Handler/Fmt/VLESSFmt.cs +++ b/v2rayN/ServiceLib/Handler/Fmt/VLESSFmt.cs @@ -33,12 +33,12 @@ public class VLESSFmt : BaseFmt string url = string.Empty; string remark = string.Empty; - if (!Utils.IsNullOrEmpty(item.remarks)) + if (Utils.IsNotEmpty(item.remarks)) { remark = "#" + Utils.UrlEncode(item.remarks); } var dicQuery = new Dictionary(); - if (!Utils.IsNullOrEmpty(item.security)) + if (Utils.IsNotEmpty(item.security)) { dicQuery.Add("encryption", item.security); } diff --git a/v2rayN/ServiceLib/Handler/Fmt/VmessFmt.cs b/v2rayN/ServiceLib/Handler/Fmt/VmessFmt.cs index 340ec04c27..698b4804d3 100644 --- a/v2rayN/ServiceLib/Handler/Fmt/VmessFmt.cs +++ b/v2rayN/ServiceLib/Handler/Fmt/VmessFmt.cs @@ -78,12 +78,12 @@ public class VmessFmt : BaseFmt item.alterId = Utils.ToInt(vmessQRCode.aid); item.security = Utils.ToString(vmessQRCode.scy); - item.security = !Utils.IsNullOrEmpty(vmessQRCode.scy) ? vmessQRCode.scy : Global.DefaultSecurity; - if (!Utils.IsNullOrEmpty(vmessQRCode.net)) + item.security = Utils.IsNotEmpty(vmessQRCode.scy) ? vmessQRCode.scy : Global.DefaultSecurity; + if (Utils.IsNotEmpty(vmessQRCode.net)) { item.network = vmessQRCode.net; } - if (!Utils.IsNullOrEmpty(vmessQRCode.type)) + if (Utils.IsNotEmpty(vmessQRCode.type)) { item.headerType = vmessQRCode.type; } diff --git a/v2rayN/ServiceLib/Handler/Fmt/WireguardFmt.cs b/v2rayN/ServiceLib/Handler/Fmt/WireguardFmt.cs index 571a38ab45..aaac166c45 100644 --- a/v2rayN/ServiceLib/Handler/Fmt/WireguardFmt.cs +++ b/v2rayN/ServiceLib/Handler/Fmt/WireguardFmt.cs @@ -34,25 +34,25 @@ public class WireguardFmt : BaseFmt string url = string.Empty; string remark = string.Empty; - if (!Utils.IsNullOrEmpty(item.remarks)) + if (Utils.IsNotEmpty(item.remarks)) { remark = "#" + Utils.UrlEncode(item.remarks); } var dicQuery = new Dictionary(); - if (!Utils.IsNullOrEmpty(item.publicKey)) + if (Utils.IsNotEmpty(item.publicKey)) { dicQuery.Add("publickey", Utils.UrlEncode(item.publicKey)); } - if (!Utils.IsNullOrEmpty(item.path)) + if (Utils.IsNotEmpty(item.path)) { dicQuery.Add("reserved", Utils.UrlEncode(item.path)); } - if (!Utils.IsNullOrEmpty(item.requestHost)) + if (Utils.IsNotEmpty(item.requestHost)) { dicQuery.Add("address", Utils.UrlEncode(item.requestHost)); } - if (!Utils.IsNullOrEmpty(item.shortId)) + if (Utils.IsNotEmpty(item.shortId)) { dicQuery.Add("mtu", Utils.UrlEncode(item.shortId)); } diff --git a/v2rayN/ServiceLib/Handler/LazyConfig.cs b/v2rayN/ServiceLib/Handler/LazyConfig.cs index 55b7be8893..4830ba92b0 100644 --- a/v2rayN/ServiceLib/Handler/LazyConfig.cs +++ b/v2rayN/ServiceLib/Handler/LazyConfig.cs @@ -104,11 +104,11 @@ public List ProfileItems(string subid, string filter) from ProfileItem a left join SubItem b on a.subid = b.id where 1=1 "; - if (!Utils.IsNullOrEmpty(subid)) + if (Utils.IsNotEmpty(subid)) { sql += $" and a.subid = '{subid}'"; } - if (!Utils.IsNullOrEmpty(filter)) + if (Utils.IsNotEmpty(filter)) { if (filter.Contains('\'')) { diff --git a/v2rayN/ServiceLib/Handler/ProfileExHandler.cs b/v2rayN/ServiceLib/Handler/ProfileExHandler.cs index 460692af95..adc4e3d425 100644 --- a/v2rayN/ServiceLib/Handler/ProfileExHandler.cs +++ b/v2rayN/ServiceLib/Handler/ProfileExHandler.cs @@ -35,7 +35,7 @@ private void Init() private void IndexIdEnqueue(string indexId) { - if (!Utils.IsNullOrEmpty(indexId) && !_queIndexIds.Contains(indexId)) + if (Utils.IsNotEmpty(indexId) && !_queIndexIds.Contains(indexId)) { _queIndexIds.Enqueue(indexId); } diff --git a/v2rayN/ServiceLib/Handler/Statistics/StatisticsSingbox.cs b/v2rayN/ServiceLib/Handler/Statistics/StatisticsSingbox.cs index b4627cafec..b26fd6b13f 100644 --- a/v2rayN/ServiceLib/Handler/Statistics/StatisticsSingbox.cs +++ b/v2rayN/ServiceLib/Handler/Statistics/StatisticsSingbox.cs @@ -88,7 +88,7 @@ private async void Run() while (!res.CloseStatus.HasValue) { var result = Encoding.UTF8.GetString(buffer, 0, res.Count); - if (!Utils.IsNullOrEmpty(result)) + if (Utils.IsNotEmpty(result)) { ParseOutput(result, out ulong up, out ulong down); diff --git a/v2rayN/ServiceLib/Handler/UpdateHandler.cs b/v2rayN/ServiceLib/Handler/UpdateHandler.cs index 11e7787457..dc097966dc 100644 --- a/v2rayN/ServiceLib/Handler/UpdateHandler.cs +++ b/v2rayN/ServiceLib/Handler/UpdateHandler.cs @@ -143,7 +143,7 @@ public void UpdateSubscriptionProcess(Config config, string subId, bool blProxy, string url = item.url.TrimEx(); string userAgent = item.userAgent.TrimEx(); string hashCode = $"{item.remarks}->"; - if (Utils.IsNullOrEmpty(id) || Utils.IsNullOrEmpty(url) || (!Utils.IsNullOrEmpty(subId) && item.id != subId)) + if (Utils.IsNullOrEmpty(id) || Utils.IsNullOrEmpty(url) || (Utils.IsNotEmpty(subId) && item.id != subId)) { //_updateFunc(false, $"{hashCode}{ResUI.MsgNoValidSubscription}"); continue; @@ -169,7 +169,7 @@ public void UpdateSubscriptionProcess(Config config, string subId, bool blProxy, //one url url = Utils.GetPunycode(url); //convert - if (!Utils.IsNullOrEmpty(item.convertTarget)) + if (Utils.IsNotEmpty(item.convertTarget)) { var subConvertUrl = Utils.IsNullOrEmpty(config.constItem.subConvertUrl) ? Global.SubConvertUrls.FirstOrDefault() : config.constItem.subConvertUrl; url = string.Format(subConvertUrl!, Utils.UrlEncode(url)); @@ -189,9 +189,9 @@ public void UpdateSubscriptionProcess(Config config, string subId, bool blProxy, } //more url - if (Utils.IsNullOrEmpty(item.convertTarget) && !Utils.IsNullOrEmpty(item.moreUrl.TrimEx())) + if (Utils.IsNullOrEmpty(item.convertTarget) && Utils.IsNotEmpty(item.moreUrl.TrimEx())) { - if (!Utils.IsNullOrEmpty(result) && Utils.IsBase64String(result!)) + if (Utils.IsNotEmpty(result) && Utils.IsBase64String(result!)) { result = Utils.Base64Decode(result); } @@ -210,7 +210,7 @@ public void UpdateSubscriptionProcess(Config config, string subId, bool blProxy, { result2 = await downloadHandle.TryDownloadString(url2, false, userAgent); } - if (!Utils.IsNullOrEmpty(result2)) + if (Utils.IsNotEmpty(result2)) { if (Utils.IsBase64String(result2!)) { @@ -277,7 +277,7 @@ private async Task CheckUpdateAsync(DownloadHandler downloadHan var url = coreInfo?.coreReleaseApiUrl; var result = await downloadHandle.DownloadStringAsync(url, true, Global.AppName); - if (!Utils.IsNullOrEmpty(result)) + if (Utils.IsNotEmpty(result)) { return await ParseDownloadUrl(type, result, preRelease); } diff --git a/v2rayN/ServiceLib/ViewModels/AddServer2ViewModel.cs b/v2rayN/ServiceLib/ViewModels/AddServer2ViewModel.cs index f2911c9a09..5f198da7c2 100644 --- a/v2rayN/ServiceLib/ViewModels/AddServer2ViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/AddServer2ViewModel.cs @@ -90,7 +90,7 @@ public void BrowseServer(string fileName) if (ConfigHandler.AddCustomServer(_config, item, false) == 0) { _noticeHandler?.Enqueue(ResUI.SuccessfullyImportedCustomServer); - if (!Utils.IsNullOrEmpty(item.indexId)) + if (Utils.IsNotEmpty(item.indexId)) { SelectedSource = JsonUtils.DeepCopy(item); } diff --git a/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs b/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs index 290a4e2e30..d621e4aa33 100644 --- a/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs @@ -37,7 +37,7 @@ public ClashConnectionsViewModel(Func>? updateV var canEditRemove = this.WhenAnyValue( x => x.SelectedSource, - selectedSource => selectedSource != null && !string.IsNullOrEmpty(selectedSource.id)); + selectedSource => selectedSource != null && Utils.IsNotEmpty(selectedSource.id)); this.WhenAnyValue( x => x.SortingSelected, @@ -121,7 +121,7 @@ public void RefreshConnections(List? connections) var lstModel = new List(); foreach (var item in connections ?? []) { - var host = $"{(string.IsNullOrEmpty(item.metadata.host) ? item.metadata.destinationIP : item.metadata.host)}:{item.metadata.destinationPort}"; + var host = $"{(Utils.IsNullOrEmpty(item.metadata.host) ? item.metadata.destinationIP : item.metadata.host)}:{item.metadata.destinationPort}"; if (HostFilter.IsNotEmpty() && !host.Contains(HostFilter)) { continue; diff --git a/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs index 2992c3a66d..ff8cdd60a1 100644 --- a/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs @@ -57,7 +57,7 @@ public ClashProxiesViewModel(Func>? updateView) this.WhenAnyValue( x => x.SelectedGroup, - y => y != null && !string.IsNullOrEmpty(y.name)) + y => y != null && Utils.IsNotEmpty(y.name)) .Subscribe(c => RefreshProxyDetails(c)); this.WhenAnyValue( @@ -194,7 +194,7 @@ public void RefreshProxyGroups() { foreach (var it in proxyGroups) { - if (string.IsNullOrEmpty(it.name) || !_proxies.ContainsKey(it.name)) + if (Utils.IsNullOrEmpty(it.name) || !_proxies.ContainsKey(it.name)) { continue; } @@ -220,7 +220,7 @@ public void RefreshProxyGroups() continue; } var item = _proxyGroups.Where(t => t.name == kv.Key).FirstOrDefault(); - if (item != null && !string.IsNullOrEmpty(item.name)) + if (item != null && Utils.IsNotEmpty(item.name)) { continue; } @@ -257,7 +257,7 @@ private void RefreshProxyDetails(bool c) return; } var name = SelectedGroup?.name; - if (string.IsNullOrEmpty(name)) + if (Utils.IsNullOrEmpty(name)) { return; } @@ -342,21 +342,21 @@ private void RefreshProxyDetails(bool c) public void SetActiveProxy() { - if (SelectedGroup == null || string.IsNullOrEmpty(SelectedGroup.name)) + if (SelectedGroup == null || Utils.IsNullOrEmpty(SelectedGroup.name)) { return; } - if (SelectedDetail == null || string.IsNullOrEmpty(SelectedDetail.name)) + if (SelectedDetail == null || Utils.IsNullOrEmpty(SelectedDetail.name)) { return; } var name = SelectedGroup.name; - if (string.IsNullOrEmpty(name)) + if (Utils.IsNullOrEmpty(name)) { return; } var nameNode = SelectedDetail.name; - if (string.IsNullOrEmpty(nameNode)) + if (Utils.IsNullOrEmpty(nameNode)) { return; } @@ -393,7 +393,7 @@ private void ProxiesDelayTest(bool blAll) GetClashProxies(true); return; } - if (string.IsNullOrEmpty(result)) + if (Utils.IsNullOrEmpty(result)) { return; } diff --git a/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs index b5bbb399d3..3541ff043c 100644 --- a/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs @@ -58,7 +58,7 @@ public DNSSettingViewModel(Func>? updateView) private async Task SaveSettingAsync() { - if (!Utils.IsNullOrEmpty(normalDNS)) + if (Utils.IsNotEmpty(normalDNS)) { var obj = JsonUtils.ParseJson(normalDNS); if (obj != null && obj["servers"] != null) @@ -73,7 +73,7 @@ private async Task SaveSettingAsync() } } } - if (!Utils.IsNullOrEmpty(normalDNS2)) + if (Utils.IsNotEmpty(normalDNS2)) { var obj2 = JsonUtils.Deserialize(normalDNS2); if (obj2 == null) @@ -82,7 +82,7 @@ private async Task SaveSettingAsync() return; } } - if (!Utils.IsNullOrEmpty(tunDNS2)) + if (Utils.IsNotEmpty(tunDNS2)) { var obj2 = JsonUtils.Deserialize(tunDNS2); if (obj2 == null) diff --git a/v2rayN/ServiceLib/ViewModels/MsgViewModel.cs b/v2rayN/ServiceLib/ViewModels/MsgViewModel.cs index c2d9f1cd54..0f924c36c1 100644 --- a/v2rayN/ServiceLib/ViewModels/MsgViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/MsgViewModel.cs @@ -76,7 +76,7 @@ private async Task EnqueueQueueMsg(string msg) { //filter msg if (MsgFilter != _lastMsgFilter) _lastMsgFilterNotAvailable = false; - if (!Utils.IsNullOrEmpty(MsgFilter) && !_lastMsgFilterNotAvailable) + if (Utils.IsNotEmpty(MsgFilter) && !_lastMsgFilterNotAvailable) { try { diff --git a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs index 14e79a9b03..dca473fa58 100644 --- a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs @@ -265,13 +265,13 @@ public void SetSpeedTestResult(SpeedTestResult result) var item = _profileItems.Where(it => it.indexId == result.IndexId).FirstOrDefault(); if (item != null) { - if (!Utils.IsNullOrEmpty(result.Delay)) + if (Utils.IsNotEmpty(result.Delay)) { int.TryParse(result.Delay, out int temp); item.delay = temp; item.delayVal = $"{result.Delay} {Global.DelayUnit}"; } - if (!Utils.IsNullOrEmpty(result.Speed)) + if (Utils.IsNotEmpty(result.Speed)) { item.speedVal = $"{result.Speed} {Global.SpeedUnit}"; } diff --git a/v2rayN/ServiceLib/ViewModels/RoutingRuleDetailsViewModel.cs b/v2rayN/ServiceLib/ViewModels/RoutingRuleDetailsViewModel.cs index 8acfc234dc..4c9f03db25 100644 --- a/v2rayN/ServiceLib/ViewModels/RoutingRuleDetailsViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/RoutingRuleDetailsViewModel.cs @@ -80,7 +80,7 @@ private async Task SaveRulesAsync() || SelectedSource.ip?.Count > 0 || SelectedSource.protocol?.Count > 0 || SelectedSource.process?.Count > 0 - || !Utils.IsNullOrEmpty(SelectedSource.port); + || Utils.IsNotEmpty(SelectedSource.port); if (!hasRule) { diff --git a/v2rayN/v2rayN.Desktop/ViewModels/ThemeSettingViewModel.cs b/v2rayN/v2rayN.Desktop/ViewModels/ThemeSettingViewModel.cs index 0794c1b9db..86b0529298 100644 --- a/v2rayN/v2rayN.Desktop/ViewModels/ThemeSettingViewModel.cs +++ b/v2rayN/v2rayN.Desktop/ViewModels/ThemeSettingViewModel.cs @@ -70,7 +70,7 @@ private void BindingUI() y => y != null && !y.IsNullOrEmpty()) .Subscribe(c => { - if (!Utils.IsNullOrEmpty(CurrentLanguage) && _config.uiItem.currentLanguage != CurrentLanguage) + if (Utils.IsNotEmpty(CurrentLanguage) && _config.uiItem.currentLanguage != CurrentLanguage) { _config.uiItem.currentLanguage = CurrentLanguage; Thread.CurrentThread.CurrentUICulture = new(CurrentLanguage); diff --git a/v2rayN/v2rayN/Converters/MaterialDesignFonts.cs b/v2rayN/v2rayN/Converters/MaterialDesignFonts.cs index 37d17f820d..0be5bade53 100644 --- a/v2rayN/v2rayN/Converters/MaterialDesignFonts.cs +++ b/v2rayN/v2rayN/Converters/MaterialDesignFonts.cs @@ -11,7 +11,7 @@ static MaterialDesignFonts() try { var fontFamily = LazyConfig.Instance.Config.uiItem.currentFontFamily; - if (!Utils.IsNullOrEmpty(fontFamily)) + if (Utils.IsNotEmpty(fontFamily)) { var fontPath = Utils.GetFontsPath(); MyFont = new FontFamily(new Uri(@$"file:///{fontPath}\"), $"./#{fontFamily}"); diff --git a/v2rayN/v2rayN/ViewModels/ThemeSettingViewModel.cs b/v2rayN/v2rayN/ViewModels/ThemeSettingViewModel.cs index abdd473664..f64b416ffc 100644 --- a/v2rayN/v2rayN/ViewModels/ThemeSettingViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/ThemeSettingViewModel.cs @@ -156,7 +156,7 @@ private void BindingUI() y => y != null && !y.IsNullOrEmpty()) .Subscribe(c => { - if (!Utils.IsNullOrEmpty(CurrentLanguage) && _config.uiItem.currentLanguage != CurrentLanguage) + if (Utils.IsNotEmpty(CurrentLanguage) && _config.uiItem.currentLanguage != CurrentLanguage) { _config.uiItem.currentLanguage = CurrentLanguage; Thread.CurrentThread.CurrentUICulture = new(CurrentLanguage);