Skip to content

Commit b5e0a77

Browse files
authored
Full Config Template (#7576)
* Feat. custom config * Fixes TypeInfoResolver Exception * Adjust UI * Fixes * Adjust Avalonia UI * Add Detour Feature * Avoids detour for private networks * Rename * Adds Documents
1 parent dffc6d9 commit b5e0a77

24 files changed

Lines changed: 1166 additions & 5 deletions

v2rayN/ServiceLib/Enums/EViewAction.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public enum EViewAction
2929
DNSSettingWindow,
3030
RoutingSettingWindow,
3131
OptionSettingWindow,
32+
FullConfigTemplateWindow,
3233
GlobalHotkeySettingWindow,
3334
SubSettingWindow,
3435
DispatcherSpeedTest,

v2rayN/ServiceLib/Handler/AppHandler.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public bool InitApp()
6464
SQLiteHelper.Instance.CreateTable<RoutingItem>();
6565
SQLiteHelper.Instance.CreateTable<ProfileExItem>();
6666
SQLiteHelper.Instance.CreateTable<DNSItem>();
67+
SQLiteHelper.Instance.CreateTable<FullConfigTemplateItem>();
6768
return true;
6869
}
6970

@@ -203,6 +204,16 @@ from ProfileItem a
203204
return await SQLiteHelper.Instance.TableAsync<DNSItem>().FirstOrDefaultAsync(it => it.CoreType == eCoreType);
204205
}
205206

207+
public async Task<List<FullConfigTemplateItem>?> FullConfigTemplateItem()
208+
{
209+
return await SQLiteHelper.Instance.TableAsync<FullConfigTemplateItem>().ToListAsync();
210+
}
211+
212+
public async Task<FullConfigTemplateItem?> GetFullConfigTemplateItem(ECoreType eCoreType)
213+
{
214+
return await SQLiteHelper.Instance.TableAsync<FullConfigTemplateItem>().FirstOrDefaultAsync(it => it.CoreType == eCoreType);
215+
}
216+
206217
#endregion SqliteHelper
207218

208219
#region Core Type

v2rayN/ServiceLib/Handler/ConfigHandler.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,6 +2238,54 @@ public static async Task<SimpleDNSItem> GetExternalSimpleDNSItem(string url)
22382238

22392239
#endregion Simple DNS
22402240

2241+
#region Custom Config
2242+
2243+
public static async Task<int> InitBuiltinFullConfigTemplate(Config config)
2244+
{
2245+
var items = await AppHandler.Instance.FullConfigTemplateItem();
2246+
if (items.Count <= 0)
2247+
{
2248+
var item = new FullConfigTemplateItem()
2249+
{
2250+
Remarks = "V2ray",
2251+
CoreType = ECoreType.Xray,
2252+
};
2253+
await SaveFullConfigTemplate(config, item);
2254+
2255+
var item2 = new FullConfigTemplateItem()
2256+
{
2257+
Remarks = "sing-box",
2258+
CoreType = ECoreType.sing_box,
2259+
};
2260+
await SaveFullConfigTemplate(config, item2);
2261+
}
2262+
2263+
return 0;
2264+
}
2265+
public static async Task<int> SaveFullConfigTemplate(Config config, FullConfigTemplateItem item)
2266+
{
2267+
if (item == null)
2268+
{
2269+
return -1;
2270+
}
2271+
2272+
if (item.Id.IsNullOrEmpty())
2273+
{
2274+
item.Id = Utils.GetGuid(false);
2275+
}
2276+
2277+
if (await SQLiteHelper.Instance.ReplaceAsync(item) > 0)
2278+
{
2279+
return 0;
2280+
}
2281+
else
2282+
{
2283+
return -1;
2284+
}
2285+
}
2286+
2287+
#endregion Custom Config
2288+
22412289
#region Regional Presets
22422290

22432291
/// <summary>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using SQLite;
2+
3+
namespace ServiceLib.Models;
4+
5+
[Serializable]
6+
public class FullConfigTemplateItem
7+
{
8+
[PrimaryKey]
9+
public string Id { get; set; }
10+
11+
public string Remarks { get; set; }
12+
public bool Enabled { get; set; } = false;
13+
public ECoreType CoreType { get; set; }
14+
public string? Config { get; set; }
15+
public string? TunConfig { get; set; }
16+
public bool? AddProxyOnly { get; set; } = false;
17+
public string? ProxyDetour { get; set; }
18+
}

v2rayN/ServiceLib/Resx/ResUI.Designer.cs

Lines changed: 90 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,4 +1470,34 @@
14701470
<data name="TbCustomDNSEnabledPageInvalid" xml:space="preserve">
14711471
<value>Custom DNS Enabled, This Page's Settings Invalid</value>
14721472
</data>
1473+
<data name="FillCorrectConfigTemplateText" xml:space="preserve">
1474+
<value>Please fill in the correct config template</value>
1475+
</data>
1476+
<data name="menuFullConfigTemplate" xml:space="preserve">
1477+
<value>Full Config Template Setting</value>
1478+
</data>
1479+
<data name="TbFullConfigTemplateEnable" xml:space="preserve">
1480+
<value>Enable Full Config Template</value>
1481+
</data>
1482+
<data name="TbRayFullConfigTemplate" xml:space="preserve">
1483+
<value>v2ray Full Config Template</value>
1484+
</data>
1485+
<data name="TbRayFullConfigTemplateDesc" xml:space="preserve">
1486+
<value>Add Outbound Config Only, routing.balancers and routing.rules.outboundTag, Click to view the document</value>
1487+
</data>
1488+
<data name="TbAddProxyProtocolOutboundOnly" xml:space="preserve">
1489+
<value>Do Not Add Non-Proxy Protocol Outbound</value>
1490+
</data>
1491+
<data name="TbSetUpstreamProxyDetour" xml:space="preserve">
1492+
<value>Set Upstream Proxy Tag</value>
1493+
</data>
1494+
<data name="TbSBFullConfigTemplate" xml:space="preserve">
1495+
<value>sing-box Full Config Template</value>
1496+
</data>
1497+
<data name="TbSBFullConfigTemplateDesc" xml:space="preserve">
1498+
<value>Add Outbound and Endpoint Config Only, Click to view the document</value>
1499+
</data>
1500+
<data name="TbFullConfigTemplateDesc" xml:space="preserve">
1501+
<value>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.</value>
1502+
</data>
14731503
</root>

v2rayN/ServiceLib/Resx/ResUI.hu.resx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,4 +1470,34 @@
14701470
<data name="TbCustomDNSEnabledPageInvalid" xml:space="preserve">
14711471
<value>Custom DNS Enabled, This Page's Settings Invalid</value>
14721472
</data>
1473+
<data name="FillCorrectConfigTemplateText" xml:space="preserve">
1474+
<value>Please fill in the correct config template</value>
1475+
</data>
1476+
<data name="menuFullConfigTemplate" xml:space="preserve">
1477+
<value>Full Config Template Setting</value>
1478+
</data>
1479+
<data name="TbFullConfigTemplateEnable" xml:space="preserve">
1480+
<value>Enable Full Config Template</value>
1481+
</data>
1482+
<data name="TbRayFullConfigTemplate" xml:space="preserve">
1483+
<value>v2ray Full Config Template</value>
1484+
</data>
1485+
<data name="TbRayFullConfigTemplateDesc" xml:space="preserve">
1486+
<value>Add Outbound Config Only, routing.balancers and routing.rules.outboundTag, Click to view the document</value>
1487+
</data>
1488+
<data name="TbAddProxyProtocolOutboundOnly" xml:space="preserve">
1489+
<value>Do Not Add Non-Proxy Protocol Outbound</value>
1490+
</data>
1491+
<data name="TbSetUpstreamProxyDetour" xml:space="preserve">
1492+
<value>Set Upstream Proxy Tag</value>
1493+
</data>
1494+
<data name="TbSBFullConfigTemplate" xml:space="preserve">
1495+
<value>sing-box Full Config Template</value>
1496+
</data>
1497+
<data name="TbSBFullConfigTemplateDesc" xml:space="preserve">
1498+
<value>Add Outbound and Endpoint Config Only, Click to view the document</value>
1499+
</data>
1500+
<data name="TbFullConfigTemplateDesc" xml:space="preserve">
1501+
<value>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.</value>
1502+
</data>
14731503
</root>

v2rayN/ServiceLib/Resx/ResUI.resx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,4 +1470,34 @@
14701470
<data name="TbCustomDNSEnabledPageInvalid" xml:space="preserve">
14711471
<value>Custom DNS Enabled, This Page's Settings Invalid</value>
14721472
</data>
1473+
<data name="FillCorrectConfigTemplateText" xml:space="preserve">
1474+
<value>Please fill in the correct config template</value>
1475+
</data>
1476+
<data name="menuFullConfigTemplate" xml:space="preserve">
1477+
<value>Full Config Template Setting</value>
1478+
</data>
1479+
<data name="TbFullConfigTemplateEnable" xml:space="preserve">
1480+
<value>Enable Full Config Template</value>
1481+
</data>
1482+
<data name="TbRayFullConfigTemplate" xml:space="preserve">
1483+
<value>v2ray Full Config Template</value>
1484+
</data>
1485+
<data name="TbRayFullConfigTemplateDesc" xml:space="preserve">
1486+
<value>Add Outbound Config Only, routing.balancers and routing.rules.outboundTag, Click to view the document</value>
1487+
</data>
1488+
<data name="TbAddProxyProtocolOutboundOnly" xml:space="preserve">
1489+
<value>Do Not Add Non-Proxy Protocol Outbound</value>
1490+
</data>
1491+
<data name="TbSetUpstreamProxyDetour" xml:space="preserve">
1492+
<value>Set Upstream Proxy Tag</value>
1493+
</data>
1494+
<data name="TbSBFullConfigTemplate" xml:space="preserve">
1495+
<value>sing-box Full Config Template</value>
1496+
</data>
1497+
<data name="TbSBFullConfigTemplateDesc" xml:space="preserve">
1498+
<value>Add Outbound and Endpoint Config Only, Click to view the document</value>
1499+
</data>
1500+
<data name="TbFullConfigTemplateDesc" xml:space="preserve">
1501+
<value>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.</value>
1502+
</data>
14731503
</root>

v2rayN/ServiceLib/Resx/ResUI.ru.resx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,4 +1470,34 @@
14701470
<data name="TbCustomDNSEnabledPageInvalid" xml:space="preserve">
14711471
<value>Custom DNS Enabled, This Page's Settings Invalid</value>
14721472
</data>
1473+
<data name="FillCorrectConfigTemplateText" xml:space="preserve">
1474+
<value>Please fill in the correct config template</value>
1475+
</data>
1476+
<data name="menuFullConfigTemplate" xml:space="preserve">
1477+
<value>Full Config Template Setting</value>
1478+
</data>
1479+
<data name="TbFullConfigTemplateEnable" xml:space="preserve">
1480+
<value>Enable Full Config Template</value>
1481+
</data>
1482+
<data name="TbRayFullConfigTemplate" xml:space="preserve">
1483+
<value>v2ray Full Config Template</value>
1484+
</data>
1485+
<data name="TbRayFullConfigTemplateDesc" xml:space="preserve">
1486+
<value>Add Outbound Config Only, routing.balancers and routing.rules.outboundTag, Click to view the document</value>
1487+
</data>
1488+
<data name="TbAddProxyProtocolOutboundOnly" xml:space="preserve">
1489+
<value>Do Not Add Non-Proxy Protocol Outbound</value>
1490+
</data>
1491+
<data name="TbSetUpstreamProxyDetour" xml:space="preserve">
1492+
<value>Set Upstream Proxy Tag</value>
1493+
</data>
1494+
<data name="TbSBFullConfigTemplate" xml:space="preserve">
1495+
<value>sing-box Full Config Template</value>
1496+
</data>
1497+
<data name="TbSBFullConfigTemplateDesc" xml:space="preserve">
1498+
<value>Add Outbound and Endpoint Config Only, Click to view the document</value>
1499+
</data>
1500+
<data name="TbFullConfigTemplateDesc" xml:space="preserve">
1501+
<value>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.</value>
1502+
</data>
14731503
</root>

0 commit comments

Comments
 (0)