diff --git a/v2rayN/ServiceLib/Enums/EViewAction.cs b/v2rayN/ServiceLib/Enums/EViewAction.cs index 4f84a7cf..bf7360e2 100644 --- a/v2rayN/ServiceLib/Enums/EViewAction.cs +++ b/v2rayN/ServiceLib/Enums/EViewAction.cs @@ -29,7 +29,7 @@ public enum EViewAction DNSSettingWindow, RoutingSettingWindow, OptionSettingWindow, - CustomConfigWindow, + FullConfigTemplateWindow, GlobalHotkeySettingWindow, SubSettingWindow, DispatcherSpeedTest, diff --git a/v2rayN/ServiceLib/Handler/AppHandler.cs b/v2rayN/ServiceLib/Handler/AppHandler.cs index d55245d4..18ba19b8 100644 --- a/v2rayN/ServiceLib/Handler/AppHandler.cs +++ b/v2rayN/ServiceLib/Handler/AppHandler.cs @@ -64,7 +64,7 @@ public sealed class AppHandler SQLiteHelper.Instance.CreateTable(); SQLiteHelper.Instance.CreateTable(); SQLiteHelper.Instance.CreateTable(); - SQLiteHelper.Instance.CreateTable(); + SQLiteHelper.Instance.CreateTable(); return true; } @@ -204,14 +204,14 @@ public sealed class AppHandler return await SQLiteHelper.Instance.TableAsync().FirstOrDefaultAsync(it => it.CoreType == eCoreType); } - public async Task?> CustomConfigItem() + public async Task?> FullConfigTemplateItem() { - return await SQLiteHelper.Instance.TableAsync().ToListAsync(); + return await SQLiteHelper.Instance.TableAsync().ToListAsync(); } - public async Task GetCustomConfigItem(ECoreType eCoreType) + public async Task GetFullConfigTemplateItem(ECoreType eCoreType) { - return await SQLiteHelper.Instance.TableAsync().FirstOrDefaultAsync(it => it.CoreType == eCoreType); + return await SQLiteHelper.Instance.TableAsync().FirstOrDefaultAsync(it => it.CoreType == eCoreType); } #endregion SqliteHelper diff --git a/v2rayN/ServiceLib/Handler/ConfigHandler.cs b/v2rayN/ServiceLib/Handler/ConfigHandler.cs index d8092610..c05424a2 100644 --- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs +++ b/v2rayN/ServiceLib/Handler/ConfigHandler.cs @@ -2240,29 +2240,29 @@ public class ConfigHandler #region Custom Config - public static async Task InitBuiltinCustomConfig(Config config) + public static async Task InitBuiltinFullConfigTemplate(Config config) { - var items = await AppHandler.Instance.CustomConfigItem(); + var items = await AppHandler.Instance.FullConfigTemplateItem(); if (items.Count <= 0) { - var item = new CustomConfigItem() + var item = new FullConfigTemplateItem() { Remarks = "V2ray", CoreType = ECoreType.Xray, }; - await SaveCustomConfigItem(config, item); + await SaveFullConfigTemplate(config, item); - var item2 = new CustomConfigItem() + var item2 = new FullConfigTemplateItem() { Remarks = "sing-box", CoreType = ECoreType.sing_box, }; - await SaveCustomConfigItem(config, item2); + await SaveFullConfigTemplate(config, item2); } return 0; } - public static async Task SaveCustomConfigItem(Config config, CustomConfigItem item) + public static async Task SaveFullConfigTemplate(Config config, FullConfigTemplateItem item) { if (item == null) { diff --git a/v2rayN/ServiceLib/Models/CustomConfigItem.cs b/v2rayN/ServiceLib/Models/FullConfigTemplateItem.cs similarity index 92% rename from v2rayN/ServiceLib/Models/CustomConfigItem.cs rename to v2rayN/ServiceLib/Models/FullConfigTemplateItem.cs index 3d4b6453..f3881325 100644 --- a/v2rayN/ServiceLib/Models/CustomConfigItem.cs +++ b/v2rayN/ServiceLib/Models/FullConfigTemplateItem.cs @@ -3,7 +3,7 @@ using SQLite; namespace ServiceLib.Models; [Serializable] -public class CustomConfigItem +public class FullConfigTemplateItem { [PrimaryKey] public string Id { get; set; } diff --git a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs index c0c21508..ec000fb2 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs +++ b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs @@ -187,11 +187,11 @@ namespace ServiceLib.Resx { } /// - /// 查找类似 Please fill in the correct custom config 的本地化字符串。 + /// 查找类似 Please fill in the correct config template 的本地化字符串。 /// - public static string FillCorrectConfigText { + public static string FillCorrectConfigTemplateText { get { - return ResourceManager.GetString("FillCorrectConfigText", resourceCulture); + return ResourceManager.GetString("FillCorrectConfigTemplateText", resourceCulture); } } @@ -861,15 +861,6 @@ namespace ServiceLib.Resx { } } - /// - /// 查找类似 Custom Config 的本地化字符串。 - /// - public static string menuCustomConfig { - get { - return ResourceManager.GetString("menuCustomConfig", resourceCulture); - } - } - /// /// 查找类似 DNS Settings 的本地化字符串。 /// @@ -951,6 +942,15 @@ namespace ServiceLib.Resx { } } + /// + /// 查找类似 Full Config Template Setting 的本地化字符串。 + /// + public static string menuFullConfigTemplate { + get { + return ResourceManager.GetString("menuFullConfigTemplate", resourceCulture); + } + } + /// /// 查找类似 Global Hotkey Setting 的本地化字符串。 /// @@ -2391,24 +2391,6 @@ namespace ServiceLib.Resx { } } - /// - /// 查找类似 Enable Custom Config 的本地化字符串。 - /// - public static string TbCustomConfigEnable { - get { - return ResourceManager.GetString("TbCustomConfigEnable", resourceCulture); - } - } - - /// - /// 查找类似 sing-box Custom Config 的本地化字符串。 - /// - public static string TbCustomConfigSingbox { - get { - return ResourceManager.GetString("TbCustomConfigSingbox", resourceCulture); - } - } - /// /// 查找类似 Enable Custom DNS 的本地化字符串。 /// @@ -2553,6 +2535,24 @@ namespace ServiceLib.Resx { } } + /// + /// 查找类似 This feature is intended for advanced users and those with special requirements. Once enabled, it will ignore the Core's basic settings, DNS settings, and routing settings. You must ensure that the system proxy port, traffic statistics, and other related configurations are set correctly — everything will be configured by you. 的本地化字符串。 + /// + public static string TbFullConfigTemplateDesc { + get { + return ResourceManager.GetString("TbFullConfigTemplateDesc", resourceCulture); + } + } + + /// + /// 查找类似 Enable Full Config Template 的本地化字符串。 + /// + public static string TbFullConfigTemplateEnable { + get { + return ResourceManager.GetString("TbFullConfigTemplateEnable", resourceCulture); + } + } + /// /// 查找类似 Global Hotkey Settings 的本地化字符串。 /// @@ -2770,20 +2770,20 @@ namespace ServiceLib.Resx { } /// - /// 查找类似 v2ray Custom Config 的本地化字符串。 + /// 查找类似 v2ray Full Config Template 的本地化字符串。 /// - public static string TbRayCustomConfig { + public static string TbRayFullConfigTemplate { get { - return ResourceManager.GetString("TbRayCustomConfig", resourceCulture); + return ResourceManager.GetString("TbRayFullConfigTemplate", resourceCulture); } } /// /// 查找类似 Add Outbound Config Only, routing.balancers and routing.rules.outboundTag 的本地化字符串。 /// - public static string TbRayCustomConfigDesc { + public static string TbRayFullConfigTemplateDesc { get { - return ResourceManager.GetString("TbRayCustomConfigDesc", resourceCulture); + return ResourceManager.GetString("TbRayFullConfigTemplateDesc", resourceCulture); } } @@ -2913,15 +2913,6 @@ namespace ServiceLib.Resx { } } - /// - /// 查找类似 Add Outbound and Endpoint Config Only 的本地化字符串。 - /// - public static string TbSBCustomConfigDesc { - get { - return ResourceManager.GetString("TbSBCustomConfigDesc", resourceCulture); - } - } - /// /// 查找类似 sing-box Direct Resolution Strategy 的本地化字符串。 /// @@ -2958,6 +2949,24 @@ namespace ServiceLib.Resx { } } + /// + /// 查找类似 sing-box Full Config Template 的本地化字符串。 + /// + public static string TbSBFullConfigTemplate { + get { + return ResourceManager.GetString("TbSBFullConfigTemplate", resourceCulture); + } + } + + /// + /// 查找类似 Add Outbound and Endpoint Config Only 的本地化字符串。 + /// + public static string TbSBFullConfigTemplateDesc { + get { + return ResourceManager.GetString("TbSBFullConfigTemplateDesc", resourceCulture); + } + } + /// /// 查找类似 Resolve Outbound Domains 的本地化字符串。 /// diff --git a/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx b/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx index f734ff62..05a6bcb8 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx @@ -1470,31 +1470,34 @@ Custom DNS Enabled, This Page's Settings Invalid - - Please fill in the correct custom config + + Please fill in the correct config template - - Custom Config + + Full Config Template Setting - - Enable Custom Config + + Enable Full Config Template - - v2ray Custom Config + + v2ray Full Config Template - - sing-box Custom Config - - + Add Outbound Config Only, routing.balancers and routing.rules.outboundTag - - Add Outbound and Endpoint Config Only - Do Not Add Non-Proxy Protocol Outbound Set Upstream Proxy Tag + + sing-box Full Config Template + + + Add Outbound and Endpoint Config Only + + + This feature is intended for advanced users and those with special requirements. Once enabled, it will ignore the Core's basic settings, DNS settings, and routing settings. You must ensure that the system proxy port, traffic statistics, and other related configurations are set correctly — everything will be configured by you. + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.hu.resx b/v2rayN/ServiceLib/Resx/ResUI.hu.resx index 6f65964f..673f19e5 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.hu.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.hu.resx @@ -1470,31 +1470,34 @@ Custom DNS Enabled, This Page's Settings Invalid - - Please fill in the correct custom config + + Please fill in the correct config template - - Custom Config + + Full Config Template Setting - - Enable Custom Config + + Enable Full Config Template - - v2ray Custom Config + + v2ray Full Config Template - - sing-box Custom Config - - + Add Outbound Config Only, routing.balancers and routing.rules.outboundTag - - Add Outbound and Endpoint Config Only - Do Not Add Non-Proxy Protocol Outbound Set Upstream Proxy Tag + + sing-box Full Config Template + + + Add Outbound and Endpoint Config Only + + + This feature is intended for advanced users and those with special requirements. Once enabled, it will ignore the Core's basic settings, DNS settings, and routing settings. You must ensure that the system proxy port, traffic statistics, and other related configurations are set correctly — everything will be configured by you. + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.resx b/v2rayN/ServiceLib/Resx/ResUI.resx index eb7afac8..7727012f 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.resx @@ -1470,31 +1470,34 @@ Custom DNS Enabled, This Page's Settings Invalid - - Please fill in the correct custom config + + Please fill in the correct config template - - Custom Config + + Full Config Template Setting - - Enable Custom Config + + Enable Full Config Template - - v2ray Custom Config + + v2ray Full Config Template - - sing-box Custom Config - - + Add Outbound Config Only, routing.balancers and routing.rules.outboundTag - - Add Outbound and Endpoint Config Only - Do Not Add Non-Proxy Protocol Outbound Set Upstream Proxy Tag + + sing-box Full Config Template + + + Add Outbound and Endpoint Config Only + + + This feature is intended for advanced users and those with special requirements. Once enabled, it will ignore the Core's basic settings, DNS settings, and routing settings. You must ensure that the system proxy port, traffic statistics, and other related configurations are set correctly — everything will be configured by you. + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.ru.resx b/v2rayN/ServiceLib/Resx/ResUI.ru.resx index 5719afda..a7c71997 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.ru.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.ru.resx @@ -1470,31 +1470,34 @@ Custom DNS Enabled, This Page's Settings Invalid - - Please fill in the correct custom config + + Please fill in the correct config template - - Custom Config + + Full Config Template Setting - - Enable Custom Config + + Enable Full Config Template - - v2ray Custom Config + + v2ray Full Config Template - - sing-box Custom Config - - + Add Outbound Config Only, routing.balancers and routing.rules.outboundTag - - Add Outbound and Endpoint Config Only - Do Not Add Non-Proxy Protocol Outbound Set Upstream Proxy Tag + + sing-box Full Config Template + + + Add Outbound and Endpoint Config Only + + + This feature is intended for advanced users and those with special requirements. Once enabled, it will ignore the Core's basic settings, DNS settings, and routing settings. You must ensure that the system proxy port, traffic statistics, and other related configurations are set correctly — everything will be configured by you. + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx index 2b80f120..8b1aa738 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx @@ -1467,31 +1467,34 @@ 自定义 DNS 已启用,此页面配置将无效 - - 请填写正确的自定义配置 + + 请填写正确的配置模板 - - 自定义配置 + + 完整配置模板设置 - - 启用自定义配置 + + 启用完整配置模板 - - v2ray 自定义配置 + + v2ray 完整配置模板 - - sing-box 自定义配置 - - + 仅添加出站配置,routing.balancers 和 routing.rules.outboundTag - - 仅添加出站和端点配置 - 不添加非代理协议出站 设置上游代理 tag + + sing-box 完整配置模板 + + + 仅添加出站和端点配置 + + + 此功能供高级用户和有特殊需求的用户使用。 启用此功能后,将忽略 Core 的基础设置,DNS 设置 ,路由设置。你需要保证系统代理的端口和流量统计等功能的配置正确,一切都由你来设置。 + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx index 56a74064..b930d285 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx @@ -1467,31 +1467,34 @@ Custom DNS Enabled, This Page's Settings Invalid - - Please fill in the correct custom config + + Please fill in the correct config template - - Custom Config + + Full Config Template Setting - - Enable Custom Config + + Enable Full Config Template - - v2ray Custom Config + + v2ray Full Config Template - - sing-box Custom Config - - + Add Outbound Config Only, routing.balancers and routing.rules.outboundTag - - Add Outbound and Endpoint Config Only - Do Not Add Non-Proxy Protocol Outbound Set Upstream Proxy Tag + + sing-box Full Config Template + + + Add Outbound and Endpoint Config Only + + + This feature is intended for advanced users and those with special requirements. Once enabled, it will ignore the Core's basic settings, DNS settings, and routing settings. You must ensure that the system proxy port, traffic statistics, and other related configurations are set correctly — everything will be configured by you. + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs index e60e77fb..6563e991 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs @@ -80,8 +80,8 @@ public class CoreConfigSingboxService ret.Msg = string.Format(ResUI.SuccessfulConfiguration, ""); ret.Success = true; - var customConfig = await AppHandler.Instance.GetCustomConfigItem(ECoreType.sing_box); - ret.Data = await ApplyCustomConfig(customConfig, singboxConfig); + var fullConfigTemplate = await AppHandler.Instance.GetFullConfigTemplateItem(ECoreType.sing_box); + ret.Data = await ApplyFullConfigTemplate(fullConfigTemplate, singboxConfig); return ret; } catch (Exception ex) @@ -434,8 +434,8 @@ public class CoreConfigSingboxService ret.Success = true; - var customConfig = await AppHandler.Instance.GetCustomConfigItem(ECoreType.sing_box); - ret.Data = await ApplyCustomConfig(customConfig, singboxConfig); + var fullConfigTemplate = await AppHandler.Instance.GetFullConfigTemplateItem(ECoreType.sing_box); + ret.Data = await ApplyFullConfigTemplate(fullConfigTemplate, singboxConfig); return ret; } catch (Exception ex) @@ -2202,60 +2202,60 @@ public class CoreConfigSingboxService return 0; } - private async Task ApplyCustomConfig(CustomConfigItem customConfig, SingboxConfig singboxConfig) + private async Task ApplyFullConfigTemplate(FullConfigTemplateItem fullConfigTemplate, SingboxConfig singboxConfig) { - var customConfigItem = customConfig.Config; + var fullConfigTemplateItem = fullConfigTemplate.Config; if (_config.TunModeItem.EnableTun) { - customConfigItem = customConfig.TunConfig; + fullConfigTemplateItem = fullConfigTemplate.TunConfig; } - if (!customConfig.Enabled || customConfigItem.IsNullOrEmpty()) + if (!fullConfigTemplate.Enabled || fullConfigTemplateItem.IsNullOrEmpty()) { return JsonUtils.Serialize(singboxConfig); } - var customConfigNode = JsonNode.Parse(customConfigItem); - if (customConfigNode == null) + var fullConfigTemplateNode = JsonNode.Parse(fullConfigTemplateItem); + if (fullConfigTemplateNode == null) { return JsonUtils.Serialize(singboxConfig); } // Process outbounds - var customOutboundsNode = customConfigNode["outbounds"] is JsonArray outbounds ? outbounds : new JsonArray(); + var customOutboundsNode = fullConfigTemplateNode["outbounds"] is JsonArray outbounds ? outbounds : new JsonArray(); foreach (var outbound in singboxConfig.outbounds) { if (outbound.type.ToLower() is "direct" or "block") { - if (customConfig.AddProxyOnly == true) + if (fullConfigTemplate.AddProxyOnly == true) { continue; } } - else if (outbound.detour.IsNullOrEmpty() && (!customConfig.ProxyDetour.IsNullOrEmpty()) && !Utils.IsPrivateNetwork(outbound.server ?? string.Empty)) + else if (outbound.detour.IsNullOrEmpty() && (!fullConfigTemplate.ProxyDetour.IsNullOrEmpty()) && !Utils.IsPrivateNetwork(outbound.server ?? string.Empty)) { - outbound.detour = customConfig.ProxyDetour; + outbound.detour = fullConfigTemplate.ProxyDetour; } customOutboundsNode.Add(JsonUtils.DeepCopy(outbound)); } - customConfigNode["outbounds"] = customOutboundsNode; + fullConfigTemplateNode["outbounds"] = customOutboundsNode; // Process endpoints if (singboxConfig.endpoints != null && singboxConfig.endpoints.Count > 0) { - var customEndpointsNode = customConfigNode["endpoints"] is JsonArray endpoints ? endpoints : new JsonArray(); + var customEndpointsNode = fullConfigTemplateNode["endpoints"] is JsonArray endpoints ? endpoints : new JsonArray(); foreach (var endpoint in singboxConfig.endpoints) { - if (endpoint.detour.IsNullOrEmpty() && (!customConfig.ProxyDetour.IsNullOrEmpty())) + if (endpoint.detour.IsNullOrEmpty() && (!fullConfigTemplate.ProxyDetour.IsNullOrEmpty())) { - endpoint.detour = customConfig.ProxyDetour; + endpoint.detour = fullConfigTemplate.ProxyDetour; } customEndpointsNode.Add(JsonUtils.DeepCopy(endpoint)); } - customConfigNode["endpoints"] = customEndpointsNode; + fullConfigTemplateNode["endpoints"] = customEndpointsNode; } - return await Task.FromResult(JsonUtils.Serialize(customConfigNode)); + return await Task.FromResult(JsonUtils.Serialize(fullConfigTemplateNode)); } #endregion private gen function diff --git a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs index 2a59d91a..96388ed3 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs @@ -70,8 +70,8 @@ public class CoreConfigV2rayService ret.Msg = string.Format(ResUI.SuccessfulConfiguration, ""); ret.Success = true; - var customConfig = await AppHandler.Instance.GetCustomConfigItem(ECoreType.Xray); - ret.Data = await ApplyCustomConfig(customConfig, v2rayConfig); + var fullConfigTemplate = await AppHandler.Instance.GetFullConfigTemplateItem(ECoreType.Xray); + ret.Data = await ApplyFullConfigTemplate(fullConfigTemplate, v2rayConfig); return ret; } catch (Exception ex) @@ -201,8 +201,8 @@ public class CoreConfigV2rayService ret.Success = true; - var customConfig = await AppHandler.Instance.GetCustomConfigItem(ECoreType.Xray); - ret.Data = await ApplyCustomConfig(customConfig, v2rayConfig, true); + var fullConfigTemplate = await AppHandler.Instance.GetFullConfigTemplateItem(ECoreType.Xray); + ret.Data = await ApplyFullConfigTemplate(fullConfigTemplate, v2rayConfig, true); return ret; } catch (Exception ex) @@ -1844,15 +1844,15 @@ public class CoreConfigV2rayService return await Task.FromResult(0); } - private async Task ApplyCustomConfig(CustomConfigItem customConfig, V2rayConfig v2rayConfig, bool handleBalancerAndRules = false) + private async Task ApplyFullConfigTemplate(FullConfigTemplateItem fullConfigTemplate, V2rayConfig v2rayConfig, bool handleBalancerAndRules = false) { - if (!customConfig.Enabled || customConfig.Config.IsNullOrEmpty()) + if (!fullConfigTemplate.Enabled || fullConfigTemplate.Config.IsNullOrEmpty()) { return JsonUtils.Serialize(v2rayConfig); } - var customConfigNode = JsonNode.Parse(customConfig.Config); - if (customConfigNode == null) + var fullConfigTemplateNode = JsonNode.Parse(fullConfigTemplate.Config); + if (fullConfigTemplateNode == null) { return JsonUtils.Serialize(v2rayConfig); } @@ -1863,7 +1863,7 @@ public class CoreConfigV2rayService var balancer = v2rayConfig.routing.balancers.First(); // Modify existing rules in custom config - var rulesNode = customConfigNode["routing"]?["rules"]; + var rulesNode = fullConfigTemplateNode["routing"]?["rules"]; if (rulesNode != null) { foreach (var rule in rulesNode.AsArray()) @@ -1877,13 +1877,13 @@ public class CoreConfigV2rayService } // Ensure routing node exists - if (customConfigNode["routing"] == null) + if (fullConfigTemplateNode["routing"] == null) { - customConfigNode["routing"] = new JsonObject(); + fullConfigTemplateNode["routing"] = new JsonObject(); } // Handle balancers - append instead of override - if (customConfigNode["routing"]["balancers"] is JsonArray customBalancersNode) + if (fullConfigTemplateNode["routing"]["balancers"] is JsonArray customBalancersNode) { if (JsonNode.Parse(JsonUtils.Serialize(v2rayConfig.routing.balancers)) is JsonArray newBalancers) { @@ -1895,31 +1895,31 @@ public class CoreConfigV2rayService } else { - customConfigNode["routing"]["balancers"] = JsonNode.Parse(JsonUtils.Serialize(v2rayConfig.routing.balancers)); + fullConfigTemplateNode["routing"]["balancers"] = JsonNode.Parse(JsonUtils.Serialize(v2rayConfig.routing.balancers)); } } // Handle outbounds - append instead of override - var customOutboundsNode = customConfigNode["outbounds"] is JsonArray outbounds ? outbounds : new JsonArray(); + var customOutboundsNode = fullConfigTemplateNode["outbounds"] is JsonArray outbounds ? outbounds : new JsonArray(); foreach (var outbound in v2rayConfig.outbounds) { if (outbound.protocol.ToLower() is "blackhole" or "dns" or "freedom") { - if (customConfig.AddProxyOnly == true) + if (fullConfigTemplate.AddProxyOnly == true) { continue; } } - else if ((outbound.streamSettings?.sockopt?.dialerProxy.IsNullOrEmpty() == true) && (!customConfig.ProxyDetour.IsNullOrEmpty()) && !(Utils.IsPrivateNetwork(outbound.settings?.servers?.FirstOrDefault()?.address ?? string.Empty) || Utils.IsPrivateNetwork(outbound.settings?.vnext?.FirstOrDefault()?.address ?? string.Empty))) + else if ((outbound.streamSettings?.sockopt?.dialerProxy.IsNullOrEmpty() == true) && (!fullConfigTemplate.ProxyDetour.IsNullOrEmpty()) && !(Utils.IsPrivateNetwork(outbound.settings?.servers?.FirstOrDefault()?.address ?? string.Empty) || Utils.IsPrivateNetwork(outbound.settings?.vnext?.FirstOrDefault()?.address ?? string.Empty))) { outbound.streamSettings ??= new StreamSettings4Ray(); outbound.streamSettings.sockopt ??= new Sockopt4Ray(); - outbound.streamSettings.sockopt.dialerProxy = customConfig.ProxyDetour; + outbound.streamSettings.sockopt.dialerProxy = fullConfigTemplate.ProxyDetour; } customOutboundsNode.Add(JsonUtils.DeepCopy(outbound)); } - return await Task.FromResult(JsonUtils.Serialize(customConfigNode)); + return await Task.FromResult(JsonUtils.Serialize(fullConfigTemplateNode)); } #endregion private gen function diff --git a/v2rayN/ServiceLib/ViewModels/CustomConfigViewModel.cs b/v2rayN/ServiceLib/ViewModels/FullConfigTemplateViewModel.cs similarity index 54% rename from v2rayN/ServiceLib/ViewModels/CustomConfigViewModel.cs rename to v2rayN/ServiceLib/ViewModels/FullConfigTemplateViewModel.cs index 75d7d5be..3aa618bf 100644 --- a/v2rayN/ServiceLib/ViewModels/CustomConfigViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/FullConfigTemplateViewModel.cs @@ -4,23 +4,23 @@ using ReactiveUI; using ReactiveUI.Fody.Helpers; namespace ServiceLib.ViewModels; -public class CustomConfigViewModel : MyReactiveObject +public class FullConfigTemplateViewModel : MyReactiveObject { #region Reactive [Reactive] - public bool EnableCustomConfig4Ray { get; set; } + public bool EnableFullConfigTemplate4Ray { get; set; } [Reactive] - public bool EnableCustomConfig4Singbox { get; set; } + public bool EnableFullConfigTemplate4Singbox { get; set; } [Reactive] - public string CustomConfig4Ray { get; set; } + public string FullConfigTemplate4Ray { get; set; } [Reactive] - public string CustomConfig4Singbox { get; set; } + public string FullConfigTemplate4Singbox { get; set; } [Reactive] - public string CustomTunConfig4Singbox { get; set; } + public string FullTunConfigTemplate4Singbox { get; set; } [Reactive] public bool AddProxyOnly4Ray { get; set; } @@ -37,7 +37,7 @@ public class CustomConfigViewModel : MyReactiveObject public ReactiveCommand SaveCmd { get; } #endregion Reactive - public CustomConfigViewModel(Func>? updateView) + public FullConfigTemplateViewModel(Func>? updateView) { _config = AppHandler.Instance.Config; _updateView = updateView; @@ -50,16 +50,16 @@ public class CustomConfigViewModel : MyReactiveObject } private async Task Init() { - var item = await AppHandler.Instance.GetCustomConfigItem(ECoreType.Xray); - EnableCustomConfig4Ray = item?.Enabled ?? false; - CustomConfig4Ray = item?.Config ?? string.Empty; + var item = await AppHandler.Instance.GetFullConfigTemplateItem(ECoreType.Xray); + EnableFullConfigTemplate4Ray = item?.Enabled ?? false; + FullConfigTemplate4Ray = item?.Config ?? string.Empty; AddProxyOnly4Ray = item?.AddProxyOnly ?? false; ProxyDetour4Ray = item?.ProxyDetour ?? string.Empty; - var item2 = await AppHandler.Instance.GetCustomConfigItem(ECoreType.sing_box); - EnableCustomConfig4Singbox = item2?.Enabled ?? false; - CustomConfig4Singbox = item2?.Config ?? string.Empty; - CustomTunConfig4Singbox = item2?.TunConfig ?? string.Empty; + var item2 = await AppHandler.Instance.GetFullConfigTemplateItem(ECoreType.sing_box); + EnableFullConfigTemplate4Singbox = item2?.Enabled ?? false; + FullConfigTemplate4Singbox = item2?.Config ?? string.Empty; + FullTunConfigTemplate4Singbox = item2?.TunConfig ?? string.Empty; AddProxyOnly4Singbox = item2?.AddProxyOnly ?? false; ProxyDetour4Singbox = item2?.ProxyDetour ?? string.Empty; } @@ -78,33 +78,33 @@ public class CustomConfigViewModel : MyReactiveObject private async Task SaveXrayConfigAsync() { - var item = await AppHandler.Instance.GetCustomConfigItem(ECoreType.Xray); - item.Enabled = EnableCustomConfig4Ray; + var item = await AppHandler.Instance.GetFullConfigTemplateItem(ECoreType.Xray); + item.Enabled = EnableFullConfigTemplate4Ray; item.Config = null; - item.Config = CustomConfig4Ray; + item.Config = FullConfigTemplate4Ray; item.AddProxyOnly = AddProxyOnly4Ray; item.ProxyDetour = ProxyDetour4Ray; - await ConfigHandler.SaveCustomConfigItem(_config, item); + await ConfigHandler.SaveFullConfigTemplate(_config, item); return true; } private async Task SaveSingboxConfigAsync() { - var item = await AppHandler.Instance.GetCustomConfigItem(ECoreType.sing_box); - item.Enabled = EnableCustomConfig4Singbox; + var item = await AppHandler.Instance.GetFullConfigTemplateItem(ECoreType.sing_box); + item.Enabled = EnableFullConfigTemplate4Singbox; item.Config = null; item.TunConfig = null; - item.Config = CustomConfig4Singbox; - item.TunConfig = CustomTunConfig4Singbox; + item.Config = FullConfigTemplate4Singbox; + item.TunConfig = FullTunConfigTemplate4Singbox; item.AddProxyOnly = AddProxyOnly4Singbox; item.ProxyDetour = ProxyDetour4Singbox; - await ConfigHandler.SaveCustomConfigItem(_config, item); + await ConfigHandler.SaveFullConfigTemplate(_config, item); return true; } } diff --git a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs index 71536ab2..8355996d 100644 --- a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs @@ -39,7 +39,7 @@ public class MainWindowViewModel : MyReactiveObject public ReactiveCommand RoutingSettingCmd { get; } public ReactiveCommand DNSSettingCmd { get; } - public ReactiveCommand CustomConfigCmd { get; } + public ReactiveCommand FullConfigTemplateCmd { get; } public ReactiveCommand GlobalHotkeySettingCmd { get; } public ReactiveCommand RebootAsAdminCmd { get; } public ReactiveCommand ClearServerStatisticsCmd { get; } @@ -170,9 +170,9 @@ public class MainWindowViewModel : MyReactiveObject { await DNSSettingAsync(); }); - CustomConfigCmd = ReactiveCommand.CreateFromTask(async () => + FullConfigTemplateCmd = ReactiveCommand.CreateFromTask(async () => { - await CustomConfigAsync(); + await FullConfigTemplateAsync(); }); GlobalHotkeySettingCmd = ReactiveCommand.CreateFromTask(async () => { @@ -225,7 +225,7 @@ public class MainWindowViewModel : MyReactiveObject await ConfigHandler.InitBuiltinRouting(_config); await ConfigHandler.InitBuiltinDNS(_config); - await ConfigHandler.InitBuiltinCustomConfig(_config); + await ConfigHandler.InitBuiltinFullConfigTemplate(_config); await ProfileExHandler.Instance.Init(); await CoreHandler.Instance.Init(_config, UpdateHandler); TaskHandler.Instance.RegUpdateTask(_config, UpdateTaskHandler); @@ -514,9 +514,9 @@ public class MainWindowViewModel : MyReactiveObject } } - private async Task CustomConfigAsync() + private async Task FullConfigTemplateAsync() { - var ret = await _updateView?.Invoke(EViewAction.CustomConfigWindow, null); + var ret = await _updateView?.Invoke(EViewAction.FullConfigTemplateWindow, null); if (ret == true) { await Reload(); diff --git a/v2rayN/v2rayN.Desktop/Views/CustomConfigWindow.axaml b/v2rayN/v2rayN.Desktop/Views/FullConfigTemplateWindow.axaml similarity index 73% rename from v2rayN/v2rayN.Desktop/Views/CustomConfigWindow.axaml rename to v2rayN/v2rayN.Desktop/Views/FullConfigTemplateWindow.axaml index fcfedfe7..bfaadce3 100644 --- a/v2rayN/v2rayN.Desktop/Views/CustomConfigWindow.axaml +++ b/v2rayN/v2rayN.Desktop/Views/FullConfigTemplateWindow.axaml @@ -1,15 +1,15 @@ @@ -35,25 +35,31 @@ - + - + - - - + - + + + + Text="{x:Static resx:ResUI.TbFullConfigTemplateEnable}" /> @@ -87,9 +93,9 @@ Margin="{StaticResource Margin4}" BorderBrush="Gray" BorderThickness="1" - Header="xray json config"> + Header="xray config template json"> - + - + - - - + - + + + + Text="{x:Static resx:ResUI.TbFullConfigTemplateEnable}" /> @@ -151,9 +163,9 @@ Grid.Column="0" BorderBrush="Gray" BorderThickness="1" - Header="sing-box json config"> + Header="sing-box config template json"> + Header="sing-box tun config template json"> +public partial class FullConfigTemplateWindow : WindowBase { private static Config _config; - public CustomConfigWindow() + public FullConfigTemplateWindow() { InitializeComponent(); _config = AppHandler.Instance.Config; btnCancel.Click += (s, e) => this.Close(); - ViewModel = new CustomConfigViewModel(UpdateViewHandler); + ViewModel = new FullConfigTemplateViewModel(UpdateViewHandler); this.WhenActivated(disposables => { - this.Bind(ViewModel, vm => vm.EnableCustomConfig4Ray, v => v.rayCustomConfigEnable.IsChecked).DisposeWith(disposables); - this.Bind(ViewModel, vm => vm.CustomConfig4Ray, v => v.rayCustomConfig.Text).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.EnableFullConfigTemplate4Ray, v => v.rayFullConfigTemplateEnable.IsChecked).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.FullConfigTemplate4Ray, v => v.rayFullConfigTemplate.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.AddProxyOnly4Ray, v => v.togAddProxyProtocolOutboundOnly4Ray.IsChecked).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.ProxyDetour4Ray, v => v.txtProxyDetour4Ray.Text).DisposeWith(disposables); - this.Bind(ViewModel, vm => vm.EnableCustomConfig4Singbox, v => v.sbCustomConfigEnable.IsChecked).DisposeWith(disposables); - this.Bind(ViewModel, vm => vm.CustomConfig4Singbox, v => v.sbCustomConfig.Text).DisposeWith(disposables); - this.Bind(ViewModel, vm => vm.CustomTunConfig4Singbox, v => v.sbCustomTunConfig.Text).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.EnableFullConfigTemplate4Singbox, v => v.sbFullConfigTemplateEnable.IsChecked).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.FullConfigTemplate4Singbox, v => v.sbFullConfigTemplate.Text).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.FullTunConfigTemplate4Singbox, v => v.sbFullTunConfigTemplate.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.AddProxyOnly4Singbox, v => v.togAddProxyProtocolOutboundOnly4Singbox.IsChecked).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.ProxyDetour4Singbox, v => v.txtProxyDetour4Singbox.Text).DisposeWith(disposables); diff --git a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml index bf36917a..91476dd7 100644 --- a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml +++ b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml @@ -72,7 +72,7 @@ - + diff --git a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs index 02924078..581e0a35 100644 --- a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs @@ -100,7 +100,7 @@ public partial class MainWindow : WindowBase this.BindCommand(ViewModel, vm => vm.OptionSettingCmd, v => v.menuOptionSetting).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.RoutingSettingCmd, v => v.menuRoutingSetting).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.DNSSettingCmd, v => v.menuDNSSetting).DisposeWith(disposables); - this.BindCommand(ViewModel, vm => vm.CustomConfigCmd, v => v.menuCustomConfig).DisposeWith(disposables); + this.BindCommand(ViewModel, vm => vm.FullConfigTemplateCmd, v => v.menuFullConfigTemplate).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.GlobalHotkeySettingCmd, v => v.menuGlobalHotkeySetting).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.RebootAsAdminCmd, v => v.menuRebootAsAdmin).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.ClearServerStatisticsCmd, v => v.menuClearServerStatistics).DisposeWith(disposables); @@ -191,8 +191,8 @@ public partial class MainWindow : WindowBase case EViewAction.DNSSettingWindow: return await new DNSSettingWindow().ShowDialog(this); - case EViewAction.CustomConfigWindow: - return await new CustomConfigWindow().ShowDialog(this); + case EViewAction.FullConfigTemplateWindow: + return await new FullConfigTemplateWindow().ShowDialog(this); case EViewAction.RoutingSettingWindow: return await new RoutingSettingWindow().ShowDialog(this); diff --git a/v2rayN/v2rayN.Desktop/v2rayN.Desktop.csproj b/v2rayN/v2rayN.Desktop/v2rayN.Desktop.csproj index e488c63a..8c274a69 100644 --- a/v2rayN/v2rayN.Desktop/v2rayN.Desktop.csproj +++ b/v2rayN/v2rayN.Desktop/v2rayN.Desktop.csproj @@ -39,6 +39,9 @@ Never + + FullConfigTemplateWindow.axaml + Always diff --git a/v2rayN/v2rayN/Views/CustomConfigWindow.xaml b/v2rayN/v2rayN/Views/FullConfigTemplateWindow.xaml similarity index 75% rename from v2rayN/v2rayN/Views/CustomConfigWindow.xaml rename to v2rayN/v2rayN/Views/FullConfigTemplateWindow.xaml index 3ec9b725..1c4f2d35 100644 --- a/v2rayN/v2rayN/Views/CustomConfigWindow.xaml +++ b/v2rayN/v2rayN/Views/FullConfigTemplateWindow.xaml @@ -1,5 +1,5 @@ - + + - - - + - + + + + Text="{x:Static resx:ResUI.TbFullConfigTemplateEnable}" /> @@ -99,10 +107,10 @@ - + + - - - + - + + + + Text="{x:Static resx:ResUI.TbFullConfigTemplateEnable}" /> @@ -175,10 +191,10 @@ { - this.Bind(ViewModel, vm => vm.EnableCustomConfig4Ray, v => v.rayCustomConfigEnable.IsChecked).DisposeWith(disposables); - this.Bind(ViewModel, vm => vm.CustomConfig4Ray, v => v.rayCustomConfig.Text).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.EnableFullConfigTemplate4Ray, v => v.rayFullConfigTemplateEnable.IsChecked).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.FullConfigTemplate4Ray, v => v.rayFullConfigTemplate.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.AddProxyOnly4Ray, v => v.togAddProxyProtocolOutboundOnly4Ray.IsChecked).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.ProxyDetour4Ray, v => v.txtProxyDetour4Ray.Text).DisposeWith(disposables); - this.Bind(ViewModel, vm => vm.EnableCustomConfig4Singbox, v => v.sbCustomConfigEnable.IsChecked).DisposeWith(disposables); - this.Bind(ViewModel, vm => vm.CustomConfig4Singbox, v => v.sbCustomConfig.Text).DisposeWith(disposables); - this.Bind(ViewModel, vm => vm.CustomTunConfig4Singbox, v => v.sbCustomTunConfig.Text).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.EnableFullConfigTemplate4Singbox, v => v.sbFullConfigTemplateEnable.IsChecked).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.FullConfigTemplate4Singbox, v => v.sbFullConfigTemplate.Text).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.FullTunConfigTemplate4Singbox, v => v.sbFullTunConfigTemplate.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.AddProxyOnly4Singbox, v => v.togAddProxyProtocolOutboundOnly4Singbox.IsChecked).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.ProxyDetour4Singbox, v => v.txtProxyDetour4Singbox.Text).DisposeWith(disposables); diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml b/v2rayN/v2rayN/Views/MainWindow.xaml index 2b36f35b..14fe809a 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml +++ b/v2rayN/v2rayN/Views/MainWindow.xaml @@ -174,9 +174,9 @@ Height="{StaticResource MenuItemHeight}" Header="{x:Static resx:ResUI.menuDNSSetting}" /> + Header="{x:Static resx:ResUI.menuFullConfigTemplate}" /> vm.OptionSettingCmd, v => v.menuOptionSetting).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.RoutingSettingCmd, v => v.menuRoutingSetting).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.DNSSettingCmd, v => v.menuDNSSetting).DisposeWith(disposables); - this.BindCommand(ViewModel, vm => vm.CustomConfigCmd, v => v.menuCustomConfig).DisposeWith(disposables); + this.BindCommand(ViewModel, vm => vm.FullConfigTemplateCmd, v => v.menuFullConfigTemplate).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.GlobalHotkeySettingCmd, v => v.menuGlobalHotkeySetting).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.RebootAsAdminCmd, v => v.menuRebootAsAdmin).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.ClearServerStatisticsCmd, v => v.menuClearServerStatistics).DisposeWith(disposables); @@ -187,8 +187,8 @@ public partial class MainWindow case EViewAction.OptionSettingWindow: return (new OptionSettingWindow().ShowDialog() ?? false); - case EViewAction.CustomConfigWindow: - return (new CustomConfigWindow().ShowDialog() ?? false); + case EViewAction.FullConfigTemplateWindow: + return (new FullConfigTemplateWindow().ShowDialog() ?? false); case EViewAction.GlobalHotkeySettingWindow: return (new GlobalHotkeySettingWindow().ShowDialog() ?? false);