mirror of https://github.com/2dust/v2rayN
Update subscription is to keep the same item
parent
03ad07733f
commit
734df5def5
|
@ -176,7 +176,7 @@ namespace v2rayN.Handler
|
||||||
VmessItem vmessItem = config.vmess[i];
|
VmessItem vmessItem = config.vmess[i];
|
||||||
UpgradeServerVersion(ref vmessItem);
|
UpgradeServerVersion(ref vmessItem);
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(vmessItem.indexId))
|
if (Utils.IsNullOrEmpty(vmessItem.indexId))
|
||||||
{
|
{
|
||||||
vmessItem.indexId = Utils.GetGUID(false);
|
vmessItem.indexId = Utils.GetGUID(false);
|
||||||
}
|
}
|
||||||
|
@ -724,6 +724,14 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//copy sub items
|
||||||
|
List<VmessItem> lstOriSub = null;
|
||||||
|
if (!Utils.IsNullOrEmpty(subid))
|
||||||
|
{
|
||||||
|
lstOriSub = config.vmess.Where(it => it.subid == subid).ToList();
|
||||||
|
RemoveServerViaSubid(ref config, subid);
|
||||||
|
}
|
||||||
//if (clipboardData.IndexOf("vmess") >= 0 && clipboardData.IndexOf("vmess") == clipboardData.LastIndexOf("vmess"))
|
//if (clipboardData.IndexOf("vmess") >= 0 && clipboardData.IndexOf("vmess") == clipboardData.LastIndexOf("vmess"))
|
||||||
//{
|
//{
|
||||||
// clipboardData = clipboardData.Replace("\r\n", "").Replace("\n", "");
|
// clipboardData = clipboardData.Replace("\r\n", "").Replace("\n", "");
|
||||||
|
@ -735,7 +743,7 @@ namespace v2rayN.Handler
|
||||||
foreach (string str in arrData)
|
foreach (string str in arrData)
|
||||||
{
|
{
|
||||||
//maybe sub
|
//maybe sub
|
||||||
if (string.IsNullOrEmpty(subid) && (str.StartsWith(Global.httpsProtocol) || str.StartsWith(Global.httpProtocol)))
|
if (Utils.IsNullOrEmpty(subid) && (str.StartsWith(Global.httpsProtocol) || str.StartsWith(Global.httpProtocol)))
|
||||||
{
|
{
|
||||||
if (AddSubItem(ref config, str) == 0)
|
if (AddSubItem(ref config, str) == 0)
|
||||||
{
|
{
|
||||||
|
@ -748,7 +756,18 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
vmessItem.subid = subid;
|
|
||||||
|
//exist sub items
|
||||||
|
if (!Utils.IsNullOrEmpty(subid))
|
||||||
|
{
|
||||||
|
var existItem = lstOriSub?.FirstOrDefault(t => CompareVmessItem(t, vmessItem, true));
|
||||||
|
if (existItem != null)
|
||||||
|
{
|
||||||
|
vmessItem = existItem;
|
||||||
|
}
|
||||||
|
vmessItem.subid = subid;
|
||||||
|
}
|
||||||
|
|
||||||
if (vmessItem.configType == (int)EConfigType.Vmess)
|
if (vmessItem.configType == (int)EConfigType.Vmess)
|
||||||
{
|
{
|
||||||
if (AddServer(ref config, vmessItem, -1, false) == 0)
|
if (AddServer(ref config, vmessItem, -1, false) == 0)
|
||||||
|
@ -955,31 +974,15 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
var indexId = config.indexId();
|
var indexId = config.indexId();
|
||||||
|
|
||||||
List<Mode.VmessItem> source = config.vmess;
|
List<VmessItem> source = config.vmess;
|
||||||
bool keepOlder = config.keepOlderDedupl;
|
bool keepOlder = config.keepOlderDedupl;
|
||||||
|
|
||||||
List<Mode.VmessItem> list = new List<Mode.VmessItem>();
|
List<VmessItem> list = new List<VmessItem>();
|
||||||
if (!keepOlder) source.Reverse(); // Remove the early items first
|
if (!keepOlder) source.Reverse(); // Remove the early items first
|
||||||
|
|
||||||
bool _isAdded(Mode.VmessItem o, Mode.VmessItem n)
|
foreach (VmessItem item in source)
|
||||||
{
|
{
|
||||||
return o.configVersion == n.configVersion &&
|
if (!list.Exists(i => CompareVmessItem(i, item, false)))
|
||||||
o.configType == n.configType &&
|
|
||||||
o.address == n.address &&
|
|
||||||
o.port == n.port &&
|
|
||||||
o.id == n.id &&
|
|
||||||
o.alterId == n.alterId &&
|
|
||||||
o.security == n.security &&
|
|
||||||
o.network == n.network &&
|
|
||||||
o.headerType == n.headerType &&
|
|
||||||
o.requestHost == n.requestHost &&
|
|
||||||
o.path == n.path &&
|
|
||||||
o.streamSecurity == n.streamSecurity;
|
|
||||||
// skip (will remove) different remarks
|
|
||||||
}
|
|
||||||
foreach (Mode.VmessItem item in source)
|
|
||||||
{
|
|
||||||
if (!list.Exists(i => _isAdded(i, item)))
|
|
||||||
{
|
{
|
||||||
list.Add(item);
|
list.Add(item);
|
||||||
}
|
}
|
||||||
|
@ -994,7 +997,10 @@ namespace v2rayN.Handler
|
||||||
|
|
||||||
public static int AddServerCommon(ref Config config, VmessItem vmessItem)
|
public static int AddServerCommon(ref Config config, VmessItem vmessItem)
|
||||||
{
|
{
|
||||||
vmessItem.indexId = Utils.GetGUID(false);
|
if (Utils.IsNullOrEmpty(vmessItem.indexId))
|
||||||
|
{
|
||||||
|
vmessItem.indexId = Utils.GetGUID(false);
|
||||||
|
}
|
||||||
vmessItem.configVersion = 2;
|
vmessItem.configVersion = 2;
|
||||||
if (Utils.IsNullOrEmpty(vmessItem.allowInsecure))
|
if (Utils.IsNullOrEmpty(vmessItem.allowInsecure))
|
||||||
{
|
{
|
||||||
|
@ -1041,6 +1047,29 @@ namespace v2rayN.Handler
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool CompareVmessItem(VmessItem o, VmessItem n, bool remarks)
|
||||||
|
{
|
||||||
|
if (o == null || n == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return o.configVersion == n.configVersion
|
||||||
|
&& o.configType == n.configType
|
||||||
|
&& o.address == n.address
|
||||||
|
&& o.port == n.port
|
||||||
|
&& o.id == n.id
|
||||||
|
&& o.alterId == n.alterId
|
||||||
|
&& o.security == n.security
|
||||||
|
&& o.network == n.network
|
||||||
|
&& o.headerType == n.headerType
|
||||||
|
&& o.requestHost == n.requestHost
|
||||||
|
&& o.path == n.path
|
||||||
|
&& o.streamSecurity == n.streamSecurity
|
||||||
|
&& o.flow == n.flow
|
||||||
|
&& (remarks ? o.remarks == n.remarks : true);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region UI
|
#region UI
|
||||||
|
|
|
@ -9,9 +9,9 @@ using v2rayN.Mode;
|
||||||
|
|
||||||
namespace v2rayN.Handler
|
namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
class MainFormHandler
|
public sealed class MainFormHandler
|
||||||
{
|
{
|
||||||
private static MainFormHandler instance;
|
private static readonly Lazy<MainFormHandler> instance = new Lazy<MainFormHandler>(() => new MainFormHandler());
|
||||||
Action<bool, string> _updateUI;
|
Action<bool, string> _updateUI;
|
||||||
|
|
||||||
//private DownloadHandle downloadHandle2;
|
//private DownloadHandle downloadHandle2;
|
||||||
|
@ -22,16 +22,8 @@ namespace v2rayN.Handler
|
||||||
//Action<int, string> _updateFunc;
|
//Action<int, string> _updateFunc;
|
||||||
public static MainFormHandler Instance
|
public static MainFormHandler Instance
|
||||||
{
|
{
|
||||||
get
|
get { return instance.Value; }
|
||||||
{
|
|
||||||
if (instance == null)
|
|
||||||
{
|
|
||||||
instance = new MainFormHandler();
|
|
||||||
}
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Icon GetNotifyIcon(Config config, Icon def)
|
public Icon GetNotifyIcon(Config config, Icon def)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
|
@ -204,8 +204,8 @@ namespace v2rayN.Handler
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigHandler.RemoveServerViaSubid(ref config, id);
|
//ConfigHandler.RemoveServerViaSubid(ref config, id);
|
||||||
_updateFunc(false, $"{hashCode}{UIRes.I18N("MsgClearSubscription")}");
|
//_updateFunc(false, $"{hashCode}{UIRes.I18N("MsgClearSubscription")}");
|
||||||
// RefreshServers();
|
// RefreshServers();
|
||||||
int ret = MainFormHandler.Instance.AddBatchServers(config, result, id);
|
int ret = MainFormHandler.Instance.AddBatchServers(config, result, id);
|
||||||
if (ret > 0)
|
if (ret > 0)
|
||||||
|
|
Loading…
Reference in New Issue