mirror of
https://github.com/2dust/v2rayN.git
synced 2025-10-13 20:09:12 +00:00
Enhances core configuration handling.
This commit is contained in:
parent
bf73e0c858
commit
6319684592
4 changed files with 32 additions and 15 deletions
|
@ -813,7 +813,7 @@ public class Utils
|
|||
}
|
||||
}
|
||||
|
||||
public static string GetBinConfigPath(string filename = "")
|
||||
public static string GetBinConfigPath(string filename = "", ECoreType coreType = ECoreType.v2rayN)
|
||||
{
|
||||
var tempPath = Path.Combine(StartupPath(), "binConfigs");
|
||||
if (!Directory.Exists(tempPath))
|
||||
|
@ -827,10 +827,27 @@ public class Utils
|
|||
}
|
||||
else
|
||||
{
|
||||
return Path.Combine(tempPath, filename);
|
||||
return Path.Combine(tempPath, GetBinConfigFileName(filename, coreType));
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetBinConfigFileName(string filename, ECoreType coreType = ECoreType.v2rayN)
|
||||
{
|
||||
var fileSuffix = coreType switch
|
||||
{
|
||||
ECoreType.sing_box => ".json",
|
||||
ECoreType.Xray => ".json",
|
||||
ECoreType.hysteria2 => ".json",
|
||||
ECoreType.naiveproxy => ".json",
|
||||
ECoreType.tuic => ".json",
|
||||
ECoreType.juicity => ".json",
|
||||
ECoreType.brook => ".cac",
|
||||
ECoreType.shadowquic => ".yaml",
|
||||
_ => string.Empty
|
||||
};
|
||||
return filename.EndsWith(fileSuffix) ? filename : $"{filename}{fileSuffix}";
|
||||
}
|
||||
|
||||
#endregion TempPath
|
||||
|
||||
#region Platform
|
||||
|
|
|
@ -12,8 +12,8 @@ public class Global
|
|||
|
||||
public const string PromotionUrl = @"aHR0cHM6Ly85LjIzNDQ1Ni54eXovYWJjLmh0bWw=";
|
||||
public const string ConfigFileName = "guiNConfig.json";
|
||||
public const string CoreConfigFileName = "config.json";
|
||||
public const string CorePreConfigFileName = "configPre.json";
|
||||
public const string CoreConfigFileName = "config";
|
||||
public const string CorePreConfigFileName = "configPre";
|
||||
public const string CoreSpeedtestConfigFileName = "configTest{0}.json";
|
||||
public const string CoreMultipleLoadConfigFileName = "configMultipleLoad.json";
|
||||
public const string ClashMixinConfigFileName = "Mixin.yaml";
|
||||
|
|
|
@ -35,7 +35,7 @@ public class CoreAdminHandler
|
|||
{
|
||||
StringBuilder sb = new();
|
||||
sb.AppendLine("#!/bin/bash");
|
||||
var cmdLine = $"{fileName.AppendQuotes()} {string.Format(coreInfo.Arguments, Utils.GetBinConfigPath(configPath).AppendQuotes())}";
|
||||
var cmdLine = $"{fileName.AppendQuotes()} {string.Format(coreInfo.Arguments, Utils.GetBinConfigPath(configPath, coreInfo.CoreType).AppendQuotes())}";
|
||||
sb.AppendLine($"sudo -S {cmdLine}");
|
||||
var shFilePath = await FileManager.CreateLinuxShellFile("run_as_sudo.sh", sb.ToString(), true);
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ public class CoreHandler
|
|||
{
|
||||
var coreType = selecteds.Exists(t => t.ConfigType is EConfigType.Hysteria2 or EConfigType.TUIC or EConfigType.Anytls) ? ECoreType.sing_box : ECoreType.Xray;
|
||||
var fileName = string.Format(Global.CoreSpeedtestConfigFileName, Utils.GetGuid(false));
|
||||
var configPath = Utils.GetBinConfigPath(fileName);
|
||||
var configPath = Utils.GetBinConfigPath(fileName, coreType);
|
||||
var result = await CoreConfigHandler.GenerateClientSpeedtestConfig(_config, configPath, selecteds, coreType);
|
||||
UpdateFunc(false, result.Msg);
|
||||
if (result.Success != true)
|
||||
|
@ -130,15 +130,15 @@ public class CoreHandler
|
|||
return -1;
|
||||
}
|
||||
|
||||
var coreType = AppHandler.Instance.GetCoreType(node, node.ConfigType);
|
||||
var fileName = string.Format(Global.CoreSpeedtestConfigFileName, Utils.GetGuid(false));
|
||||
var configPath = Utils.GetBinConfigPath(fileName);
|
||||
var configPath = Utils.GetBinConfigPath(fileName, coreType);
|
||||
var result = await CoreConfigHandler.GenerateClientSpeedtestConfig(_config, node, testItem, configPath);
|
||||
if (result.Success != true)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
var coreType = AppHandler.Instance.GetCoreType(node, node.ConfigType);
|
||||
var coreInfo = CoreInfoHandler.Instance.GetCoreInfo(coreType);
|
||||
var proc = await RunProcess(coreInfo, fileName, true, false);
|
||||
if (proc is null)
|
||||
|
@ -231,7 +231,8 @@ public class CoreHandler
|
|||
|
||||
private async Task<bool> CoreStart(CoreLaunchContext context)
|
||||
{
|
||||
var fileName = Utils.GetBinConfigPath(Global.CoreConfigFileName);
|
||||
var coreType = context.SplitCore ? context.PureEndpointCore : context.CoreType;
|
||||
var fileName = Utils.GetBinConfigPath(Global.CoreConfigFileName, coreType);
|
||||
var result = context.SplitCore
|
||||
? await CoreConfigHandler.GeneratePureEndpointConfig(context.Node, fileName)
|
||||
: await CoreConfigHandler.GenerateClientConfig(context.Node, fileName);
|
||||
|
@ -257,7 +258,7 @@ public class CoreHandler
|
|||
|
||||
var coreInfo = CoreInfoHandler.Instance.GetCoreInfo(context.CoreType);
|
||||
var displayLog = context.Node.ConfigType != EConfigType.Custom || context.Node.DisplayLog;
|
||||
var proc = await RunProcess(coreInfo, Global.CoreConfigFileName, displayLog, true);
|
||||
var proc = await RunProcess(coreInfo, Utils.GetBinConfigFileName(Global.CoreConfigFileName, coreType), displayLog, true);
|
||||
|
||||
if (proc is null)
|
||||
{
|
||||
|
@ -266,8 +267,7 @@ public class CoreHandler
|
|||
}
|
||||
|
||||
_process = proc;
|
||||
var (_, coreType, preCoreType) = AppHandler.Instance.GetCoreAndPreType(context.Node);
|
||||
_config.RunningCoreType = (ECoreType)(preCoreType != null ? preCoreType : coreType);
|
||||
_config.RunningCoreType = (ECoreType)(context.PreCoreType != null ? context.PreCoreType : coreType);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -278,7 +278,7 @@ public class CoreHandler
|
|||
return true; // No pre-core needed, consider successful
|
||||
}
|
||||
|
||||
var fileName = Utils.GetBinConfigPath(Global.CorePreConfigFileName);
|
||||
var fileName = Utils.GetBinConfigPath(Global.CorePreConfigFileName, (ECoreType)context.PreCoreType);
|
||||
var itemSocks = new ProfileItem()
|
||||
{
|
||||
CoreType = context.PreCoreType,
|
||||
|
@ -296,7 +296,7 @@ public class CoreHandler
|
|||
}
|
||||
|
||||
var coreInfo = CoreInfoHandler.Instance.GetCoreInfo((ECoreType)context.PreCoreType);
|
||||
var proc = await RunProcess(coreInfo, Global.CorePreConfigFileName, true, true);
|
||||
var proc = await RunProcess(coreInfo, Utils.GetBinConfigFileName(Global.CorePreConfigFileName, (ECoreType)context.PreCoreType), true, true);
|
||||
|
||||
if (proc is null || (_process?.HasExited == true))
|
||||
{
|
||||
|
@ -355,7 +355,7 @@ public class CoreHandler
|
|||
StartInfo = new()
|
||||
{
|
||||
FileName = fileName,
|
||||
Arguments = string.Format(coreInfo.Arguments, coreInfo.AbsolutePath ? Utils.GetBinConfigPath(configPath).AppendQuotes() : configPath),
|
||||
Arguments = string.Format(coreInfo.Arguments, coreInfo.AbsolutePath ? Utils.GetBinConfigPath(configPath, coreInfo.CoreType).AppendQuotes() : configPath),
|
||||
WorkingDirectory = Utils.GetBinConfigPath(),
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = displayLog,
|
||||
|
|
Loading…
Reference in a new issue