Skip to content

Commit 855fd4f

Browse files
authored
Merge pull request #5026 from GibMeMyPacket/feat/singbox/exp_cachefile
Add `Enable cache file for sing-box`
2 parents 870955f + 8078399 commit 855fd4f

12 files changed

+480
-401
lines changed

v2rayN/v2rayN/Handler/ConfigHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public static int LoadConfig(ref Config? config)
5050
{
5151
logEnabled = false,
5252
loglevel = "warning",
53-
5453
muxEnabled = false,
54+
enableCacheFile4Sbox = false,
5555
};
5656
}
5757

@@ -305,6 +305,7 @@ public static int ImportOldGuiConfig(Config config, string fileName)
305305
logEnabled = configOld.logEnabled,
306306
loglevel = configOld.loglevel,
307307
muxEnabled = configOld.muxEnabled,
308+
enableCacheFile4Sbox = false,
308309
};
309310
}
310311

v2rayN/v2rayN/Handler/CoreConfigSingbox.cs

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public int GenerateClientConfigContent(ProfileItem node, out SingboxConfig? sing
5454

5555
GenDns(node, singboxConfig);
5656

57-
GenStatistic(singboxConfig);
57+
GenExperimental(singboxConfig);
5858

5959
ConvertGeo2Ruleset(singboxConfig);
6060

@@ -822,30 +822,66 @@ private int GenDns(ProfileItem node, SingboxConfig singboxConfig)
822822
return 0;
823823
}
824824

825-
private int GenStatistic(SingboxConfig singboxConfig)
825+
private int GenExperimentalStatistic(SingboxConfig singboxConfig)
826826
{
827827
if (_config.guiItem.enableStatistics)
828828
{
829-
singboxConfig.experimental = new Experimental4Sbox()
829+
singboxConfig.experimental ??= new Experimental4Sbox();
830+
singboxConfig.experimental.clash_api = new Clash_Api4Sbox()
830831
{
831-
cache_file = new CacheFile4Sbox()
832-
{
833-
enabled = true
834-
},
835-
//v2ray_api = new V2ray_Api4Sbox()
836-
//{
837-
// listen = $"{Global.Loopback}:{Global.StatePort}",
838-
// stats = new Stats4Sbox()
839-
// {
840-
// enabled = true,
841-
// }
842-
//},
843-
clash_api = new Clash_Api4Sbox()
844-
{
845-
external_controller = $"{Global.Loopback}:{LazyConfig.Instance.StatePort}",
846-
}
832+
external_controller = $"{Global.Loopback}:{LazyConfig.Instance.StatePort}",
833+
};
834+
// singboxConfig.experimental.v2ray_api = new V2ray_Api4Sbox()
835+
// {
836+
// listen = $"{Global.Loopback}:{Global.StatePort}",
837+
// stats = new Stats4Sbox()
838+
// {
839+
// enabled = true,
840+
// }
841+
// };
842+
// singboxConfig.experimental = new Experimental4Sbox()
843+
// {
844+
// cache_file = new CacheFile4Sbox()
845+
// {
846+
// enabled = true
847+
// },
848+
// //v2ray_api = new V2ray_Api4Sbox()
849+
// //{
850+
// // listen = $"{Global.Loopback}:{Global.StatePort}",
851+
// // stats = new Stats4Sbox()
852+
// // {
853+
// // enabled = true,
854+
// // }
855+
// //},
856+
// clash_api = new Clash_Api4Sbox()
857+
// {
858+
// external_controller = $"{Global.Loopback}:{LazyConfig.Instance.StatePort}",
859+
// }
860+
// };
861+
}
862+
return 0;
863+
}
864+
865+
private int GenExperimentalCacheFile(SingboxConfig singboxConfig)
866+
{
867+
if (_config.coreBasicItem.enableCacheFile4Sbox)
868+
{
869+
singboxConfig.experimental ??= new Experimental4Sbox();
870+
singboxConfig.experimental.cache_file = new CacheFile4Sbox()
871+
{
872+
enabled = true
847873
};
848874
}
875+
876+
return 0;
877+
}
878+
879+
private int GenExperimental(SingboxConfig singboxConfig)
880+
{
881+
var r = GenExperimentalStatistic(singboxConfig);
882+
if (r != 0) return r;
883+
r = GenExperimentalCacheFile(singboxConfig);
884+
if (r != 0) return r;
849885
return 0;
850886
}
851887

v2rayN/v2rayN/Models/ConfigItems.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public class CoreBasicItem
3333
public string defUserAgent { get; set; }
3434

3535
public bool enableFragment { get; set; }
36+
37+
public bool enableCacheFile4Sbox { get; set; }
3638
}
3739

3840
[Serializable]

v2rayN/v2rayN/Models/SingboxConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class SingboxConfig
77
public List<Inbound4Sbox> inbounds { get; set; }
88
public List<Outbound4Sbox> outbounds { get; set; }
99
public Route4Sbox route { get; set; }
10-
public Experimental4Sbox experimental { get; set; }
10+
public Experimental4Sbox? experimental { get; set; }
1111
}
1212

1313
public class Log4Sbox

0 commit comments

Comments
 (0)