Skip to content

Commit

Permalink
修复CommandLine的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
DearVa committed Mar 29, 2023
1 parent 32573f2 commit a0a5a08
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
17 changes: 14 additions & 3 deletions src/ChatShell.Core/Models/ProcessConfigure.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;

namespace ChatShell.Core.Models;

[Serializable]
public class ProcessConfigure {
public partial class ProcessConfigure {
public required string Name { get; init; }

public required string CommandLine { get; init; }
Expand All @@ -17,9 +19,15 @@ public class ProcessConfigure {
public string? WorkingDirectory { get; init; }

public ProcessStartInfo ToStartInfo(string arguments) {
var commands = SplitBySpace().Split(CommandLine);
var argumentsBuilder = new StringBuilder();
foreach (var command in commands.Skip(1)) {
argumentsBuilder.Append(command).Append(' ');
}

return new ProcessStartInfo {
FileName = CommandLine,
Arguments = arguments,
FileName = commands[0],
Arguments = argumentsBuilder.Append(arguments).ToString(),
WorkingDirectory = WorkingDirectory,
CreateNoWindow = true,
UseShellExecute = false,
Expand All @@ -28,4 +36,7 @@ public ProcessStartInfo ToStartInfo(string arguments) {
RedirectStandardInput = true,
};
}

[GeneratedRegex(@"[ ](?=(?:[^""]*""[^""]*"")*[^""]*$)")]
private static partial Regex SplitBySpace();
}
2 changes: 1 addition & 1 deletion src/ChatShell/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static class Program {
private static readonly CancellationTokenSource CancellationTokenSource = new();

public static async Task Main(string[] args) {
var fs = File.OpenRead("./AppConfigure.json");
var fs = File.OpenRead(Path.Combine(Path.GetDirectoryName(Environment.ProcessPath.NotNull()).NotNull(), "AppConfigure.json"));
var configure = (await JsonSerializer.DeserializeAsync<AppConfigure>(fs)).NotNull("Invalid AppConfigure.json");
await fs.DisposeAsync();

Expand Down
1 change: 1 addition & 0 deletions src/publish-linux-x64.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dotnet publish -r linux-x64 -c Release --self-contained
1 change: 1 addition & 0 deletions src/publish-win-x64.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dotnet publish -r win-x64 -c Release --self-contained

0 comments on commit a0a5a08

Please sign in to comment.