Refactor node pre check (#8848)

* Refactor node pre check

* Rename method

* I18n

* Add remark not found warnings

* Fix

* Fix

* Fix

* Update v2rayN/ServiceLib/Handler/CoreConfigHandler.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
DHR60
2026-02-28 08:31:02 +00:00
committed by GitHub
parent 67c4ae02ba
commit 584e538623
19 changed files with 1041 additions and 804 deletions
@@ -234,13 +234,6 @@ public class AddGroupServerViewModel : MyReactiveObject
SelectedSource.SetProtocolExtra(protocolExtra);
var hasCycle = await GroupProfileManager.HasCycle(SelectedSource.IndexId, protocolExtra);
if (hasCycle)
{
NoticeManager.Instance.Enqueue(string.Format(ResUI.GroupSelfReference, remarks));
return;
}
if (await ConfigHandler.AddServerCommon(_config, SelectedSource) == 0)
{
NoticeManager.Instance.Enqueue(ResUI.OperationSuccess);
@@ -540,7 +540,14 @@ public class MainWindowViewModel : MyReactiveObject
{
SetReloadEnabled(false);
var msgs = await ActionPrecheckManager.Instance.Check(_config.IndexId);
var profileItem = await ConfigHandler.GetDefaultServer(_config);
if (profileItem == null)
{
NoticeManager.Instance.Enqueue(ResUI.CheckServerSettings);
return;
}
var (context, validatorResult) = await CoreConfigContextBuilder.Build(_config, profileItem);
var msgs = new List<string>([..validatorResult.Errors, ..validatorResult.Warnings]);
if (msgs.Count > 0)
{
foreach (var msg in msgs)
@@ -548,12 +555,15 @@ public class MainWindowViewModel : MyReactiveObject
NoticeManager.Instance.SendMessage(msg);
}
NoticeManager.Instance.Enqueue(Utils.List2String(msgs.Take(10).ToList(), true));
return;
if (!validatorResult.Success)
{
return;
}
}
await Task.Run(async () =>
{
await LoadCore();
await LoadCore(context);
await SysProxyHandler.UpdateSysProxy(_config, false);
await Task.Delay(1000);
});
@@ -594,10 +604,9 @@ public class MainWindowViewModel : MyReactiveObject
RxApp.MainThreadScheduler.Schedule(() => BlReloadEnabled = enabled);
}
private async Task LoadCore()
private async Task LoadCore(CoreConfigContext? context)
{
var node = await ConfigHandler.GetDefaultServer(_config);
await CoreManager.Instance.LoadCore(node);
await CoreManager.Instance.LoadCore(context);
}
#endregion core job
@@ -788,7 +788,8 @@ public class ProfilesViewModel : MyReactiveObject
return;
}
var msgs = await ActionPrecheckManager.Instance.Check(item);
var (context, validatorResult) = await CoreConfigContextBuilder.Build(_config, item);
var msgs = new List<string>([..validatorResult.Errors, ..validatorResult.Warnings]);
if (msgs.Count > 0)
{
foreach (var msg in msgs)
@@ -796,12 +797,14 @@ public class ProfilesViewModel : MyReactiveObject
NoticeManager.Instance.SendMessage(msg);
}
NoticeManager.Instance.Enqueue(Utils.List2String(msgs.Take(10).ToList(), true));
return;
if (!validatorResult.Success)
{
return;
}
}
if (blClipboard)
{
var context = await CoreConfigHandler.BuildCoreConfigContext(_config, item);
var result = await CoreConfigHandler.GenerateClientConfig(context, null);
if (result.Success != true)
{
@@ -825,7 +828,20 @@ public class ProfilesViewModel : MyReactiveObject
{
return;
}
var context = await CoreConfigHandler.BuildCoreConfigContext(_config, item);
var (context, validatorResult) = await CoreConfigContextBuilder.Build(_config, item);
var msgs = new List<string>([..validatorResult.Errors, ..validatorResult.Warnings]);
if (msgs.Count > 0)
{
foreach (var msg in msgs)
{
NoticeManager.Instance.SendMessage(msg);
}
NoticeManager.Instance.Enqueue(Utils.List2String(msgs.Take(10).ToList(), true));
if (!validatorResult.Success)
{
return;
}
}
var result = await CoreConfigHandler.GenerateClientConfig(context, fileName);
if (result.Success != true)
{