v2rayN/v2rayN/ServiceLib/Handler/Fmt/FmtHandler.cs

104 lines
3.5 KiB
C#
Raw Normal View History

namespace ServiceLib.Handler.Fmt;
public class FmtHandler
2024-06-04 01:48:04 +00:00
{
private static readonly string _tag = "FmtHandler";
2025-01-03 07:02:31 +00:00
public static string? GetShareUri(ProfileItem item)
{
try
2024-06-04 01:48:04 +00:00
{
var url = item.ConfigType switch
2024-06-04 01:48:04 +00:00
{
EConfigType.VMess => VmessFmt.ToUri(item),
EConfigType.Shadowsocks => ShadowsocksFmt.ToUri(item),
EConfigType.SOCKS => SocksFmt.ToUri(item),
EConfigType.Trojan => TrojanFmt.ToUri(item),
EConfigType.VLESS => VLESSFmt.ToUri(item),
EConfigType.Hysteria2 => Hysteria2Fmt.ToUri(item),
EConfigType.TUIC => TuicFmt.ToUri(item),
EConfigType.WireGuard => WireguardFmt.ToUri(item),
EConfigType.Anytls => AnytlsFmt.ToUri(item),
EConfigType.Naive => NaiveFmt.ToUri(item),
_ => null,
};
2024-06-04 01:48:04 +00:00
return url;
2024-06-04 01:48:04 +00:00
}
catch (Exception ex)
2024-06-04 01:48:04 +00:00
{
Logging.SaveLog(_tag, ex);
return string.Empty;
}
}
public static ProfileItem? ResolveConfig(string config, out string msg)
{
msg = ResUI.ConfigurationFormatIncorrect;
2024-06-04 01:48:04 +00:00
try
{
2025-10-31 12:25:45 +00:00
var str = config.TrimEx();
if (str.IsNullOrEmpty())
2024-06-04 01:48:04 +00:00
{
msg = ResUI.FailedReadConfiguration;
return null;
}
2024-06-04 01:48:04 +00:00
if (str.StartsWith(Global.ProtocolShares[EConfigType.VMess]))
{
return VmessFmt.Resolve(str, out msg);
2024-06-04 01:48:04 +00:00
}
else if (str.StartsWith(Global.ProtocolShares[EConfigType.Shadowsocks]))
2024-06-04 01:48:04 +00:00
{
return ShadowsocksFmt.Resolve(str, out msg);
}
else if (str.StartsWith(Global.ProtocolShares[EConfigType.SOCKS]))
{
return SocksFmt.Resolve(str, out msg);
}
else if (str.StartsWith(Global.ProtocolShares[EConfigType.Trojan]))
{
return TrojanFmt.Resolve(str, out msg);
}
else if (str.StartsWith(Global.ProtocolShares[EConfigType.VLESS]))
{
return VLESSFmt.Resolve(str, out msg);
}
else if (str.StartsWith(Global.ProtocolShares[EConfigType.Hysteria2]) || str.StartsWith(Global.Hysteria2ProtocolShare))
{
return Hysteria2Fmt.Resolve(str, out msg);
}
else if (str.StartsWith(Global.ProtocolShares[EConfigType.TUIC]))
{
return TuicFmt.Resolve(str, out msg);
}
else if (str.StartsWith(Global.ProtocolShares[EConfigType.WireGuard]))
{
return WireguardFmt.Resolve(str, out msg);
}
else if (str.StartsWith(Global.ProtocolShares[EConfigType.Anytls]))
{
return AnytlsFmt.Resolve(str, out msg);
}
else if (str.StartsWith(Global.ProtocolShares[EConfigType.Naive])
|| str.StartsWith(Global.NaiveHttpsProtocolShare)
|| str.StartsWith(Global.NaiveQuicProtocolShare))
{
return NaiveFmt.Resolve(str, out msg);
}
else
{
msg = ResUI.NonvmessOrssProtocol;
2024-06-04 01:48:04 +00:00
return null;
}
}
catch (Exception ex)
{
Logging.SaveLog(_tag, ex);
msg = ResUI.Incorrectconfiguration;
return null;
}
2024-06-04 01:48:04 +00:00
}
}