v2rayN/v2rayN/ServiceLib/Handler/Fmt/TrojanFmt.cs

48 lines
1.2 KiB
C#
Raw Normal View History

namespace ServiceLib.Handler.Fmt;
public class TrojanFmt : BaseFmt
2024-06-04 01:48:04 +00:00
{
public static ProfileItem? Resolve(string str, out string msg)
2024-06-04 01:48:04 +00:00
{
msg = ResUI.ConfigurationFormatIncorrect;
ProfileItem item = new()
2024-06-04 01:48:04 +00:00
{
ConfigType = EConfigType.Trojan
};
2024-06-04 01:48:04 +00:00
var url = Utils.TryUri(str);
if (url == null)
{
return null;
}
2024-10-24 09:56:39 +00:00
item.Address = url.IdnHost;
item.Port = url.Port;
item.Remarks = url.GetComponents(UriComponents.Fragment, UriFormat.Unescaped);
item.Id = Utils.UrlDecode(url.UserInfo);
2024-06-04 01:48:04 +00:00
var query = Utils.ParseQueryString(url.Query);
_ = ResolveStdTransport(query, ref item);
2024-06-04 01:48:04 +00:00
return item;
}
2024-06-04 01:48:04 +00:00
public static string? ToUri(ProfileItem? item)
{
if (item == null)
{
return null;
2024-06-04 01:48:04 +00:00
}
var remark = string.Empty;
if (item.Remarks.IsNotEmpty())
2024-06-04 01:48:04 +00:00
{
remark = "#" + Utils.UrlEncode(item.Remarks);
2024-06-04 01:48:04 +00:00
}
var dicQuery = new Dictionary<string, string>();
_ = GetStdTransport(item, null, ref dicQuery);
return ToUri(EConfigType.Trojan, item.Address, item.Port, item.Id, dicQuery, remark);
2024-06-04 01:48:04 +00:00
}
2025-01-30 09:10:05 +00:00
}