diff --git a/v2rayN/ServiceLib/Handler/Fmt/SingboxFmt.cs b/v2rayN/ServiceLib/Handler/Fmt/SingboxFmt.cs index 07098d2b..c730ce6c 100644 --- a/v2rayN/ServiceLib/Handler/Fmt/SingboxFmt.cs +++ b/v2rayN/ServiceLib/Handler/Fmt/SingboxFmt.cs @@ -5,51 +5,44 @@ namespace ServiceLib.Handler.Fmt public static List? ResolveFullArray(string strData, string? subRemarks) { var configObjects = JsonUtils.Deserialize(strData); - if (configObjects != null && configObjects.Length > 0) + if (configObjects is not { Length: > 0 }) { - List lstResult = []; - foreach (var configObject in configObjects) - { - var objectString = JsonUtils.Serialize(configObject); - var singboxCon = JsonUtils.Deserialize(objectString); - if (singboxCon?.inbounds?.Count > 0 - && singboxCon.outbounds?.Count > 0 - && singboxCon.route != null) - { - var fileName = WriteAllText(objectString); - - var profileIt = new ProfileItem - { - CoreType = ECoreType.sing_box, - Address = fileName, - Remarks = subRemarks ?? "singbox_custom", - }; - lstResult.Add(profileIt); - } - } - return lstResult; + return null; } - return null; + + List lstResult = []; + foreach (var configObject in configObjects) + { + var objectString = JsonUtils.Serialize(configObject); + var profileIt = ResolveFull(objectString, subRemarks); + if (profileIt != null) + { + lstResult.Add(profileIt); + } + } + return lstResult; } public static ProfileItem? ResolveFull(string strData, string? subRemarks) { - var singboxConfig = JsonUtils.Deserialize(strData); - if (singboxConfig?.inbounds?.Count > 0 - && singboxConfig.outbounds?.Count > 0 - && singboxConfig.route != null) + var config = JsonUtils.ParseJson(strData); + if (config?["inbounds"] == null + || config["outbounds"] == null + || config["route"] == null + || config["dns"] == null) { - var fileName = WriteAllText(strData); - var profileItem = new ProfileItem - { - CoreType = ECoreType.sing_box, - Address = fileName, - Remarks = subRemarks ?? "singbox_custom" - }; - - return profileItem; + return null; } - return null; + + var fileName = WriteAllText(strData); + var profileItem = new ProfileItem + { + CoreType = ECoreType.sing_box, + Address = fileName, + Remarks = subRemarks ?? "singbox_custom" + }; + + return profileItem; } } } diff --git a/v2rayN/ServiceLib/Handler/Fmt/V2rayFmt.cs b/v2rayN/ServiceLib/Handler/Fmt/V2rayFmt.cs index ee5c8512..9e4474b4 100644 --- a/v2rayN/ServiceLib/Handler/Fmt/V2rayFmt.cs +++ b/v2rayN/ServiceLib/Handler/Fmt/V2rayFmt.cs @@ -5,52 +5,45 @@ namespace ServiceLib.Handler.Fmt public static List? ResolveFullArray(string strData, string? subRemarks) { var configObjects = JsonUtils.Deserialize(strData); - if (configObjects != null && configObjects.Length > 0) + if (configObjects is not { Length: > 0 }) { - List lstResult = []; - foreach (var configObject in configObjects) - { - var objectString = JsonUtils.Serialize(configObject); - var v2rayCon = JsonUtils.Deserialize(objectString); - if (v2rayCon?.inbounds?.Count > 0 - && v2rayCon.outbounds?.Count > 0 - && v2rayCon.routing != null) - { - var fileName = WriteAllText(objectString); - - var profileIt = new ProfileItem - { - CoreType = ECoreType.Xray, - Address = fileName, - Remarks = v2rayCon.remarks ?? subRemarks ?? "v2ray_custom", - }; - lstResult.Add(profileIt); - } - } - return lstResult; + return null; } - return null; + + List lstResult = []; + foreach (var configObject in configObjects) + { + var objectString = JsonUtils.Serialize(configObject); + var profileIt = ResolveFull(objectString, subRemarks); + if (profileIt != null) + { + lstResult.Add(profileIt); + } + } + + return lstResult; } public static ProfileItem? ResolveFull(string strData, string? subRemarks) { - var v2rayConfig = JsonUtils.Deserialize(strData); - if (v2rayConfig?.inbounds?.Count > 0 - && v2rayConfig.outbounds?.Count > 0 - && v2rayConfig.routing != null) + var config = JsonUtils.ParseJson(strData); + if (config?["inbounds"] == null + || config["outbounds"] == null + || config["routing"] == null) { - var fileName = WriteAllText(strData); - - var profileItem = new ProfileItem - { - CoreType = ECoreType.Xray, - Address = fileName, - Remarks = v2rayConfig.remarks ?? subRemarks ?? "v2ray_custom" - }; - - return profileItem; + return null; } - return null; + + var fileName = WriteAllText(strData); + + var profileItem = new ProfileItem + { + CoreType = ECoreType.Xray, + Address = fileName, + Remarks = config?["remarks"]?.ToString() ?? subRemarks ?? "v2ray_custom" + }; + + return profileItem; } } }