Add Run multiple commands at one time

This commit is contained in:
2023-09-20 12:56:38 +08:00
parent 78be273c7a
commit 41c644f2af
3 changed files with 30 additions and 3 deletions

View File

@ -442,7 +442,7 @@ namespace GrasscutterTools.Forms
/// <returns>是否执行成功</returns> /// <returns>是否执行成功</returns>
private async Task<bool> RunRawCommands(string commands) private async Task<bool> RunRawCommands(string commands)
{ {
if (commands.IndexOf('|') == -1) if (commands.IndexOf('|') == -1 || Common.OC?.CanInvokeMultipleCmd == true)
return await RunCommands(FormatCommand(commands)); return await RunCommands(FormatCommand(commands));
return await RunCommands(commands.Split('|').Select(FormatCommand).ToArray()); return await RunCommands(commands.Split('|').Select(FormatCommand).ToArray());
} }

View File

@ -44,11 +44,28 @@ namespace GrasscutterTools.OpenCommand
public bool CanInvoke { get; private set; } public bool CanInvoke { get; private set; }
private Version version = new Version(1, 6, 1);
public Version Version
{
get => version;
private set
{
version = value;
CanInvokeMultipleCmd = version >= new Version(1, 7);
}
}
public bool CanInvokeMultipleCmd { get; private set; }
public async Task<bool> Ping() public async Task<bool> Ping()
{ {
//try //try
//{ //{
var response = await DoRequest("ping"); var response = await DoRequest("ping");
if (response.Data is string str && Version.TryParse(str, out var version))
Version = version;
return response.RetCode == 200; return response.RetCode == 200;
//} //}
//catch (Exception) //catch (Exception)

View File

@ -189,12 +189,22 @@ namespace GrasscutterTools
} }
try try
{
Common.OC.Ping().Wait(1000);
if (Common.OC.CanInvokeMultipleCmd)
{
var msg = Common.OC.Invoke(FormatCommand(commands)).Result;
Console.WriteLine(string.IsNullOrEmpty(msg) ? "OK" : msg);
}
else
{ {
foreach (var cmd in commands.Split('|').Select(FormatCommand)) foreach (var cmd in commands.Split('|').Select(FormatCommand))
{ {
var msg = Common.OC.Invoke(cmd).Result; var msg = Common.OC.Invoke(cmd).Result;
Console.WriteLine(string.IsNullOrEmpty(msg) ? "OK" : msg); Console.WriteLine(string.IsNullOrEmpty(msg) ? "OK" : msg);
} }
}
return true; return true;
} }
catch (Exception ex) catch (Exception ex)