diff --git a/v2rayN/v2rayN/Handler/ConfigHandler.cs b/v2rayN/v2rayN/Handler/ConfigHandler.cs index 1e15824a..28d5dcd0 100644 --- a/v2rayN/v2rayN/Handler/ConfigHandler.cs +++ b/v2rayN/v2rayN/Handler/ConfigHandler.cs @@ -972,46 +972,40 @@ namespace v2rayN.Handler } profileItem.subid = subid; profileItem.isSub = isSub; + var addStatus = -1; if (profileItem.configType == EConfigType.VMess) { - if (AddServer(ref config, profileItem, false) == 0) - { - countServers++; - } + addStatus = AddServer(ref config, profileItem, false); } else if (profileItem.configType == EConfigType.Shadowsocks) { - if (AddShadowsocksServer(ref config, profileItem, false) == 0) - { - countServers++; - } + addStatus = AddShadowsocksServer(ref config, profileItem, false); } else if (profileItem.configType == EConfigType.Socks) { - if (AddSocksServer(ref config, profileItem, false) == 0) - { - countServers++; - } + addStatus = AddSocksServer(ref config, profileItem, false); } else if (profileItem.configType == EConfigType.Trojan) { - if (AddTrojanServer(ref config, profileItem, false) == 0) - { - countServers++; - } + addStatus = AddTrojanServer(ref config, profileItem, false); } else if (profileItem.configType == EConfigType.VLESS) { - if (AddVlessServer(ref config, profileItem, false) == 0) - { - countServers++; - } + addStatus = AddVlessServer(ref config, profileItem, false); + } + + if (addStatus == 0) + { + countServers++; + lstAdd.Add(profileItem); } - lstAdd.Add(profileItem); } - SqliteHelper.Instance.InsertAll(lstAdd); + if (lstAdd.Count > 0) + { + SqliteHelper.Instance.InsertAll(lstAdd); + } ToJsonFile(config); return countServers; diff --git a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs index a6edad19..2a59b74a 100644 --- a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs @@ -700,7 +700,7 @@ namespace v2rayN.ViewModels _subId = SelectedSub?.id; _config.subIndexId = _subId; - RefreshServers(false); + RefreshServers(); _updateView("ProfilesFocus"); } @@ -715,13 +715,12 @@ namespace v2rayN.ViewModels RefreshServers(); } - private void RefreshServers(bool blCheckDefault = true) + private void RefreshServers() { List lstModel = LazyConfig.Instance.ProfileItems(_subId, _serverFilter); - if (blCheckDefault) - { - ConfigHandler.SetDefaultServer(_config, lstModel); - } + + ConfigHandler.SetDefaultServer(_config, lstModel); + List lstServerStat = new(); if (_statistics != null && _statistics.Enable) {