Optimizing reload core

pull/3380/head
2dust 2023-02-28 20:23:15 +08:00
parent eeab8e4a90
commit 1f7eb2d48a
4 changed files with 39 additions and 55 deletions

View File

@ -124,7 +124,6 @@
#region global variable
public static bool reloadCore { get; set; }
public static int statePort { get; set; }
public static Job processJob { get; set; }
public static bool ShowInTaskbar { get; set; }

View File

@ -195,16 +195,6 @@ namespace v2rayN.Handler
config.guiItem.statisticsFreshRate = 1;
}
if (config == null)
{
Global.reloadCore = false;
}
else
{
Global.reloadCore = true;
}
LazyConfig.Instance.SetConfig(config);
return 0;
}
@ -215,7 +205,6 @@ namespace v2rayN.Handler
/// <returns></returns>
public static int SaveConfig(ref Config config, bool reload = true)
{
Global.reloadCore = reload;
ToJsonFile(config);
@ -446,7 +435,6 @@ namespace v2rayN.Handler
}
config.indexId = indexId;
Global.reloadCore = true;
ToJsonFile(config);
@ -856,7 +844,6 @@ namespace v2rayN.Handler
}
else if (profileItem.indexId == config.indexId)
{
Global.reloadCore = true;
}
if (SqliteHelper.Instance.Replace(profileItem) > 0)
@ -1461,8 +1448,6 @@ namespace v2rayN.Handler
config.routingBasicItem.routingIndexId = routingItem.id;
}
Global.reloadCore = true;
ToJsonFile(config);
return 0;

View File

@ -27,46 +27,43 @@ namespace v2rayN.Handler
public void LoadCore(Config config)
{
if (Global.reloadCore)
var node = ConfigHandler.GetDefaultServer(ref config);
if (node == null)
{
var node = ConfigHandler.GetDefaultServer(ref config);
if (node == null)
{
ShowMsg(false, ResUI.CheckServerSettings);
return;
}
ShowMsg(false, ResUI.CheckServerSettings);
return;
}
if (SetCore(config, node) != 0)
{
ShowMsg(false, ResUI.CheckServerSettings);
return;
}
string fileName = Utils.GetConfigPath(_coreCConfigRes);
if (CoreConfigHandler.GenerateClientConfig(node, fileName, out string msg, out string content) != 0)
{
ShowMsg(false, msg);
}
else
{
ShowMsg(false, msg);
ShowMsg(true, $"{node.GetSummary()}");
CoreStop();
CoreStart(node);
}
if (SetCore(config, node) != 0)
{
ShowMsg(false, ResUI.CheckServerSettings);
return;
}
string fileName = Utils.GetConfigPath(_coreCConfigRes);
if (CoreConfigHandler.GenerateClientConfig(node, fileName, out string msg, out string content) != 0)
{
ShowMsg(false, msg);
}
else
{
ShowMsg(false, msg);
ShowMsg(true, $"{node.GetSummary()}");
CoreStop();
CoreStart(node);
}
//start a socks service
if (_process != null && !_process.HasExited && node.configType == EConfigType.Custom && node.preSocksPort > 0)
//start a socks service
if (_process != null && !_process.HasExited && node.configType == EConfigType.Custom && node.preSocksPort > 0)
{
var itemSocks = new ProfileItem()
{
var itemSocks = new ProfileItem()
{
configType = EConfigType.Socks,
address = Global.Loopback,
port = node.preSocksPort
};
if (CoreConfigHandler.GenerateClientConfig(itemSocks, null, out string msg2, out string configStr) == 0)
{
_processId = CoreStartViaString(configStr);
}
configType = EConfigType.Socks,
address = Global.Loopback,
port = node.preSocksPort
};
if (CoreConfigHandler.GenerateClientConfig(itemSocks, null, out string msg2, out string configStr) == 0)
{
_processId = CoreStartViaString(configStr);
}
}
}

View File

@ -540,8 +540,12 @@ namespace v2rayN.ViewModels
_noticeHandler?.SendMessage(msg);
if (success)
{
var indexIdOld = _config.indexId;
RefreshServers();
Reload();
if (indexIdOld != _config.indexId)
{
Reload();
}
if (_config.uiItem.enableAutoAdjustMainLvColWidth)
{
_updateView("AdjustMainLvColWidth");
@ -740,6 +744,7 @@ namespace v2rayN.ViewModels
subRemarks = t.subRemarks,
isActive = t.indexId == _config.indexId,
sort = t33 == null ? 0 : t33.sort,
delay = t33 == null ? 0 : t33.delay,
delayVal = t33?.delay != 0 ? $"{t33?.delay} {Global.DelayUnit}" : string.Empty,
speedVal = t33?.speed != 0 ? $"{t33?.speed} {Global.SpeedUnit}" : string.Empty,
todayDown = t22 == null ? "" : Utils.HumanFy(t22.todayDown),
@ -1367,7 +1372,6 @@ namespace v2rayN.ViewModels
public void Reload()
{
Global.reloadCore = true;
_ = LoadV2ray();
}
@ -1387,7 +1391,6 @@ namespace v2rayN.ViewModels
{
_coreHandler.LoadCore(_config);
Global.reloadCore = false;
//ConfigHandler.SaveConfig(ref _config, false);
ChangeSystemProxyStatus(_config.sysProxyType, false);