Enhances core configuration handling.

This commit is contained in:
DHR60 2025-07-30 09:08:59 +08:00
parent bf73e0c858
commit 6319684592
4 changed files with 32 additions and 15 deletions

View file

@ -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"); var tempPath = Path.Combine(StartupPath(), "binConfigs");
if (!Directory.Exists(tempPath)) if (!Directory.Exists(tempPath))
@ -827,10 +827,27 @@ public class Utils
} }
else 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 #endregion TempPath
#region Platform #region Platform

View file

@ -12,8 +12,8 @@ public class Global
public const string PromotionUrl = @"aHR0cHM6Ly85LjIzNDQ1Ni54eXovYWJjLmh0bWw="; public const string PromotionUrl = @"aHR0cHM6Ly85LjIzNDQ1Ni54eXovYWJjLmh0bWw=";
public const string ConfigFileName = "guiNConfig.json"; public const string ConfigFileName = "guiNConfig.json";
public const string CoreConfigFileName = "config.json"; public const string CoreConfigFileName = "config";
public const string CorePreConfigFileName = "configPre.json"; public const string CorePreConfigFileName = "configPre";
public const string CoreSpeedtestConfigFileName = "configTest{0}.json"; public const string CoreSpeedtestConfigFileName = "configTest{0}.json";
public const string CoreMultipleLoadConfigFileName = "configMultipleLoad.json"; public const string CoreMultipleLoadConfigFileName = "configMultipleLoad.json";
public const string ClashMixinConfigFileName = "Mixin.yaml"; public const string ClashMixinConfigFileName = "Mixin.yaml";

View file

@ -35,7 +35,7 @@ public class CoreAdminHandler
{ {
StringBuilder sb = new(); StringBuilder sb = new();
sb.AppendLine("#!/bin/bash"); 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}"); sb.AppendLine($"sudo -S {cmdLine}");
var shFilePath = await FileManager.CreateLinuxShellFile("run_as_sudo.sh", sb.ToString(), true); var shFilePath = await FileManager.CreateLinuxShellFile("run_as_sudo.sh", sb.ToString(), true);

View file

@ -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 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 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); var result = await CoreConfigHandler.GenerateClientSpeedtestConfig(_config, configPath, selecteds, coreType);
UpdateFunc(false, result.Msg); UpdateFunc(false, result.Msg);
if (result.Success != true) if (result.Success != true)
@ -130,15 +130,15 @@ public class CoreHandler
return -1; return -1;
} }
var coreType = AppHandler.Instance.GetCoreType(node, node.ConfigType);
var fileName = string.Format(Global.CoreSpeedtestConfigFileName, Utils.GetGuid(false)); 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); var result = await CoreConfigHandler.GenerateClientSpeedtestConfig(_config, node, testItem, configPath);
if (result.Success != true) if (result.Success != true)
{ {
return -1; return -1;
} }
var coreType = AppHandler.Instance.GetCoreType(node, node.ConfigType);
var coreInfo = CoreInfoHandler.Instance.GetCoreInfo(coreType); var coreInfo = CoreInfoHandler.Instance.GetCoreInfo(coreType);
var proc = await RunProcess(coreInfo, fileName, true, false); var proc = await RunProcess(coreInfo, fileName, true, false);
if (proc is null) if (proc is null)
@ -231,7 +231,8 @@ public class CoreHandler
private async Task<bool> CoreStart(CoreLaunchContext context) 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 var result = context.SplitCore
? await CoreConfigHandler.GeneratePureEndpointConfig(context.Node, fileName) ? await CoreConfigHandler.GeneratePureEndpointConfig(context.Node, fileName)
: await CoreConfigHandler.GenerateClientConfig(context.Node, fileName); : await CoreConfigHandler.GenerateClientConfig(context.Node, fileName);
@ -257,7 +258,7 @@ public class CoreHandler
var coreInfo = CoreInfoHandler.Instance.GetCoreInfo(context.CoreType); var coreInfo = CoreInfoHandler.Instance.GetCoreInfo(context.CoreType);
var displayLog = context.Node.ConfigType != EConfigType.Custom || context.Node.DisplayLog; 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) if (proc is null)
{ {
@ -266,8 +267,7 @@ public class CoreHandler
} }
_process = proc; _process = proc;
var (_, coreType, preCoreType) = AppHandler.Instance.GetCoreAndPreType(context.Node); _config.RunningCoreType = (ECoreType)(context.PreCoreType != null ? context.PreCoreType : coreType);
_config.RunningCoreType = (ECoreType)(preCoreType != null ? preCoreType : coreType);
return true; return true;
} }
@ -278,7 +278,7 @@ public class CoreHandler
return true; // No pre-core needed, consider successful 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() var itemSocks = new ProfileItem()
{ {
CoreType = context.PreCoreType, CoreType = context.PreCoreType,
@ -296,7 +296,7 @@ public class CoreHandler
} }
var coreInfo = CoreInfoHandler.Instance.GetCoreInfo((ECoreType)context.PreCoreType); 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)) if (proc is null || (_process?.HasExited == true))
{ {
@ -355,7 +355,7 @@ public class CoreHandler
StartInfo = new() StartInfo = new()
{ {
FileName = fileName, 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(), WorkingDirectory = Utils.GetBinConfigPath(),
UseShellExecute = false, UseShellExecute = false,
RedirectStandardOutput = displayLog, RedirectStandardOutput = displayLog,