From 3b826e3e368676a168948e6e7e61237a8c230f7c Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Wed, 21 Jan 2026 20:59:10 +0800 Subject: [PATCH] Refactor ProfileItem protocol extra handling --- v2rayN/ServiceLib/Handler/ConfigHandler.cs | 1 + v2rayN/ServiceLib/Models/ProfileItem.cs | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/v2rayN/ServiceLib/Handler/ConfigHandler.cs b/v2rayN/ServiceLib/Handler/ConfigHandler.cs index d010acba..d2cda968 100644 --- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs +++ b/v2rayN/ServiceLib/Handler/ConfigHandler.cs @@ -1102,6 +1102,7 @@ public static class ConfigHandler if (toFile) { + profileItem.SetProtocolExtra(); await SQLiteHelper.Instance.ReplaceAsync(profileItem); } return 0; diff --git a/v2rayN/ServiceLib/Models/ProfileItem.cs b/v2rayN/ServiceLib/Models/ProfileItem.cs index 5e060b0b..60cbe9b2 100644 --- a/v2rayN/ServiceLib/Models/ProfileItem.cs +++ b/v2rayN/ServiceLib/Models/ProfileItem.cs @@ -3,7 +3,7 @@ namespace ServiceLib.Models; [Serializable] public class ProfileItem : ReactiveObject { - private ProtocolExtraItem _protocolExtraItem = new(); + private ProtocolExtraItem? _protocolExtraCache; public ProfileItem() { @@ -129,12 +129,18 @@ public class ProfileItem : ReactiveObject public void SetProtocolExtra(ProtocolExtraItem extraItem) { - _protocolExtraItem = extraItem; + _protocolExtraCache = extraItem; + ProtoExtra = JsonUtils.Serialize(extraItem, false); + } + + public void SetProtocolExtra() + { + ProtoExtra = JsonUtils.Serialize(_protocolExtraCache, false); } public ProtocolExtraItem GetProtocolExtra() { - return _protocolExtraItem; + return _protocolExtraCache ??= JsonUtils.Deserialize(ProtoExtra) ?? new ProtocolExtraItem(); } #endregion function @@ -173,20 +179,20 @@ public class ProfileItem : ReactiveObject public string EchConfigList { get; set; } public string EchForceQuery { get; set; } - public string ProtoExtra - { - get => JsonUtils.Serialize(_protocolExtraItem, false); - set => _protocolExtraItem = JsonUtils.Deserialize(value); - } + public string ProtoExtra { get; set; } [Obsolete("Use ProtocolExtraItem.Ports instead.")] public string Ports { get; set; } + [Obsolete("Use ProtocolExtraItem.AlterId instead.")] public int AlterId { get; set; } + [Obsolete("Use ProtocolExtraItem.Flow instead.")] public string Flow { get; set; } + [Obsolete("Use ProfileItem.Password instead.")] public string Id { get; set; } + [Obsolete("Use ProtocolExtraItem.xxx instead.")] public string Security { get; set; } }