From 565a7b1680378cab6353def79a3aadae4683c551 Mon Sep 17 00:00:00 2001
From: 2dust <31833384+2dust@users.noreply.github.com>
Date: Sun, 3 Oct 2021 16:36:48 +0800
Subject: [PATCH] Optimize storage performance
---
v2rayN/v2rayN/Handler/ConfigHandler.cs | 49 +++++++++++++++++---------
1 file changed, 32 insertions(+), 17 deletions(-)
diff --git a/v2rayN/v2rayN/Handler/ConfigHandler.cs b/v2rayN/v2rayN/Handler/ConfigHandler.cs
index 41f354b9..2381a77a 100644
--- a/v2rayN/v2rayN/Handler/ConfigHandler.cs
+++ b/v2rayN/v2rayN/Handler/ConfigHandler.cs
@@ -174,7 +174,7 @@ namespace v2rayN.Handler
///
///
///
- public static int AddServer(ref Config config, VmessItem vmessItem, int index)
+ public static int AddServer(ref Config config, VmessItem vmessItem, int index, bool toFile = true)
{
vmessItem.configVersion = 2;
vmessItem.configType = (int)EConfigType.Vmess;
@@ -212,8 +212,10 @@ namespace v2rayN.Handler
}
}
- ToJsonFile(config);
-
+ if (toFile)
+ {
+ ToJsonFile(config);
+ }
return 0;
}
@@ -524,7 +526,7 @@ namespace v2rayN.Handler
///
///
///
- public static int AddShadowsocksServer(ref Config config, VmessItem vmessItem, int index)
+ public static int AddShadowsocksServer(ref Config config, VmessItem vmessItem, int index, bool toFile = true)
{
vmessItem.configVersion = 2;
vmessItem.configType = (int)EConfigType.Shadowsocks;
@@ -557,8 +559,11 @@ namespace v2rayN.Handler
Global.reloadV2ray = true;
}
}
-
- ToJsonFile(config);
+
+ if (toFile)
+ {
+ ToJsonFile(config);
+ }
return 0;
}
@@ -570,7 +575,7 @@ namespace v2rayN.Handler
///
///
///
- public static int AddSocksServer(ref Config config, VmessItem vmessItem, int index)
+ public static int AddSocksServer(ref Config config, VmessItem vmessItem, int index, bool toFile = true)
{
vmessItem.configVersion = 2;
vmessItem.configType = (int)EConfigType.Socks;
@@ -597,7 +602,10 @@ namespace v2rayN.Handler
}
}
- ToJsonFile(config);
+ if (toFile)
+ {
+ ToJsonFile(config);
+ }
return 0;
}
@@ -610,7 +618,7 @@ namespace v2rayN.Handler
///
///
///
- public static int AddTrojanServer(ref Config config, VmessItem vmessItem, int index)
+ public static int AddTrojanServer(ref Config config, VmessItem vmessItem, int index, bool toFile = true)
{
vmessItem.configVersion = 2;
vmessItem.configType = (int)EConfigType.Trojan;
@@ -644,7 +652,10 @@ namespace v2rayN.Handler
}
}
- ToJsonFile(config);
+ if (toFile)
+ {
+ ToJsonFile(config);
+ }
return 0;
}
@@ -754,40 +765,41 @@ namespace v2rayN.Handler
vmessItem.subid = subid;
if (vmessItem.configType == (int)EConfigType.Vmess)
{
- if (AddServer(ref config, vmessItem, -1) == 0)
+ if (AddServer(ref config, vmessItem, -1, false) == 0)
{
countServers++;
}
}
else if (vmessItem.configType == (int)EConfigType.Shadowsocks)
{
- if (AddShadowsocksServer(ref config, vmessItem, -1) == 0)
+ if (AddShadowsocksServer(ref config, vmessItem, -1, false) == 0)
{
countServers++;
}
}
else if (vmessItem.configType == (int)EConfigType.Socks)
{
- if (AddSocksServer(ref config, vmessItem, -1) == 0)
+ if (AddSocksServer(ref config, vmessItem, -1, false) == 0)
{
countServers++;
}
}
else if (vmessItem.configType == (int)EConfigType.Trojan)
{
- if (AddTrojanServer(ref config, vmessItem, -1) == 0)
+ if (AddTrojanServer(ref config, vmessItem, -1, false) == 0)
{
countServers++;
}
}
else if (vmessItem.configType == (int)EConfigType.VLESS)
{
- if (AddVlessServer(ref config, vmessItem, -1) == 0)
+ if (AddVlessServer(ref config, vmessItem, -1, false) == 0)
{
countServers++;
}
}
}
+ ToJsonFile(config);
return countServers;
}
@@ -915,7 +927,7 @@ namespace v2rayN.Handler
///
///
///
- public static int AddVlessServer(ref Config config, VmessItem vmessItem, int index)
+ public static int AddVlessServer(ref Config config, VmessItem vmessItem, int index, bool toFile = true)
{
vmessItem.configVersion = 2;
vmessItem.configType = (int)EConfigType.VLESS;
@@ -953,7 +965,10 @@ namespace v2rayN.Handler
}
}
- ToJsonFile(config);
+ if (toFile)
+ {
+ ToJsonFile(config);
+ }
return 0;
}