mirror of
https://github.com/2dust/v2rayN.git
synced 2025-10-13 11:59:13 +00:00
Add generate policy group
This commit is contained in:
parent
9ef228db1e
commit
e29d292732
3 changed files with 29 additions and 45 deletions
|
@ -1179,7 +1179,7 @@ public static class ConfigHandler
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a custom server that combines multiple servers for load balancing
|
||||
/// Create a group server that combines multiple servers for load balancing
|
||||
/// Generates a configuration file that references multiple servers
|
||||
/// </summary>
|
||||
/// <param name="config">Current configuration</param>
|
||||
|
@ -1187,27 +1187,17 @@ public static class ConfigHandler
|
|||
/// <param name="coreType">Core type to use (Xray or sing_box)</param>
|
||||
/// <param name="multipleLoad">Load balancing algorithm</param>
|
||||
/// <returns>Result object with success state and data</returns>
|
||||
public static async Task<RetResult> AddCustomServer4Multiple(Config config, List<ProfileItem> selecteds, ECoreType coreType, EMultipleLoad multipleLoad)
|
||||
public static async Task<RetResult> AddGroupServer4Multiple(Config config, List<ProfileItem> selecteds, ECoreType coreType, EMultipleLoad multipleLoad, string? subId)
|
||||
{
|
||||
var indexId = Utils.GetMd5(Global.CoreMultipleLoadConfigFileName);
|
||||
var configPath = Utils.GetConfigPath(Global.CoreMultipleLoadConfigFileName);
|
||||
var result = new RetResult();
|
||||
|
||||
var result = await CoreConfigHandler.GenerateClientMultipleLoadConfig(config, configPath, selecteds, coreType, multipleLoad);
|
||||
if (result.Success != true)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
var indexId = Utils.GetGuid(false);
|
||||
var childProfileIndexId = Utils.List2String(selecteds.Select(p => p.IndexId).ToList());
|
||||
|
||||
if (!File.Exists(configPath))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
var profileItem = await AppManager.Instance.GetProfileItem(indexId) ?? new();
|
||||
profileItem.IndexId = indexId;
|
||||
var remark = string.Empty;
|
||||
if (coreType == ECoreType.Xray)
|
||||
{
|
||||
profileItem.Remarks = multipleLoad switch
|
||||
remark = multipleLoad switch
|
||||
{
|
||||
EMultipleLoad.Random => ResUI.menuGenGroupMultipleServerXrayRandom,
|
||||
EMultipleLoad.RoundRobin => ResUI.menuGenGroupMultipleServerXrayRoundRobin,
|
||||
|
@ -1218,14 +1208,28 @@ public static class ConfigHandler
|
|||
}
|
||||
else if (coreType == ECoreType.sing_box)
|
||||
{
|
||||
profileItem.Remarks = ResUI.menuGenGroupMultipleServerSingBoxLeastPing;
|
||||
remark = ResUI.menuGenGroupMultipleServerSingBoxLeastPing;
|
||||
}
|
||||
profileItem.Address = Global.CoreMultipleLoadConfigFileName;
|
||||
profileItem.ConfigType = EConfigType.Custom;
|
||||
profileItem.CoreType = coreType;
|
||||
|
||||
await AddServerCommon(config, profileItem, true);
|
||||
|
||||
var profile = new ProfileItem
|
||||
{
|
||||
IndexId = indexId,
|
||||
CoreType = coreType,
|
||||
ConfigType = EConfigType.PolicyGroup,
|
||||
Remarks = remark,
|
||||
Address = childProfileIndexId,
|
||||
};
|
||||
if (!subId.IsNullOrEmpty())
|
||||
{
|
||||
profile.Subid = subId;
|
||||
}
|
||||
var profileGroup = new ProfileGroupItem
|
||||
{
|
||||
ChildItems = childProfileIndexId,
|
||||
MultipleLoad = multipleLoad,
|
||||
ParentIndexId = indexId,
|
||||
};
|
||||
var ret = await AddGroupServerCommon(config, profile, profileGroup, true);
|
||||
result.Success = ret == 0;
|
||||
result.Data = indexId;
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -132,24 +132,4 @@ public static class CoreConfigHandler
|
|||
await File.WriteAllTextAsync(fileName, result.Data.ToString());
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async Task<RetResult> GenerateClientMultipleLoadConfig(Config config, string fileName, List<ProfileItem> selecteds, ECoreType coreType, EMultipleLoad multipleLoad)
|
||||
{
|
||||
var result = new RetResult();
|
||||
if (coreType == ECoreType.sing_box)
|
||||
{
|
||||
result = await new CoreConfigSingboxService(config).GenerateClientMultipleLoadConfig(selecteds);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await new CoreConfigV2rayService(config).GenerateClientMultipleLoadConfig(selecteds, multipleLoad);
|
||||
}
|
||||
|
||||
if (result.Success != true)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
await File.WriteAllTextAsync(fileName, result.Data.ToString());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -618,7 +618,7 @@ public class ProfilesViewModel : MyReactiveObject
|
|||
return;
|
||||
}
|
||||
|
||||
var ret = await ConfigHandler.AddCustomServer4Multiple(_config, lstSelected, coreType, multipleLoad);
|
||||
var ret = await ConfigHandler.AddGroupServer4Multiple(_config, lstSelected, coreType, multipleLoad, SelectedSub?.Id);
|
||||
if (ret.Success != true)
|
||||
{
|
||||
NoticeManager.Instance.Enqueue(ResUI.OperationFailed);
|
||||
|
|
Loading…
Reference in a new issue