diff --git a/v2rayN/ServiceLib/Handler/ConfigHandler.cs b/v2rayN/ServiceLib/Handler/ConfigHandler.cs index 4fbffbe6..5920a1f8 100644 --- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs +++ b/v2rayN/ServiceLib/Handler/ConfigHandler.cs @@ -1296,6 +1296,20 @@ namespace ServiceLib.Handler } } + //Keep the last traffic statistics + if (lstOriSub != null) + { + var lstSub = await AppHandler.Instance.ProfileItems(subid); + foreach (var item in lstSub) + { + var existItem = lstOriSub?.FirstOrDefault(t => config.UiItem.EnableUpdateSubOnlyRemarksExist ? t.Remarks == item.Remarks : CompareProfileItem(t, item, true)); + if (existItem != null) + { + await StatisticsHandler.Instance.CloneServerStatItem(existItem.IndexId, item.IndexId); + } + } + } + return counter; } diff --git a/v2rayN/ServiceLib/Handler/StatisticsHandler.cs b/v2rayN/ServiceLib/Handler/StatisticsHandler.cs index 1c307d11..1858780e 100644 --- a/v2rayN/ServiceLib/Handler/StatisticsHandler.cs +++ b/v2rayN/ServiceLib/Handler/StatisticsHandler.cs @@ -65,6 +65,25 @@ } } + public async Task CloneServerStatItem(string indexId, string toIndexId) + { + if (_lstServerStat == null) + { + return; + } + + var stat = _lstServerStat.FirstOrDefault(t => t.IndexId == indexId); + if (stat == null) + { + return; + } + + var toStat = JsonUtils.DeepCopy(stat); + toStat.IndexId = toIndexId; + await SQLiteHelper.Instance.ReplaceAsync(toStat); + _lstServerStat.Add(toStat); + } + private async Task InitData() { await SQLiteHelper.Instance.ExecuteAsync($"delete from ServerStatItem where indexId not in ( select indexId from ProfileItem )");